2010-10-27 105 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