IBM WebSphere Multichannel Bank Transformation Toolkit, Version 7.1

Service object sample

The following is a sample service object. The service object uses the handleCommand method to receive requests from the service holder, assign corresponding methods to process the request, and return the process result to its service holder.
public class SampleService extends BTTServiceImpl {

protected int counter = 0;

/**
* Add the counter
* @param inc. A String to increase the counter.
* @return A string to present the counter's value
*/
public String addCounter(String inc) {
    if (inc != null) {
        counter = counter + Integer.parseInt(inc);
    } else {
        counter++;
    }
    
    return String.valueOf(counter);
}

/**
* @see com.ibm.btt.services.BTTServiceImpl#handleCommand(String, Hashtable)
*/
public Object handleCommand(String opName, Hashtable parts) throws Exception {
    Object result = null;
    
    if (opName.equals("addCounter")) {
        Object obj = parts.get("inc");
        result = addCounter((String)(((Hashtable)obj).get("inc")));
    }
    
    return result;
}

/**
* Initializes the Service reading its attributes values from aTag. 
* @param aTag com.ibm.dse.base.Tag
* @return java.lang.Object - this object
*/
public Object initializeFrom(Tag aTag) throws IOException, DSEException {

    TagAttribute attr = null;
    Enumeration attrs = aTag.getAttrList().elements();
    
    while (attrs.hasMoreElements()) {
        attr = (TagAttribute) attrs.nextElement();
        if(attr.getName().equals("startValue")) {
            counter = Integer.parseInt((String) attr.getValue());
        } else if(attr.getName().equals("id")) {
            setName((String) attr.getValue());
        }
        return super.initializeFrom(aTag);
    }
}


Feedback