3

我的 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>

由于按顺序生成的 java 文件看起来像这样:

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

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

有没有办法配置 CXF/JAXB/JAXWS 在 java 类中生成字段,而不是这个不直观的列表。

WSDL不能修改,所以只能配置wsdl2java。我在 jaxb 绑定中尝试了 xjc:simple,但它并没有像我预期的那样工作。

我正在使用带有 maven cxf-codegen-plugin 的 CXF 2.7.5。

使用 xjc 我有以下注释

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

生成的类:

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

具有上述配置的 Xjc 生成了另一个 JAXBelement 列表,这就是它没有按我预期工作的原因(删除所有 JAXBElement 列表并将它们替换为包含适当字段的对象)。

编辑

使用以下配置:

<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>

我得到了从 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;

}

我必须在内部序列中添加一些 id 才能正确绑定。

有没有办法将allowCaseWithExistingContractSequenceallowCaseWithNewContractSequence列表分解为一些具有适当字段的对象?

4

1 回答 1

1

我的绑定文件中有以下设置,并摆脱了 JAXBElements 并获得了不错的字段:)

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

如果您不希望 1 个字段中的选择元素(...或...或...),请将其设置为false

于 2013-09-02T13:27:14.053 回答