users@jaxb.java.net

Re: inheritance issue: elements (via xs:restriction) in xsd not showing up as fields in subclass in generated java file

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 26 Aug 2011 10:36:06 +0200

Deriving a complexType by restriction must repeat all the particle
components
of the base type, providing more restrictive facets or simple types.

Once the base type is mapped to a Java class, its properties are fixed; in
Java
there is no way to "override" the types of fields of a supertype in its
subtype.

The wildcard particle in PayloadType is mapped to List<Object> any, and this
property is what will contain the EndDeviceEvents element data from a
EndDeviceEventsPayloadType.

-W






On 12 May 2011 23:22, Daniel Kan <dkan_at_silverspringnet.com> wrote:

> I'm using xjc maven plugin to generate java classes from xsds, but am
> encountering some inheritance problem. I have two complexTypes:
> EndDeviceEventsPayloadType and PayloadType. EndDeviceEventsPayloadType
> inherits from PayloadType and additionally contains a reference to
> EndDeviceEvents via xs:restriction. The problem is that this reference
> fails to show up in the generated EndDeviceEventsPayloadType class.
> EndDeviceEventsPayloadType simply extends PayloadType as shown below. I
> would like to see a field called endDeviceEvents to show up in the
> EndDeviceEventsPayloadType class. I haven't yet tried custom bindings.
> Thanks in advance for any help.
>
> Dan
>
>
>
> /**
> * <p>Java class for EndDeviceEventsPayloadType complex type.
> *
> * <p>The following schema fragment specifies the expected content
> contained within this class.
> *
> * <pre>
> * &lt;complexType name="EndDeviceEventsPayloadType">
> * &lt;complexContent>
> * &lt;restriction
> base="{http://www.iec.ch/TC57/2010/schema/message}PayloadType">
> * &lt;sequence>
> * &lt;choice>
> * &lt;element
> ref="{http://iec.ch/TC57/2009/EndDeviceEvents#}EndDeviceEvents"/>
> * &lt;element name="Compressed"
> type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> * &lt;/choice>
> * &lt;element name="Format"
> type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> * &lt;/sequence>
> * &lt;/restriction>
> * &lt;/complexContent>
> * &lt;/complexType>
> * </pre>
> *
> *
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "EndDeviceEventsPayloadType")
> public class EndDeviceEventsPayloadType
> extends PayloadType
> {
>
>
> }
>
>
> /**
> * Payload container
> *
> * <p>Java class for PayloadType complex type.
> *
> * <p>The following schema fragment specifies the expected content
> contained within this class.
> *
> * <pre>
> * &lt;complexType name="PayloadType">
> * &lt;complexContent>
> * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> * &lt;sequence>
> * &lt;choice>
> * &lt;any namespace='##other' maxOccurs="unbounded"
> minOccurs="0"/>
> * &lt;element name="Compressed"
> type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> * &lt;/choice>
> * &lt;element name="Format"
> type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
> * &lt;/sequence>
> * &lt;/restriction>
> * &lt;/complexContent>
> * &lt;/complexType>
> * </pre>
> *
> *
> */
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "PayloadType", propOrder = {
> "any",
> "compressed",
> "format"
> })
> @XmlSeeAlso({
> EndDeviceEventsPayloadType.class
> })
> public class PayloadType {
>
> @XmlAnyElement(lax = true)
> protected List<Object> any;
> @XmlElement(name = "Compressed")
> protected String compressed;
> @XmlElement(name = "Format")
> protected String format;
>
>
>
>