29

我有两个使用 JAXB 处理的模式。第一个模式经过预处理,并使用剧集文件使用其信息(遵循http://www.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21)。第二个模式导入第一个,并再次使用 jaxb 进行处理。这一切都按预期工作。

但是现在我在第一个模式中有一个元素,在第二个模式中使用引用。

架构一:

<schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://www.example.org/Test/"
targetNamespace="http://www.example.org/Test/">
<element name="type" type="test:MyType"></element>

模式 b:

<schema elementFormDefault="qualified" 
xmlns="http://www.w3.org/2001/XMLSchema" 
xmlns:second="http://www.example.org/Second/"
xmlns:test="http://www.example.org/Test/"
targetNamespace="http://www.example.org/Second/">

<import namespace="http://www.example.org/Test/" />

<complexType name="SomeType">
    <sequence>
        <element ref="test:type" minOccurs="1" maxOccurs="unbounded" />
    </sequence>
</complexType>

在处理过程中没有任何问题,但是为两种模式生成的代码提供了相同的方法:

public JAXBElement<EventType> createType(TypeType value)

在运行时,这会导致以下错误:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of 
    IllegalAnnotationExceptions
The element name {http://www.example.org/Type/}type has more than one mapping.

如何防止 JAXB 创建重复的 createType 方法?

提前致谢!

更新:我在 JAXB 邮件列表上问了同样的问题,在该列表上我还发布了一个工作示例。可以在以下位置找到线程和示例:http: //java.net/projects/jaxb/lists/users/archive/2011-03/message/18

在这个列表中,有人向我建议了一个解决方法,现在我可以按照我喜欢的方式使用这些模式。但我仍然认为 JAXB 不应该创建额外的“创建”方法,因为它应该已经在剧集文件中。

4

1 回答 1

1

我一天中写了一些模式定义。您在第二个模式声明中声明了您的第一个 xsd,然后您正在导入它。

根据 MSDN,当您导入 XSD 时,您不会将其包含在架构声明中。这是它在您的模式声明中的位置。

xmlns:test="http://www.example.org/Test/"

删除它并进行导入... ( <xs:import namespace="http://www.example.com/IPO" /> )

请参阅:http: //msdn.microsoft.com/en-us/library/ms256480.aspx

于 2011-05-03T22:31:39.307 回答