change package of generated jaxb class

rouble picture rouble · Nov 29, 2011 · Viewed 10.9k times · Source

I have the following data type defined in a wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="myService" targetNamespace="http://example.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="example.com" targetNamespace="example.com" version="1.0">
            <xs:simpleType name="MyEnum">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="one"/>
                    <xs:enumeration value="two"/>
                </xs:restriction>
            </xs:simpleType>
            <!-- SNIP other data types -->
        </xs:schema>
    </wsdl:types>
</wsdl:definitions>

I want MyEnum to fall into its own package. So, I used a jaxws binding file, and used XPATH to traverse the schema and jaxb bindings to set the package, as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://java.sun.com/xml/ns/jaxws">
    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='example.com']">
      <jxb:schemaBindings>
          <jxb:package name="abra.ca.dabra" /> <!-- this works, and changes package of all classes in the namespace-->
      </jxb:schemaBindings>
      <jxb:bindings node="//xs:simpleType[@name='MyEnum']">
          <jxb:package name="a.b.c"/> <!-- this does not work -->
      </jxb:bindings>
    </jaxws:bindings>
    <!-- SNIP - other functional jaxws bindings -->
</jaxws:bindings>

Now, the path set in schemaBindings takes - and puts all data types from that schema/targetnamespace into package abra.ca.dabra. However, I can't seem to set the package of just MyEnum - which is what I want.

I use cxf's wsdl2java to provide the bindings file. Am I missing something?

Answer

max picture max · Feb 19, 2013

I would try it with something likethis:

<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">

<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>

<!-- set default package structure -->
<jaxws:package name="abra.ca.dabra" />

<!-- set package structure for complex schema types -->
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema/xs:simpleType[@name='MyEnum']">
    <jaxb:schemaBindings>
        <jaxb:package name="a.b.c" />
    </jaxb:schemaBindings>
</jaxws:bindings>

To be more precise you should make the whole wsdl available

Hope this helps ...