users@jaxb.java.net

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

From: Sekhar Vajjhala <sekhar.vajjhala_at_sun.com>
Date: Thu, 10 Jul 2003 08:01:00 -0400

Thomas Pl?mpe wrote:

> 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.

Thanks for the pointer to the errata as well as the pointer to the thread
noted
below. The errata quoted above is with respect to the primer (XML Schema
Part 0) which is non normative. JAXB specification is based on XML Schema Part

1 (Structures) and XML Schema Part 2 (Datatypes) not on the primer.
Regardless of the errata in the primer, according to the XML Schema Part 1,
instance document such as above should be valid with respect to the schema.
The specification does provide a getMyAttribute() in the generated interfaces
via the inheritance relationship between the generated interfaces
for the base and the derived types. So this is an implementation bug which we
will fix in a future release. The work around is to list the attributes that
would have
been inherited explicitly within the restriction.

Sekhar Vajjhala
Sun Microsystems

>
>
> Thomas
>
> PS: Please also see the thread "derived attribute not accepted when
> validating", June, 19th, where I had mentioned this giving a different
> example.
>
> ------------------------------------------------------------------------
> Name: AttribInRestriction.xml
> AttribInRestriction.xml Type: Works Project File (text/xml)
> Encoding: 7bit
>
> Name: AttribInRestriction.xsd
> AttribInRestriction.xsd Type: Plain Text (text/plain)
> Encoding: 7bit