编译器无法兑现此ci:代码自定义。它附加到错误的位置,或与其他绑定不一致

时间:2015-01-09 19:07:08

标签: java xml jaxb xsd xjc

使用jaxb xjc从模式生成java类,我试图自定义绑定以将java代码注入到生成的java类中。

我使用的模式是标准模式,但是对于此模式中的每个元素,我想将java变量添加到模式中不存在的生成的java中。例如: 架构有元素:

<xs:element name="long-desc">
  <xs:complexType mixed="true">
    <xs:attribute name="id" type="xs:ID"/>
    <xs:attribute name="content-type"/>
    <xs:attribute name="specific-use"/>
    <xs:attribute ref="xml:lang"/>
  </xs:complexType>
</xs:element>

对于生成的java类,我想注入类似的代码:

@XmlAttribute(name = "sem-uri")
@XmlSchemaType(name = "anyURI")
protected String semUri;

所以我创建了一个如下所示的绑定文件:

<jxb:bindings multiple="true" node="//xs:element/xs:complexType[not(@mixed='true')]">
    <ci:code>
    @XmlAttribute(name = "sem-uri")
    @XmlSchemaType(name = "anyURI")
    protected String semUri;
    </ci:code>
</jxb:bindings>

但是当我使用xjc -Xinject-code -extension simpleBinding.schemalet ISOSTS.xsd -b binding.xjb -d C:\outputcode运行xjc时,我收到错误:

[ERROR] compiler was unable to honor this ci:code customization. It is attached to a wrong place, or its inconsistent with other bindings.
line 25 of file:/C:/helen/working/ISOSTS/dtd/testing/inject-code-2/binding.xjb

[ERROR] (the above customization is attached to the following location in the schema)
line 856 of file:/C:/helen/working/ISOSTS/dtd/testing/inject-code-2/ISOSTS.xsd

我发现当架构中的元素具有子元素mixed=true的属性xs:compleType时,我才会收到此错误:xs:complexType mixed="true"

有类似错误的人有命名冲突我确认不是。

任何人都可以帮助我吗?

先谢谢,海伦


编辑:1月12日:

我做了一个测试,让jaxb生成的所有java类扩展一个普通的java类,所以现在生成的java类看起来像

public class Num
    extends SpecificationDocumentElement
    implements Serializable 
    {...
    }

我的公共基类如下

public class SpecificationDocumentElement 
{
    @XmlAttribute(name = "sem-uri")
    @XmlSchemaType(name = "anyURI")
    protected String semUri;

    public String getSemUri() {
        return semUri;
    }

    public void setSemUri(String value) {
        this.semUri = value;
    }
}

我需要使用这些jaxb生成的java类来为xml文件执行marshall / unmarshall。当我尝试从xml文件解组到java对象时,我遇到了以下错误:

javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 66 counts of IllegalAnnotationExceptions
@XmlValue is not allowed on a class that derives another class.
this problem is related to the following location:
    at protected java.lang.String com.xsb.isosts.isosts.Num.content
    at com.xsb.isosts.isosts.Num
    at protected java.util.List com.xsb.isosts.isosts.ChemStruct.content
    at com.xsb.isosts.isosts.ChemStruct
    at protected java.util.List com.xsb.isosts.isosts.Title.content
    at com.xsb.isosts.isosts.Title
    at protected java.util.List com.xsb.isosts.isosts.Std.content
    at com.xsb.isosts.isosts.Std
    at protected java.util.List com.xsb.isosts.isosts.RelatedArticle.content
    at com.xsb.isosts.isosts.RelatedArticle
    at public com.xsb.isosts.isosts.RelatedArticle com.xsb.isosts.isosts.ObjectFactory.createRelatedArticle()
    at com.xsb.isosts.isosts.ObjectFactory
    .....

0 个答案:

没有答案