The situation is easier as it appears. I don't want to reuse already serialized 
SourceVO instances. I misunderstood your first posting, therefore the thread 
went into the wrong direction I guess, sorry.

The situation is as follows:

A recursive java.util.List<SourceVO> (with every SourceVO containing a 
List<SourceVO> itself) shall be bound to an XML structure that is structurally 
the same as the Java structure, and looks like the following:


<source>
  <a>...</a>
  <b>...</b>
  ...
  <source>
    <a>...</a>
    <b>...</b>
    ...
    <source>...</source>
    <source>...</source>
    <source>...</source>
  </source>
  <source>...</source>
  ...
<source>

The nesting level depth of the sources in the XML shall not be restricted, 
neither shall be the nesting level depth of the Java SourceVOs.

Is this possible? Or is the "flat" XML structure you proposed the only way of 
dealing with this situation?

Regards,

Johannes







-------- Original-Nachricht --------
Datum: Wed, 07 Mar 2007 23:24:03 +1300
Von: Dennis Sosnoski <[EMAIL PROTECTED]>
An: JiBX users <[email protected]>
CC: 
Betreff: Re: [jibx-users] Handling recursive collections: How?

> Then if I understand you correctly, you want to serialize each SourceVO 
> instance only the first time it's seen, and if it's later referenced 
> again just refer back to the already-serialized copy. Handling this 
> automatically was something I'd originally intended for JiBX, but I 
> found it was an uncommon requirement and I've never been motivated to 
> make it work. You can still do it using custom 
> marshalling/unmarshalling, though it's somewhat involved.
> 
> The basic idea is to define an abstract <mapping> for SourceVO with a 
> type-name, and specify force-classes="true" on the <binding> element. 
> Then your code can find the index number assigned to the generated 
> marshaller/unmarshaller (what I'll call a "handler") using the 
> getTypeIndex() call of the IBindingFactory instance.
> 
> You can track which instances have already been marshalled in your 
> custom marshaller code. When told to marshal an instance, if it hasn't 
> previously been marshalled you'd just record the id value and write the 
> start tag, then delegate to the generated marshaller for the bulk of the 
> processing, and finish by writing the end tag. If it *has* previously 
> been marshalled, you'd instead write and empty tag with a single 
> attribute (say ref="id") that identifies the instance.
> 
> Unmarshalling is similar. If the element you're called on has the 
> ref="id" attribute you just look up the previously-unmarshalled instance 
> using the id. If the element doesn't have the ref="id" attribute you use 
> the normal unmarshalling, but record the result in a hashmap.
> 
> Hope that gets you started...
> 
>   - Dennis
> 
> Dennis M. Sosnoski
> SOA and Web Services in Java
> Training and Consulting
> http://www.sosnoski.com - http://www.sosnoski.co.nz
> Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
> 
> 
> 
> Johannes Müller wrote:
> > Hello Dennis,
> >
> > thanks for your reply.
> >
> > If I understand you correctly, this would mean that there had to be a
> finite set of possible SourceVO structures that are known in advance to
> implement this.
> >
> > But the set of possible SourceVO-structures is infinite and not known in
> advance.
> >
> > If you imagine the recursive List<SourceVO> structure as a tree, then
> all possible trees shall be mapped from and to XML, a flat tree consisting of
> one root element with 128 direct child-SourceVO's just as well as a highly
> complex tree with thousands of SourceVO-nodes and dozens of levels, with
> every single SourceVO having different amounts of child-SourceVOs, for
> instance.
> >
> > Is this possible with JiBX?
> >
> > Regards,
> >
> > Johannes
> >
> >
> >
> >
> > -------- Original-Nachricht --------
> > Datum: Mon, 05 Mar 2007 19:23:19 +1300
> > Von: Dennis Sosnoski <[EMAIL PROTECTED]>
> > An: JiBX users <[email protected]>
> > CC: 
> > Betreff: Re: [jibx-users] Handling recursive collections: How?
> >
> >   
> >> Hi Johannes,
> >>
> >> The only way of handling this type of situation is to have a collection
> >> of all the SourceVO instances at one point in your binding, then use 
> >> ID/IDREF links to refer to each instance. So it'd end up looking 
> >> something like this:
> >>
> >>   <SourceVO id="ID8">
> >>     ...
> >>     <sources>ID1 ID3 ID10 ...</source>
> >>     ...
> >>   </SourceVO>
> >>   <SourceVO id="ID10">
> >>     ...
> >>   </SourceVO>
> >>
> >> See the Working with IDs section of the tutorial 
> >> (http://jibx.sourceforge.net/tutorial/binding-collects.html#ids) for 
> >> some details on how to handle this in the binding. Note that you'd 
> >> probably have to use some extension code of your own to convert the 
> >> SourceVOs into this type of structure - you'd basically want to build a
> >> collection of the closure of all the SourceVOs being marshalled in your
> >> own code, then have JiBX marshal the constructed collection.
> >>
> >>   - Dennis
> >>
> >> Dennis M. Sosnoski
> >> SOA and Web Services in Java
> >> Training and Consulting
> >> http://www.sosnoski.com - http://www.sosnoski.co.nz
> >> Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
> >>
> >>
> >>
> >> Johannes Müller wrote:
> >>     
> >>> Hello all,
> >>>
> >>> in a Java object called "SourceVO", I have an attribute called
> >>>       
> >> "sources", which is a list of "SourceVO"'s. Therefore, each of the list
> objects
> >> contains a list of SourceVO's itself (recursion).
> >>     
> >>> I tried to bind this with the following JiBX mappings, but with these,
> >>>       
> >> the binding compiler (v1.1.3) runs into an endless loop.
> >>     
> >>> How can I get the recursive collections bound properly?
> >>>
> >>> <mapping [...]>
> >>>   [...]
> >>>   <collection field="sources"
> >>>       
> >> factory="org.foobar.JiBXHelper.sourceVOListFactory" usage="optional">
> >>     
> >>>     <structure name="source"  map-as="org.foobar.SourceVO" />
> >>>   </collection> 
> >>>   [...]
> >>> </mapping>   
> >>>
> >>>
> >>> <mapping class="org.foobar.SourceVO" ordered="false"
> >>>       
> >> allow-repeats="true" abstract="true">                 
> >>     
> >>>    [...]                                                            
> >>>    <collection field="sources"
> >>>       
> >> factory="org.foobar.JiBXHelper.sourceVOListFactory" usage="optional">
> >>     
> >>>       <structure name="source" map-as="org.foobar.SourceVO" />
> >>>       
> >> </collection>                                                          
>       [...]
> >>     
> >>> </mapping>
> >>>
> >>> Regards,
> >>>
> >>> Johannes
> >>>
> >>>
> >>>       
> >>
> -------------------------------------------------------------------------
> >>     
> >>> Take Surveys. Earn Cash. Influence the Future of IT
> >>> Join SourceForge.net's Techsay panel and you'll get the chance to
> share
> >>>       
> >> your
> >>     
> >>> opinions on IT & business topics through brief surveys-and earn cash
> >>>
> >>>       
> >>
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> >>     
> >>> _______________________________________________
> >>> jibx-users mailing list
> >>> [email protected]
> >>> https://lists.sourceforge.net/lists/listinfo/jibx-users
> >>>
> >>>   
> >>>       
> >>
> -------------------------------------------------------------------------
> >> Take Surveys. Earn Cash. Influence the Future of IT
> >> Join SourceForge.net's Techsay panel and you'll get the chance to share
> >> your
> >> opinions on IT & business topics through brief surveys-and earn cash
> >>
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> >> _______________________________________________
> >> jibx-users mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/jibx-users
> >>     
> >
> >   
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> jibx-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jibx-users

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to