Hello,
I've asked a few stupid questions before but I've again run into a problem I
can't figure out :-)
Basically, I'm marshalling, then unmarshalling, then comparing two objects
to see if they're the same. The objects are rather large object graphs, and
uses a custom comparator object to do the comparison automatically.
Anyway, my problem is as follows:
I have a class, Foo.
Foo contains an array of other objects, Bar.
Foo is itself contained inside Boo.
So,
class Foo {
Bar[] bars;
}
class Bar {
//some stuff
}
class Boo {
List listOfFoos;
}
Now, the special thing is, that almost all of the information in the Bar
class can be inferred from just knowing Boo when creating Foo.
In order to transfer the information that cannot be inferred from what I
know, I create (and export) some light-weight Bar objects to represent the
Bar[]. These objects contain only the specific information I need, and
nothing else.
Because I don't just want to set the Bar[] automatically by Jibx (most of it
is auto-constructed), I instead define get-method and set-method in my xml:
<mapping class="dk.Foo" factory="dk.Factory.createFoo name="Foo">
<collection name="Bars" get-method="getBars"
set-method="jibxSetBars"/>
</mapping>
(getBars returns Bar[]; setBars takes Bar[] as an argument)
But this is where it starts to become strange - I can follow the way through
the constructor fine using a debugger, and I can see the objects being
set-up properly (the information not available notwithstanding), and
everything is good.
However, once I enter the set-method *the objects inside Bar[] bars have
changed! *They're completely new, with new "number identifiers". (I'm using
IDEA debugger and each object is assigned a number).
The bars-array itself is the same as in the constructor, though - only the
objects inside it have changed. What's more, the objects inside it are
created by Bar's factory method.
If you look at the ID numbers you'll see something like:
this.bars Before:
[]: 1361
[0]: 1329
[1]: 1375
this.bars After:
[]: 1361
[0]: 1397
[1]: 1392
The Bar XML looks something like this:
<mapping abstract="true" class="dk.Bar" type-name="bar">
<structure name="lala" field="lala"/>
</mapping>
<mapping name="BarDerivativeOne"
class="dk.BarDerivativeOne"
factory="dk.Factory.createBarDerivativeOne">
<structure map-as="bar" name="BarElements"/>
</mapping>
<mapping name="BarDerivativeTwo"
class="dk.BarDerivativeTwo"
factory="dk.Factory.createBarDerivativeTwo"> <--- this is the
factor that creates the "wrong" elements -->
<structure map-as="bar" name="BarElements"/>
</mapping>
Now, I truly do not understand what's happening. I've checked the obvious
stuff - I do not change the Bar-elements in bars myself at any time before
the set-method (though I do see calls to the createBarDerivativeTwo method).
I also fail to see why jibx feels the need to insert these elements into the
Bar-array? I have a set method, but the Bar[] has been changed before it's
even called?
What's perhaps even stranger is that not only are the arrays before and
after the same, but the array passed into jibxSetBars method *is exactly the
same as the one already on the Foo object! *(== returns true)
That is, it seems like (to me, anyway...) that Jibx first sets the array
manually, and then for good measure calls the set-method as well?
I must have really screwed something up, and any help would be greatly
appreciated.
(Note - any information from the set-method was taken before anything was
changed, so that's not the source)
Regards,
Søren Andersen
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users