xjc fails on imported schema when using episodes due to property customization

怎甘沉沦 提交于 2019-12-11 17:21:13

问题


I have two schemas a.xsd and b.xsd. b imports a. On one element, a customizes the JAXB compilation.

a.xsd:

<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    targetNamespace="a"
    xmlns:a="a"
    jaxb:version="2.0"
    elementFormDefault="qualified">

    <xsd:element name="a" type="a:A1Type"/>

    <xsd:complexType name="A1Type">
        <xsd:sequence>
            <xsd:element name="a" type="xsd:string">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jaxb:property name="a0"></jaxb:property>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>

b.xsd:

<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="b"
    xmlns:a="a"
    xmlns:b="b"
    elementFormDefault="qualified">

    <xsd:import namespace="a" schemaLocation="a.xsd"/>

</xsd:schema>

xjc -extensions a.xsd works, as does xjc -extensions a.xsd b.xsd. However, if I do xjc -extensions -episode a.ep a.xsd and then xjc -extensions b.xsd -b a.ep, compilation fails with the following error

[ERROR] compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings.
  line 16 of file:/D:/episode/d/src/main/resources/a.xsd

[ERROR] (the above customization is attached to the following location in the schema)
  line 13 of file:/D:/episode/d/src/main/resources/a.xsd

If I remove the <xsd:annotation> from a.xsd, everything works.

Why do I get this error and how can I make this work with the customization and episodes?

Edit: Some findings from my own investigations:

I found this question which sounded very similar. The answer suggests to use an external binding file instead of inline customizations. I tried this out and created a binding file bindings.xjb including the following.

   <jaxb:bindings schemaLocation="a.xsd" node="/xs:schema">
      <jaxb:bindings node="xs:complexType[@name='A1Type']/xs:sequence/xs:element">
         <jaxb:property name="a0"></jaxb:property>
      </jaxb:bindings>
   </jaxb:bindings>

With this, the two-step compilation works and has the correct customization. If I include the bindings.xjb in the second step, i.e. xjc -extension b.xsd -b a.ep -b bindings.xjb, I once again get the error.

Because I was curious, I included the customization in a's episode file a.ep and tried running xjc -extension b.xsd -b a.ep once again. This again gave the error.

This leads me to believe that JAXB/xjc sees the customization as incompatible with the episode's <class> binding, even if the referenced class agrees with the customization.

It would seem then, that inline customization and modular schema compilation with episodes are incompatible with each other. This is impractical, so I would love to be proven wrong here.

来源:https://stackoverflow.com/questions/56686096/xjc-fails-on-imported-schema-when-using-episodes-due-to-property-customization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!