Alexander-

I have to admit your problem sounded quite intriguing to me, so I spent some time yesterday trying to formulate a solution. The bad news is, I couldn't get anything to work as specified. I dug through the code for quite some time, and after understanding what Keith is hinting at, I believe it will work for unmarshalling (xml->java). My problem was on the marshalling end, where the FieldDescriptors/Handlers don't even see the object in question (and thus the value of Attribute.key) until well after the XML name for the element is supposedly known (and grabbed by the marshaller). So I guess at this point I'll have to wait and see if Keith gets some time to enlighten both of us.

On a side note (a rather sacrilegious one on this list), I'm 99% sure you can do exactly what you want using Perl and the XML::Simple package if the implementation language is flexible (it's where I got my feet wet with XML, so I tend to tie problems back to it).

Thanks,
Stephen


Alexander Papaspyrou wrote:
Keith,

Keith Visco wrote:

This isn't something easily done in Castor. I've done this myself in the past using a dynamic FieldDescriptor approach, basically you need to override the XMLClassDescriptor#getFieldDescriptor method such that it creates an XMLFieldDescriptor using the passed in xml name, or returns a cached one based on the given name.


I'm not that deep into the Castor API, so I'll definitely need some examples. However, I considered alternatives such as building a DOM tree using JDOM, as the aforementioned Attribute class participates in the GoF's Composite and Visitor patterns as the abstract element.

Thus, it shouldn't be too hard to write an XMLModelAttributeVisitor which walks down the Attribute tree and creates an org.w3c.dom.Document. The question is, however, whether hacking Castor would be *less effort*. What do you think?

I don't have time to provide more details at the moment, but if you're feeling brave you may want to start looking into that approach. If you're having trouble with this, I'll see if I can dig up the code I wrote a while back and provide a more concrete example for you when I get some free time.


Please take your time -- I'm not in such a hurry (although I need it for my thesis...).

Regards,
Alexander


Reply via email to