Here are two approaches -- I'm sure there are others.
If your subclasses will contain only methods and transient data,
then it is very easy.
If Foo.java and FooDescriptor.java were code generated, then
code this:
public class FooSub extends Foo {
//put your transient stuff here
}
also create one of these:
package same.package.as.FooSub;
//THe class name MUST end in 'Descriptor' and
//start with your subclass name.
public class FooSubDescriptor extends FooDescriptor {
//don't put any code here
}
A second way is to model your hierarcy in the schema.
HEre is an example from Roger Costello's xml schema tutorial:
<xsd:complexType name="Publication">
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"
maxOccurs="unbounded"/>
<xsd:element name="Author" type="xsd:string"
maxOccurs="unbounded"/>
<xsd:element name="Date" type="xsd:gYear"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookPublication">
<xsd:complexContent>
<xsd:extension base="Publication" >
<xsd:sequence>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Castor will generate these two classes:
public class Publication
public class BookPublication extends Publication
OPtionally, you could move BookPublication to a separate
schema if you want to avoid re-gen'ing on top of your custom code in the
subclass.
> -----Original Message-----
> From: POLLOCK Alex [mailto:alex.pollock@;eurocontrol.int]
> Sent: Monday, October 28, 2002 3:08 AM
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] Source Generator - unmarshalling
> into sub classes
>
>
> I've just started using the Castor Source Generator to
> unmarshall XML file
> into an internal java object representation. But I
> would like to add my
> application-specific behaviour so I want to use
> sub-classes of the classes
> generated by the Source Generator. Is there any way of
> unmarshalling XML
> data into subclasses of the generated classes?
>
> Thanks for any help.
> Alex
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev