gpt4 book ai didi

jaxb - xjc:无法兑现职业定制

转载 作者:行者123 更新时间:2023-12-01 04:51:25 26 4
gpt4 key购买 nike

我正在尝试从 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

最佳答案

当然,我应该想到的。我一发布问题,解决方案就出现了。

根据 JAXB "default binding rules" ,绑定(bind)编译器尝试为每个 Element 和每个命名的 ComplexType 创建一个 Java 类。发生冲突是因为 cxml.payment 用于两个名称。

在这种情况下,只需要这个简单的类定制:

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

教训是密切注意 xjc 错误消息中的行号。在这种情况下,他们一直将我指向第 2477 行。

关于jaxb - xjc:无法兑现职业定制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21171657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com