This is going to be difficult to do with the current code. The big problem is that JiBX doesn't currently support forward references to IDs as elements of collections. When you use forward references to IDs there's no way to set a value until after the ID is found, later in the unmarshalling process. JiBX has code to handle this for normal references from a field, but not for references from collections.

If you need this support the only way of getting it right now is by writing a custom marshaller/unmarshaller for the collection. This would need to define an org.jibx.runtime.impl.BackFillReference instance (in the form of an implementation class, which would be similar to org.jibx.runtime.impl.BackFillArray) for each element of the collection that references an ID that's not yet defined. As these ID values are found later in the document the BackFillReference items are processed, with the backfill method passed the actual object represented by the reference.

 - Dennis

Fran�ois Eric wrote:

Hi,

I'm not sure my problem is related to this issue but I have a problem marshalling referenced collections. Here is my xml structure:

.....
   <PNR>
                   <passengers>
                       <PassengerInfo refid="N10092"/>
                       <PassengerInfo refid="N10095"/>
                   </passengers>
   <PNR>
.....
   <PassengerInfoList>
       <PassengerInfo id="N10092">
...
       </PassengerInfo>
       <PassengerInfo id="N10095">
...
       </PassengerInfo>
   </PassengerInfoList>

Obviously the PNR class contains a collection of passengers. I don't know how to map this using the def/ref principle. I would like to use the following mapping:

<collection name="passengers" add-method="addPassengers" iter-method="getPassengersIterator" test-method="hasPassengers" usage="optional">
<structure name="PassengerInfo">
<value style="attribute" name="refid" ident="ref"/>
</structure>
</collection>


but I get a NullPointerException since I haven't given a field attribute to the value element.

Any ideas?

Thank you,

Fran�ois



Guillaume Pothier wrote:

   Looking at the JiBX source code, it seems that non-global id support
   is pretty advanced, does it need anything more than testing?

A number of the hooks are in place, but I've never tried it out. You're welcome to try it and see how far it gets (global-ids="false" on the <binding>). I may even provide some support if the fixes are easy...

   However, I think that type-based id spaces might not work for every
   situation: there can be cases where elements that are bound to
   distinct classes have to share the same id space, and conversely
   elements of the same class could need to be in two distinct id spaces.
   I think more situations could be handled by a scheme like this:
   instead of ident="ref" and ident="def", using attributes like
   key="keyid" and keyref="keyid", like in xsd shemas. This would let
   the user define its id spaces.

The schema key/keyref idea gets into XPath constructions, which I don't think will fit well with JiBX. If you want to look into this and suggest a way they could be worked into the existing framework I'll certainly consider it, though.


There is another use case of IDs that I have not been able to handle with JiBX. Consider the following file:

<functions>
   <function id="1">
       (...)
       <related-functions>
           <function-ref functionId="2"/>
       </related-functions>
   </function>
   <function id="2">
       (...)
       <related-functions/>
   </function>
</functions>


In each function element I have a collection of related functions. In my java classes, the collection contains instances of Function directly. In other words, each <function-ref> tag is unmarshalled to the Function object that corresponds to its id, not to a FunctionRef object that has a Function field. Is it possible to do that with JiBX? Right now I am doing it with a custom marshaller/unmarshaller. Guillaume

You *should* be able to do this:

<collection name="related-functions" ...>
  <structure name="function-ref">
    <value style="attribute" name="functionId" ident="ref"/>
  </structure>
</collection>


This is getting into the edge cases where the current code generation may have problems (especially since the value is actually a reference), so it may not work. If it doesn't, please enter a bug report in Jira.


- Dennis



------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to