JAXB SAXParseException while generating models from *.xsd delivered by EURID (EPP Protocol) - java

I'm trying to generate Java code from the *.xsd files delivered by EurID.
Currently I'm receiving several exceptions:
Error while parsing schema(s).Location [ file:~/src/main/resources/epp-1.0.xsd{375,32}].
org.xml.sax.SAXParseException; systemId: file:~/src/main/resources/epp-1.0.xsd; lineNumber: 375; columnNumber: 32; src-resolve: Cannot resolve the name 'eppcom:minTokenType' to a(n) 'type definition' component.
[ERROR] Error while parsing schema(s).Location [ file:~/src/main/resources/nsgroup-1.0.xsd{86,42}].
org.xml.sax.SAXParseException; systemId: file:~/src/main/resources/nsgroup-1.0.xsd; lineNumber: 86; columnNumber: 42; src-resolve: Cannot resolve the name 'euridcom:nsgType' to a(n) 'type definition' component.
[ERROR] Error while parsing schema(s).Location [ file:~/src/main/resources/domain-1.0.xsd{94,53}].
org.xml.sax.SAXParseException; systemId: file:~/src/main/resources/domain-1.0.xsd; lineNumber: 94; columnNumber: 53; src-resolve: Cannot resolve the name 'host:addrType' to a(n) 'type definition' component.
The Maven plugin configuration looks like following:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<bindingDirectory>src/main/resources</bindingDirectory>
<bindingIncludes>
<include>bindings.xml</include>
</bindingIncludes>
<extension>true</extension>
<debug>true</debug>
<args>
<arg>-extension</arg>
<arg>-Xnamespace-prefix</arg>
</args>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-namespace-prefix</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</plugin>
And the bindings.xml file:
<?xml version="1.0"?>
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://jaxb2-commons.dev.java.net/namespace-prefix http://java.net/projects/jaxb2-commons/sources/svn/content/namespace-prefix/trunk/src/main/resources/prefix-namespace-schema.xsd">
<jxb:bindings schemaLocation="authInfo-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.authInfo"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="authInfo"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="epp-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.epp"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="epp"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="eppcom-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.eppcom"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="eppcom"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="contact-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.contact"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="contact"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="contact-ext-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.contact.ext"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="contact-ext"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="domain-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.domain"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="domain"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="domain-ext-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.domain.ext"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="domain-ext"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="dss-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.dss"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="dss"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="dynUpdate-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.dynupdate"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="dynupdate"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="euridcom-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.euridcom"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="euridcom"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="host-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.host"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="host"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="idn-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.idn"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="idn"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="keygroup-1.1.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.keygroup"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="keygroup"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="nsgroup-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.nsgroup"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="nsgroup"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="poll-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.poll"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="poll"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="secDNS-1.1.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.secdns"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="secdns"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="registrar-1.0.xsd">
<jxb:schemaBindings>
<jxb:package name="eu.eurid.xml.epp.registrar"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="registrar"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
For the reference host.xsd file contents is here: http://pastebin.com/ZdAGrNXF
and eppcom.xsd is here: http://pastebin.com/hYSwXQ11
I've already spent like 5 days trying to figure out what is wrong - trying different combinations of maven plugin options etc.
The SO's community is my last chance now.
Thank you in advance for the tips.

I am changed xsd. Add attribute schemaLocation to import elements in all xsd schemas. Then generating of class was ok.
If I use catalog for resolving namespaces, then I have problems with duplicit definition of some elements.

The JRE/JDK I've used was not complete somehow. Installation of JDK with Java EE solved the problem of JaxB.

