我正在尝试从 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.
Run Code Online (Sandbox Code Playgroud)
其他人也遇到过这个问题并且能够解决它。(这个链接很有帮助。)
我想知道我的问题是否与元素的抽象性质有关。
这次绕道令人沮丧,非常感谢任何帮助。
这是架构中的片段:
<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>
Run Code Online (Sandbox Code Playgroud)
以下是原始错误:
> 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
Run Code Online (Sandbox Code Playgroud)
嗯,当然,我应该想到的。我一发布问题,解决方案就出现了。
根据 JAXB “默认绑定规则”,绑定编译器尝试为每个 Element 和每个命名的 ComplexType 创建一个 Java 类。造成冲突的原因是两个名称都使用了 cxml. payment。
在本例中,只需要这个简单的类自定义即可:
<jxb:bindings node="//xs:element[@name='cxml.payment']/xs:complexType">
<jxb:class name="CxmlInnerPaymentType" />
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)
我们的教训是密切关注 xjc 错误消息中的行号。在这种情况下,他们一直将我指向第 2477 行。
| 归档时间: |
|
| 查看次数: |
15108 次 |
| 最近记录: |