Hi all,
Some people have already sent about the same questions I am going to ask
alas I found no reply.
The problem I have is to unmarshal and marshal a sequence of objects that
may be of different type( still they inherit from a same base class).
Here is an example:
1) Node is the base class.
2) NodeA, NodeB and NodeC inherit from Node.
3) NodeA instance could have NodeB and NodeC instances as children
an xml file would be:
<nodeA>
   <nodeB/>
   <nodeB/>
   <nodeC/>
   <nodeB/>
</nodeA>
And the DTD would include <!ELEMENT nodeA (nodeB | nodeC)*>

I would want the mapping file to set nodeA children from a single method (to
get objects as well).
So, I would want to know if it's possible using Castor!
By now, I have found a work around to set objects as I want:
The name attribute of a field element has to be unique but we can set a
random name (I am using my own classes so I have no side-effects that could
happen using the source generator tool) and set the "direct" attribute to
"false". This way we can have the same set method for different object types
as below:

<class name="NodeA" extends="Node">
   <map-to xml="nodeA" />
    <field name="g_childrenB" -- in fact g_children --
           direct="false"
           set-method="addChild"
           type="NodeB"
           collection="vector"
           >
      <bind-xml name="nodeB" />
    </field>
    <field name="g_childrenC" -- in fact g_children --
           direct="false"
           set-method="addChild"
           type="NodeC"
           collection="vector"
           >
      <bind-xml name="nodeC" />
    </field>
</class>
...

But then I am stuck if I want to marshal again as I need a specific method
for each NodeX (X = B or C) type to return a subset of g_children.
I would have hope that there is an easier solution and if there is such
thing please tell me!

If you read this line thanks for reading it all.
Thanks for your help.

Olivier



<<application/ms-tnef>>

Reply via email to