How do I create JAXB bindings for docbook - java

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

Related

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

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.

Create Java classes with JaxB

I tried to create Java classes with JaXB from this XSD http://pda.rosreestr.ru/upload/www/files/02_V04_STD_Region_Cadastr_KV.rar but got these errors.
parsing a schema...
[WARNING] Simple type "dAllDocuments" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 298, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
line 3 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV/dAllDocuments.xsd
compiling a schema...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 1645 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV/STD_Region_Cadastr_KV.xsd
[ERROR] (Related to above error) This is the other declaration.
line 1587 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV/STD_Region_Cadastr_KV.xsd
Failed to produce code.
When I work with another schemas everything is fine. I am not good in work with XML, can you tell me what these errors mean and how to solve it?
UPDATE
I tried to use binding.xml in class generation but got this error.
C:\Documents and Settings\kliver\Мои документы\Загрузки\jaxb-ri-2.2.6\bin>xjc -d
out -b binding.xml D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region
_Cadastr_KV/STD_Region_Cadastr_KV.xsd
parsing a schema...
[ERROR] "D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV
/STD_Region_Cadastr_KV.xsd" is not a part of this compilation. Is this a mistake
for "file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr
_KV/STD_Region_Cadastr_KV.xsd"?
line 6 of file:/C:/Documents%20and%20Settings/kliver/%D0%9C%D0%BE%D0%B8%20%D0%
B4%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%8B/%D0%97%D0%B0%D0%B3%D1%80%D1%8
3%D0%B7%D0%BA%D0%B8/jaxb-ri-2.2.6/bin/binding.xml
[WARNING] Simple type "dAllDocuments" was not mapped to Enum due to EnumMemberSi
zeCap limit. Facets count: 298, current limit: 256. You can use customization at
tribute "typesafeEnumMaxMembers" to extend the limit.
line 3 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_C
adastr_KV/dAllDocuments.xsd
Failed to parse a schema.
UPDATE2
I try this binding:
<jxb:bindings
xmlns:xs="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="D:\liferay-develop\workspace\JABX_test\src\02_V04_STD_Region_Cadastr_KV\STD_Region_Cadastr_KV.xsd">
<jxb:bindings node="//xs:complexType[#name='tRight_Owner']">
<jxb:class name="tRight_Owner2"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
And this console command:
C:\Documents and Settings\kliver\Мои документы\Загрузки\jaxb-ri-2.2.6\bin>xjc -d
out -b binding.xml D:\liferay-develop\workspace\JABX_test\src\02_V04_STD_Region
_Cadastr_KV\STD_Region_Cadastr_KV.xsd
You can use an external bindings file to specify a different class name for one of the complex types.
binding.xml
<jxb:bindings
xmlns:xs="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="your-schema.xsd">
<jxb:bindings node="//xs:complexType[#name='tRight_Owner']">
<jxb:class name="TRight_Owner2"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
The xjc command line would be:
xjc -d out -b binding.xml your-schema.xsd
For those of you coming across this question in later years this method worked for me.
Environment: Netbeans 7.4
Build method: Maven - jaxb2-maven-plugin
Create a folder called xjb in src\main.
In that folder create a file called binding.xjb (or any other .xjb name).
In it:
<jxb:bindings
xmlns:xs="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>
Note that this is not an alternative solution to Blaise's post.
I'm using version 0.13.0 of the maven-jaxb2-plugin, and I found the correct path to the binding file is:
src/main/resources/binding.xjb
The content is the same as OldCurmudgeon proposed, namely:
<jxb:bindings xmlns:xs="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>
You have an issue with your XSD, there are multiple declarations of same name tRight_Owner
line 1587:
<xs:complexType>
<xs:complexContent>
<xs:extension base="tRight_Owner"/>
</xs:complexContent>
</xs:complexType>
line 1645:
<xs:complexType name="tRight_Owner">

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 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