2

I'm generating java code based on various WSDL's. We have a different WSDL for every new version of the WebService that we release, each with its own namespace.

The thing is that normally the changes are minimal from one release to another, but I want to keep classes divided by namespace.

Is there a way to configure JAXB so that the auto generated classes implement a single interface/extend a single class, so I can refer to either of them without changing my code?

Dummy example:

WebService method: listScripts(ResultSize size);

Auto generated classes:

  • com.test.ws1.ResultSize
  • com.test.ws2.ResultSize

Both classes are exactly the same. Is there a way to arrange them in a class hierarchy so my code is isolated from changes in version numbers? i.e. a com.test.ResultSize interface implemented by both classes?

skaffman
  • 398,947
  • 96
  • 818
  • 769
German
  • 3,560
  • 7
  • 32
  • 34

2 Answers2

1

XJC has an extension for this purpose

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           jaxb:extensionBindingPrefixes="xjc"
           jaxb:version="2.0">

    <xs:annotation>
       <xs:appinfo>
          <jaxb:globalBindings>
           <xjc:superClass name="com.mycompany.xml.UserRootObject"/>
          </jaxb:globalBindings>
       </xs:appinfo>
    </xs:annotation>
.
.
.
</xs:schema>

For more information see:

The schema annotations can also be supplied via an external bindings file. For an example see:

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Good answer, although this has the disadvantage that produces a super class for all the generated code, not just a specific class. – German Jan 12 '11 at 16:10
  • This doesn't answer German's question since, as himself pointed out, applies to ALL the generated classes, not only the ones he wants to tweak... – Clint Eastwood Dec 18 '13 at 12:13
1

It turned out that I can use a plugin provided in the JAXB2 Basics package:

Inheritance plugin

With this plugin I can specify different super classes for my generated ones, although I couldn't make the auto generated enums to implement a given interface.

To use it in Maven it was a pain (I'm generating classes from a WSDL, not using JAXB directly), so I switched to an external Ant task as specified in this blog

German
  • 3,560
  • 7
  • 32
  • 34