Hi,
I am working in a application that needs to read a XML file and convert it into
Value Objects that the application will process. I have started to use castor
and I have completed 99% of the mapping between the XML File and our Value
Object. I have a couple of questions about best practice and to ensure that I
have defined the mapping correctly. The XML Data File and Value Object class
hierarchy are fixed and can not be changed. I have developed a simple example
of how I believe I should define the Castor Mapping file. I can provide you
with the files and the java object if that helps...
The XML Data File:
<?xml version="1.0" encoding="UTF-8"?>
<Outer>
<Inner FieldOne="Field One A Value">
<FieldTwo>
<BlahBlah>Field Two Value Line 1</BlahBlah>
</FieldTwo>
<FieldTwo>
<BlahBlah>Field Two Value Line 2</BlahBlah>
</FieldTwo>
<FieldTwo>
<BlahBlah>Field Two Value Line 3</BlahBlah>
</FieldTwo>
</Inner>
</Outer>
The Castor Mapping File:
<mapping>
<class name="castor.OuterObject">
<map-to xml="Outer"/>
<field name="fieldOneObject" type="castor.FieldOneObject"
container="true">
<bind-xml name="FieldOne" location="Inner"
node="attribute"/>
</field>
<field name="fieldTwoObjects" type="castor.FieldTwoObject"
collection="arraylist" set-method="addFieldTwoObject">
<bind-xml name="FieldTwo" location="Inner"
node="element"/>
</field>
</class>
<class name="castor.FieldOneObject">
<field name="fieldOne" type="string" direct="false">
<bind-xml name="FieldOne" location="Inner"
node="attribute"/>
</field>
</class>
<class name="castor.FieldTwoObject">
<field name="fieldTwo" type="string" direct="false">
<bind-xml name="BlahBlah" node="element"/>
</field>
</class>
</mapping>
Questions:
1. My first question is about mapping the attribute "FieldOne" and the FieldTwo
collection to two separate objects on the "castor.OuterObject", I had define
the fieldOneObject as a container yet I had to specify the same binding that I
was using within the class specification. Is this the correct approach or is
there another way that I can achieve the same thing?
2. I wanted to be able to set the "castor.OuterObject" on the
"castor.FieldTwoObject" when it is being added to the OuterObject. Originally
I had a set method called setFieldTwoObjects that would set this relationship
whenever Castor added the FieldTwoObjects to the OuterObject. When I tested
this I realised that Castor called the getFieldTwoObjects and added the new
object to the returned list. Then I added a separate method that took a single
FieldTwoObject and set this as the "set-method" and in this class set the
relationship. Is this the correct approach or is there a way to specify this
relationship in the mapping file.
3. Can someone please explain what the usage of the "container" element and
what it should be used for...
I hope that you can help.
Thanks
Declan
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email