xjc: unable to honor class customization

12,597

Well of course, I should have figured. As soon as I posted the question the solution presented itself.

According to JAXB "default binding rules", the binding compiler attempts to create a Java class for each Element and each named ComplexType. The collision was caused because cxml.payment was used for both names.

In this case, this simple class customization was all that was needed:

 <jxb:bindings node="//xs:element[@name='cxml.payment']/xs:complexType">
     <jxb:class name="CxmlInnerPaymentType" />
 </jxb:bindings>

The lesson is to pay close attention to the line numbers in the xjc error messages. In this case, they were pointing me to line 2477 all the time.

Share:
12,597
TomEE
Author by

TomEE

Updated on July 31, 2022

Comments

  • TomEE
    TomEE over 1 year

    I'm trying to generate code from a single ~7,000 line cXML schema file generated from a DTD. I've been able to resolve a handful of conflicts with xjc customizations, but this last one has me stumped.

    I've tried class and factory method customizations with no success.

    When I try to apply a factory method customization, I wind up with the message:

      [xjc] [ERROR] compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings.
    

    Others have run across this issue and have been able to resolve it. (This link was helpful.)

    I'm wondering if my problem has something to do with the abstract nature of the element.

    This detour has been frustrating and any help would be very much appreciated.

    Here is the fragment from the schema:

      <xs:element name="cxml.payment" abstract="true">
        <xs:complexType> <!-- Line 2477 -->
          <xs:sequence>
            <xs:element minOccurs="0" ref="PostalAddress"/>
          </xs:sequence>
          <xs:attributeGroup ref="PCard.attlist"/>
        </xs:complexType>
      </xs:element>
      <xs:complexType name="cxml.payment">
        <xs:sequence>
          <xs:element ref="cxml.payment"/>
        </xs:sequence>
      </xs:complexType>
    
      <xs:element name="Payment" type="cxml.payment" />
    
     <xs:element name="PCard" substitutionGroup="cxml.payment"/>
    
      <xs:attributeGroup name="PCard.attlist">
        <xs:attribute name="number" use="required" type="number"/>
        <xs:attribute name="expiration" use="required" type="date"/>
        <xs:attribute name="name" type="string"/>
      </xs:attributeGroup>
    

    Here are the raw errors:

    > compile:
    >      [echo] Compiling the schema...
    >       [xjc] Compiling file:/..cXML.xsd
    >       [xjc] [ERROR] A class/interface with the same name "cXML.CxmlPayment" is already in use. Use a class customization to
    > resolve this conflict.
    >       [xjc]   line 2477 of file:..cXML.xsd
    >       [xjc]
    >       [xjc] [ERROR] (Relevant to above error) another "CxmlPayment" is generated from here.
    >       [xjc]   line 2477 of file:..cXML.xsd
    >       [xjc]
    >       [xjc] [ERROR] (Relevant to above error) This confusing error happened most likely because the schema uses a technique called
    > "chameleon schema", which causes a single definition to be loaded
    > multiple times into different namespaces. See
    > http://forums.java.net/jive/thread.jspa?threadID=18631 for more about
    > this.
    >       [xjc]   line 2477 of file:..cXML.xsd
    >       [xjc]
    >       [xjc] [ERROR] Two declarations cause a collision in the ObjectFactory class.
    >       [xjc]   line 2477 of file:..cXML.xsd
    >       [xjc]
    >       [xjc] [ERROR] (Related to above error) This is the other declaration.
    >       [xjc]   line 2477 of file:..cXML.xsd
    >       [xjc]
    >       [xjc] failure in the XJC task. Use the Ant -verbose switch for more details