Hi.

I am considering switching to Castor from Borland XML (an XML DTD->Java
binder for those not familiar with it) and wanted to ask the advice of this
group before doing so. My reason for switching is that I think I need
functionality that doesn't seem to be in either product, but I am hopeful
that Castor might be made to do this!

My problem is that the classes generated by BXML, while they marshal &
unmarshal successfully, do not have the functionality required of the data
model for my application.  This means that I end up having two trees of
classes, the generated classes and my own data model classes.  When I
unmarshal a file I have to translate the generated "XML element instance"
(hereafter 'element') tree into a tree of custom instances.  Each custom
instance holds a reference to its element and uses the reference to keep the
element in sync.  This allows the element to be marshalled back to file.
This is a lot of overhead.

The solution I had in mind was to use subclasses of the generated classes to
add the extra functionality.  However this leads to a problem.  The generated
classes know nothing about my subclasses & I have no way to override what
they create.  Here's an example:

BorlandXML generates code like:

        /**
         * Unmarshals the specified "author" element back to a Author object.
         */
        public static Author unmarshal(com.borland.xml.toolkit.Element elem)
        {
                Author __objAuthor =
(Author)com.borland.xml.toolkit.TextElement.unmarshal(elem, new Author());
                return __objAuthor;
        }

embedding the decision about which class to create into the 'new Author()'
statement.  If I had the source to BXML I could, for example, have replaced
this with a class factory for creating new elements along the lines of:

public class ElementFactory {
        public static Author createAuthor() {
                ....  create an author element according to some rule or
other
        }
}

....

        public static Author unmarshal(com.borland.xml.toolkit.Element elem)
        {
                Author __objAuthor =
(Author)com.borland.xml.toolkit.TextElement.unmarshal(elem,
ElementFactory.createAuthor());
                return __objAuthor;
        }

The concrete class mappings for the factory could be specified by a
properties file & read at run-time, e.g.

element.book = default.generated.by.bxml.Book    # a default mapping
element.author = com.mowerm.app.model.ExtendedAuthor   # a customised mapping

The mapping tool would only modify the properties file in order to add new
type mappings to it.  Existing customised mappings would be preserved no
matter how many times BXML's generator is run.

And so I come to Castor.

Is there already such a facility available in Castor?  I've examined the
documentation and cannot find any reference to this kind of problem.

This leads me to two lines of questioning:

1) Have I got something wrong with my approach to designing using XML
generators?  How do other people tackle this problem?  Is there another
approach that sidesteps this problem?

2) How much effort would be required to add this kind of functionality?  Is
modification of Castor easy?  What's the learning curve?  Is modification
encouraged?

I'd really appreciate any help/wisdom you could give me.

Regards,

matt.
---
To guess is cheap. To guess wrong is expensive - Old Chinese Proverb
BEGIN:VCARD
VERSION:2.1
N:Mower;Matt
FN:Matt Mower
ORG:Hipbone, Inc;Sales
TITLE:Systems Engineer
TEL;WORK;VOICE:+44 (1932) 895902
TEL;CELL;VOICE:+44 (7977) 076709
ADR;WORK:;;3000 Hillswood Drive;Chertsey;Surry;KT16 0RS;United Kingdom
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:3000 Hillswood Drive=0D=0AChertsey, Surry KT16 0RS=0D=0AUnited Kingdom
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20010723T144203Z
END:VCARD

Reply via email to