简体   繁体   English

Wsdl2Java CXF - 生成JAXBElement列表而不是字段

[英]Wsdl2Java CXF - generating JAXBElement list instead of fields

I have following entry in my xsd file: 我在我的xsd文件中有以下条目:

<xsd:element name="isCaseCreationAllowedResponse">
    <xsd:complexType>
        <xsd:sequence>
            ....
            <xsd:element maxOccurs="1" minOccurs="0" name="operatorNote" type="xsd:string">
            </xsd:element>
            ....
            <xsd:sequence id="allowCaseWithNewContract">
                <xsd:element maxOccurs="1" minOccurs="1" name="allowCaseWithNewContract" type="xsd:boolean">
                </xsd:element>
                <xsd:choice minOccurs="0">
                    <xsd:element name="validationError" type="mnp:ErrorType"/>
                    <xsd:element name="internalError" type="mnp:ErrorType"/>
                    <xsd:element name="businessError" type="mnp:ErrorType"/>
                    <xsd:element name="externalError" type="mnp:ErrorType"/>
                </xsd:choice>
            </xsd:sequence>
            ....
            <xsd:sequence id="allowCaseWithExistingContract">
                <xsd:element maxOccurs="1" minOccurs="1" name="allowCaseWithExistingContract" type="xsd:boolean">
                </xsd:element>
                <xsd:choice minOccurs="0">
                    <xsd:element name="validationError" type="mnp:ErrorType"/>
                    <xsd:element name="internalError" type="mnp:ErrorType"/>
                    <xsd:element name="businessError" type="mnp:ErrorType"/>
                    <xsd:element name="externalError" type="mnp:ErrorType"/>
                </xsd:choice>
             </xsd:sequence>
             ....
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

Because of that sequence in sequence generated java file looks like this: 因为顺序生成的java文件序列如下所示:

public class OperationResponse {
    protected List<JAXBElement<?>> content;

    public List<JAXBElement<?>> getContent() {
        if (content == null) {
            content = new ArrayList<JAXBElement<?>>();
        }
        return this.content;
    } 
}

Is there any way to configure CXF/JAXB/JAXWS to generate fields in java class, not this not intuitive list. 有没有办法配置CXF / JAXB / JAXWS来生成java类中的字段,而不是这个不直观的列表。

WSDL can't be modified, so only wsdl2java can be configured. 无法修改WSDL,因此只能配置wsdl2java。 I tried xjc:simple in jaxb bindings, but it didn't work as I expect. 我试过xjc:简单的jaxb绑定,但它没有像我期望的那样工作。

I'm using CXF 2.7.5 with maven cxf-codegen-plugin. 我正在使用带有maven cxf-codegen-plugin的CXF 2.7.5。

With xjc I had following annotation 使用xjc我有以下注释

<xsd:schema>
    <xsd:annotation>
        <xsd:appinfo>
            <jaxb:globalBindings generateValueClass="false">
                <xjc:simple />
            </jaxb:globalBindings>
        </xsd:appinfo>
    </xsd:annotation>
</xsd:schema>

Generated class: 生成的类:

public class OperationResponse {
    protected String operatorNote;
    ....
    protected boolean allowCaseWithNewContract;
    @XmlElementRefs({
        @XmlElementRef for allowCaseWithExistingContract 
        @XmlElementRef for validationError and so on  
    })
    protected List<JAXBElement<?>>        validationErrorsAndAllowCaseWithExistingContractsAndInternalErrors;
}

Xjc with above configuration generated another JAXBelement list, that's why it didn't work as I expect (remove all list of JAXBElement and replace them with object containing proper fields). 具有上述配置的Xjc生成了另一个JAXBelement列表,这就是为什么它没有按预期工作的原因(删除所有JAXBElement列表并用包含适当字段的对象替换它们)。

EDIT 编辑

With following config: 使用以下配置:

<xsd:appinfo>
<jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true" choiceContentProperty="true">
</jaxb:globalBindings>
<jaxb:bindings>
    <jaxb:bindings node="//xsd:element[@name='isContractSigningAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowStandardContract']">
        <jaxb:property name="allowStandardContractSequence"/>
    </jaxb:bindings>
    <jaxb:bindings node="//xsd:element[@name='isContractSigningAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowOneVisitContract']">
        <jaxb:property name="allowOneVisitContractSequence" />
    </jaxb:bindings>
    <jaxb:bindings node="//xsd:element[@name='isCaseCreationAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowCaseWithNewContract']">
        <jaxb:property name="allowCaseWithNewContractSequence"/>
    </jaxb:bindings>
    <jaxb:bindings node="//xsd:element[@name='isCaseCreationAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowCaseWithExistingContract']">
        <jaxb:property name="allowCaseWithExistingContractSequence" />
    </jaxb:bindings>
</jaxb:bindings>
</xsd:appinfo>

I got something like this generated from wsdl2java: 我从wsdl2java生成这样的东西:

public class IsCaseCreationAllowedResponse {

    @XmlElement(required = true)
    protected String msisdn;
    protected String operator;
    protected String operatorNote;
    protected String routingNumber;
    @XmlElementRefs({
        @XmlElementRef(name = "internalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "externalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "validationError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "businessError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "allowCaseWithNewContract", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class)
    })
    protected List<JAXBElement<?>> allowCaseWithNewContractSequence;
    @XmlElementRefs({
        @XmlElementRef(name = "validationError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "externalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "businessError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "internalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
        @XmlElementRef(name = "allowCaseWithExistingContract", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class)
    })
    protected List<JAXBElement<?>> allowCaseWithExistingContractSequence;
    protected String mnpmContractId;
    protected String contractNumber;
    protected String ccbsAccountId;
    protected Boolean fixedNumber;
    protected String description;
    @XmlElement(required = true)
    protected OperatorListType activeOperators;

}

I had to add some id's to inner sequences for proper bindings. 我必须在内部序列中添加一些id才能正确绑定。

Is there any way to break allowCaseWithExistingContractSequence and allowCaseWithNewContractSequence lists into some objects with proper fields? 有没有办法打破allowCaseWithExistingContractSequenceallowCaseWithNewContractSequence列表到一些具有适当字段的对象?

I've the following settings in my bindings file and got rid of the JAXBElements and got nice fields :) 我在我的绑定文件中有以下设置,摆脱了JAXBElements并得到了很好的字段:)

<jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true" choiceContentProperty="true">

If you don't want the choice elements in 1 field (...Or...Or...) then set it to false . 如果您不想在1字段中选择元素(...或......或...),则将其设置为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM