users@jaxb.java.net

List<JAXBElement<?>> incompatible with generated types

From: Jason Harrop <jharrop_at_gmail.com>
Date: Tue, 11 Dec 2007 11:43:30 +1100

Hi

I'm experimenting with JAXB to generate classes for a subset of the
WordprocessingML component of OOXML.

It is generating a class P with a member

    protected List<JAXBElement<?>> paragraphContent;

However, one of the object types which is allowed in the list is class
R. I've attached the complete classes below.

JAXB evidently thinks this is of type JAXBElement, but it isn't.

Any idea why this is happening and how to fix it?

I'm using jaxb-ri-20070917, and the XSD can be found at

    http://dev.plutext.org/trac/docx4j/browser/branches/jaxb/src/main/resources/wml-subset-document.xsd?format=raw

The relevant bits are:

  <xsd:complexType name="CT_P">
    <xsd:annotation>
            <xsd:appinfo>
                    <jaxb:class name="P"/>
            </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element minOccurs="0" ref="main:pPr"/>
      <xsd:group minOccurs="0" maxOccurs="unbounded" ref="main:EG_PContent"/>
    </xsd:sequence>
  </xsd:complexType>

 <xsd:group name="EG_PContent">
    <xsd:annotation>
            <xsd:appinfo>
                    <jaxb:property name="ParagraphContent" />
            </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:group minOccurs="0" maxOccurs="unbounded"
ref="main:EG_ContentRunContent"/>
    </xsd:sequence>
  </xsd:group>

  <xsd:group name="EG_ContentRunContent">
    <xsd:choice>
      <xsd:element ref="main:r"/>
      <xsd:group minOccurs="0" maxOccurs="unbounded"
ref="main:EG_RunLevelElts"/>
    </xsd:choice>
  </xsd:group>

  <xsd:element name="r" type="main:CT_R"/>

  <xsd:complexType name="CT_R">
    <xsd:annotation>
            <xsd:appinfo>
                    <jaxb:class name="R"/>
            </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element minOccurs="0" ref="main:EG_RPr"/>
      <xsd:group minOccurs="0" maxOccurs="unbounded"
ref="main:EG_RunInnerContent"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:group name="EG_RunLevelElts">
    <xsd:choice>
      <xsd:element minOccurs="0" ref="main:ins"/>
      <xsd:element minOccurs="0" ref="main:del"/>
    </xsd:choice>
  </xsd:group>

thanks

Jason


/**
 * <p>Java class for CT_P complex type.
 *
 * <p>The following schema fragment specifies the expected content
contained within this class.
 *
 * <pre>
 * &lt;complexType name="CT_P">
 * &lt;complexContent>
 * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 * &lt;sequence>
 * &lt;element
ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pPr"
minOccurs="0"/>
 * &lt;group
ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}EG_PContent"
maxOccurs="unbounded" minOccurs="0"/>
 * &lt;/sequence>
 * &lt;/restriction>
 * &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CT_P", propOrder = {
    "pPr",
    "paragraphContent"
})
public class P {

    protected PPr pPr;
    @XmlElementRefs({
        @XmlElementRef(name = "del", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class),
        @XmlElementRef(name = "r", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class),
        @XmlElementRef(name = "ins", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class)
    })
    protected List<JAXBElement<?>> paragraphContent;

    /**
     * Gets the value of the pPr property.
     *
     * @return
     * possible object is
     * {_at_link PPr }
     *
     */
    public PPr getPPr() {
        return pPr;
    }

    /**
     * Sets the value of the pPr property.
     *
     * @param value
     * allowed object is
     * {_at_link PPr }
     *
     */
    public void setPPr(PPr value) {
        this.pPr = value;
    }

    /**
     * Gets the value of the paragraphContent property.
     *
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the
paragraphContent property.
     *
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     * getParagraphContent().add(newItem);
     * </pre>
     *
     *
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {_at_link JAXBElement }{_at_code <}{_at_link RunTrackChange }{_at_code >}
     * {_at_link JAXBElement }{_at_code <}{_at_link R }{_at_code >}
     * {_at_link JAXBElement }{_at_code <}{_at_link RunTrackChange }{_at_code >}
     *
     *
     */
    public List<JAXBElement<?>> getParagraphContent() {
        if (paragraphContent == null) {
            paragraphContent = new ArrayList<JAXBElement<?>>();
        }
        return this.paragraphContent;
    }

}


/**
 * <p>Java class for CT_R complex type.
 *
 * <p>The following schema fragment specifies the expected content
contained within this class.
 *
 * <pre>
 * &lt;complexType name="CT_R">
 * &lt;complexContent>
 * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 * &lt;sequence>
 * &lt;element
ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}EG_RPr"
minOccurs="0"/>
 * &lt;group
ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}EG_RunInnerContent"
maxOccurs="unbounded" minOccurs="0"/>
 * &lt;/sequence>
 * &lt;/restriction>
 * &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CT_R", propOrder = {
    "rPr",
    "runContent"
})
public class R {

    @XmlElementRef(name = "EG_RPr", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class)
    protected JAXBElement<CTRPr> rPr;
    @XmlElementRefs({
        @XmlElementRef(name = "delInstrText", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class),
        @XmlElementRef(name = "delText", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class),
        @XmlElementRef(name = "cr", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
Cr.class),
        @XmlElementRef(name = "instrText", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class),
        @XmlElementRef(name = "br", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
Br.class),
        @XmlElementRef(name = "softHyphen", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
SoftHyphen.class),
        @XmlElementRef(name = "noBreakHyphen", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
NoBreakHyphen.class),
        @XmlElementRef(name = "t", namespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", type =
JAXBElement.class)
    })
    protected List<Object> runContent;

    /**
     * Gets the value of the rPr property.
     *
     * @return
     * possible object is
     * {_at_link JAXBElement }{_at_code <}{_at_link CTRPr }{_at_code >}
     * {_at_link RPrZZ }
     *
     */
    public JAXBElement<CTRPr> getRPr() {
        return rPr;
    }

    /**
     * Sets the value of the rPr property.
     *
     * @param value
     * allowed object is
     * {_at_link JAXBElement }{_at_code <}{_at_link CTRPr }{_at_code >}
     * {_at_link RPrZZ }
     *
     */
    public void setRPr(JAXBElement<CTRPr> value) {
        this.rPr = ((JAXBElement<CTRPr> ) value);
    }

    /**
     * Gets the value of the runContent property.
     *
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the
runContent property.
     *
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     * getRunContent().add(newItem);
     * </pre>
     *
     *
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {_at_link JAXBElement }{_at_code <}{_at_link Text }{_at_code >}
     * {_at_link JAXBElement }{_at_code <}{_at_link Text }{_at_code >}
     * {_at_link Cr }
     * {_at_link JAXBElement }{_at_code <}{_at_link Text }{_at_code >}
     * {_at_link Br }
     * {_at_link SoftHyphen }
     * {_at_link NoBreakHyphen }
     * {_at_link JAXBElement }{_at_code <}{_at_link Text }{_at_code >}
     *
     *
     */
    public List<Object> getRunContent() {
        if (runContent == null) {
            runContent = new ArrayList<Object>();
        }
        return this.runContent;
    }

}