I had the same problem trying to validate xml with epp-1.0.xsd (http://www.iana.org/assignments/xml-registry/schema/epp-1.0.xsd) and replacing
<import namespace="urn:ietf:params:xml:ns:eppcom-1.0"/>
in epp-1.0.xsd file with
<import namespace="urn:ietf:params:xml:ns:eppcom-1.0" schemaLocation="http://www.iana.org/assignments/xml-registry/schema/eppcom-1.0.xsd"/>
solved the problem.

Related

JAXB apply bindings to more than one .xsd schema

I have several XML schemas over which I do not have control and I'd like to apply certain customizations when generating the Java classes via XJC.
Some customizations should apply to all .xsd files, but I'm not sure how to achieve this.
At the moment I have this .xjb file:
<jxb:bindings version="2.1"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance">
<jxb:bindings schemaLocation="../schemas/A.xsd">
<jxb:schemaBindings>
<jxb:package name="my.foo.a" />
</jxb:schemaBindings>
<jxb:bindings node="//xs:complexType[#name='A']">
<jxb:class name="A" />
<inheritance:implements>my.foo.interfaces.IA</inheritance:implements>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[#name='Device']">
<jxb:class name="Device" />
<inheritance:implements>my.foo.interfaces.IDevice</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../schemas/B.xsd">
<jxb:schemaBindings>
<jxb:package name="my.foo.b" />
</jxb:schemaBindings>
<jxb:bindings node="//xs:complexType[#name='B']">
<jxb:class name="B" />
<inheritance:implements>my.foo.interfaces.IB</inheritance:implements>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[#name='Device']">
<jxb:class name="Device" />
<inheritance:implements>my.foo.interfaces.IDevice</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
And this Ant task:
<taskdef name="xjc" classname="org.jvnet.jaxb2_commons.xjc.XJC2Task">
<classpath>
<fileset dir="../../dependencies/lib" >
<include name="activation-*.jar"/>
<include name="jaxb-api-*.jar"/>
<include name="jaxb-impl-*.jar"/>
<include name="jsr173_api-*.jar"/>
<include name="stax-api-*.jar"/>
<include name="jaxb2-basics-jaxb-xjc-*.jar"/>
<include name="jaxb-xjc-*.jar"/>
<include name="jaxb2-basics-ant-*.jar"/>
</fileset>
</classpath>
</taskdef>
<xjc destdir="../src" extension="true" header="false" binding="bindings.xjb">
<arg line="-Xinheritance"/>
<schema dir="../schemas">
<include name="*.xsd"/>
<exclude name="Foo.xsd"/>
</schema>
<!-- Plugins -->
<classpath>
<fileset dir="../../dependencies/lib">
<!-- JAXB2 Basics library -->
<include name="jaxb2-basics-*.jar"/>
<!-- JAXB2 Basics library dependencies -->
<include name="jaxb2-basics-runtime-*.jar"/>
<include name="jaxb2-basics-tools-*.jar"/>
<include name="javaparser-*.jar"/>
<include name="commons-beanutils-*.jar"/>
<include name="commons-lang-*.jar"/>
<include name="commons-logging-*.jar"/>
</fileset>
</classpath>
</xjc>
Finally what I would like to do is to somehow specify the common blocks (of which I have more than one), ie:
<jxb:bindings node="//xs:complexType[#name='Device']">
<jxb:class name="Device" />
<inheritance:implements>my.foo.interfaces.IDevice</inheritance:implements>
</jxb:bindings>
For all of my .xsd files.
Hypothetically, something like this:
<jxb:bindings version="2.1"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance">
<jxb:bindings schemaLocation="../schemas/*.xsd">
<jxb:bindings node="//xs:complexType[#name='Device']">
<jxb:class name="Device" />
<inheritance:implements>my.foo.interfaces.IDevice</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../schemas/A.xsd">
<jxb:schemaBindings>
<jxb:package name="my.foo.a" />
</jxb:schemaBindings>
<jxb:bindings node="//xs:complexType[#name='A']">
<jxb:class name="A" />
<inheritance:implements>my.foo.interfaces.IA</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../schemas/B.xsd">
<jxb:schemaBindings>
<jxb:package name="my.foo.b" />
</jxb:schemaBindings>
<jxb:bindings node="//xs:complexType[#name='B']">
<jxb:class name="B" />
<inheritance:implements>my.foo.interfaces.IB</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
How can I accomplish this?
So, for (the most part) using this answer here: https://stackoverflow.com/a/18592030/770023
I have managed to get the schema working, for reference all you need to do is set schemaLocation="*" (in order to read all the schemas, of course) and mark the binding elements with multiple="true" and required="false" since some schemas may contain those elements (one or more times), some may not contain them at all.
<jxb:bindings version="2.1"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance">
<jxb:bindings schemaLocation="*">
<jxb:bindings node="//xs:complexType[#name='Device']" multiple="true" required="false">
<inheritance:implements>my.foo.interfaces.IDevice</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
<!-- rest of the bindings (per schema ones) go here -->
</jxb:bindings>
Please note that for some (unknown to me) reason I had to remove the class bindings (eg. <jxb:class name="Device" />) for the file to be accepted by XJC.
It mostly works, what I haven't been able to get working is the inheritance:extends customization, which doesn't want to run under the same conditions as the implements one...

jaxb override package of a specific generated set of classes

I have a large third party xsd file that pulls in a whole bunch of other xsd files through imports. The whole thing generates over 1000 classes. When I tell the xjc (jaxb) processor to generate everything in a specific package I get all kinds of naming conflicts. If I don't specify a package, then the processor creates java packages using the target attributes in the xsd files, and the whole thing generates without any errors.
The problem is that the package structure is awful because the target names are chosen really poorly. Other developers hate it. They only need a few classes.
So what I've been trying to do is to give the processor a bindings.xml file where I want to specify certain classes to be generated in a given package name.
I've gone back and forth between documentation on Oracle's site, forums, samples. I can't quote every single iteration of my bindings file. My current incarnation is this:
<jaxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.1"
schemaLocation="heavy.xsd"
node="//xsd:element[#name='Error']"
>
<jaxb:bindings node="//xsd:element[#name='Error']">
<jaxb:package name="ABC"/>
</jaxb:bindings>
<jaxb:globalBindings
underscoreBinding="asCharInWord"
localScoping="toplevel"
typesafeEnumMaxMembers="10000"
generateElementClass="true"
>
</jaxb:globalBindings>
<!--
<jaxb:package name="ABC"/>
-->
<!--
<jaxb:schemaBindings>
<jaxb:package name="ABC"/>
</jaxb:schemaBindings>
-->
<!--
<jaxb:schemaBindings>
<jaxb:package name="ABC"/>
<jaxb:nameXmlTransform>
<jaxb:elementName prefix="Error"/>
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
-->
</jaxb:bindings>
No matter what I try, I have not yet seen it generate any classes in the ABC package. In this case I want Error to get generated in ABC. Any help would be greatly appreciated.
Unfortunately it is not possible to do what you want. I want the same thing and I'm in the same boat. But straight from Oracles mouth:
http://docs.oracle.com/cd/E19316-01/819-3669/bnbbt/index.html
Relevant Info:
name - is the name of the derived Java interface. It must be a legal Java interface name and must not contain a package prefix. The package prefix is inherited from the current value of package.
So there is simply no way on the element to specify a different package its inherited per xsd.
The way I would do it is more like this:
<?xml version="1.0" encoding="utf-8"?>
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1" jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="XSD1.xsd" node="/xs:schema">
<jxb:globalBindings>
<!-- -->
</jxb:globalBindings>
<jxb:schemaBindings xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jxb:package name="com.something">
</jxb:package>
</jxb:schemaBindings>
<jxb:bindings node="//xs:element[#name='Error']">
<jxb:class xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" name="MyError"/>
<jxb:property xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" name="Whatever"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="XSD2.xsd" node="/xs:schema">
<jxb:schemaBindings xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jxb:package name="com.somethingelse">
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
Here is an example of bindings.xjb file where java source is generated in primer.myPo package.
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="po.xsd" node="/xs:schema">
<jxb:globalBindings
fixedAttributeAsConstantProperty="false"
collectionType="java.util.Vector"
typesafeEnumBase="xs:NCName"
choiceContentProperty="false"
typesafeEnumMemberName="generateError"
enableFailFastCheck="false"
generateIsSetMethod="false"
underscoreBinding="asCharInWord"/>
<jxb:schemaBindings>
<jxb:package name="primer.myPo">
<jxb:javadoc><![CDATA[<body>Package level documentation for generated package primer.myPo.</body>]]>
</jxb:javadoc>
</jxb:package>
<jxb:nameXmlTransform>
<jxb:elementName suffix="Element"/>
</jxb:nameXmlTransform>
</jxb:schemaBindings>
<jxb:bindings node="//xs:complexType[#name='PurchaseOrderType']">
<jxb:class name="POType">
<jxb:javadoc>A <b>Purchase Order</b> consists of addresses and items.</jxb:javadoc>
</jxb:class>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[#name='USAddress']">
<jxb:class>
<jxb:javadoc><![CDATA[First line of documentation for a <b>USAddress</b>.]]></jxb:javadoc>
</jxb:class>
<jxb:bindings node=".//xs:element[#name='name']">
<jxb:property name="toName"/>
</jxb:bindings>
<jxb:bindings node=".//xs:element[#name='zip']">
<jxb:property name="zipCode"/>
</jxb:bindings>
</jxb:bindings> <!-- node="//xs:complexType[#name='USAddress']" -->
<jxb:bindings node="//xs:complexType[#name='Items']">
<jxb:bindings node=".//xs:element[#name='item']//xs:element[#name='quantity']">
<jxb:property generateIsSetMethod="true"/>
<jxb:bindings node="./xs:simpleType">
<jxb:javaType name="short"
parseMethod="javax.xml.bind.DatatypeConverter.parseShort"
printMethod="javax.xml.bind.DatatypeConverter.printShort" />
</jxb:bindings>
</jxb:bindings> <!-- node="//xs:complexType[#name='Items']" -->
<jxb:bindings node=".//xs:element[#name='USPrice']">
<jxb:property name="Price"/>
</jxb:bindings>
<jxb:bindings node=".//xs:attribute[#name='partNum']">
<jxb:property name="partNumber"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xs:simpleType[#name='USState']">
<jxb:typesafeEnumClass/>
</jxb:bindings>
<jxb:bindings node="//xs:simpleType[#name='ZipCodeType']">
<jxb:javaType name="int"
parseMethod="javax.xml.bind.DatatypeConverter.parseInt"
printMethod="javax.xml.bind.DatatypeConverter.printInt"/>
</jxb:bindings>
</jxb:bindings> <!-- schemaLocation="po.xsd" node="/xs:schema" -->
</jxb:bindings>

Generating web service proxy client for HR-XML PositionOpening WSDL

I'm trying to generate Java web service proxy client using Apache Axis2 for Position Opening WSDL provided by HR-XML Consortium. I'm using wsdl2java command-line tool to generate proxy client.
Command:
wsdl2java -uri http://ns.hr-xml.org/schemas/org_hr-xml/3_1_1/Services/Web_Services/WSDL/PositionOpening.wsdl -d adb -o hrxml-positionopening
Finally, I then try to convert the generated classes into JAR by calling ant jar.all. Unfortunately, it is failing to compile properly and throwing some errors. I don't know what the reasons are. There are more than 100 errors, but I have shown below the first 3 errors that appear at the top.
E:\axis2-1.5.4\bin\hrxml-positionopening>ant jar.all
Buildfile: build.xml
init:
pre.compile.test:
[echo] Stax Availability= true
[echo] Axis2 Availability= true
compile.src:
[javac] Compiling 3 source files to E:\axis2-1.5.4\bin\hrxml-positionopening\build\classes
[javac] E:\axis2-1.5.4\bin\hrxml-positionopening\src\org\hr_xml\www\_3\ws\PositionOpening_ServiceStub.java:315862: 'else' without 'if'
[javac] else
[javac] ^
[javac] E:\axis2-1.5.4\bin\hrxml-positionopening\src\org\hr_xml\www\_3\ws\PositionOpening_ServiceStub.java:315964: 'else' without 'if'
[javac] } else {
[javac] ^
[javac] E:\axis2-1.5.4\bin\hrxml-positionopening\src\org\hr_xml\www\_3\ws\PositionOpening_ServiceStub.java:315718: 'try' without 'catch' or 'finally'
[javac] try {
[javac] ^
Can somebody throw some light on this? My purpose is to convert this Position Opening WSDL into a JAR, so that I can use/call the functions directly from within my application.
EDIT:
Meantime, I even tried with wsimport tool of JAX-WS, but it is failing at the command itself.
E:\jdk1.6.0\bin>wsimport.exe -d hrxml-positionopening http://ns.hr-xml.org/schemas/org_hr-xml/3_1_1/Services/Web_Services/WSDL/PositionOpening.wsdl
error: Property "Type" is already defined.
line 1473 of http://ns.hr-xml.org/schemas/org_openapplications_platform/1_1/Common/OAGi/Components/Components.xsd
error: The following location is relevant to the above error
line 1480 of http://ns.hr-xml.org/schemas/org_openapplications_platform/1_1/Common/OAGi/Components/Components.xsd
error: com.sun.istack.internal.SAXParseException2: The following location is relevant to the above error
I've managed to find the reason why it was failing with wsimport tool of JAX-WS. From HR-XML and Java documentation, reason and its work around is explained as shown below:
JAX‐WS cannot process the supplied HR‐XML WSDLs and XSDs as supplied by the HR‐XML Consortium. There are no errors with the schemas or web service definitions, but the patterns and directory structures employed are not supported by the JAX processing engine. This is a limitation of JAX‐WS that will hopefully be rectified in future versions. To work around these issues, the following changes must be made.
The attribute type in file
org_openapplications_platform\1_1\Common\OAGi\Components\components.xsd
must be renamed for code generation.
However, still I don't have any idea/answer on why it was failing with Apache Axis2 while trying to build JAR using ant.
I was able to make it work by specifying this binding file in my call to wsimport "wsimport -b binding.xml ..."
(Note that I had the schemas on my local so the schemaLocation for Components.xsd would have to be changed in the xml below)
<jxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<!-- Raise theEnumMemberSizeCap limit -->
<jxb:bindings>
<jxb:globalBindings typesafeEnumMaxMembers="2000"/>
</jxb:bindings>
<jxb:bindings schemaLocation="DataQuery_wsdl/Components.xsd" version="1.0">
<!-- Customise the package name -->
<!--<schemaBindings>
<package name="com.example.schema"/>
</schemaBindings>-->
<!-- rename the value element -->
<jxb:bindings node="//xsd:complexType[#name='ContactType']">
<jxb:bindings node=".//xsd:attribute[#name='type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='DocumentReferenceType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='ClassificationType']">
<jxb:bindings node=".//xsd:attribute[#name='type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='ImageAttachmentType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='OpenAttachmentType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='SpecificationType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='EventType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='QualifiedAmountType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='TermABIEType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='DimensionABIEType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='CurrencyExchangeBaseType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='ProjectABIEType']">
<jxb:bindings node=".//xsd:attribute[#name='type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='AddressBaseType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='TaxABIEType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='AllowanceChargeABIEType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[#name='LocationABIEType']">
<jxb:bindings node=".//xsd:element[#ref='Type']">
<jxb:property name="TypeAttribute"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

How do I create JAXB bindings for docbook

When I run xjc against docbook.xsd, I get a lot of errors:
parsing a schema...
[ERROR] Property "Revision" is already defined. Use <jaxb:property> to resolve this conflict.
line 5965 of file:/C:/log/11/04/20/docbook-4.5/dbpoolx.xsd
[ERROR] The following location is relevant to the above error
line 521 of file:/C:/log/11/04/20/docbook-4.5/dbpoolx.xsd
[ERROR] Element "seealsoie" shows up in more than one properties.
line 1737 of file:/C:/log/11/04/20/docbook-4.5/dbhierx.xsd
[ERROR] The following location is relevant to the above error
line 1733 of file:/C:/log/11/04/20/docbook-4.5/dbhierx.xsd
[ERROR] Element "imageobjectco" shows up in more than one properties.
line 3526 of file:/C:/log/11/04/20/docbook-4.5/dbpoolx.xsd
[ERROR] The following location is relevant to the above error
line 3525 of file:/C:/log/11/04/20/docbook-4.5/dbpoolx.xsd
....etc.
I've tried this with docbook version 4.5 and version 5.0, but with the same result.
Any pointers would be apreciated.
Thanks.
You could use the following bindings file with the DocBook version 5 XML Schema:
binding.xml
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:docbook="http://docbook.org/ns/docbook"
version="2.1">
<jxb:globalBindings>
<xjc:simple />
</jxb:globalBindings>
<jxb:bindings schemaLocation="docbook.xsd">
<jxb:bindings node="//xs:attributeGroup[#name='db.common.attributes']/xs:attribute[#name='version']">
<jxb:property name="commonVersion"/>
</jxb:bindings>
<jxb:bindings node="//xs:attributeGroup[#name='db.common.attributes']/xs:attribute[#name='revision']">
<jxb:property name="commonRevision"/>
</jxb:bindings>
<jxb:bindings node="//xs:attributeGroup[#name='db.common.attributes']/xs:attribute[#ref='xml:lang']">
<jxb:property name="xmlLang"/>
</jxb:bindings>
<jxb:bindings node="//xs:attributeGroup[#name='db.common.linking.attributes']/xs:attribute[#ref='xlink:role']">
<jxb:property name="xlinkRole"/>
</jxb:bindings>
<jxb:bindings node="//xs:attributeGroup[#name='db.common.linking.attributes']/xs:attribute[#ref='xlink:type']">
<jxb:property name="xlinkType"/>
</jxb:bindings>
<jxb:bindings node="//xs:attributeGroup[#name='db.common.linking.attributes']/xs:attribute[#ref='xlink:title']">
<jxb:property name="xlinkTitle"/>
</jxb:bindings>
<jxb:bindings node="//xs:element[#name='table']/xs:complexType/xs:attribute[#name='title']">
<jxb:property name="titleAttribute"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
The command line to include the bindings is:
xjc -extension -d out -b binding.xml docbook.xsd

How do I rename top level Classname during JAXB code generation using XJC?

I am trying to generate some beans from several xsd's. Unfortunately they all have the same root element. I have successfully created a xjc bindings file for renaming sub-elements but cannot find a way to select the root node to change that.
I tried the following but get the error: [ERROR] XPath evaluation of "/" needs to result in an element.
<jxb:bindings version="1.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:com.fnf="http://www.fnf.com/xes">
<jxb:bindings schemaLocation="transcode-submit.xsd" node="/xs:schema">
<jxb:bindings node="/">
<jxb:property name="Newname"/>
</jxb:bindings>
</jxb:bindings>
I figured it out.
<jxb:bindings version="1.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:com.fnf="http://www.fnf.com/xes">
<jxb:bindings schemaLocation="transcode-submit.xsd" node="/xs:schema">
<jxb:bindings node="//xs:element[#name='OLDROOTNAME']">
<jxb:class name="NEWNAME"/>
</jxb:bindings>

Categories