3
votes

I have following entry in my xsd file:

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

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.

WSDL can't be modified, so only wsdl2java can be configured. I tried xjc:simple in jaxb bindings, but it didn't work as I expect.

I'm using CXF 2.7.5 with maven cxf-codegen-plugin.

With xjc I had following annotation

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

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:

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.

Is there any way to break allowCaseWithExistingContractSequence and allowCaseWithNewContractSequence lists into some objects with proper fields?

1
Can you tell us why xjc:simple was not working as you expected? Didn't you like the pluralization or did you get the same source code?MystyxMac
I responded in main question, because of comment length limitTomek Zaremba

1 Answers

1
votes

I've the following settings in my bindings file and got rid of the JAXBElements and got nice fields :)

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