Check the last paragraph of http://jibx.sourceforge.net/tutorial/binding-collects.html#ids and the linked http://jibx.sourceforge.net/extras.html#ididref I think that gives you what you need.

 - Dennis

Ross Bagley wrote:

I'm trying to map an object model to XML that happens to have multiple
collection references to a particular class.  However, there does not appear to
be support for using the 'ident' capability on a 'collection of references'
property.

Here's a simplified description of the actual case.  I'm managing SQL metadata
(simplified: just tables, varchar columns, and indices).  Relationship
semantics are: 1) tables have columns and indices 2) indices refer to columns.

public class Table {
   public String name;
   public List columns;
   public Set indices;
}

public class Column {
   public String name;
   public int size;
}

public class Index {
   public String name;
   public boolean unique;
   public List columns;
}

Here is the JiBX binding XML for the table and column:

<binding>
 <mapping name="table" value-style="attribute" class="Table">
   <value name="name" field="name"/>
   <collection field="columns" item-type="Column"
factory="ListFactory.create"/>
   <collection field="indices" item-type="Index" factory="SetFactory.create"/>
 </mapping>
 <mapping name="column" value-style="attribute" class="Column">
   <value name="name" field="name" ident="def"/>
   <value name="size" field="size"/>
 </mapping>

Pretty simple stuff.  But how to bind the index's collection of columns?  Since
it's a collection property, I can't use a "value" element to bind it, and
"collection" and "structure" elements don't offer an "ident" attribute (yet). But maybe it's just undocumented...

Here was attempt #1 (ident attribute on collection):

 <mapping name="index" value-style="attribute" class="Index">
   <value name="name" field="name"/>
   <value name="unique" field="unique"/>
   <collection field="columns" item-type="Column" ident="ref"
factory="ListFactory.create"/>
 </mapping>

Which resulted in a warning during binding (the 'line' and 'col' values in the
actual warning are '0'):

"Warning: Undefined attribute ident for collection element at (line 0, col 0)"

And, given the failure during the binding, a predictable exception is thrown
during unmarshalling:

org.jibx.runtime.JiBXException: Duplicate ID definition (line 11, col 89, in
UTF-8)

Here's attempt #2 (ident attribute on structure):

 <mapping name="index" value-style="attribute" class="Index">
   <value name="name" field="name"/>
   <value name="unique" field="unique"/>
   <collection field="columns" factory="ListFactory.create">
     <structure name="column" type="Column" ident="ref"/>
   </collection>
 </mapping>

Which resulted in a similar warning:

"Warning: Undefined attribute ident for structure element at (line 0, col 0)"

And the exact same exception is thrown during unmarshalling.

In desperation, I did try one other thing.  Attempt #3:

 <mapping name="index" value-style="attribute" class="Index">
   <value name="name" field="name"/>
   <value name="unique" field="unique"/>
   <collection field="columns" factory="ListFactory.create">
     <structure name="column" type="Column">
       <value name="name" field="name" ident="ref"/>
     </structure>
   </collection>
 </mapping>

Which failed because Column.name is a String and not a reference to a Column
object...

So I'm stuck for the moment, unless there's some approach that I missed in
reading the documentation (which I've now read through a few times).

Regards,
Ross


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to