You can create a custom field handler to be your GUID generator.
And then use the following mapping:
<class name="...ClientDcl" identity="clientGUID">
<map-to xml="ClientDcl"/>
...
<field name="clientGUID" handler="MyGUIDHandler"/>
<bind-xml name="ClientGUID"/>
</field>
...
</class>
Once you have your GUID generator working you can then add the following
to your mapping file:
<class name="...AddressRoleDcl">
<map-to xml="AddressRoleDcl"/>
...
<field name="clientGUID" reference="true">
<bind-xml name="ClientGUID" node="element"/>
</field>
...
</class>
Keep in mind that your handler (your GUID generator) will need to keep
track of GUIDs during the marshalling for each object that it generates
a GUID for so that when the handler is called again for the same object
it will return the correct GUID for that object as your handler will get
called each time it needs to output the GUID. This will be once for the
object itself and then once for each reference to the object.
For help on creating a custom FieldHandler please see the website.
--Keith
Sandeep Khanna wrote:
Hi All,
Given the following visual representation of Object relationships & the
relevant Castor mapping:
ClientDcl
|-ClientGUID
|-FirstName
|-LastName
|-...
|-AddressRoleDcl
|-AddressRoleGUID
|-ClientGUID
|-AddressGUID
|-...
|-AddressDcl
|-AddressGUID
|-...
I would like to unmarshall the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<AsClient>
<ClientGUID/>
<FirstName>Sandeep</FirstName>
<LastName>Khanna</LastName>
<Fields>
<AsClientField>
<ClientGUID/>
<FieldName>ExtraFieldName</FieldName>
<FieldTypeCode>02</FieldTypeCode>
<TextValue>ExtraFieldValue</TextValue>
</AsClientField>
</Fields>
<AddressRoles> <!-- Map -->
<AsAddressRole> <!-- value -->
<AddressRoleGUID/>
<AddressGUID/>
<ClientGUID/>
<AddressRoleCode>2</AddressRoleCode> <!-- key -->
<AsAddress>
<AddressGUID/>
<AddressLine1>81 ALEXANDRA DRIVE</AddressLine1>
<AddressLine2/>
<AddressLine3/>
<addressLine4/>
<City>NEW BRITIAN</City>
<StateCode>07</StateCode>
<CountryCode/>
<PostalID>06789</PostalID>
<Fields>
<AsAddressField>
<ClientGUID/>
<FieldName/>
<FieldTypeCode>02</FieldTypeCode>
<TextValue/>
</AsAddressField>
</Fields>
</AsAddress>
</AsAddressRole>
</AddressRoles>
</AsClient>
We have a GUIDGeneratorUtl class that creates unique GUIDs. We would
like to use it from within the Castor framework to generate the GUID and
set it in the above Object relationships.
Questions:
1) How do I setup/use a GUID generator class from within the Castor
mapping file.
2) As per the above visual Object relationship, we would require the
ClientGUID that was generated and set on the ClientDcl object to be used
while setting the ClientGUID attribute on the AddressRoleDcl object
contained in the ClientDcl instance.
3) As per the above visual Object relationship,
AddressRoleDcl.AddressGUID needs to be set from the
AddressDcl.AddressGUID which would be generated only after we unmarshall
or parse the AddressDcl element/node. One way would be to unmarshall the
AddressDcl element/node first to have the AddressGUID ready before
unmarshalling AddressRoleDcl element/node.
Any comments, suggestions, pointers would be helpful.
--Sandeep Khanna
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------