This executor will eventually replace the java executor. Tools are now simple created implementing a specific interface. Next the user can create the tools inside the Cyberintegrator using a simple wizard. The wizard will ask for the location of the jar file(s) needed and will create the tool based on the interface implemented. The interface can be found in cyberintegratortool.jar.

Following is an example of a class implementing this interface.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.Collection;
import java.util.HashSet;

import edu.uiuc.ncsa.cyberintegrator.executor.cyberintegrator.tool.CyberintegratorTool;
import edu.uiuc.ncsa.cyberintegrator.executor.cyberintegrator.tool.Dataset;
import edu.uiuc.ncsa.cyberintegrator.executor.cyberintegrator.tool.Parameter;

/**

  • Find a word in a sentence. This will only return those sentences that contain
  • the specified word.
  • @author Rob Kooper
  • */
    public class WordFinder implements CyberintegratorTool {
    private File input;
    private File output;
    private String word;

/**

  • Return the name of the tool.
  • @return name of the tool.
    */
    public String getName()
    Unknown macro: { return "Find word"; }

/**

  • Return the version number of the tool.
  • @return version of the tool.
    */
    public int getVersion()
    Unknown macro: { return 3; }

/**

  • Return a long description of the tool. This description is used to help
  • the user understand what the tool does, and what the inputs, outputs and
  • parameters mean. This can also contain links to papers published,
  • references to algorithms etc.
  • @return description of the tool.
    */
    public String getDescription()
    Unknown macro: { return "Search through the input file and find the word specified as parameter." + " Only those lines that contain the word will be put in the output."; }

/**

  • Return a list of inputs needed by the tool. In this particular case we
  • need a text file that will be examined.
  • @return list of inputs needed by the tool.
    */
    public Collection getInputs()
    Unknown macro: { HashSet result = new HashSet(); result.add(new Dataset("1", "input", "", "text/plain", "filename.txt")); return result; }

/**

  • Set the input for the tool. In this case it will set the name of the
  • input file.
  • @param id
  • the id of the input.
  • @param input
  • a pointer to a file on disk with the input data.
    */
    public void setInput(String id, File input)
    Unknown macro: { if ("1".equals(id))
    Unknown macro: { this.input = input; }
    }

/**

  • Return a list of outputs generated by the tool. In this particular case
  • we return a text file with only those lines that contain the word
  • specified as a parameter.
  • @return list of outputs generated by the tool.
    */
    public Collection getOutputs()
    Unknown macro: { HashSet result = new HashSet(); result.add(new Dataset("1", "output", "", "text/plain", null)); return result; }

/**

  • Retrieve the output of the tool.
  • @param id
  • the id of the output.
  • @return a pointer to a file on disk with the output data.
    */
    public File getOutput(String id)
    Unknown macro: { if ("1".equals(id))
    Unknown macro: { return output; }
    return null; }

/**

  • Return a list of parameters needed by the tool. In this particular case
  • we need a single word that will be checked for.
  • @return list of parameters needed by the tool.
    */
    public Collection getParameters()
    Unknown macro: { HashSet result = new HashSet(); result.add(new Parameter("1", "output", "", "string", "test", false)); return result; }

/**

  • Set the parameter for the tool. In this case it will set the word that
  • will be searched for in the input file.
  • @param id
  • the id of the parameter.
  • @param value
  • the value for the parameter
    */
    public void setParameter(String id, String value)
    Unknown macro: { if ("1".equals(id))
    Unknown macro: { word = value; }
    }

/**

  • Execute the tool. In this case it will load the input file, read the
  • input file, check each line for the presence of the word and create the
  • output file with only those lines that contain the word.
  • @throws an
  • exception is thrown if the function fails to execute
  • properly.
    */
    public void execute() throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(input));
    output = File.createTempFile("output", ".txt");
    PrintStream ps = new PrintStream(output);
    String line;
    while ((line = br.readLine()) != null)
    Unknown macro: { if (line.contains(word))
    Unknown macro: { ps.println(line); }
    }
    ps.close();
    }
    }
  • No labels