as pointed out by Puspendu, setting up the JAXB binding client is exactly / close to what you need - you need to use the JAX-WS client setting for your example. Setting up JAXB and JAX-WS essentially allows you to extend the definition of schema elements to WSDL / schemas that you do not control. There are many different things you can do, for example, matching the names of xml elements with custom java elements, changing the generated API and answers to your question, creating enumerated classes for elements that are limited to enumeration.
There are two ways / parts to configure the client for JAX-WS.
1) if WSDL imports an external schema file 2) if WSDL contains a full schema definition without import
if wsdl imports an external schema file,
basically you need to create a new file (usually with the jxb extension, but it really doesnβt matter) that you will support next to the wsdl that you create for the stub / api client. I usually call these files schema-file-name_clientcustomization.jxb
every time you get updated wsdl, you should check that your jxb file is still valid for that wsdl. The biggest things I found for searching, especially with enumeration restrictions, are limited value changes, namespace changes, type name changes, etc.
the contents of this new file will look something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" targetNamespace="http://java.sun.com/xml/ns/jaxb" version="1.0"> <jxb:bindings schemaLocation="NameOfYourSchemaFile.xsd" node="/xsd:schema[@targetNamespace='SCHEMANAMESPACE']"> <jxb:schemaBindings> <jxb:package name="com.amazon.webservices.ecs" /> </jxb:schemaBindings> <jxb:bindings node="xsd:element[@name='Condition']/xsd:simpleType"> <jxb:typesafeEnumClass name="ConditionEnum" > <jxb:typesafeEnumMember value="All" name="ALL" /> <jxb:typesafeEnumMember value="New" name="NEW" /> <jxb:typesafeEnumMember value="Used" name="USED" /> <jxb:typesafeEnumMember value="Collectible" name="COLLECTIBLE" /> <jxb:typesafeEnumMember value="Refurbished" name="REFURBISHED" /> </jxb:typesafeEnumClass> </jxb:bindings> </jxb:bindings> </jxb:bindings>
Essentially, this file defines the addition that should be made to the referenced xsd file. all anchor elements in this file have a node attribute, which is an XPATH expression that selects the schema element that you want to enlarge. in this example, I have no namespace or other information, so I pointed out XPATH to choose a simple simple type declaration. inside this binding, we define feenumclass types, this causes jaxb / wsimport to generate an enum class to represent a reference simple type. since it is an anonymous simple type, it effectively defines the class only for the reference element. The generated class will be ENUM whose members are defined by the "name" attribute of the typeafeEnumMember element.
in order to use this JXB file, you need to reference it in your ant task, for example:
<wsimport debug="true" keep="true" verbose="true" destdir="${generated.src}" package="com.amazon.webservices.ecs" wsdl="wsdl/AWSECommerceService.wsdl"> <binding dir="wsdl" includes="*.jxb"/> </wsimport>
if the WSDL internally defines the whole scheme, then you need to use the JAX-WS configuration file. This question is relevant to your question.
http://jax-ws.java.net/nonav/2.1.7/docs/customizations.html
Setting up a JAX-WS client is very similar to setting up JAXB. The idea is identical, for the most part, the JAX-WS configuration file modifies the generated artifacts that are specifically associated with WSDL, while the JAXB built-in configuration performs the same function as the external configuration file: it modifies the created objects based on the diagram.
The big difference is that instead of telling the JAXB parser where the schema file is located, you provide a binding section that selects the schema definition (using XPATH) to which you want to apply the setting.
In this example, I actually tested and verified to create an Enum class for the item you are asking questions about, so you can copy this JAX-WS configuration example verbatim.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <jaxws:bindings wsdlLocation="AWSECommerceService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" > <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://webservices.amazon.com/AWSECommerceService/2010-11-01']"> <jaxb:schemaBindings> <jaxb:package name="com.amazon.webservices.ecs"/> </jaxb:schemaBindings> <jaxb:bindings node="xsd:element[@name='Condition']/xsd:simpleType"> <jaxb:typesafeEnumClass name="ConditionEnum" > <jaxb:typesafeEnumMember value="All" name="ALL" /> <jaxb:typesafeEnumMember value="New" name="NEW" /> <jaxb:typesafeEnumMember value="Used" name="USED" /> <jaxb:typesafeEnumMember value="Collectible" name="COLLECTIBLE" /> <jaxb:typesafeEnumMember value="Refurbished" name="REFURBISHED" /> </jaxb:typesafeEnumClass> </jaxb:bindings> </jaxws:bindings> </jaxws:bindings>
you would then reference this JAX-WS configuration file in the same way as the JXB file.
I did not test a separate JAXB configuration example, since I really included it only as an example and as a description of the predecessor for the JAX-WS configuration example.
An example JAX-WS setup that I really tested / tested against the associated WSDL, so you should use it as a starting point. I noticed that in a specific WSDL there are many of the listed restrictions, so I assume that you want to create enumerations for most / all of them.
Hope this helps.