webMethods 10.2 | Service Development Help | Building Java Services | Using an IData Object for the Java Service Input and Output
 
Using an IData Object for the Java Service Input and Output
An IData object is the universal container that Java services use for service input and output. A Java service method signature takes exactly one argument of type IData, and the same IData object contains the output from the service. An IData object contains an ordered collection of key/value pairs on which a service operates. For a key/value pair:
*The key must be a String.
*The value can be any Java object (including an IData object).
Tip: You can use Designer to generate code for getting input from and writing output to an IData object. After generating the code, you can copy and paste it into the Java service you are creating. For more information, see Generating Java Code from Service Input and Output Parameters.
Sample Code for Getting and Setting Input Values
A Java service is a method that is public and static. It takes a single instance of com.wm.data.IData as input and must place output in the same IData object. The following code shows a sample:
public final static void myservice (IData pipeline)
throws ServiceException
{
return;
}
When the Java service is invoked, Integration Server passes the IData object to it. The service needs to get the input values it needs from the key/value pairs within the IData object. The following sample code uses methods of the IDataCursor class to position the cursor and uses the getValue method to get the input value of the myVariable input variable from the IData object:
public final static void myservice (IData pipeline)
throws ServiceException
{
IDataCursor myCursor = pipeline.getCursor();
if (myCursor.first( "inputValue1" )) {
String myVariable = (String) myCursor.getValue();
.
.
}
myCursor.destroy();
.
.
return;
}
A service returns output by inserting it into the same IData object that was used for the input values. All of the service outputs must be written to the IData object. For example:
public final static void myservice (IData pipeline)
throws ServiceException
{
IDataCursor myCursor = pipeline.getCursor();
if (myCursor.first( "inputValue1" )) {
String myVariable = (String) myCursor.getValue();
.
.
}
myCursor.last();
myCursor.insertAfter( "outputValue1", myOutputVariable );
myCursor.destroy();
return;
}
Note: Integration Server passes everything that the Java service puts into the pipeline (that is, the IData object) as output, regardless of what is declared as its input/output parameters. Declaring a service's input and output parameters does not filter what variables the service actually receives or outputs at run time. It simply provides a formal description of what the service requires as input and produces as output.
Creating IData Objects
Use the IDataFactory class to create IData objects. For example:
public final static void myservice (IData pipeline)
throws ServiceException
{
myIDataObject = IDataFactory.create();
IDataCursor myCursor = myObject.getCursor();
myCursor.insertAfter("VA", new Double("0.045"));
myCursor.insertAfter("MD", new Double("0.05"));
myCursor.insertAfter("DE", new Double("0.0"));
return;
}
Getting and Setting Elements in an IData Object
Use the IDataCursor class to get values from and set values into IData elements (that is, key/value pairs). Getting or setting values in IData elements takes two steps.
First, position the cursor at the IData element you want to get or set. The IDataCursor class contains methods for performing basic cursor operations such as placing the cursor at the first, last, or next element in an IData object.
After positioning the cursor, use the getValue or setValue methods to read or write the value of the element, respectively. This class also provides methods for inserting new elements, getting key names, and deleting elements.
For more information about using the cursor classes, see webMethods Integration Server Java API Reference.
Creating a Java Service
Editing an Existing Java Service
Generating Java Code from Service Input and Output Parameters
Overview of Building Java Services
Building Java Services in Your Own IDE

Copyright © 2017-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release