Lex Uijthof created CXF-6201:
--------------------------------
Summary: Issue parsing xs:choice with maxoccurs attribute when
using cxf-codegen-plugin
Key: CXF-6201
URL: https://issues.apache.org/jira/browse/CXF-6201
Project: CXF
Issue Type: Bug
Components: JAXB Databinding
Affects Versions: 2.7.14
Environment: windows 7 Professional, JDK 1.7.0_71, mvn 3.2.3
Reporter: Lex Uijthof
I'm trying to create a client based on a WDSL and it's XSD's from an external
party.
I don't want to modify the XSD's manually, because the schema's change once in
a while.
In the plugins excecution part of my Pom I have the following configuration:
<configuration>
<additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
<defaultOptions>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/bindings.xjb</bindingFile>
</bindingFiles>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-xjc-Xvalue-constructor</extraarg>
<extraarg>-xjc-Xfluent-api</extraarg>
<extraarg>-xjc-Xcollection-setter-injector</extraarg>
<exreaarg>-autoNameResolution</exreaarg>
</extraargs>
</defaultOptions>
<sourceRoot>/${basedir}/src-generated/main/java/</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>/${basedir}/src/main/resources/bg0310/vraagAntwoord/bg0310_beantwoordVraag_vraagAntwoord.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
My bindings.xjb:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc"
version="2.1">
<jxb:globalBindings
underscoreBinding="asCharInWord"
fixedAttributeAsConstantProperty="true"
choiceContentProperty="false">
<jxb:javaType name="java.lang.Integer" xmlType="xs:int"/>
<jxb:javaType name="java.lang.Integer" xmlType="xs:positiveInteger"/>
</jxb:globalBindings>
</jxb:bindings>
The part of the XSD that is parsed incorrectly :
<complexType name="NPSNINING-basis">
<annotation>
<documentation>Gezamenlijk basistype voor Natuurlijk persoon, ingezetene
en niet-ingezetene</documentation>
</annotation>
<sequence>
<choice minOccurs="0" maxOccurs="2">
<element name="inp.bsn" type="BG:BSN-e" nillable="true" minOccurs="0"/>
<element name="authentiek" type="BG:Authentiek" default="N"
nillable="true" minOccurs="0"/>
<element name="anp.identificatie" type="BG:IdentificatieRPSBTL-e"
nillable="true" minOccurs="0"/>
</choice>
</sequence>
<attribute ref="StUF:entiteittype"/>
<attributeGroup ref="StUF:entiteit"/>
</complexType>
When parsed the following Java class is generated:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "NPSNINING-basis", propOrder = {
"inpBsnOrAuthentiekOrAnpIdentificatie"
})
public class NPSNININGBasis {
@XmlElements({
@XmlElement(name = "inp.bsn", type = BSNE.class, nillable = true),
@XmlElement(name = "authentiek", type = Authentiek.class, defaultValue
= "N", nillable = true),
@XmlElement(name = "anp.identificatie", type =
IdentificatieRPSBTLE.class, nillable = true)
})
protected List<Object> inpBsnOrAuthentiekOrAnpIdentificatie;
.
public List<Object> getInpBsnOrAuthentiekOrAnpIdentificatie() {
if (inpBsnOrAuthentiekOrAnpIdentificatie == null) {
inpBsnOrAuthentiekOrAnpIdentificatie = new ArrayList<Object>();
}
return this.inpBsnOrAuthentiekOrAnpIdentificatie;
}
public void setInpBsnOrAuthentiekOrAnpIdentificatie(List<Object>
inpBsnOrAuthentiekOrAnpIdentificatie) {
this.inpBsnOrAuthentiekOrAnpIdentificatie =
inpBsnOrAuthentiekOrAnpIdentificatie;
}
public NPSNININGBasis withInpBsnOrAuthentiekOrAnpIdentificatie(Object...
values) {
if (values!= null) {
for (Object value: values) {
getInpBsnOrAuthentiekOrAnpIdentificatie().add(value);
}
}
return this;
}
public NPSNININGBasis
withInpBsnOrAuthentiekOrAnpIdentificatie(Collection<Object> values) {
if (values!= null) {
getInpBsnOrAuthentiekOrAnpIdentificatie().addAll(values);
}
return this;
}
}
The globalbinding param choiceContentProperty="false" normally creates 3
different Jaxbelement type values for each element inside the choice and that
is what i need, because i need to be able to set nill='true' on eacht of these
elements.
When I just remove the maxOccurs="2" in the choice element, the following code
is generated:
@XmlAccessorType (XmlAccessType.FIELD)
@XmlType (
name = "NPSNINING-basis",
propOrder = {
"inpBsn",
"authentiek",
"anpIdentificatie"
})
public class NPSNININGBasis {
@XmlElementRef (
name = "inp.bsn",
namespace = "http://www.egem.nl/StUF/sector/bg/0310",
type = JAXBElement.class,
required = false
)
protected JAXBElement<BSNE> inpBsn;
@XmlElementRef (
name = "authentiek",
namespace = "http://www.egem.nl/StUF/sector/bg/0310",
type = JAXBElement.class,
required = false
)
protected JAXBElement<Authentiek> authentiek;
@XmlElementRef (
name = "anp.identificatie",
namespace = "http://www.egem.nl/StUF/sector/bg/0310",
type = JAXBElement.class,
required = false
)
public JAXBElement<BSNE> getInpBsn () {
return inpBsn;
}
public void setInpBsn (JAXBElement<BSNE> value) {
this.inpBsn = value;
}
public JAXBElement<Authentiek> getAuthentiek () {
return authentiek;
}
public void setAuthentiek (JAXBElement<Authentiek> value) {
this.authentiek = value;
}
public JAXBElement<IdentificatieRPSBTLE> getAnpIdentificatie () {
return anpIdentificatie;
}
public void setAnpIdentificatie (JAXBElement<IdentificatieRPSBTLE> value) {
this.anpIdentificatie = value;
}
public NPSNININGBasis withInpBsn (JAXBElement<BSNE> value) {
setInpBsn (value);
return this;
}
public NPSNININGBasis withAuthentiek (JAXBElement<Authentiek> value) {
setAuthentiek (value);
return this;
}
public NPSNININGBasis withAnpIdentificatie
(JAXBElement<IdentificatieRPSBTLE> value) {
setAnpIdentificatie (value);
return this;
}
}
This generated code is exactly what I need.
I believe there should not be any difference in parsing an xs:choice with a
maxOccurs and an xs:choice without a maxOccurs, since the maxOccurs attribure
is pure for validation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)