First of all I am very satisfied with the JiBX binding library !
I need to know if there is a possibility to populate a collection
by using reference (ident="ref" and ident="def")
I have been able to populate a field using a reference with no problem
but the only way I found to populate a collection by reference was by
creating a wrapper object, so I populate the only field of the wrapper
with a reference and create a collection to this wrapper object...
Even if it works, the solution is not acceptable for our project because we do
not wish to modify the java classes.
Here I'm sending you a modified version of the tutorial no 5.
In attachement you'll see the complete code I use for testing.
By reading the previous messages I think I'm not the first one
to encounter this problem. Maybe by sending a complete example
someone will have a better idea of what the problem is ((-;
Our Configuration:
-------------------
jibx-beta3c (also tried cvs version)
java version "1.4.2_04"
Thanks in advance, and i'll be watching for any suggestions.
==================== binding.xml (START) ==========================
<mapping name="timetable" class="example5b.TimeTable">
<collection name="carriers" field="carriers"/>
<collection name="airports" field="airports"/>
<collection name="flights" field="flights"/>
<structure name="route" field="route" type="example5b.Route">
<value name="from" style="attribute" field="from" ident="ref"/>
<value name="to" style="attribute" field="to" ident="ref"/>
<collection name="flights" field="flights">
<structure name="flight" type="example5b.Flight">
-------------------------------------------------------------------
- The value element with the ident attribute generates the error
- org.jibx.runtime.JiBXException:
- No mapping defined for java.lang.Object used as IDREF target
-------------------------------------------------------------------
<value name="refid" style="attribute" field="id" ident="ref"/>
</structure>
</collection>
</structure>
</mapping>
<mapping name="carrier" class="example5b.Carrier">
<value style="attribute" name="code" field="code" ident="def"/>
<value style="attribute" name="rating" field="rating"/>
<value name="url" field="url"/>
<value name="name" field="name"/>
</mapping>
<mapping name="airport" class="example5b.Airport">
<value style="attribute" name="code" field="code" ident="def"/>
<value name="location" field="location"/>
<value name="name" field="name"/>
</mapping>
<mapping name="flight" class="example5b.Flight">
<value name="id" style="attribute" field="id" ident="def"/>
<value name="carrier" style="attribute" field="carrier" ident="ref"/>
<value name="number" style="attribute" field="number"/>
<value name="depart" style="attribute" field="departure"/>
<value name="arrive" style="attribute" field="arrival"/>
</mapping>
====================== binding.xml (END) ==========================
====================== data.xml (START) ==========================
<carriers>
<carrier code="NL" rating="4">
<url>http://www.northleft.com</url>
<name>Northleft Airlines</name>
</carrier>
<carrier code="CL" rating="9">
<url>http://www.classyskylines.com</url>
<name>Classy Skylines</name>
</carrier>
</carriers>
<airports>
<airport code="BOS">
<location>Boston, MA</location>
<name>Logan International Airport</name>
</airport>
<airport code="SEA">
<location>Seattle, WA</location>
<name>Seattle-Tacoma International Airport</name>
</airport>
<airport code="LAX">
<location>Los Angeles, CA</location>
<name>Los Angeles International Airport</name>
</airport>
</airports>
<flights>
<flight id="01" carrier="CL" number="796" depart="4:12a" arrive="1:26a"/>
<flight id="02" carrier="NL" number="328" depart="2:54a" arrive="1:29a"/>
<flight id="03" carrier="CL" number="401" depart="4:12a" arrive="1:25a"/>
<flight id="04" carrier="CL" number="634" depart="7:43a" arrive="9:13a"/>
<flight id="05" carrier="NL" number="508" depart="4:38p" arrive="6:12p"/>
<flight id="06" carrier="CL" number="687" depart="1:38p" arrive="3:08p"/>
</flights>
<route from="BOS" to="SEA">
<flights>
<flight refid="01"/>
<flight refid="02"/>
<flight refid="03"/>
</flights>
</route>
======================= data.xml (END) ===========================
BTW. Marking the value with ident="ref" as optional does not help. I tried all sort of syntax, all lead to some NullPointerException when trying to get a name.