Default XML to Java Mapping

When you generate a Spring component implementation or XML data binding classes, TIBCO Business Studio maps WSDL and XSD schema elements to Java programming language elements.

The following sections describes the default mappings of WSDL definitions, types, portType, operation, message, part, and fault elements to Java.

Note: Generating implementations for two or more components in the same Java plug-in project using different binding types is not supported.
Note: The payload for a xsd:gMonth datatype is converted incorrectly if you use JAXB data binding.

wsdl:definitions

The wsdl:definitions element's targetNamespace attribute is mapped to a Java package. By default, for a target namespace whose structure is: http://rootPart/subPart, the order of the elements in the root part of the target namespace are reversed in the package name. Subparts appearing after the root part separated by slashes are appended to the root part with a period (.). For example, the namespace http://ns.tibco.com/StockQuote becomes the package com.tibco.ns.stockQuote. If the first character of a namespace identifier is invalid, the preprocessor prepends an underscore _ in front of the identifier.

wsdl:portType

A wsdl:portType element is mapped to a Java interface. The name of the interface is the value of the name attribute of the corresponding wsdl:portType element.

The generated interface contains Java methods mapped from the wsdl:operation subelements of the wsdl:portType element. Since WSDL 1.1 does not support port type inheritance, each generated interface contains methods for all the operations in the corresponding port type.

wsdl:operation

Each wsdl:operation element is mapped to a Java method in the corresponding Java interface. The name attribute of the wsdl:operation element determines the name of the generated method. If the wsdl:operation element contains a wsdl:fault message, the fault is mapped to a Java exception that appears in the throws clause of the generated method. See also wsdl:fault .

wsdl:output, wsdl:input, and wsdl:part

The name attribute of the part element of the wsdl:output message is mapped to the return type of the generated Java method according to the XML data binding type as follows:

  • JAXB - name
  • XMLBeans - nameDocument

The method for accessing components of request parameters and defining response objects depends on the type of data binding you choose.

JAXB

