julien julien - 4 months ago 23
Java Question

Solve JAXB "name collision in the ObjectFactory class" problem with customisation

Executing a "xjc" command on these xsd files returns a

Two declarations cause a collision in the ObjectFactory class
because there are 2 elements named "Scale" and "scale".

According to this page, this problem may be solved by customizing the xsd files with
<factoryMethod>
.

Do you know how to do that? Do you have an example of binding file to do that?

Answer

You can use the bindings tag. Set the schemaLocation attribute to the location of a particular xsd. The child tags, schemaBindings and package, then define a new package namespace for that xsd. Below is the bindings file I used with xjc a while ago. If it still works, great. If not, example =).

<?xml version="1.0" ?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1"
      xmlns:kml="http://www.opengis.net/kml/2.2"
      xmlns:atom="http://www.w3.org/2005/Atom">

  <bindings schemaLocation="ogckml22.xsd">
    <schemaBindings>
      <package name="net.opengis.kml"/>
    </schemaBindings>
  </bindings>
  <bindings schemaLocation="kml22gx.xsd">
    <schemaBindings>
      <package name="net.opengis.kml.ex"/>
    </schemaBindings>
  </bindings>
  <bindings schemaLocation="atom-author-link.xsd">
    <schemaBindings>
      <package name="org.w3c.atom"/>
    </schemaBindings>
  </bindings>
  <bindings schemaLocation="xAL.xsd">
    <schemaBindings>
      <package name="org.oasis.xal"/>
    </schemaBindings>
  </bindings>
  <bindings scd="kml:scale">
    <class name="scaleliteral"/>
  </bindings>
  <bindings scd="kml:snippet">
    <class name="snippetliteral"/>
  </bindings>
  <bindings scd="kml:Snippet">
    <property name="snippetDeprecated"/>
  </bindings>
  <bindings scd="atom:link">
    <property name="atomLink"/>
  </bindings>
</bindings>
Comments