Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | Service Development | Building Java Services in Your Own IDE | Adding Comments to Your Java Code for the jcode Utility | Example of Code Commented for the jcode Utility
 
Example of Code Commented for the jcode Utility
The following is a complete example of Java source code that includes jcode tags (comments) that the jcode utility requires.
package recording;
/**
* This is an example of Java source code that includes jcode tags
* (comments) that the Integration Serverjcode utility requires. Note that, unless
* noted otherwise, when using the frag or fragall command of the
* jcode utility, the utility strips out all comments in the Java source
* file.
*/
/**
* == IMPORTS ==
* Wrap imports the START-IMPORTS and END-IMPORTS tags.
*/
// --- <<IS-START-IMPORTS>> ---
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;
import java.util.*;
// --- <<IS-END-IMPORTS>> ---
/**
* == CLASS NAMING ==
* This class contains the definition of all the Java services
* within the recording.accounts folder (note the declaration for the
* recording Java package at the top). Each service is defined by a
* method. The service will have the same name as the method name.
* /
public class accounts
{
/* *
* == INDIVIDUAL SERVICES ==
* The createAccount service expects three parameters: a string
* ("name", a string array ("references"), and a document. The
* service returns two strings ("message" and "id") .
*
* Wrap the start and end of the service with the
* IS-START(<serviceName>)and IS-END tags, where <serviceName>
* is the method/service name.
* Note that the two lines immediately before start tag and after
* the end tags are mandatory.
*
* Also note the use of comments to establish a signature for the
* service. Each signature line has the following format:
*
* [direction] type:dimension:option name
*
* where:
* - direction: is "i" for input or "o" for output
* - type: is one of the following:
* "field" for instances of java.lang.String
* "document type" for instances of com.wm.data.IData
* "object" for instances of any other class
* - option: is one of the following:
* "required" if the parameter is required
* "optional" if the parameter is optional
* - name: is the name of the parameter
*
* To indicate nesting, use a single "-" at the beginning of
* each line for each level of nesting.
* /
public static void createAccount (IData pipeline)
throws ServiceException
{
// --- <<IS-START(createAccount)>> ---
// [i] field:0:required name
// [i] field:1:required references
// [i] record:0:required data
// [i] - field:1:required address
// [i] - field:1:required phone
// [o] field:1:required message
// [o] field:1:required id
IDataCursor idc = pipeline.getCursor();
String name = IDataUtil.getString(idc, "name");
String [] refs = IDataUtil.getStringArray(idc, "references");
IData data = IDataUtil.getIData(idc, "data");
// Service logic that takes action on the input information
// goes here. Note that when you use the jcode utility to
// fragment the service, it does not strip comments inside
// the service body. As a result, the comments are
// preserved and will display if you use Designer
// to view the service.
idc.last();
idc.insertAfter ("message", "createAccount not fully implemented");
idc.insertAfter ("id", "00000000");
idc.destroy();
// --- <<IS-END>> -- -
return ;
}
/* *
* == COMPLEX SIGNATURES = =
* The getAccount service takes a single string "id", and returns
* a complex structure representing the account information.
* Note the use of the helper functions (defined below).
* /
public static void getAccount (IData pipeline)
throws ServiceException
{
// --- <<IS-START(getAccount)>> -- -
// [i] field:0:required id
// [o] record:1:required account
// [o] - field:0:required name
// [o] - field:1:required refs
// [o] - record:0:required contact
// [o] -- field:0:required address
// [o] -- field:0:required phone
IDataCursor idc = pipeline.getCursor();
if(idc.first("id"))
{
try
{
String id = IDataUtil.getString(idc);
IData data = getAccountInformation(id);
idc.last();
idc.insertAfter ("account", data);
}
catch (Exception e)
{
throw new ServiceException(e.toString());
}
}
idc.destroy();
// --- <<IS-END>> -- -
}
/* *
* == SHARED SOURCE ==
* Wrap the start and end of the shared code with the
* IS-START-SHARED and IS-END-SHARED tags. The shared code includes
* both global data structures and non-public functions that are
* not exposed as services.
*/
// --- <<IS-START-SHARED>> ---
private static Vector accounts = new Vector( );
private static IData getAccountInformation (String id) {
throw new RuntimeException ("this service is not implemented yet");
}
// --- <<IS-END-SHARED>> ---
}