I have an interesting problem that perhaps some of you have dealt with before.  I need 
to export parts of my document (an object graph) out as "template" XML instances so 
that they can later be imported (perhaps multiple times) into another document.

The problem is that I need to regenerate/rewire the primary keys (ID) and references 
(IDREF) in the template upon import into the new document to avoid duplicate IDs when 
the same template is imported multiple times into a single document.

e.g.

Let's say I have three classes: Computer, Slot and Card.  A Computer has Slots.  Each 
slot can hold one Card.   I may have a Dell computer with a network card.  I want to 
export the network card so that I can add it to other computers.  Some computers may 
even have multiple network cards in it.  Each network card has it's own unique primary 
key (ID) so if I add/import it twice into a computer, each one network card needs to 
get a new ID to preserve uniqueness.

So, to regenerate the IDs and rewire the IDREFs on import of my template, I think I 
need to create a hook in the Unmarshaller perhaps via the UnmarshalListener.  That 
hook has to somehow inspect each object as it's getting unmarshalled and see if it's 
primary key is in a hashmap, if not, it is added to the hashmap as a "key" and a new 
primary key is generated as a "value".  This hashmap allows me to keep a running list 
of IDs in the template and the new IDs I need to replace them with.  I then replace 
the ID of the object with the new one.  I now have to somehow look at any other 
properties that are of type IDREF and substitute those with the new values from the 
hashmap.

How can I do this?  Especially the last part where as each object is being 
unmarshalled, I have to somehow find any properties that are IDREF.  I'd prefer to do 
this entirely with Castor.  I suppose if I really really have to, I'll resort to using 
JDOM or something similar.

Thoughts?  Ideas?

Robert

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

Reply via email to