Bryan,

Have you thought about using an ID/IDREF approach?

In the mapping file you can specify an identity field for a class:

<class name="MyClass" identity="id">
   <field name="id" ...>
   ...
</class>

Then whatever fields use the MyClass you can mark them as references:

<class name="SomeOtherClass">
    <field name="myClass" type="MyClass">
     <bind-xml reference="true" node="attribute"/>
    </field>
    ...
</class>

--Keith


Bryan LaPlante wrote:
I hate the idea that I came up with and I have a better one, but I will need
some help to point me in the right direction or come up with a better way.
Let me know if I need to move this to the developer list.

Concern

ing object references. To instances that have already been created
but are referred to in many places in the output xml, I need a way to reuse
the instances already created. Upon unmarshalling I need only one instance
of an object created for ever setter and adder method that expects it.

Create an interface that tells the Marshaller that I want to temporarily
store a reference to all created objects.

public interface ReferenceObject{
    public Hashtable references = new HashTable();
    public Object getReference(int hashCode);
    public void addReference(int hash, Object ref);
    public boolean hasReference(int hash);
}

Now my root object implements this interface so that Marshaller knows it has
a place to store references. As the xml is being created you store each
instance received from the getValue or convertUponGet method if used in the
Hashtable.

In addition to the normal xml output expected will be the tags representing
the Hashtable with the hasCode as the key and the xsi:type or classPath or
even null indicating to the unmarshaller that the instance has not yet been
created.

When the Unmarshaller is given the xml it will populate the hastable first
and then before every tag is converted into an object, check to see if the
hascode in the tag refers to an instance in the hastable that already exists
and use that instance to populate the setValue or convertUponGet if used
instead of creating yet another instance of the object.

I can come close to doing this by using the GeneralizedFieldHandler except
that I am creating an API and the (user) developer will have to carry the
baton and continue this for his or her own classes, I would like to make
this functionality available while expecting a minimum of effort from the
developer.

What do you think.

Bryan LaPlante



----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user






----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user

Reply via email to