WebSphere Application Server defines a CustomBinder interface that you can implement to provide concrete custom data binders for a specific XML schema type.
The CustomBinder interface has three properties, in addition to deserialize and serialize methods. These properties are QName for the XML schema type, the QName scope, and the Java type that the schema type maps to. The properties are accessible through the corresponding getter methods.
getQName
The getQNameScope method returns the QName of the target XML schema type. custom data binders only work with the root level schema type, for example, the global definition of <xsd:complexType>, <xsd:simpleType> and <xsd:element> that does not use the type attribute. The <xsd:complexType> and the <xsd:simpleType> schemas are also referred to as the named type. The <xsd:element> is also referred to as the anonymous type because it does not have a real name for the type definition that is embedded in the <xsd:element>. The custom data binder does not work the <xsd:element> with the type attribute.
For named types, the getQName method returns the QName of the schema type definition, for example, the getQName method returns the QName of the enclosing element. When a named type and an anonymous type use the same QName, they are differentiated by the qnameScope property.
getQNameScope
The getQNameScope method returns the binder qnameScope property that indicates whether the schema type is a name type or an anonymous type. The qnameScope property value can be element for an anonymous type, complexType for an <xsd:complexType>, or simpleType for an <xsd:simpleType>.
The qnameScope property affects how the custom data binder interacts with the run time system because of the differences between the name type and the anonymous type. The custom data binder has to know the enclosing element, therefore, the SOAPElement that is returned from the serialize method has the same QName as the enclosing element. The custom data binder does not have to know the referencing element because the runtime passes the custom data binder a valid QName as the referencing element.
getJavaName
The getJavaName method returns the fully-qualified class name for the Java type that works with the custom data binder. The class can be an interface or a concrete class. The object returned from the deserialize method has a type that is compatible with the name that is returned by the getJavaName method.
serialize
The serialize method returns the SOAPElement that the custom data binder builds from the Java object. The Java object is passed from the run time system and is expected to match what is returned from the getJavaName method. The SOAPElement parameter does not have child elements, but it does have a valid QName. This parameter is a reference for the binder to create the final SOAPElement.
In most cases, the binder implementation appends the child elements to the root SOAPElement. The run time system guarantees that the SOAPElement QName is correct. Therefore, the custom data binder for named types keeps the QName of the root element because the binder does not know the enclosing element. The binder implementation for an anonymous type should always include the QName in the returned SOAPElement that matches the defined schema type. WebSphere Application Server does not have concrete methods in the CustomBindingContext parameter.
deserialize
The deserialize method returns a Java object that the custom data binder builds from the passed root SOAPElement. The object type of the returned Java object must match what is returned from the getJavaName method. Unlike the parameter serialize method, the passed SOAPElement contains the original XML data with the necessary namespace declarations.
The following is an example of an implementation of the SDO DataGraph binder, where the convertToSDO and convertToSAAJ utility methods convert between SOAPElement and an SDO object.
package test.sdo.binder; import javax.xml.namespace.QName; import javax.xml.soap.SOAPElement; import com.ibm.wsspi.webservices.binding.CustomBinder; import com.ibm.wsspi.webservices.binding.CustomBindingContext; public class DataGraphBinder implements CustomBinder { public QName getQName() { return new QName("commonj.sdo", "DataGraphyType"); } public String getJavaName() { return CustomBinder.QNAME_SCOPE_COMPLEXTYPE; } public String getJavaName() { return commonj.sdo.DataGraph.class.getName(); } public javax.xml.soap.SOAPElement serialize( Object bean, SOAPElement rootNode, CustomBindingContext context) throws javax,xml.soap.SOAPException { // convertToSAAJ is a utility method to convert // the SDO DataGraph to the SOAPElement return convertToSAAJ(bean, rootNode); public Object deserialize( SOAPElement source, CustomBindingContext context) throws javax.xml.soap.SOAPException { // convertToSDO is a utility method to convert // the SOAPElement to the SDO DataGraph return convertToSDO(source); } }
To learn more about custom data binders, see Custom data binders. To learn how to plug your custom data binders into the WSDL2Java command-line tool for development, see Custom binder providers.
To review the Javadoc used for APIs and SPIs, see Reference: Generated API documentation. Follow the instructions in this topic that lead you to the API and SPI interfaces.
You can also review the specifications for the standards and APIs used in developing Web services.
Related concepts
Custom data binders
Custom binding providers
Related reference
Usage patterns for deploying custom data binders
WSDL2Java command
Web services: Resources for learning