org.figure8.join.services.scripting
Class ScriptLauncher

java.lang.Object
  extended by org.figure8.join.services.scripting.ScriptLauncher
All Implemented Interfaces:
Configurable
Direct Known Subclasses:
AntScriptLauncher, GroovyScriptLauncher, JSR223ScriptLauncher, RubyScriptLauncher

public abstract class ScriptLauncher
extends java.lang.Object
implements Configurable

This is an abstract base class allowing to manage script initialization, parameters binding and execution. This class implements Configurable so that it can be configured through an interactive process.
Subclasses may implement behaviour specific to the script engine they are wrapping. They may also be Configurable in order to add specific configuration parameters to the one defined in base class (that is the script path).

Version:
$Revision: 1.2 $
Author:
Laurent Broudoux
See Also:
Configurable

Field Summary
protected static java.util.List parameters
          List of ParameterDefinitions supported by this launcher
static java.lang.String SCRIPT_PARAM
          Name of configurable parameter denoting the path of script to run.
protected static ParameterDefinition scriptParam
          ParameterDefinition representation of parameter denoting the path of script to run.
 
Constructor Summary
protected ScriptLauncher()
          Creates a new instance of ScriptLauncher.
protected ScriptLauncher(java.lang.String scriptPath)
          Creates a new instance of ScriptLauncher spceifying script path.
 
Method Summary
 java.io.OutputStream getLogOutputStream()
           
 ParameterDefinition[] getParameterDefinitions()
          Get this object parameters definitions as an array.
 java.util.List getParameterDefinitionsAsList()
          Get this object parameters definitions as a list
 java.io.File getScript()
           
 java.lang.String getScriptPath()
           
abstract  void runScript(java.util.Properties properties)
          Abstract method that do the real job by running the script specified by scriptPath.
 void setLogOutputStream(java.io.OutputStream logOutputStream)
           
 void setParameter(ParameterDefinition parameter, java.lang.String parameterValue)
          Set the value of a parameter using its definition.
 void setParameter(java.lang.String parameterName, java.lang.String parameterValue)
          Set the value of a parameter using its nama
 void setParameters(java.util.Properties parameters)
          Convenient methods for setting all attributes values using a single method.
 void setScriptPath(java.lang.String scriptPath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCRIPT_PARAM

public static final java.lang.String SCRIPT_PARAM
Name of configurable parameter denoting the path of script to run.

See Also:
Constant Field Values

parameters

protected static java.util.List parameters
List of ParameterDefinitions supported by this launcher


scriptParam

protected static final ParameterDefinition scriptParam
ParameterDefinition representation of parameter denoting the path of script to run.

Constructor Detail

ScriptLauncher

protected ScriptLauncher()
Creates a new instance of ScriptLauncher.


ScriptLauncher

protected ScriptLauncher(java.lang.String scriptPath)
                  throws InvalidParameterException
Creates a new instance of ScriptLauncher spceifying script path.

Parameters:
scriptPath - the path of script to later execute
Throws:
InvalidParameterException - if path cannot be accessed
Method Detail

getScriptPath

public java.lang.String getScriptPath()
Returns:
The path of script to execute

setScriptPath

public void setScriptPath(java.lang.String scriptPath)
                   throws InvalidParameterException
Parameters:
scriptPath - the path of script to execute
Throws:
InvalidParameterException - if path cannot be accessed

getScript

public java.io.File getScript()
Returns:
The file corresponding to script or null if scriptPath has not been set yet.

getLogOutputStream

public java.io.OutputStream getLogOutputStream()
Returns:
The output stream that script may use for logging output

setLogOutputStream

public void setLogOutputStream(java.io.OutputStream logOutputStream)
Parameters:
logOutputStream - The output stream that script may use for logging output

runScript

public abstract void runScript(java.util.Properties properties)
                        throws ScriptException
Abstract method that do the real job by running the script specified by scriptPath. Implementation may use properties to initialize their runtime environment with corresponding global variables.

Parameters:
properties - The runtime properties to inject into execution environment
Throws:
ScriptException - if something wrong occurs during script parsing, evaluation, ...

getParameterDefinitionsAsList

public java.util.List getParameterDefinitionsAsList()
Get this object parameters definitions as a list

Specified by:
getParameterDefinitionsAsList in interface Configurable
Returns:
A list of ParameterDefinition objects

getParameterDefinitions

public ParameterDefinition[] getParameterDefinitions()
Get this object parameters definitions as an array. Implementation uses result from getParameterDefintiionsAdList() so that subclasses may not override this implementation.

Specified by:
getParameterDefinitions in interface Configurable
Returns:
An array of ParameterDefinition objects

setParameter

public void setParameter(java.lang.String parameterName,
                         java.lang.String parameterValue)
                  throws InvalidParameterException
Set the value of a parameter using its nama

Specified by:
setParameter in interface Configurable
Parameters:
parameterName - The name of parameter so set value for
parameterValue - The value of the paramater
Throws:
InvalidParameterException - if this parameter is not supported by this object

setParameter

public void setParameter(ParameterDefinition parameter,
                         java.lang.String parameterValue)
                  throws InvalidParameterException
Set the value of a parameter using its definition. Implementation deletgates the setting of parameter to setParameter(String, String) so that subclasses may not ovveride this implementation.

Specified by:
setParameter in interface Configurable
Parameters:
parameter - The definitino of the paramater to set
parameterValue - The value of the parameter
Throws:
InvalidParameterException - if this parameter is not supported by this object

setParameters

public void setParameters(java.util.Properties parameters)
                   throws InvalidParameterException
Convenient methods for setting all attributes values using a single method.

Specified by:
setParameters in interface Configurable
Parameters:
parameters - Properties where keys are parameter names
Throws:
InvalidParameterException - if one of these parameters is not supported by this object


Copyright © 2005-2008 Join. All Rights Reserved.