I'm trying to generate enums from a simple-type of base int using the Maven maven-jaxb2-plugin. But no enum is being generated.
I can see that the generator is using the bindings-file, since it throws errors if it couldn't find a mapping.
When I change the base to string the enum gets generated (but I'm not allowed to change the base).
So do I have something configured wrong, or is it simply not possible?
xsd-excerpt:
<xs:simpleType name="codeType">
<xs:restriction base="xs:int">
<xs:enumeration value="200"/>
<xs:enumeration value="400"/>
</xs:restriction>
</xs:simpleType>
bindings-file excerpt:
<jaxb:bindings schemaLocation="some.xsd">
<jaxb:bindings node="//xs:simpleType[#name='codeType']/xs:restriction/xs:enumeration[#value='200']">
<jaxb:typesafeEnumMember name="OK" />
</jaxb:bindings>
<jaxb:bindings node="//xs:simpleType[#name='codeType']/xs:restriction/xs:enumeration[#value='400']">
<jaxb:typesafeEnumMember name="BAD_REQUEST" />
</jaxb:bindings>
</jaxb:bindings>
I finally managed, that the enum is generated.
bindings-file excerpt:
<jaxb:bindings schemaLocation="some.xsd">
<jaxb:bindings node="//xs:simpleType[#name='codeType']">
<jaxb:typesafeEnumClass>
<jaxb:typesafeEnumMember value="200" name="OK" />
<jaxb:typesafeEnumMember value="400" name="BAD_REQUEST" />
</jaxb:typesafeEnumClass>
</jaxb:bindings>
</jaxb:bindings>
See https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Developing_Applications_Using_JAX-WS/files/JAXWSCustomTypeMappingEnum.html for more details.
Related
I'm trying to change the package name space for some namespaces because they have objects that collide.
Here is the wsdl:
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/"
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="https://localhost/DS/Search.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="https://localhost/DS/Search.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
</wsdl:definitions>
Here are the bindings:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0"
wsdlLocation="https://localhost/DS/Search.svc?wsdl">
<jaxb:bindings node="//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://tempuri.org/']">
<jaxb:schemaBindings>
<jaxb:package name="directoryservice"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings node="//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://localhost.datacontract.org/2004/07/Search.Models.SearchAPI']">
<jaxb:schemaBindings>
<jaxb:package name="directoryservice.model"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
When I run wsimport with the -b option I get this error
[ERROR] XPath evaluation of "//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://tempuri.org/']" results in empty target node
line 7 of file:service-bindings.xml
I get the error for both bindings..
Am I missing something with the definition of the bindings?
I found a way round this issue by using the global binding. The binding will create the serivce ObjectFactory but not the model pojos.
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
Hi I'm trying to create an external bindings XML for xjc but I'm getting 2 errors:
[ERROR] A class/interface with the same name "x.x.DaysOfWeek" is already in use. Use a class customization to resolve this conflict.
[ERROR] (Relevant to above error) another "DaysOfWeek" is generated from here.
Am I missing something major? I need a second pair of eyes. Thanks
<!-- data.xsd -->
<xs:complexType name="DaysOfWeek">
<xs:sequence>
<xs:element ref="DaysOfWeek"/>
</xs:sequence>
</xs:complexType>
<xs:element name="DaysOfWeek">
<xs:complexType mixed="true">
<xs:attribute name="Type" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
and I have bindings.xml right now
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings schemaLocation="data.xsd">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.kml.v_2_2_0"/>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[#name='DaysOfWeek']//xs:element[#ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:element[#name='DaysOfWeek']">
<jaxb:factoryMethod name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>
You have a collision on generated classes. Try adding:
<jaxb:bindings node="xs:element[#name='DaysOfWeek']//xs:complexType">
<jaxb:class name="ComplexDaysOfWeekType"/>
</jaxb:bindings>
(Maybe without //xs:complexType, not quite sure.)
The issue has been solved using
<jaxb:bindings schemaLocation="data.xsd" node="/xs:schema">
<jaxb:bindings node="xs:element[#name='DaysOfWeek']">
<jaxb:class name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[#name='DaysOfWeek']//xs:element[#ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>
I have following schema and corresponding bindings file. I use jaxb2 maven plugin to generate JAXB classes.
person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="pType" type="pType" minOccurs="0" />
<xs:element name="sex" type="xs:string"
minOccurs="1" />
<xs:element name="dob" type="xs:string"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- some more elements ignored for clarity.................
.......................... -->
<xs:complexType name="pType">
<xs:sequence>
<xs:element name="category" type="xs:string"
minOccurs="0" />
<xs:element name="blahh" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
jaxb bindings
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings node="//xs:complexType[#name='pType']">
<jxb:class name="PersonType" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings
node="//xs:element[#name='person']//xs:element[#name='pType']">
<jxb:class ref="PersonType" />
</jxb:bindings>
</jxb:bindings>
I have defined bindings to override the name for the <xs:complexType name="pType"> as PersonType. On XJC generation, it generates PersonType.class and PType.class.
If I define <xs:complexType name="pType"> internally inside the element <xs:element name="pType" > then it did not generate PType.class.
But I have to declare <xs:complexType name="pType"> at the root level in schema, because this xs:complexType is referenced by other schemas as well.
I tried to override for both <xs:complexType name="pType"> and <xs:element name="pType" > in bindings and yet the PType.class gets generated.
How could I instruct it not to generate PType.class ?
The problem was that I have 2 executions for each of the schemas (dependent schema person2.xsd and person.xsd) in maven-jaxb2-plugin. So I had manually written the episode file to reference the already created <xs:complexType name="pType"> and resolved the issue.
For the benefit of someone who has same problem, here are the plugin execution details and episode file. Please note that I did not use namespaces hence you find the scd is simple without namespace.
person-episode
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">
<jaxb:bindings scd="x-schema::">
<jaxb:bindings scd="/type::pType">
<jaxb:class ref="org.wipo.pct.test.PersonType"/>
<jaxb:package name="org.wipo.pct.test" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
pom.xml
<execution>
<id>person</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>person2</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person2.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings2.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
<args>
<arg>-b</arg>
<arg>src/main/resources/person-episode</arg>
<arg>-Xsimplify</arg>
<arg>-Xinheritance</arg>
</args>
</configuration>
</execution>
I tried to find a solution for some time to the following problem. I have a wsdl file containing several (6) xsd imports. I cannot change these xsd's because they are external to my project. There are 4 definitions all together which are slightly defined different in 2 of these schemas. I was attempting to translate each 'conflicting' xsd schema to it's own package. I tried following bindings, but it did not do the job:
testbindings.jaxb:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1">
<bindings schemaLocation="a.xsd">
<schemaBindings>
<package name="org.wsi.a" />
</schemaBindings>
</bindings>
</bindings>
using: wsimport -p org.wsi -b testbindings.jaxb broker.wsdl
All classes are generated in org.wsi and no classes in org.wsi.a. Without the -p switch all xsd are generated in their own default package. But could not tell wsimport to use specific packages for each xsd. At this moment I use following binding file, which is probably incorrect, but for which the wsimport doesn't complain:
<?xml version="1.0"?>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxws:bindings wsdlLocation="broker.wsdl" node="wsdl:definitions/wsdl:types/xsd:schema">
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" node="//xs:schema/xs:import[#namespace='http://docs.oasis-open.org/wsn/b-2']">>
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.b_2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" node="//xs:schema/xs:import[#namespace='http://docs.oasis-open.org/wsn/t-1']">>
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.t_1"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxws:bindings>
In packages org.broker.wsi.b_2 and org.broker.wsi.t_1, no files are generated.
I used bindings as specified in: http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv/data_types.html#wp227713 but probably incorrect.
Suggestions are welcome.
The problem of setting up the correct package names for the wsdl, the internal xsd and the external xsd's is described in question/answer:
wsimport - how to generate service endpoint classes and JAXB classes in separate projects/folders, posted by:
dma-k
int-bindings.xml file:
<?xml version="1.0"?>
<jaxws:bindings version="2.0"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
wsdlLocation="broker.wsdl">
<jaxws:package name="org.broker.wsi" />
<jaxb:bindings node="//xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.al"/>
</jaxb:schemaBindings>
</jaxb:bindings>
The external-bindings file (abbreviated):
<jaxb:bindings version="1.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="http://docs.oasis-open.org/wsn/b-2.xsd" node="//xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.oasis.b2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Forgive me if this is a duplicate. Here is my binding.xjb file. But now i am getting the regular error that the complex type target "AddBankVaultRplyType" is not found. I don't see any issue. Can somebody help me with this? I am listing the xsd that i am trying to customize
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
jxb:version="2.1"
>
<jxb:bindings node="/xs:schema/xs:ServiceReply/xs:complexType[#name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>
Here is the piece of XSD that i am trying to customize
<xs:schema xmlns:pd="http://com/polsvc/xmlobj" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://com/polsvc/xmlobj" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="AddBankVaultRplyType">
</xs:complexType>
<xs:element name="ServiceReply">
<xs:complexType>
<xs:sequence>
<xs:element name="ReplyHeader" type="pd:MsgHeaderType"/>
<xs:element name="RequestHeader" type="pd:MsgHeaderType"/>
<xs:choice>
<xs:element name="AddBankVaultReply" type="pd:AddBankVaultRplyType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Now if i run XJC it is saying me that the target "/xs:schema/xs:ServiceReply/xs:complexType[#name='AddBankVaultRplyType']" results in empty node. What is the mistake i am doing here
You will need to wrap in a bindings that has the schema location set. It should be something like:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
version="2.1">
<jxb:bindings schemaLocation="your-schema.xsd">
<jxb:bindings node="//xs:complexType[#name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
For more information:
http://jaxb.java.net/guide/Dealing_with_errors.html
I finally got mine workign with subclassing as well as adding #XmlRootElement to those dang complexTypes that are used by a root element(I don't get why JAXB doesn't add it for me, but this does the trick of doing that since JAXB doesn't)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://annox.dev.java.net "
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:globalBindings>
<jaxb:serializable uid="1"/>
<!-- All generated classes must have MySignature interface (supplied in dependencies) -->
<xjc:superClass name="com.cigna.framework.DataObject"/>
<xjc:superInterface name="com.cigna.framework.InterfaceTest"/>
<!-- All temporal fields are implemented as Joda DateTime and use DateUtils as an adapter -->
<jaxb:javaType
name="org.joda.time.DateTime"
xmlType="xs:time"
parseMethod="com.cigna.framework.util.DateUtil.stringToDateTime"
printMethod="com.cigna.framework.util.DateUtil.dateTimeToString"
/>
</jaxb:globalBindings>
<!-- Application of annotations to selected classes within schemas -->
<!-- org.example.SomeRootType #XmlRootElement -->
<jaxb:bindings schemaLocation="../schemas/externalaction_2012_03.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.action"></jaxb:package>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../schemas/common_2012_04.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.common"></jaxb:package>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[#name='PersonNameType']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="SomeRootType"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../schemas/utilities_2012_03.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.util"></jaxb:package>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Of course I struggled with the pom.xml alot but finally came to this solution which worked for me.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>process-xsd</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<schemaIncludes>
<include>schemas/*.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>schemas/*.xjb.xml</include>
</bindingIncludes>
<generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
<extension>true</extension>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.3</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
later,
Dean