Keith,

Thanks for your valuable info.

A few questions:

On Thu, 2006-01-05 at 22:29 -0600, Keith Visco wrote:
> 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>

I want the 'MyGUIDHandler' to be invoked only while Unmarshalling
objects and not while Marshalling them. 

While marshalling, the objects being marshalled already have the GUIDs
correctly set on them and is just a matter of printing them out.

While unmarshalling the XML element placeholders are a hint to the
Unmarshaller to create & populate the GUIDs on the objects being created
from XML.

Is this possible?

> 
> 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>

After looking at the Castor docs, it appears that the attribute
'reference' is available on element 'bind-xml' rather than on 'field'.
Is that correct?

By just saying reference="true" as shown above, how does the
Unmarshaller know that it has to reference the parent/contained object's
'clientGuid' property. Don't we have to say reference so & so property
name from the parent object? Or do the property names have to be same on
the parent & the contained/child object?

> 
> 
> 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.

As per my comments above, I just need the GUID generation & setting
functionality while Unmarshalling. Do you still see an issue here?

> 
> For help on creating a custom FieldHandler please see the website.

Thanks,
--Sandeep Khanna

> 
> --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]
> -------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to