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.
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:
The method for accessing components of request parameters and defining response objects depends on the type of data binding you choose.
JAXB
public AddPhoneResponse addPhone(AddPhoneRequest addPhoneParameters) { ... String firstName = addPhoneParameters.getFirstName(); String lastName = addPhoneParameters.getLastName(); String phone = addPhoneParameters.getPhone();
- Import packageName.ObjectFactory, where packageName is the package name generated from the WSDL document namespace.
- Create an instance of ObjectFactory.
- Create an object of type Type with the createType method.
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;
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.
<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>
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 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>
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.