不会为JAXB生成XSD架构的选择属性

时间:2016-01-25 13:34:38

标签: java maven xsd jaxb

我有complexType的XSD架构,其中包含choice元素。

<xsd:complexType mixed="true" name="CreateApprovedPurchaseRequestType">
    <xsd:choice maxOccurs="unbounded" minOccurs="0">
      <xsd:element maxOccurs="unbounded" minOccurs="0" name="ALSRules" type="RuleSetType"/>
      <xsd:element name="CDFs">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="CDF" type="CDFType"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:choice>
    <xsd:attribute name="RequestId" type="xsd:string" use="optional"/>
  </xsd:complexType>

我想使用XSDJAXB架构maven-jaxb2-plugin类生成。当我运行maven命令clean install时,它生成complexType而没有错误。但choice元素不包含在类的属性中(也没有getter&amp; setters)。只有@XmlElementRef注释。

这是生成的类。

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for CreateApprovedPurchaseRequestType complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="CreateApprovedPurchaseRequestType"&gt;
 *   &lt;complexContent&gt;
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
 *       &lt;choice maxOccurs="unbounded" minOccurs="0"&gt;
 *         &lt;element name="ALSRules" type="{}RuleSetType" maxOccurs="unbounded" minOccurs="0"/&gt;
 *         &lt;element name="CDFs"&gt;
 *           &lt;complexType&gt;
 *             &lt;complexContent&gt;
 *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
 *                 &lt;sequence&gt;
 *                   &lt;element name="CDF" type="{}CDFType" maxOccurs="unbounded" minOccurs="0"/&gt;
 *                 &lt;/sequence&gt;
 *               &lt;/restriction&gt;
 *             &lt;/complexContent&gt;
 *           &lt;/complexType&gt;
 *         &lt;/element&gt;
 *       &lt;/choice&gt;
 *       &lt;attribute name="RequestId" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
 *     &lt;/restriction&gt;
 *   &lt;/complexContent&gt;
 * &lt;/complexType&gt;
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CreateApprovedPurchaseRequestType", propOrder = {
    "content"
})
public class CreateApprovedPurchaseRequestType {

    @XmlElementRefs({
        @XmlElementRef(name = "ALSRules", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "CDFs", type = JAXBElement.class, required = false)
    })
    @XmlMixed
    protected List<Serializable> content;
    @XmlAttribute(name = "RequestId")
    protected String requestId;

    /**
     * Gets the value of the content 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 content property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getContent().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link CreateApprovedPurchaseRequestType.CDFs }{@code >}
     * {@link String }
     * {@link JAXBElement }{@code <}{@link RuleSetType }{@code >}
     * 
     * 
     */
    public List<Serializable> getContent() {
        if (content == null) {
            content = new ArrayList<Serializable>();
        }
        return this.content;
    }

    /**
     * Gets the value of the requestId property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getRequestId() {
        return requestId;
    }

    /**
     * Sets the value of the requestId property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setRequestId(String value) {
        this.requestId = value;
    }

    /**
     * <p>Java class for anonymous complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType&gt;
     *   &lt;complexContent&gt;
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
     *       &lt;sequence&gt;
     *         &lt;element name="CDF" type="{}CDFType" maxOccurs="unbounded" minOccurs="0"/&gt;
     *       &lt;/sequence&gt;
     *     &lt;/restriction&gt;
     *   &lt;/complexContent&gt;
     * &lt;/complexType&gt;
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "cdf"
    })
    public static class CDFs {

        @XmlElement(name = "CDF")
        protected List<CDFType> cdf;

        /**
         * Gets the value of the cdf 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 cdf property.
         * 
         * <p>
         * For example, to add a new item, do as follows:
         * <pre>
         *    getCDF().add(newItem);
         * </pre>
         * 
         * 
         * <p>
         * Objects of the following type(s) are allowed in the list
         * {@link CDFType }
         * 
         * 
         */
        public List<CDFType> getCDF() {
            if (cdf == null) {
                cdf = new ArrayList<CDFType>();
            }
            return this.cdf;
        }

    }

}

我尝试使用绑定文件和设置权限生成。但它没有任何影响,我无法达到预期的效果。

<jxb:bindings
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        version="2.1">

        <jxb:globalBindings choiceContentProperty="true">
            <xjc:simple />
        </jxb:globalBindings>

</jxb:bindings>

0 个答案:

没有答案