users@jaxb.java.net

Re: attribute inheritance

From: Anders Hessellund <anders.hessellund_at_gmail.com>
Date: Thu, 25 Feb 2010 13:04:58 +0100

Hi everyone,

I don't mean to be annoying but I never got an answer to the question below
about attribute inheritance. I am using version 2.1.12. Has support for
overriding default values been added since? And a related question: If I
declared an attribute in a supertype and then override it (restrict it) with
a fixed value in a subtype, why doesn't the generated code reflect this.

If xjc does not support it, is there perhaps a plugin which does?

Thanks,

Anders

On Wed, Sep 23, 2009 at 11:07 AM, Anders Hessellund <
anders.hessellund_at_gmail.com> wrote:

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



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