Dennis Sosnoski wrote:

Hi Jules,

TypedArrayMapper isn't supposed to require you to use the name, and if used without a name as in your original binding it should be able to handle things properly. I think it's broken, though, as your experience would indicate. :-( If you look at the code the TypedArrayMapper unmarshal method assumes it can take everything up to the end of the enclosing element:
// process all items present in document
while (!ctx.isEnd()) {
Object item = ctx.unmarshalElement();
m_holder.add(item);
}


What this really needs to do is a lot more complex - basically get the unmarshaller for the class of objects that go into the array, then loop only as long as the isPresent() method of the unmarshaller returns true. There are some problems with doing this in the general case, though - suppose the array is of java.lang.Object, or of an interface type that's implemented by multiple classes in the binding (which are not otherwise related)? Yuck.

In my first pass I hacked up something that created a table of item-class:item-list - as it came across each item it would push it into the correct bucket on the first pass, only returning the bucket relevant to itself - later incarnations of the same Mapper would return other buckets immediately without having to parse again - the map was shared... horrible - but vaguely works...


Second pass is to get your collection stuff to work properly with Arrays, unless you have already done it ? I need this stuff in production within about 6 weeks, so am prepared to extend it myself if I have to....


I'm hoping to handle this directly in JiBX with beta 4, pretty much as is done with ArrayList now. I'll need to think through what I'm doing to make sure I've got the above concerns covered. In the meantime, your best approach may be to do it "by hand", with separate collection get/set methods in your class A that work with each type, along the lines of:


 <mapping name="A" class="A">
   <collection item-type="B" add-method="addB" load-method="getB"/>
   <collection item-type="C" add-method="addC" load-method="getC"/>

This means you'd need to actually implement the arrays yourself, though, behind the scenes in these add/load methods.

This is the bit that worries me - I am mapping to 3rd party classes that are regularly regenerated from a backend written in COBOL :-( Any investment that I make in handcrafted code will be sitting on foundations that may be swept away at any moment... and the API is in terms of Arrays, not Collections :-(


I will be looking at this again on monday or tuesday - would it be hard to figure out the collection code and extend it to wrap Arrays with something that makes them look like an ArrayList for the duration of their processing ? This looks like the easiest solution to me - otherwise I have to start subclassing the classes that I think will be used in the first release of this server and altering them by hand to do things the JiBX way.... and there may be quite a few...

Ideally I would like to be able to plug in stateless Wrapper or Interceptor/Aspect classes around each setter/getter pair to perform any validation, reformatting, stripping etc of data on the way in or out - since the code generated from this backend is particularly flaky....

Thanks for your time,


Jules


- Dennis

Jules Gosnell wrote:

you always think of the answer as soon as you have posted :-)

Perhaps this is my problem...

TypedArrayMapper expects to be used with an intermediate array object i.e.

<A>
<Bs>
 <B.../>
 <B .../>
 ...
</Bs>
</A>

So I took this a while ago and realized that I could collapse the 'A' and 'Bs' element into the same class, which suited the arrangement of the 3rd party library to which I am mapping.

Then, having forgotten that I had done this, I tried to extend my working code to accomodate the second relationship - Bang !

I'm going to have another look at the problem. In the meantime, if anyone has any ideas I'd be grateful to hear them....

Jules


Jules Gosnell wrote:


Guys,

I've just started using jibx and have come across a problem with [my
use of] org.jibx.extras.TypedArrayMapper....

Imagine input that looks like this :

<A>
 <B.../>
 <B.../>
 <C.../>
 <C.../>
</A>

i.e. an 'A' owns a number of 'B's and a number of 'C's...

'A' might look like :

public class A
{
 public void setBs(B[] bs){...}
 public B[] getBs(){...}

 public void setCs(C[] bs){...}
 public C[] getCs(){...}
}

my binding.xml might look like this :

<binding>

 <mapping class="B[]"
   marshaller="org.jibx.extras.TypedArrayMapper"
   unmarshaller="org.jibx.extras.TypedArrayMapper"
   />

 <mapping name="B" class="B">
 </mapping>

 <mapping class="C[]"
   marshaller="org.jibx.extras.TypedArrayMapper"
   unmarshaller="org.jibx.extras.TypedArrayMapper"
   />

 <mapping name="C" class="C">
 </mapping>

 <mapping name="A" class="A">
  <structure set-method="setBs" get-method="getBs"/>
  <structure set-method="setCs" get-method="getCs"/>
 </mapping>

</binding>

I put together a testcase for the A's relationship with B - which
worked fine. However when I added the A-C relationship I found that as
the 'C's were parsed they where dumped into the same array as the
'B's. Jibx then attempts to pass a heterogeneous array of 'B's and
'C's (I assume into A.setCs()), but blows up with a java.lang.ArrayStoreException
in A.JiBX_binding2_unmarshal_2_0() because the array is of mixed type.


I have tried extending TypedArrayMapper into BMapper and CMapper and
using those in its place, but this does not seem to effect the problem
- in fact only one Mapper instance seems to get used, the other one
does not even get constructed before I encounter the error.

Perhaps I have misunderstood the intended use of these Mappers ?

Any help would be much appreciated - I can put together a testcase if
it would be of help.

Thanks for your time,


Jules

P.S.

I'm running beta3c on Sun 1.4.2_05




-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users




-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to