0

I have following schema and corresponding bindings file. I use jaxb2 maven plugin to generate JAXB classes.

person.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="person">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="pType" type="pType" minOccurs="0" />
                <xs:element name="sex" type="xs:string"
                    minOccurs="1" />
                <xs:element name="dob" type="xs:string"
                    minOccurs="1" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
<!-- some more elements ignored for clarity.................
.......................... -->

    <xs:complexType name="pType">
        <xs:sequence>
            <xs:element name="category" type="xs:string"
                minOccurs="0" />
            <xs:element name="blahh" type="xs:string"
                minOccurs="0" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>

jaxb bindings

<jxb:bindings schemaLocation="person.xsd">
    <jxb:bindings node="//xs:complexType[@name='pType']">
        <jxb:class name="PersonType" />
    </jxb:bindings>
</jxb:bindings>

<jxb:bindings schemaLocation="person.xsd">
    <jxb:bindings
        node="//xs:element[@name='person']//xs:element[@name='pType']">
        <jxb:class ref="PersonType" />
    </jxb:bindings>
</jxb:bindings>

I have defined bindings to override the name for the <xs:complexType name="pType"> as PersonType. On XJC generation, it generates PersonType.class and PType.class.

If I define <xs:complexType name="pType"> internally inside the element <xs:element name="pType" > then it did not generate PType.class. But I have to declare <xs:complexType name="pType"> at the root level in schema, because this xs:complexType is referenced by other schemas as well.

I tried to override for both <xs:complexType name="pType"> and <xs:element name="pType" > in bindings and yet the PType.class gets generated.

How could I instruct it not to generate PType.class ?

ulab
  • 1,079
  • 3
  • 15
  • 45

1 Answers1

1

The problem was that I have 2 executions for each of the schemas (dependent schema person2.xsd and person.xsd) in maven-jaxb2-plugin. So I had manually written the episode file to reference the already created <xs:complexType name="pType"> and resolved the issue.

For the benefit of someone who has same problem, here are the plugin execution details and episode file. Please note that I did not use namespaces hence you find the scd is simple without namespace.

person-episode

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">

 <jaxb:bindings scd="x-schema::">
    <jaxb:bindings scd="/type::pType">
      <jaxb:class ref="org.wipo.pct.test.PersonType"/>
      <jaxb:package name="org.wipo.pct.test" />
    </jaxb:bindings>
  </jaxb:bindings>
</jaxb:bindings>

pom.xml

<execution>
        <id>person</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <schemaIncludes>
                <include>person.xsd</include>
            </schemaIncludes>
            <bindingIncludes>
                <include>pbindings.xjb</include>
            </bindingIncludes>
            <verbose>true</verbose>
        </configuration>
    </execution>
<execution>
    <id>person2</id>
    <phase>generate-sources</phase>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <schemaIncludes>
            <include>person2.xsd</include>
        </schemaIncludes>
        <bindingIncludes>
            <include>pbindings2.xjb</include>
        </bindingIncludes>
        <verbose>true</verbose>
        <args>
            <arg>-b</arg>
            <arg>src/main/resources/person-episode</arg>
            <arg>-Xsimplify</arg>
            <arg>-Xinheritance</arg>
        </args>
    </configuration>
</execution>
ulab
  • 1,079
  • 3
  • 15
  • 45