我正在尝试从一个由DTD生成的大约7,000行cXML模式文件生成代码。我已经能够用xjc定制解决一些冲突,但最后一个问题让我感到困惑。
我已经尝试了类和工厂方法定制,但没有成功。
当我尝试应用工厂方法定制时,我得到了这样的消息:
[xjc] [ERROR] compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings.其他人也遇到了这个问题,并能够解决它。(This link很有帮助。)
我想知道我的问题是否与元素的抽象性质有关。
这条弯路令人沮丧,任何帮助都将不胜感激。
以下是模式中的片段:
<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>以下是原始错误:
> 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发布于 2014-01-18 03:54:41
当然,我应该想到的。当我发布这个问题时,解决方案就出现了。
根据Java,绑定编译器尝试为每个元素和每个命名的ComplexType创建一个"default binding rules"类。导致冲突的原因是两个名称都使用cxml.payment。
在这种情况下,需要的就是这个简单的类定制:
<jxb:bindings node="//xs:element[@name='cxml.payment']/xs:complexType">
<jxb:class name="CxmlInnerPaymentType" />
</jxb:bindings>教训是要密切关注xjc错误消息中的行号。在这种情况下,他们一直将我指向2477行。
https://stackoverflow.com/questions/21171657
复制相似问题