Skip to content

Plugin for XJC when you want to use JAXB Episode-files with wsImport

License

Notifications You must be signed in to change notification settings

etraveli/xjc-classref-mapper

 
 

Repository files navigation

xjc-classref-mapper

Allow episodes and classref to be used with wsimport

Usecase

Multiple WSDL (SOAP) services share a common header part (session). and you want to encapsulate the services because they evolve indenpendently (hence the multiple wsdl-files) But the authentication (session) is shared.

You want to mimic this at the consumer end.

Not out of the box

XJC supports "class ref" for binding Elements to existing classes, but this in not exposed in the Outline,
which is used to create a JAXBModel which in turns is used by WSImport.

The plugin will find all jaxb bindings with create an elementmapping(CElementInfo).
CElementInfo won't create a class, but an ObjectFactory will be created.
So the plugin will later remove that ObjectFactory so that it wont shadow the shared lib ObjectFactory.
(more precisely it will remove the class ref="" package and all it's classes)

Add jar to wsImport classpath add xjc argument -classref and it "should" produce generated code with references to existing.

This type of usecase exists under example/wsimport-episode as a separate project.

Development

For fancy development in the root (xjc-classref-mapper) you can bump the version
and run ./gradlew pTML then in example/wsimport-episode/build.gradle you
can bump the version of the plugin in and it will use the version in you maveLocal repo ~/.m2

When to try this plugin

You get the following typ of message when using wsimport:

 [ERROR] Schema descriptor {[namespace]}[element] in message part "[part]" is not defined and could not be bound to Java. Perhaps the schema descriptor {[namespace]}[element] is not defined in the schema imported/included in the WSDL. You can either add such imports/includes or run wsimport and provide the schema location using -b switch.

Disclaimer this has not been tested at runtime yet!!! It generates, it compiles, but it has not yet been used.

Its been tried a little more and there is now a version 0.0.2 Also since it removes in relation to package the episode must look something like this

!!The important part is that xjc -episode will generate the episode file with <schemaBindings map="false"> map needs to be change to true i.e <schemaBindings map="true">

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
      <!--
    
    This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.X
    See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
    Any modifications to this file will be lost upon recompilation of the source schema.
    Generated on: 2016.06.29 at 12:40:49 AM CEST
    
      -->
      <bindings scd="x-schema::tns" xmlns:tns="[namespace]">
        <schemaBindings map="true">
          <package name="[packageName]"/>
        </schemaBindings>
        <bindings scd="~tns:[complexTypeName]">
          <class ref="[fullyQualifiedClassname]"/>
        </bindings>
      </bindings>
    </bindings>

Using gradle or ant you can simply do:

ant.replace(file: "$generatedResources/META-INF/sun-jaxb.episode", token: "<schemaBindings map=\"false\">", value: "<schemaBindings map=\"true\">")

If you noticed the episode-file is located in META-INF and named sun-jaxb.episode. Nice thing is that it will be loaded if jar is added as argument for xjc

xjcarg(file: "${configurations.session.asPath}")

Usage

We/I are on bintray Add repo and dependency

repository {
    maven {
        url  "http://dl.bintray.com/npetzall/maven"
    }
}
dependencies {
    compile 'npetzall.xjc.plugin:xjc-classref-mapper:0.0.2'
}

About

Plugin for XJC when you want to use JAXB Episode-files with wsImport

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%