Hi,
I am hoping to use Castor in the following way:
1. define an .xsd (fairly complicated)
2. use the SourceGenerator to make .java classes for the schema
3. override a subset of the generated classes to add extra
application functionality unrelated to
XML marshalling/unmarshalling (I was hoping to use a mapping
file, and not mention
the other classes for which the generated Descriptors are fine)
4. implement the application override classes (which extend the
originally generated classes) to have my extra functionality
This doesn't seem to be easy/possible as far as I can see, as using a
mapping file seems to force me to mention all the generated classes (not
just the ones I want to override).
The reason I'm trying to override these classes is to avoid the overhead
(both runtime and in terms of coding) of having to traverse my
unmarshalled objects again to make corresponding application class
instances for each of them (this is commonly required when using DOM).
The ideal solution would seem to be if I could tell the SourceGenerator
during code generation that I want the generated code for an element (I
use the element generation flavour) to cause a derived instance to be
created rather then the generated one:
e.g.
// generated by SourceGenerator
public class GenElement
{
}
// added application logic unrelated to XML marshalling
public class MyGenElement extends GenElement
{
private int myAppField;
public int myAppMethod() {}
}
which I presume would be reflected in the generated
GenElementDescriptor.java file.
The second best option would be to tell the UnMarshaller itself (at
runtime rather then build time) that I wanted to override the class
specified in the Descriptor so that when the relevant XML construct is
encountered in the input file an instance of MyGenElement is created
instead of GenElement. I presume some sort of factory is responsible for
doing this (or is it just a straight Class.newInstance())?
Anyone tried to do this before?
Is there a safe single place in the Castor code where the class used in
the Class.newInstance() call can be changed without upsetting any other
references elsewhere in the code?
Any help/ideas would be greatly appreciated. I think Castor is a great
idea and would feel much happier if I can avoid the "second walk through
the object tree" mentioned above.
Thanks,
Norval Hope
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev