users@jaxb.java.net

attribute inheritance

From: Anders Hessellund <anders.hessellund_at_gmail.com>
Date: Wed, 23 Sep 2009 12:07:01 +0200

Hi,

Suppose you have the following schema:

 <xs:complexType name="XB">
   <xs:attribute name="a1" type="xs:int"/>
   <xs:attribute name="a2" type="xs:int" default="2"/>
 </xs:complexType>

 <xs:complexType name="X1">
   <xs:complexContent>
     <xs:restriction base="XB">
       <xs:attribute name="a1" type="xs:int" default="11"/>
     </xs:restriction>
   </xs:complexContent>
 </xs:complexType>

 <xs:complexType name="X2">
   <xs:complexContent>
     <xs:restriction base="XB">
       <xs:attribute name="a1" type="xs:int" default="21"/>
     </xs:restriction>
   </xs:complexContent>
 </xs:complexType>

You get the following generated code

 public class XB {
   @XmlAttribute
   protected Integer a1;
   @XmlAttribute
   protected Integer a2;

   public Integer getA1() {
     return a1;
   }

   ...

   public int getA2() {
     if (a2 == null) {
       return 2;
       } else {
       return a2;
     }
   }
   ...
 }

 public class X1
 extends XB
 {
 }

 public class X2
 extends XB
 {
 }

Why are attributes not generated in the subclasses? Is this a bug? It
seems like a fairly trivial thing to do (without knowing anything
about the implementation).

Cheers,

Anders

-- 
Anders Hessellund
www.itu.dk/people/hessellund/