I'm trying to generate classes from wsdl using jaxws-maven-plugin
, but I get uncompilable results. The problem is this part of one of the xsds, where you can see that there are nested elements with the same name:
<xs:complexType name="TrafficCountsReplyData" abstract="true">
<xs:sequence>
<xs:element name="effectiveTrafficWindow" type="common:DateTimeMinutePeriod" minOccurs="1" maxOccurs="1"/>
<xs:element name="flows" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="item" type="flow:Flow" minOccurs="0" maxOccurs="100"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="counts" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="item" minOccurs="0" maxOccurs="1440">
<xs:complexType>
<xs:sequence>
<xs:element name="key" type="common:DateTimeMinutePeriod" minOccurs="1"
maxOccurs="1"/>
<xs:element name="value" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="item" minOccurs="1" maxOccurs="3">
<xs:complexType>
<xs:sequence>
<xs:element name="key" type="flight:TrafficType"
minOccurs="1" maxOccurs="1"/>
<xs:element name="value" type="flow:Counts" minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
As you can see, there there are multiple elements named item
. This result in multiple inner classes with the same name inside of the single class TrafficCountsReplyData
So I'm trying to put together a binding file which would rename one of them. When I try to rename the outer item
in the counts
element using this:
<jaxb:bindings node="//xs:complexType[@name='TrafficCountsReplyData']//xs:element[@name='counts']//xs:element[@name='item']">
<jaxb:class name="Lulz"/>
</jaxb:bindings>
I get the following error:
[ERROR] XPath evaluation of "//xs:complexType[@name='TrafficCountsReplyData']//xs:element[@name='counts']//xs:element[@name='item']" results in too many (2) target nodes
When I create the binding xpath expression for the inner one like this:
<jaxb:bindings node="//xs:complexType[@name='TrafficCountsReplyData']//xs:element[@name='counts']//xs:element[@name='item']//xs:element[@name='value']//xs:element[@name='item']">
Then I get following error:
java.lang.IllegalArgumentException: Illegal class inheritance loop. Outer class Lulz may not subclass from inner class: Lulz
I can't figure out how to make this work. Where does the inheritance come from? There's another item
in the flows
element, but that shouldn't be matched by the Xpath. Without the binding file, I can generate the sources. I have correct schema in the binding file, because I can for example rename the class generated by the parent element.
I've found the solution here: JAXB Customizations With a Poorly Formed WSDL
I had to add /xs:complexType
at the end of the Xpath. I guess it's because the root of the class is in fact the complexType and not enclosing xs:element. So it was like this:
<jaxb:bindings node="//xs:complexType[@name='TrafficCountsReplyData']//xs:element[@name='counts']/xs:complexType/xs:sequence/xs:element[@name='item']/xs:complexType">
<jaxb:class name="Lulz"/>
</jaxb:bindings>
Now I can generate classes and compile them.