2010-10-27 116 views
0

我用CXF生成從WSDL類,但我不知道如何訪問以下字段:CXF/JAXB複雜類型

<s:complexType name="text-with-layout-type" mixed="true"> 
<s:sequence> 
<s:any minOccurs="0" maxOccurs="unbounded"/> 
</s:sequence> 
<s:attribute name="L" type="s:string"/> 
</s:complexType> 

生成的類是:

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "text-with-layout-type", propOrder = { 
    "content" 
}) 
public class TextWithLayoutType { 

    @XmlMixed 
    @XmlAnyElement(lax = true) 
    protected List<Object> content; 
    @XmlAttribute(name = "L") 
    protected String l; 

    /** 
    * 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 Object } 
    * {@link String } 
    * 
    * 
    */ 
    public List<Object> getContent() { 
     if (content == null) { 
      content = new ArrayList<Object>(); 
     } 
     return this.content; 
    } 

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

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

} 

我有一個對象類型,如果我試圖獲取數據使用

.getTextWithLayout().get(0).getContent() 

那麼如何讀取對象中的數據呢?

謝謝

+0

預期的內容是HTML/XHTML。 – BenoitD 2010-11-02 07:08:02

回答

0

您的複雜類型「text-with-layout-type」包含一個「any」標籤。這意味着JAXB需要能夠處理任何類型的數據,因此它將數據輸入爲Object。

使用代碼,您需要利用getClass()或instanceof來確定類型。如果你有特定的方式你想要這個屬性,然後讓我知道通過對問題的更新,我們可以討論替代映射來啓用該行爲。

+0

感謝您的回答。期望的內容是HTML/XHTML。 – BenoitD 2010-10-30 10:41:48

+0

有任何問題嗎? – BenoitD 2010-12-28 17:14:36