Custom activity sample code

The Java code in this section is a simple example of custom activity called StringBean, which is included with the Custom Activity SDK.

StringBean contains the following:

  • Ten input properties, inString1 through inString10
  • One output property, outputString
  • Three action methods:
    • concatStrings, which concatenates inString1 through inString10 and puts the results in outputString
    • logStrings, which calls concatStrings and then outputs the results to the IPA logs using the BPMAdapterRuntime interface
    • stripTrailingLinefeedChars, which calls concatStrings then removes new line characters and puts the result in outputString
package  com.lawson.bpm.adapter.sdk;
/**
 * This is a sample java adapter bean to do something moderately usefull:
 * concatenate some strings together.
 */
public class StringBean implements BPMAdapter {
 public static String version = ":@(#)$Header$"; //$NON-NLS-1$

    String[] inStrings = new String[10];
    String outputString;

    /**
     */
    public void setInString1(String val) {
        inStrings[0] = val;
    }

    /**
     */
    public void setInString2(String val) {
        inStrings[1] = val;
    }

    /**
     */
    public void setInString3(String val) {
        inStrings[2] = val;
    }

    /**
     */
    public void setInString4(String val) {
        inStrings[3] = val;
    }

    /**
     */
    public void setInString5(String val) {
        inStrings[4] = val;
    }

    /**
     */
    public void setInString6(String val) {
        inStrings[5] = val;
    }

    /**
     */
    public void setInString7(String val) {
        inStrings[6] = val;
    }

    /**
     */
    public void setInString8(String val) {
        inStrings[7] = val;
    }

    /**
     */
    public void setInString9(String val) {
        inStrings[8] = val;
    }

    /**
     */
    public void setInString10(String val) {
        inStrings[9] = val;
    }

    /**
     */
    public String getOutputString() {
        return  outputString;
    }

    /**
     * The constructor.
     */
    public StringBean() {
    }

    /**
     * Concatenate inString1...inString10 and put the resulting string in outputString.
     */
    public void concatStrings() {
        String out = ""; //$NON-NLS-1$
        for (int n = 0; n < 10; n++) {
            if (inStrings[n] != null)
                out += inStrings[n];
        }
        outputString = out;
    }

    /**
     * Call concatStrings() and then write outputString to the ProcessFlow log.
     */
    public void logStrings(BPMAdapterRuntime runtime) {
        concatStrings();
        runtime.writeToLog(outputString);
    }

    /**
     * Concatenate then take any trailing /r/n characters from the string and put the result in outputString.
     */
    public void stripTrailingLinefeedChars() {
        int len;
        char ch;
        concatStrings();
        while (true) {
            len = outputString.length();
            if (len > 0) {
                ch = outputString.charAt(len-1);
                if ((ch == '\n') || (ch == '\r') || (ch == 0))
                    outputString = outputString.substring(0, len-1);
                else
                    break;
            }
            else {
                break;
            }
        }
    }
}