Adapter for Enterprise JavaBeans 6.5 SP3 | webMethods Adapter for Enterprise JavaBeans Documentation | webMethods Adapter for Enterprise JavaBeans Installation and User’s Documentation | Creating Flows for Adapter for Enterprise Javabeans Services | Working with Different Object Types | Creating Java Services to Use with Objects | Example 2
 
Example 2
This example builds on Example 1 and shows how to convert the output of the BuyComplexStock adapter service into a simple document. The signature of the remote EJB method that is executed by BuyComplexStock looks like this:
public TradeResult buy (StockOrder order) throws RemoteException;
Note that this method returns an object of type TradeResult. Examine the public interface of this class:
public final class TradeResult implements Serializable
{
public TradeResult(String symbol, int quantity, double price);

public String getStockSymbol();
public int getSharesTraded();
public double getExecutePrice();
}
Notice that the output signature of the BuyComplexStock adapter service does not mention any TradeResult objects. Rather, it contains a document that in turn contains a String status field and another instance of an Object list named Results. This is not the same Results Object list as was returned by the GetComplexTrader adapter service. It just has the same name.
In this example, you will take the contents of Results (which is a list of opaque Objects to Designer) and turn it into a document that contains the actual values in the underlying TradeResult object. As with all CreateEJB 2.1 or FetchEJB 3.0 adapter services, all corresponding InvokeEJB 2.1 or InvokeEJB 3.0 adapter services will fill their outbound Results array starting at the first element (that is, the “zero-th” element). For this example, assume that the BuyComplexStock adapter service always returns a single TradeResult object in its Results array.
To accomplish this task, you need to write another coded Java service. Its implementation could be something like the following:
public static final void ResultsToDoc (IData pipeline) throws ServiceException {
// Get the expected TradeResult object from the inbound pipeline...
IDataCursor idc0 = pipeline.getCursor();
if (idc0.next("ExecutionDetail"))
{
Object obj = idc0.getValue();
try
{
// Cast it to an actual TradeResult object...
TradeResult tr = (TradeResult)obj;

// Extract the attributes of the TradeResult...
String symbol = tr.getStockSymbol();
String quantity = String.valueOf(tr.getSharesTraded());
String price = String.valueOf(tr.getExecutePrice());

// Create the outbound document object...
IData out = IDataFactory.create();
IDataCursor idc1 = out.getCursor();
idc1.first();

// Insert the extracted values into the out doc
idc1.insertAfter("StockSymbol", symbol);
idc1.insertAfter("QuantityTraded", quantity);
idc1.insertAfter("ExecutePrice", price);

// Relinquish the out doc cursor...
idc1.destroy();

// Insert the out doc into the pipeline...
idc0.insertAfter("TradeResultDoc", out);
}
catch (ClassCastException e) {}
}

// Relinquish the pipeline cursor...
idc0.destroy();
}
This coded service, ResultsToDoc, manipulates the content of the pipeline, performing the following tasks:
*Retrieves an object labeled ExecutionDetail from the pipeline
*Casts the ExecutionDetail object to the user-defined TradeResult type
*Extracts the values of the TradeResult object into three Strings: StockSymbol, QuantityTraded, and ExecutePrice
*Creates a new IData document called TradeResultDoc
*Inserts the three String values (StockSymbol, QuantityTraded, and ExecutePrice) into the TradeResultDoc document
*Adds the TradeResultDoc to the pipeline
In order for this service to work properly, you must declare its input (ExecutionDetail) and output (TradeResultDoc) signatures as shown below.
With the ResultsToDoc coded service complete, you can now add it to the LimitedBuy flow service, as shown in the figure below:
The LimitedBuy flow service is now complete. When you execute it with valid input values, you should see those values echoed in the TradeResultDoc document created by the final flow step.