users@jaxb.java.net

Re: Comparing two jaxb-generated objects by value

From: Jean-Marie Condom <jmc_at_meteorage.com>
Date: Mon, 17 Jan 2005 12:13:39 +0100

Hello

I downloaded hyperjaxb.jar and jaxb-verification.jar and put them
under jaxb/lib, then i modified my build file according (I think)
to your sample ; when i run ant, i get a java.lang.NullPointerException
when building sources at the first line where i specify xjc :

    <xjc schema="configuration_test.xsd"
package="meteorage.jobs.params.configuration" target="../gen-src">
     <produces dir="../gen-src" includes="../gen-src/**/*.java" />
      <arg line="-nv"/>
      <arg line="-extension"/>
      <arg line="-Xverification"/>
      <arg line="-Xequality"/>
      <arg line="-use-runtime meteorage.jobs.jaxbruntime.impl.runtime" />
     </xjc>

is there a mistake, sth missing ?

some source files are generated under a folder "verification"
at the same level as "impl" ; it contains files "...Verifier.java"
definig ckeck.. methods ; in folder "impl" methods
equals(java.lang.Object obj) are generated
in files ...impl.java ; all seems ok except this NullPointerException
which prevents
from compiling sources

thanks in advance

Jean-Marie
 

Aleksei Valikov wrote:

> Hi.
>
>> this question has been posted 2 years ago under
>> the subject "JAXB and equals" with no solution
>> at that time
>> is it possible now with the last JAXB version to
>> compare two jaxb-generated objects by value ?
>
>
> Since I needed to compare JAXB objects by value in my current project,
> I've implemented a small add-on to generate equals(...) and hashCode()
> methods.
> For the time being, I've included this add-on into the
> jaxb-verification (https://jaxb-verification.dev.java.net). I'm not
> sure, may be I'll move it to HyperJAXB since Hibernate also requires
> well-implemented equals(...) and hashCode() methods.
>
> No documentation yet, sorry. No thorough test also. The add-on is far
> from the release state (as I see release states), but is (hopefully)
> functional and usable.
>
> Usage:
>
> <xjc target="${generated.sources}">
> <arg line="-nv"/>
> <arg line="-extension"/>
> <arg line="-Xverification"/>
> <arg line="-Xequality"/>
> <binding dir="${basedir}">
> <include name="binding/*.xml"/>
> </binding>
> <schema dir="${basedir}">
> <include name="schema/*.xsd"/>
> </schema>
> </xjc>
>
> You'll need hyperjaxb.jar and jaxb-verification.jar on the classpath.
>
> The generated code looks as follows:
>
> public boolean equals(java.lang.Object obj) {
> if (this == obj) {
> return true;
> }
> if ((null == obj)||(obj.getClass()!= this.getClass())) {
> return false;
> }
> de.fzi.dbs.verification.tests.one.impl.RootImpl target =
> ((de.fzi.dbs.verification.tests.one.impl.RootImpl) obj);
> {
> de.fzi.dbs.verification.tests.one.SimpleTypesType value =
> this.getSimpleTypes();
> de.fzi.dbs.verification.tests.one.SimpleTypesType
> targetValue = target.getSimpleTypes();
> if (!((value == targetValue)||((value!=
> null)&&value.equals(targetValue)))) {
> return false;
> }
> }
> {
> de.fzi.dbs.verification.tests.one.SequenceType value =
> this.getSequence();
> de.fzi.dbs.verification.tests.one.SequenceType targetValue
> = target.getSequence();
> if (!((value == targetValue)||((value!=
> null)&&value.equals(targetValue)))) {
> return false;
> }
> }
> {
>
> de.fzi.dbs.verification.tests.one.ElementWithListAttribute1 value =
> this.getElementWithListAttribute1();
>
> de.fzi.dbs.verification.tests.one.ElementWithListAttribute1
> targetValue = target.getElementWithListAttribute1();
> if (!((value == targetValue)||((value!=
> null)&&value.equals(targetValue)))) {
> return false;
> }
> }
> {
> de.fzi.dbs.verification.tests.one.FacetType value =
> this.getFacet();
> de.fzi.dbs.verification.tests.one.FacetType targetValue =
> target.getFacet();
> if (!((value == targetValue)||((value!=
> null)&&value.equals(targetValue)))) {
> return false;
> }
> }
> return true;
> }
>
> public int hashCode() {
> int hash = 7;
> {
> de.fzi.dbs.verification.tests.one.SimpleTypesType value =
> this.getSimpleTypes();
> hash = ((31 *hash)+((null == value)? 0 :value.hashCode()));
> }
> {
> de.fzi.dbs.verification.tests.one.SequenceType value =
> this.getSequence();
> hash = ((31 *hash)+((null == value)? 0 :value.hashCode()));
> }
> {
>
> de.fzi.dbs.verification.tests.one.ElementWithListAttribute1 value =
> this.getElementWithListAttribute1();
> hash = ((31 *hash)+((null == value)? 0 :value.hashCode()));
> }
> {
> de.fzi.dbs.verification.tests.one.FacetType value =
> this.getFacet();
> hash = ((31 *hash)+((null == value)? 0 :value.hashCode()));
> }
> return hash;
> }
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Jean-Marie Condom
Software development team
Sté Météorage
2 av Angot
64053 PAU
France 
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net