Skip to main content

Summary

How to avoid name clashing in JAX-WS generated code.

Prevent name clashing in generated code.

Using Artix custom bindings

What is custom binding?

Article Number

17498

Environment

Artix 5.x

All Supported Operating Systems

Question/Problem Description

It may be necessary to specify the names generated by the Artix wsdl2java tool. This can be achieved through the use of custom bindings.

Resolution

With JAX-WS, the Artix wsdl2java utility is used to generate Java code from WSDL files. During that process, it is possible to have name clashes in the generated Java code, if the WSDL or associated xsd file(s) have similar names containing underscores. (The wsdl2java tool removes underscores from names when generating Java code.)
For example, if one element is named USER_NAME and another element is named USERNAME, both elements would be called "USERNAME" in the generated Java code, which could cause problems if the elements in question are at the same level in the XML file:

Sample 1

<xs:complexType name="FooBar">
 <xs:sequence>
  <xs:element name="USER_NAME" type="xs:string"/>
  <xs:element name="USERNAME" type="xs:string"/>
 </xs:sequence>
</xs:complexType>

One way to avoiding such name-clashes is through custom bindings. For more information, please see the manual "Developing Artix Applications with JAX-WS". Specifically, the section entitled "Customizing How Types are Generated".

Below, please find a sample of the custom binding, which resolves the possible name clashing between USER_NAME and USERNAME: For example:

Sample 2

<jaxb:bindings schemaLocation="test.xsd" node="/xs:schema">
 <jaxb:bindings node="//xs:complexType/xs:sequence/xs:element[@name='USER_NAME']">
  <jaxb:property name="USRNAME"/>
 </jaxb:bindings>
</jaxb:bindings>


The binding file is passed to the code generation utility wsdl2java using the -b flag. For example, if the WSDL file is named "nameclashingtest.wsdl" and the binding file "nameclashingsolution.xml", then the command line to generating JAX-WS code is as follows:

> artix wsdl2java -b nameclashingsolution.xml nameclashingtest.wsdl


The generated code will use "USRNAME" for element "USER_NAME" (as specified in the binding file) rather than the default "USERNAME" which would have clashed with element "USERNAME".

Support Incidents

  • 2798998

Notes

Custom binding can also be done using inline binding specifications.
The Artix manuals can be accessed from here.


#Orbix
#KnowledgeDocs