[英]Use generated JAXB class with lists in web servise wsdl/xsd
I have class definition in xsd file. 我在xsd文件中有类定义。 I generated class using JAXB binding.
我使用JAXB绑定生成了类。 For lists I haven't setters.
对于列表,我没有设置者。
After that, I used this classes in my web services. 之后,我在Web服务中使用了此类。 I created wsdl + xsd for service.
我创建了wsdl + xsd服务。 But ... in xsd I haven't some field definition (for lists, because I haven't setters for these).
但是...在xsd中,我没有任何字段定义(对于列表,因为我没有这些设置方法)。
How can I generate correctly wsdl + xsd for my classes? 如何为我的班级正确生成wsdl + xsd?
Netbeans 7.3.1 + Glassfish Netbeans 7.3.1 + Glassfish
Sample code: Base XSD: 示例代码:基本XSD:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="B">
<xs:complexType>
<xs:sequence>
<xs:element name="FIELD1" type="xs:dateTime">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
I do JAX binding, so It generated class: 我做JAX绑定,所以它生成了类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"b"
})
@XmlRootElement(name = "A")
public class A {
@XmlElement(name = "B", required = true)
protected List<A.B> b;
public List<A.B> getB() {
if (b == null) {
b = new ArrayList<A.B>();
}
return this.b;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"field1"
})
public static class B {
@XmlElement(name = "FIELD1", required = true)
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar field1;
public XMLGregorianCalendar getFIELD1() {
return field1;
}
public void setFIELD1(XMLGregorianCalendar value) {
this.field1 = value;
}
}
} }
As You can see, there is no setter for b field... 如您所见,b字段没有设置器。
And I use it in web service: 我在网络服务中使用它:
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") A txt) {
return "Hello " + txt + " !";
}
So finnaly, I have wsdl + xsd, with A class, but with no field: 所以最后,我有wsdl + xsd,带有A类,但是没有字段:
<xs:complexType name="a"><xs:sequence/>
</xs:complexType>
JAXB doesn't generate setters for Collections. JAXB不会为Collection生成setter。 You can access your list with its getter then use the list methods to modify it.
您可以使用其getter访问列表,然后使用list方法对其进行修改。
Example: 例:
txt.getB().add(new B());
Source: See here for details. 来源:有关详细信息,请参见此处 。
After further analysis of the question, I think what you're looking for is the JiBX's BindGen Tool . 经过对问题的进一步分析,我认为您正在寻找的是JiBX的BindGen工具 。 It is a "tool used to generate a binding definition and matching schema definition from existing Java code".
它是“用于从现有Java代码生成绑定定义和匹配架构定义的工具”。
Hope this helps you further with your problem. 希望这可以帮助您进一步解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.