Use complex types
WSIF supports user-defined complex types through the mapping of complex types to Java classes.
You specify this mapping manually or automatically as described in the following sections:
Any calls to the WSIFService mapType and mapPackage methods used for manual mapping override any equivalent mapping information that is produced automatically. This override helps to maintain backwards compatibility, and also accommodates less standard mappings.
Manual mapping of complex types
The method to use when you create these mappings manually depends on the provider that is used. For the Java and EJB providers, the mappings are specified in the WSDL file in the binding element. The following example provides the syntax for specifying the mapping:
<binding .... > <ejb:binding|java:binding/> <format:typeMapping style="Java" encoding="Java"/>? <format:typeMap typeName="qname" formatType="nmtoken"/>* </format:typeMapping> ... </binding>In this example:
- A question mark ("?") means "optional" and an asterisk ("*") means "0 or more".
- The format:typeMap typeName attribute is a qualified name of a complex type or simple type used by one of the operations.
- The format:typeMap formatType attribute is the fully qualified class name for the Java class to which the element specified by typeName maps.
If you use the Apache SOAP provider then you specify the mapping of a complex type to a Java class in the client code through two methods on the org.apache.wsif.WSIFService interface:
public void mapType(QName elementType, Class javaType)and
public void mapPackage(String namespaceURI, String packageName)Use the mapType method to specify a mapping between an XML schema element and a Java class. The method takes a QName representing the complex type or simple type, and the corresponding Java class to which it maps.
Use the mapPackage method to specify a more general mapping between a namespace and a Java package. Any custom, complex or simple type whose namespace matches that of the mapping is mapped to a Java class in the corresponding package. The name of the actual class is derived from the name of the complex type using standard XML to Java naming conventions.
Automatic mapping of complex types
For complex types defined in the WSDL, where a generated bean is used to represent this type in Java, the Web Services Invocation Framework (WSIF) programming model requires that a call is made to the WSIFService.mapType() method. This call tells WSIF the package and class name of the bean representing the XML schema type that is identified with a QName. To make things easier, the WSIFService.mapPackage() method provides a mechanism to specify a wildcard version of this, where any class within a specified package is mapped to the namespace of a QName. This is a mechanism for manually mapping an XML schema type to a Java class and back again (one mapping entry provides a bidirectional mapping).
There are many ways to convert a QName representing an XML schema type name to a Java package name and class. To enable automatic type mapping, set the WSIF_FEATURE_AUTO_MAP_TYPES feature on the WSIFServiceFactory instance:
WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); factory.setFeature(WSIFConstants.WSIF_FEATURE_AUTO_MAP_TYPES, new Boolean(true));WSIF maps types by converting the URI part of the XML schema type <tt>QName</tt> to a package name, and converting the local part to a class name. WSIF does this mapping using the WSIFUtils methods <tt>getPackageNameFromNamespaceURI</tt> and <tt>getJavaClassNameFromXMLName</tt>.
Related Tasks
Using the WSIF providers
Developing a WSIF service
Using the Java Naming and Directory Interface (JNDI)
Interacting with the J2EE container in WebSphere Application Server
Run WSIF as a client