WebService客户端和列表< JAXBElement<?>> [英] WebService Client and List<JAXBElement<?>>

查看:132
本文介绍了WebService客户端和列表< JAXBElement<?>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从wsdl文档生成客户端时,我得到一个似乎有很多JAXBElement属性的客户端,例如

When I try to generate a client from a wsdl document, I get a client that seems to have a lot of JAXBElement atributes, for instance

protected List<JAXBElement<?>> nameOrLinkingNameOrFamilyName;

我使用soapUI生成apache cxf 2.3.3作为工具,也作为配置文件生成以下内容:

I use soapUI to generate with apache cxf 2.3.3 as tool, also as config file the following:

<jaxb:bindings version="2.1"
 xmlns:jaxb="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"> 
 <jaxb:globalBindings generateElementProperty="false"/> 
</jaxb:bindings> 

据我所知,这与选择标签有关wsdl文件。

As far as I saw this is related with the choice tags in the wsdl document.

提前谢谢

推荐答案

A <$ c将为多个XML元素对应于同一Java类的选择属性生成$ c> JAXBElement 。这是为了保留有关元素的信息,因为这不能从值的类型派生。

A JAXBElement will be generated for choice properties where multiple XML elements will correspond to the same Java class. This is in order to preserve information about the element since this can not be derived from the type of the value.

binding.xml

以下JAXB模式绑定文件将确保生成选择属性:

The following JAXB schema bindings file will ensure that a choice property is generated:

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          version="2.1">
    <globalBindings choiceContentProperty="true"/>
</bindings> 






将生成的XML架构对象属性


XML Schema That Will Produce Object Property

在这个版本的XML模式中,所有XML元素都对应于不同的Java类:

In this version of the XML schema, all of the XML elements will correspond to a different Java class:

<xsd:choice>
    <xsd:element name="address" type="address"/>
    <xsd:element name="phone-number" type="phoneNumber"/>
    <xsd:element name="note" type="xsd:string"/>
</xsd:choice>

由于choice属性的值足以唯一标识元素,因此该属性不包含JAXBElement保留此信息:

Since the value of the choice property is sufficient to uniquely identify the element, the property does not contain a JAXBElement to preserve this information:

@XmlElements({
    @XmlElement(name = "address", type = Address.class),
    @XmlElement(name = "phone-number", type = PhoneNumber.class),
    @XmlElement(name = "note", type = String.class)
})
protected Object addressOrPhoneNumberOrNote;






将生成的XML架构 JAXBElement 属性


XML Schema That Will Produce JAXBElement Property

现在我们将修改选择结构,以便 note email 方法将对应 String 类。

Now we will modify the choice structure so that both the note and email methods will correspond to the String class.

<xsd:choice>
    <xsd:element name="address" type="address"/>
    <xsd:element name="phone-number" type="phoneNumber"/>
    <xsd:element name="note" type="xsd:string"/>
    <xsd:element name="email" type="xsd:string"/>
</xsd:choice>

由于choice属性的值不再足以唯一标识元素,因此该属性必须包含保存此信息的JAXBElement:

Since the value of the choice property is no longer sufficient to uniquely identify the element, the property must contain a JAXBElement to preserve this information:

@XmlElementRefs({
    @XmlElementRef(name = "phone-number", type = JAXBElement.class),
    @XmlElementRef(name = "email", type = JAXBElement.class),
    @XmlElementRef(name = "address", type = JAXBElement.class),
    @XmlElementRef(name = "note", type = JAXBElement.class)
})
protected JAXBElement<?> addressOrPhoneNumberOrNote;






更多信息

  • http://blog.bdoughan.com/2011/04/xml-schema-to-java-xsd-choice.html

这篇关于WebService客户端和列表&lt; JAXBElement&lt;?&gt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