org.semwebcentral.sweetrules.util
Class SweetScriptLauncher

java.lang.Object
  extended byorg.semwebcentral.sweetrules.util.SweetScriptLauncher

public class SweetScriptLauncher
extends java.lang.Object

Created on Nov 1, 2004 A utility to launch a script file.

Author:
Shashidhara K Ganjugunte, Dr. Benjamin Grosof, Dr. Said Tabet, Chitravanu Neogy

Nested Class Summary
private  class SweetScriptLauncher.StreamHandler
           
 
Field Summary
private static SweetScriptLauncher sweetScriptLauncher
          Singleton instance
 
Constructor Summary
private SweetScriptLauncher()
          The hidden constructor
 
Method Summary
static SweetScriptLauncher getInstance()
          Accessor for the singleton
 int invokeDefaultShell(java.lang.String scriptName, java.lang.String[] scriptArgs)
          Invokes a shell based on configuration settings.
 int launchScript(java.lang.String shellPath, java.lang.String[] shellOptions, java.lang.String scriptPath, java.lang.String[] scriptArgs)
          Launches a script in the specified shell and passes the appropriate command line arguments to the script.
private  void redirectStreams(java.lang.Process process)
          Explicitly read the process's stream and redirect them to the calling process's streams
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sweetScriptLauncher

private static SweetScriptLauncher sweetScriptLauncher
Singleton instance

Constructor Detail

SweetScriptLauncher

private SweetScriptLauncher()
The hidden constructor

Method Detail

invokeDefaultShell

public int invokeDefaultShell(java.lang.String scriptName,
                              java.lang.String[] scriptArgs)
                       throws SweetException
Invokes a shell based on configuration settings. The caller of this API should ensure that the scriptPath parameter does not have file extension e.g. suppose the script to be invoked is helloWorld.cmd on a win32 machine, then only helloWorld should be passed. The extension ".cmd" is automatically appended based on the paramters in the config file. Also the directory prefix is appended using SCRIPT_ROOT_DIR property This API also passes default arguments to the shell

Parameters:
scriptName - The name of the script, using the final properties in SweetConfigLoader
scriptArgs - The arguments to the script
Returns:
Result of invoking the script (error level).
Throws:
SweetException - if an error occurs

launchScript

public int launchScript(java.lang.String shellPath,
                        java.lang.String[] shellOptions,
                        java.lang.String scriptPath,
                        java.lang.String[] scriptArgs)
                 throws SweetException
Launches a script in the specified shell and passes the appropriate command line arguments to the script. This is a raw API which just does the job of lauching a script Warning: This is blocking call and waits for the script to return

Parameters:
shellPath - The shell process to host the script
shellOptions - The options for the shell
scriptPath - The path to the script
scriptArgs - The arguments to the script
Returns:
The exit value after running the script
Throws:
SweetException

redirectStreams

private void redirectStreams(java.lang.Process process)
                      throws java.io.IOException
Explicitly read the process's stream and redirect them to the calling process's streams

Parameters:
process - The process whose streams are to be redirected
Throws:
java.io.IOException - if an error occurs

getInstance

public static SweetScriptLauncher getInstance()
Accessor for the singleton

Returns:
The singleton object