English 中文(简体)
1. 用XSD文档绘制阿雷拉目标图
原标题:Mapping an ArrayList of Object with XSD file

I m working with Java/Eclipse/Spring to create a Web Services. I m writing a XSD file with the structure for the Java Classes for the Web Services (Request, Response, etc). I used the option "Generate Jaxb Classes", over the XSD file, to create the Java classes. It is working fine for data types like int, string, long, etc, but, when my property is an ArrayList of Objects, the Java class generated doesn t have the "SET" method of the property. It only have the "GET" method.

例如:

XSD 档案:

<element name="GetPrizesAndCatalogsResponse">
    <complexType>
        <sequence>
            <element name="answerCode" type="int" />
            <element name="prizes" type="tns:SW_Prize" maxOccurs="unbounded"></element>
            <element name="prizesCatalog" type="tns:SW_Catalog" maxOccurs="unbounded"></element>            
            <element name="pagination" type="tns:SW_Pagination"></element>          
        </sequence>
    </complexType>
</element>

Java类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "answerCode",
    "prizes",
    "prizesCatalog",
    "pagination"
})
@XmlRootElement(name = "GetPrizesAndCatalogsResponse")
public class GetPrizesAndCatalogsResponse {

    protected int answerCode;
    @XmlElement(required = true)
    protected List<SWPrize> prizes;
    @XmlElement(required = true)
    protected List<SWCatalog> prizesCatalog;
    @XmlElement(required = true)
    protected SWPagination pagination;

    /**
     * Obtiene el valor de la propiedad answerCode.
     * 
     */
    public int getAnswerCode() {
        return answerCode;
    }

    /**
     * Define el valor de la propiedad answerCode.
     * 
     */
    public void setAnswerCode(int value) {
        this.answerCode = value;
    }

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

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

    /**
     * Obtiene el valor de la propiedad pagination.
     * 
     * @return
     *     possible object is
     *     {@link SWPagination }
     *     
     */
    public SWPagination getPagination() {
        return pagination;
    }

    /**
     * Define el valor de la propiedad pagination.
     * 
     * @param value
     *     allowed object is
     *     {@link SWPagination }
     *     
     */
    public void setPagination(SWPagination value) {
        this.pagination = value;
    }

}

我对XSD档案的定义是否正确? 是否需要在XML上添加另一个标签?

最佳回答

溶解:

there is a new method (I don t know if is it a new one) called "addAll". You can get your collection and then use addAll to add another collection.

法典:

getPrizesAndCatalogsResponse.getPrizes().addAll(newPrizes);
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签