An example client toolkit activity implementation for the stringTokenizer activity is shown below:
package uk.org.ogsadai.client.toolkit.activity.transform; import org.apache.log4j.Logger; import uk.org.ogsadai.client.toolkit.activity.Activity; import uk.org.ogsadai.client.toolkit.activity.ActivityOutput; /** * This activity seperates the blocks of input data it receives into a * sequence of tokens for output. * * @author The OGSA-DAI Project Team */ public class StringTokenizerActivity extends Activity { /** The number of blocks to aggregate into each larger block. */ private String mDelimiters; /** * Constructs an activity to tokenize the input. */ public StringTokenizerActivity() { addInput("input"); addOutput("output"); } /** * Constructs an activity to tokenize the input using the specified * delimiters. * * @param delimiters the delimiters used to separate tokens */ public StringTokenizerActivity(final String delimiters) { this(); setDelimiters(delimiters); } /** * Constructs a request to perform an aggregation of the blocks generated * by the output of another activity. * * @param delimiters the delimiters used to separate tokens * @param input the output from another activity */ public StringTokenizerActivity( final String delimiters, final ActivityOutput input) { this(delimiters); setInput(input); } /** * Gets the activity's only output. * * @return the activity output */ public ActivityOutput getOutput() { return getOutputs()[0]; } /** * Sets the name of the output that will provide the input to this activity. * * @param input output from another activity * @throws IllegalArgumentException if the argument is null */ public final void setInput(final ActivityOutput input) { if (input == null) { throw new IllegalArgumentException("Argument must not be null"); } super.setInput(0, input.getName()); } /** * Sets the number of blocks to aggregate together into each larger block. * * @param blockSize the number of blocks */ public final void setDelimiters(final String delimiters) { if (delimiters == null) { throw new IllegalArgumentException("Argument must not be null"); } mDelimiters = delimiters; } /* * @see uk.org.ogsadai.client.toolkit.Activity#generateXML() */ protected String generateXML() { final StringBuffer sb = new StringBuffer(); sb.append("<stringTokenizer name=\""); sb.append(getName()); sb.append("\">\n"); // stringBlocksInput sub-element sb.append(" <stringBlocksInput from=\""); sb.append(getInputParameters()[0].getOutputName()); sb.append("\"/>\n"); // delimiters sub-element sb.append(" <delimiters value=\""); sb.append(mDelimiters); sb.append("\"/>\n"); // stringTokensOutput sub-element sb.append(" <stringTokensOutput name=\""); sb.append(getOutputs()[0].getName()); sb.append("\"/>"); sb.append("</stringTokenizer>"); return sb.toString(); } }
| Back: How to Write an Activity | ||
| © International Business Machines Corporation, 2004. | © The University of Edinburgh, 2004. |