0

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.

Balz Guenat
  • 1,552
  • 2
  • 15
  • 35
  • You throw in a lot of things there. Please describe one specific scenario when this does not work - including all the relevant files (MCVE). Few notes. Modular schema compilation is tricky. Really, don't use inline customizations. Try adding `if-exists="true"` to `jaxb:bindings` in the generated episode files (just to see if it helps). I compile a lot of schemas with modular compilation but I don't use inline customizations ever. – lexicore Jun 21 '19 at 08:20
  • The two given files a.xsd and b.xsd, together with the two xjc calls ("xjc -extensions -episode a.ep a.xsd and then xjc -extensions b.xsd -b a.ep") are enough to demonstrate the issue. I first encountered the issue while using your own maven plugin, which uses if-exists="true" by default, so that doesn't help. – Balz Guenat Jun 22 '19 at 09:53

0 Answers0