users@jaxb.java.net

restricted types inherit their base type's attributes (was Re: Default attribute values on derived complex type (JAXB v.1.0.1))

From: Thomas Plümpe <thomanski_at_gmx.de>
Date: Thu, 03 Jul 2003 01:44:25 +0200

Hi Sekhar,

> > > JAXB does not implement the inheritance of attributes when
> > restricting a type, although it should.
> > [...]
> The spec does not say that. The spec states (in Section 5.3.2 ) that
> derivation by restriction is handled the same as derivation by
> extension.
I see, the JAXB spec says so. However, this is problematic, because it
means that JAXB generated classes for a schema such as this:


        <xsd:complexType name="myBaseType">
                <xsd:attribute name="myAttribute" type="xsd:string"/>
        </xsd:complexType>

        <xsd:complexType name="myDerivedType">
                <xsd:complexContent>
                        <xsd:restriction base="myBaseType">
                        </xsd:restriction>
                </xsd:complexContent>
        </xsd:complexType>

        <xsd:element name="myRoot" type="myDerivedType"/>


will never successfully validate instance documents such as this:


<myRoot myAttribute="foo"/>.


But according to the clarification here
        http://www.w3.org/2001/05/xmlschema-errata#e0-21
they should, because myDerivedType inherits myAttribute from myBaseType.
I think JAXB should not only accept the instance as valid, but also
provide a getMyAttribute() method in class MyDerivedType.


Thomas

PS: Please also see the thread "derived attribute not accepted when
validating", June, 19th, where I had mentioned this giving a different
example.