I just discovered that using references only works when there is no 
inheritance. (latest CVS)

Let us say this is the mapping file:
------------------------------------
<mapping>
   <class name="javax.vecmath.Vector3d">
     <field direct="true" name="x" type="double">
       <bind-xml node="attribute"/>
     </field>
     <field direct="true" name="y" type="double">
       <bind-xml node="attribute"/>
     </field>
     <field direct="true" name="z" type="double">
       <bind-xml node="attribute"/>
     </field>
   </class>
   <class name="dk.ifad.adt.Composite" identity="name">
        <map-to xml="Composite"/>
        <field
                direct="false"
                name="name"
                type="string"
                set-method="setName"
                get-method="getName">
                <bind-xml node="attribute"/>
     </field>
     <field
                direct="false"
                name="Component"
                type="dk.ifad.adt.Composite"
                collection="array"
                set-method="addComponent"
                get-method="getComponents">
                <bind-xml node="element" reference="true"/>
     </field>
   </class>
   <class name="dk.ifad.sim.SimComponent"
          extends="dk.ifad.adt.Composite">
     <field
         direct="false"
         name="Translation"
         type="javax.vecmath.Vector3d">
       <bind-xml name="position" node="element"/>
     </field>
   </class>
</mapping>

Notice that SimComponent extends Composite.

Then marshalling to this will work when house1 & house2 = Composite:
-----------------------------------
<Composite name="City"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:type="java:dk.ifad.adt.Composite">
    <Component name="House1"/>
    <Component name="House2"/>
</Composite>

Note that the referered element still works even though Kieth Visco 
wrote that it would only work when the identity field AND the referered 
field both is attributes. :)


But will NOT work when house1 & house2 = SimComponent who inherits from 
Composite:
---------------------------------------
<Composite name="City"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:type="java:dk.ifad.adt.Composite">
    <dk.ifad.sim.SimComponent name="House1">
                <position x="0.0" y="0.0" z="0.0">
    </dk.ifad.sim.SimComponent>
    <dk.ifad.sim.SimComponent name="House2">
                <position x="0.0" y="0.0" z="0.0">
    </dk.ifad.sim.SimComponent>
</Composite>



BUG 1: (maybe a feature request)
  It would be nice if references fields would work also in inherited 
classes. (see above explanation)

BUG 2: (real bug)
  When specifying the array in the above listed mapping file as an 
attribute I get this:

  java.lang.ClassCastException:
    org.exolab.castor.mapping.loader.J1CollectionHandlers$ArrayEnumerator
         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:782)
         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:540)
         at dk.ifad.experimental.MTest2.main(MTest2.java:105)

BUG 3: (real bug)
  If the array in the above listed mapping file is not an array but 
normal object, and specified as an attribute(as Keith recommends), I get 
this:

Unable to resolve ID for instance of class '[Ldk.ifad.adt.Composite;' 
due to the following error: Unable to resolve ClassDescriptor.
         at 
org.exolab.castor.xml.Marshaller.getObjectID(Marshaller.java:1031)
         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:792)
         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:969)
         at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:540)
         at dk.ifad.experimental.MTest.main(MTest.java:104)


Somebody please reply on this mail.
Nikolai

----------------------------------------------
Nikolai V. Christensen, Computer Engineer,
Simulation and Training department
IFAD, Forskerparken 10A, DK-5230 Odense M
Phone: +45 63 15 71 31  Fax: +45 65 93 29 99
WWWeb: http://www.ifad.dk
e-mail: [EMAIL PROTECTED]
----------------------------------------------

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to