The type or element attribute of the part element of the wsdl:input message is mapped to the type of the input parameter of the generated Java method. The name attribute of the part element of the wsdl:input message is mapped to the name of an input parameter of the generated Java method.You can directly access components of a request parameter as follows:
public AddPhoneResponse addPhone(AddPhoneRequest addPhoneParameters) {
  ...
  String firstName = addPhoneParameters.getFirstName();
  String lastName = addPhoneParameters.getLastName();
  String phone = addPhoneParameters.getPhone();
To create a response object or a complex object defined in the WSDL document:
  1. Import packageName.ObjectFactory, where packageName is the package name generated from the WSDL document namespace.
  2. Create an instance of ObjectFactory.
  3. Create an object of type Type with the createType method.
For example:
import com.tibco.ns.hello.phonebook.ObjectFactory;
import com.tibco.ns.hello.phonebook.GetPhoneResponse;
...
ObjectFactory objectFactory = new ObjectFactory();
GetPhoneResponse phoneResponse = objectFactory.createGetPhoneResponse();

  try{
    ...
    PhoneEntryType entry = objectFactory.createPhoneEntryType();
    while(rs.next()){
      entry.setEntryId(rs.getString("id"));
      entry.setFirstName(rs.getString("firstName"));
      entry.setLastName(rs.getString("lastName"));
      entry.setPhone(rs.getString("phone"));			
    }
  }catch(SQLException e){
    ...
  }
  return phoneResponse;
Note: When implementing a JAXB-based Spring component service, users typically form a response object in their service method, populate it with some response data, and return it from the method. Such a returned object is then marshalled into an XML (DOM) payload by the platform. While the platform code is marshalling this payload, if the user code manipulates the contents of the same object, the JAXB marshaller throws a java.util.ConcurrentModificationException. Make sure the contents of the response object returned from the service method are not modified by multiple threads.

XMLBeans

There are two ways to specify the type of a message part: indirectly through an element attribute that is defined in the wsdl:types element or directly with a type attribute. If you use XMLBeans binding, the generated Java code depends on how you specify the types of message parts.

When you define the types of the parts through the element, attribute classes named ElementNameDocument, where ElementName is the input and output message type element name with the first letter capitalized, are generated. The generated Java method accepts a document type named ElementNameDocument. The generated method returns a document type similarly named according to the element that specifies the type of the output message part.

In the following WSDL document, the types of the message parts are defined through an element attribute:
<wsdl:definitions
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
  xmlns:tns="http://ns.tibco.com/StockQuote/" 
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
  targetNamespace="http://ns.tibco.com/StockQuote/">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
         attributeFormDefault="unqualified" elementFormDefault="qualified" 
         targetNamespace="http://ns.tibco.com/StockQuote/">
           <xs:element name="symbol" type="xs:string"/>
           <xs:element name="quote" type="xs:float"/>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="OperationRequest">
        <wsdl:part name="stockQuoteRequest" element="tns:symbol"/>
    </wsdl:message>
    <wsdl:message name="OperationResponse">
        <wsdl:part name="stockQuoteResponse" element="tns:quote"/>
    </wsdl:message>
    <wsdl:portType name="StockPT">
        <wsdl:operation name="getQuote">
            <wsdl:input message="tns:OperationRequest"/>
            <wsdl:output message="tns:OperationResponse"/>
        </wsdl:operation>
    </wsdl:portType>
</wsdl:definitions>
The following code fragment shows the generated Java class implementation:
import com.tibco.stockQuote.SymbolDocument;
import com.tibco.stockQuote.QuoteDocument;

public class StockQuoteServiceImpl extends AbstractStockQuoteServiceImpl {
   public QuoteDocument getQuote(SymbolDocument stockQuoteRequest)
   {
      String sym = stockQuoteRequest.getSymbol();
      float quote = quoteLookup(sym);
      QuoteDocument response = QuoteDocument.Factory.newInstance();
      response.setQuote(quote);
      return response;
   }
}
The relationships between the message part, message part type, message type element, and document type are:
Message Part Type Element Document Type
stockQuoteRequest xs:string tns:symbol SymbolDocument
stockQuoteResponse xs:float tns:quote QuoteDocument

The value of the request message part is retrieved from the document using bean-style accessors. In the example, the stock symbol is retrieved from the SymbolDocument object with the getSymbol method.

You create a response document, of type QuoteDocument, by calling the newInstance method of the document factory class. Finally, you set the value of the response message part by calling the setQuote method on the response document.

In the following WSDL document, the types of the message parts are specified through a type attribute:

<wsdl:definitions
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:tns="http://ns.tibco.com/StockQuote/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
name="Untitled" targetNamespace="http://ns.tibco.com/StockQuote/">
    <wsdl:message name="OperationRequest">
        <wsdl:part name="symbol" type="xs:string"/>
    </wsdl:message>
    <wsdl:message name="OperationResponse">
        <wsdl:part name="quote" type="xs:float"/>
    </wsdl:message>
    <wsdl:portType name="StockPT">
        <wsdl:operation name="getQuote">
            <wsdl:input message="tns:OperationRequest"/>
            <wsdl:output message="tns:OperationResponse"/>
        </wsdl:operation>
    </wsdl:portType>
</wsdl:definitions>
For this WSDL document, the generated Java code references the message parts directly, instead of through documents. However, the types of the message parts are XMLBeans types, which means that you must use the XMLBeans API to access the XML data bound to Java objects and convert between XMLBeans types and native Java types in your method implementation. To perform this conversion, you use [get|set]TypeValue methods, where Type is the native Java type. Like the document types described earlier, you create XMLBeans objects by calling the newInstance method of the type’s Factory class.
import org.apache.xmlbeans.XmlFloat;
import org.apache.xmlbeans.XmlString;

public class StockQuoteServiceImpl extends AbstractStockQuoteServiceImpl {

   public XmlFloat getQuote(XmlString symbol){
      float quote = quoteLookup(symbol.getStringValue());
      XmlFloat resp = XmlFloat.Factory.newInstance();
      resp.setFloatValue(quote);
      return resp;
   }
}

wsdl:fault

A wsdl:fault element is mapped to a Java exception. The generated exception class extends the class java.lang.Exception. The name of the exception is formed by concatentating the name attribute of the wsdl:message referenced by the wsdl:fault element with Exception. For the following WSDL fragment, the exception class would be named GetCurrentTimeFaultMsgException.

<schema>
...
<element name="CurrentTimeFault" type="string"/>
...
</schema>
<wsdl:message name="getCurrentTimeFaultMsg">
  <wsdl:part element="tns:getCurrentTimeFault" name="faultInfo"/>
</wsdl:message>
<wsdl:portType name="DateManagerPT">
  <wsdl:operation name="getCurrentTime">
    <wsdl:input message="tns:OperationRequest"/>
    <wsdl:output message="tns:OperationResponse"/>
    <wsdl:fault message="ns0:getCurrentTimeFaultMsg" name="faultMsg"/>
  </wsdl:operation>
</wsdl:portType>

XMLBeans

A fault object named faultDocument is generated, where fault is the type of the fault message's part. For the preceding WSDL fragment,the fault object would be named GetCurrentTimeFaultDocument.