4

While trying to generate classes from a xsd, i got this error:

java.lang.IllegalArgumentException: Illegal class inheritance loop.  Outer class OrderPropertyList may not subclass from inner class: OrderPropertyList

My xsd define a element to group a unbounded element like this:

  <element minOccurs="0" name="orderPropertyList">
    <complexType>
      <sequence>
        <element maxOccurs="unbounded" name="orderProperty" type="tns:orderProperty" />
      </sequence>
    </complexType>
  </element>

And my customization binding follows as specified on this page, but it doesn´t work. Here my binding:

<jaxb:bindings schemaLocation="../xsd/Schema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='orderPropertyList']">
        <jaxb:class name="OrderPropertyList"/>
    </jaxb:bindings>
</jaxb:bindings>

My intention is to generate a individual class for orderPropertyList, not the default behave that is generating a inner class inside the root element of the xsd.

I´ve watched someone with the same intention here and here, but it doesn´t work properly for me. :(

JAXB version:

Specification-Version: 2.1
Implementation-Version: 2.1.8

Any help?

paulosuzart
  • 1,082
  • 2
  • 13
  • 28
  • This is a kind of horror situation, how to always generate classes without the use of inner classes? Oh god! If you use Weblogic 10 with jax-ws, you can't have inner classes inside you request/response types. Sad! – paulosuzart Sep 28 '08 at 02:55

5 Answers5

14

I believe what you need to to is set:

<jaxb:globalBindings localScoping="toplevel"/>

This will generate standalone classes instead of nested classes.

Doing

<jaxb:bindings schemaLocation="../xsd/Schema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='orderPropertyList']">
            <jaxb:class name="OrderPropertyList"/>
    </jaxb:bindings>
</jaxb:bindings>

is a redundant binding, since orderPropertyList will map by default to OrderPropertyList. The name of the package includes the outer class name it is nested in by default, so you're not changing that.

Also, if you did want to change the name of the generated class, I think the XPath would actually be:

<jaxb:bindings node="//xs:element[@name='orderPropertyList']/xs:complexType">

with complexType on the end. I think excluding this was what was causing the error message you got.

Abel
  • 56,041
  • 24
  • 146
  • 247
  • Without effect! I´ve tried to use toplevel and many combinations for xPath expression. When I use the toplevel localScoping I get: [xjc] [ERROR] A class/interface with the same name "order.OrderLineList" is already in use. Use a class customization to resolve this conflict. – paulosuzart Oct 09 '08 at 16:43
  • After override all definitions with the same name, one-by-one it worked! Urf! Lot of work involving more than 15 xsds to generate classes and solve conflicts... Thanks! – paulosuzart Oct 13 '08 at 21:37
2

It's really fun when you have a schema like the following:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
    <xsd:element name="TopLevelElement">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Something">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Something" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="somethingFieldA" type="xsd:string"/>
                                        <xsd:element name="somethingFieldB" type="xsd:string"/>
                                    </xsd:sequence>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

In this case, xjc seems to be trying to actually generate four classes called Something, one for each element named Something, and one for each of their complexTypes. So you need to provide a binding that hits each of these four elements and complex types specifically at the level where they occur in the schema (well really only three, because then the 4th can just become the lone Something class).

Jeff Evans
  • 1,257
  • 1
  • 15
  • 31
0

I believe this is happening because it's likely that the generated Java class representing the sequence of "orderProperty" is itself named "OrderPropertyList".

What I would do is first generate it without any custom bindings, and look at the class names and hierarchies that it generates. Then, consider what you want to override, and how.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • Actually, when i remove the binding i have the default behave: OrderPropertyList as a inner class of the root element. I´m using a custom binding to scape (even without succeed) from this situation. – paulosuzart Sep 27 '08 at 18:16
0

Entering this /xs:complexType at the end of the element helped in fixing the illegal class inheritance loop error.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
amit dahiya
  • 179
  • 1
  • 2
0

I needed to do customizations for a schema like the one jeff303 presented. My scenario was slightly different in that the schema was inlined within a WSDL document.

One thing pointed out by philvarner is that the node selection for the element should end with '/xs:complexType' and this seemed very important, as the compiler would continually generate an IllegalArgumentException related to looping inheritance without it.

These posts are related so I figured a link back would be helpful to someone 'googling' that ends up here.

Check out question 7881883

Community
  • 1
  • 1
dolbysurnd
  • 736
  • 1
  • 6
  • 14