0

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.

NeplatnyUdaj
  • 6,052
  • 6
  • 43
  • 76

2 Answers2

1

mmm I had a similar issue, but with properties.. I don't ahve the full xsd to check, but provided you want to change the OUTER item tag into something else, try this one:

    <?xml version="1.0"?>
    <jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        jxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <jxb:bindings schemaLocation="../yourlocation/yourschema.xsd" version="1.0">
            <!-- Customise the package name -->

            <jxb:schemaBindings>
                <jxb:package name="whatyouwant.something"/>
            </jxb:schemaBindings>

            <!-- rename the value element -->
            <jxb:bindings node="//xs:complexType[@name='TrafficCountsReplyData']//xs:sequence//xs:element[@name='counts']//xs:complexType//xs:sequence//xs:element[@name='item']">
                     <jaxb:class name="Lulz"/>
            </jxb:bindings>
        </jxb:bindings>
    </jxb:bindings> 

If this seems not to work if you can disclose the xml I should be able to help you furthe (on vacation until monday in case) , but consider that you were giving the wrong "path", jumping away a few "subelement" in your xpath expression. Let me know.

witchedwiz
  • 295
  • 2
  • 10
  • If I get it correctly, you've added the unnamed elements to the xpath, right? I've tried that now like you suggested, but the problem is the same... too many target nodes. And if I put there the full path to the innermost `item`, I still get `Illegal class inheritance loop`. I've also tried single-slash Xpath and creating binding entry for all occurences of `item`, but it also didn't help. I'm not sure I can disclose the XSDs, but the complete schema is about 3MB large anyway and I have other binding files fixing other issues... – NeplatnyUdaj Mar 13 '15 at 17:38
0

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.

Community
  • 1
  • 1
NeplatnyUdaj
  • 6,052
  • 6
  • 43
  • 76