アプリケーションソース
以下のコードは、この例を実装します。
package com.infoengine.examples.applications;
import com.infoengine.au.NamingService;
import com.infoengine.object.factory.Group;
import com.infoengine.SAK.Task;
import com.infoengine.util.IEException;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Vector;
public class ExecuteTask {
/**
* Demonstrate the com.infoengine.SAK interface of Infoengine.
*
* command line: java com.infoengine.examples.applications.ExecuteTask
* -t <task uri>
* -p <processor>
* -u <username>
* -n <naming service name>
* -props <property resource>
*
* @param args
*/
public static void main ( String [] args ) {
String taskUri = null;
String processor = null;
String username = null;
String namingService = null;
String props = null;
for ( int i = 0; i < args.length; i++ ) {
if ( args[i].equals ( "-t" ) ) {
if ( i < args.length-1 )
taskUri = args[++i];
}
else if ( args[i].equals ( "-p" ) ) {
if ( i < args.length-1 )
processor = args[++i];
}
else if ( args[i].equals ( "-u" ) ) {
if ( i < args.length-1 )
username = args[++i];
}
else if ( args[i].equals ( "-n" ) ) {
if ( i < args.length-1 )
namingService = args[++i];
}
else if ( args[i].equals ( "-props" ) ) {
if ( i < args.length-1 )
props = args[++i];
}
else {
System.err.println
("unrecognized parameter \"" + args[i] + "\"");
usage ();
}
}
if ( taskUri == null ) {
System.err.println ( "missing required parameter -t <task uri>" );
usage ();
}
if ( namingService == null )
namingService = "namingService";
if ( props == null )
System.err.println
("missing required parameter -props <property resource>");
usage ();
// Initialize the naming service and read the infoengine properties
try {
NamingService ns =
NamingService.newInstance (namingService, props);
}
catch ( FileNotFoundException f ) {
System.err.println (props + ": property file not found");
System.exit (1);
}
catch ( Exception e ) {
System.err.println (props + ": unable to read properties");
e.printStackTrace (System.err);
System.exit (1);
}
// Create a Task object to execute
Task task = null;
if ( processor == null ) {
task = new Task (taskUri);
}
else {
Vector procVector = new Vector ();
procVector.addElement (processor);
task = new Task (taskUri, procVector);
}
// execute the task
try {
task.invoke ();
}
catch ( Exception e ) {
e.printStackTrace (System.err);
System.exit (1);
}
// retrieve and print the results
Enumeration groups = task.getGroupNames ();
System.out.println ("groups produced by " + taskUri + ": " + groups);
PrintWriter pw = new PrintWriter (System.out);
while ( groups.hasMoreElements () ) {
Group group = task.getGroup ((String)groups.nextElement ());
group.toXML (pw, true, true);
}
System.exit ( 0 );
}
/**
* Print the command line parameters
*/
public static void usage () {
System.err.println
("java com.infoengine.examples.applications.ExecuteTask");
System.err.println ("\t-t <task uri>");
System.err.println ("\t-p <processor>");
System.err.println ("\t-u <username>");
System.err.println ("\t-n <naming service name>");
System.err.println ("\t-props <property resource>");
System.exit (1);
}
}