Sandeep,

See inline comments...

Sandeep Khanna wrote:
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.


Ah ok, well that's easy enough to tweak your handler so that it doesn't generate a GUID during marshalling...just have your handler can check the respective field in the target object to see if the GUID has been set, if so, just return it, if not it can generate one. So during marshalling, since the GUID has already been set in the target object, it will just return that value.

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?

See my comments above. However, I guess I'm a bit confused on what you call a "placeholder". Castor will need an ID to be present in the XML during unmarshalling or it won't know which object to reference.



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?


That sounds right...sorry for the confusion...you can place the reference="true" on the bind-xml element.

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?

Ah yes, I knew I left out an important note. The GUID must be document-unique. Basically references are treated as ID/IDREF within the XML, which means each ID must be unique within the document, regardless of the element name.

During unmarshalling when Castor finds a field marked as a reference it will find the object with the given ID and set the associated field with that 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?


Yes, I do seen an issue here, because for your fields that reference another object Castor will need to know it's ID in order to resolve the field properly during unmarshalling.

So I guess I'm now having trouble understanding how you expect things to work. During marshalling, you say the object already has a GUID...so Castor will just print it out...which is fine...but how does that go from having an actual GUID that got printed out into the XML to just being a place holder which needs to generate a GUID upon unmarshalling back to an object? Shouldn't the GUID still exist in the XML from the marshalling?

I guess I need more explaination in order to help you come up with a solution.

--Keith


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

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

Reply via email to