Paul-

  Try this: (Class1 is an abstract class, Class2 just extends class1,
Class3 extends class1 and adds new attribute)


    <xsd:complexType name="class1">
      <xsd:sequence>
        <xsd:element name="attr1" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>

    <xsd:element name= "class2" type="class1"/>

    <xsd:complexType name= "class3">
      <xsd:complexContent>
        <xsd:extension base="class1">
           <xsd:attribute name="attr2" type="xsd:string"/>
        </xsd:extension>
      </xsd:complexContent>   
    </xsd:complexType>


--- "Young, Paul" <[EMAIL PROTECTED]> wrote:
> Keith,
> 
> Thanks for the quick reply.  
> 
> I took a stab at using xsd:extension as suggested, but so far haven't
> been
> able to create a valid schema incorporating xsd:extension into the
> existing
> schema I was trying to modify to reflect their inheritance relationship.
> Perhaps a look at what I initially had in mind for the two schemas would
> help.
> 
> Schema1
> <xsd:element name="class1">
>       <xsd:complexType>
>               <xsd:sequence>
>                       <xsd:element ref="attribute1"/>
>                       <xsd:element ref="attribute2"/>
>               </xsd:sequence>
>       </xsd:complexType>
>       <xsd:simpleType name="attribute1" type ="xsd:string"/>
>       <xsd:simpleType name="attribute2" type ="xsd:string"/>
> </xsd:element>
> 
> 
> Schema2
> <xsd:element name="class2">
>       <xsd:complexType>
>               <xsd:sequence>
>                       <xsd:element ref="attribute1"/>
>                       <xsd:element ref="attribute2"/>
>                       <xsd:element ref="attribute3"/>
>               </xsd:sequence>
>       </xsd:complexType>
>       <xsd:simpleType name="attribute1" type ="xsd:string"/>
>       <xsd:simpleType name="attribute2" type ="xsd:string"/>
>       <xsd:simpleType name="attribute3" type ="xsd:string"/>
> </xsd:element>
> 
> Recognizing that Schema2 is an extension of Schema1, I want to redefine
> Schema2 to eliminate duplicate definition of attribute1 and attribute2
> (perhaps using <xsd:import> or <xsd:include>) in such a way that Castor
> generates the classes and their inheritance relationship as provided in
> my
> previous email.  Any thoughts on how I might do this?
> 
> Thanks again,
> 
> Paul
> 
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 18, 2002 12:25 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] Establishing class inheritance using Castor
> 
> 
> 
> Hi Paul,
> 
> Since you are coming from a .mil domain I will do my duty to help :-)
> 
> The easiest way to do it, is to switch (see castorbuilder.properties) to
> type-centric approach using t "type" as the value of the
> "org.exolab.castor.builder.javaclassmapping"  property.
> 
> Then you can use the following fragment:
> 
> <xsd:complexType="class1">
>    <xsd:attribute name="attribute1" type="xsd:string"/>
>    <xsd:attribute name="attribute2" type="xsd:string"/>
> </xsd:complexType>
> 
> <xsd:complexType name="class2">
>   <xsd:complexContent>
>      <xsd:extension base="class1">
>         <xsd:attribute name="attribute3 type="xsd:string"/>
>      </xsd:extension>
>   </xsd:complexContent>   
> </xsd:complexType>
> 
> 
> Now I just coded this up and haven't run it through the SourceGenerator,
> but it should work for you...
> 
> --Keith
> 
> "Young, Paul" wrote:
> > 
> > How do you establish an inheritance relationship between generated
> classes
> > using Castor?  For example, how would I define the XML Schemas such
> that
> > Castor Source Generation generates the following classes?
> > 
> > public class Class1 {
> >         java.lang.String attribute1
> >         java.lang.String attribute 2
> > 
> >         public java.lang.String getAttribute1() {
> >                 return this._attribute1;
> >         } //-- java.lang.String getAttribute1()
> > 
> >         public java.lang.String getAttribute2() {
> >                 return this._attribute2;
> >         } //-- java.lang.String getAttribute2()
> > 
> >         public java.lang.String setAttribute1(_attribute1) {
> >                 this._attribute1 = _attribute1;
> >         } //-- java.lang.String setAttribute1()
> > 
> >         public java.lang.String setAttribute2(_attribute2) {
> >                 this._attribute2 = _attribute2;
> >         } //-- java.lang.String setAttribute2()
> > }//--Class1
> > ------------------------------------------------------------------
> > 
> > public class Class2 extends Class1{
> >         java.lang.String attribute3
> > 
> >         public java.lang.String getAttribute3() {
> >                 return this._attribute3;
> >         } //-- java.lang.String getAttribute3()
> > 
> >         public java.lang.String setAttribute3(_attribute3) {
> >                 this._attribute3 = _attribute3;
> >         } //-- java.lang.String setAttribute3()
> > }//--Class2
> > 
> > -----------------------------------------------------------
> > 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
> 
> ----------------------------------------------------------- 
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>       unsubscribe castor-dev
> 


=====
Virtually,        |                   "Must you shout too?" 
Ned Wolpert       |                                  -Dante
[EMAIL PROTECTED] |             
_________________/              "Who watches the watchmen?"
4e75                                       -Juvenal, 120 AD

-- Place your commercial here --                      fnord

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

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

Reply via email to