public abstract class AbstractScript extends java.lang.Object implements Script
You should only have to implement the *Imp() methods; you may feel free to throw any exceptions and they will be dealt with appropriately.
Example implementation:
public class FooScript extends AbstractScript {
protected void reloadImp() throws Exception {
// source file changed; compile or reparse or reload or whatever
}
protected Object runScriptImp(Naming<Object> variables) throws Exception {
// set variables and run the script, returning the result
}
}
Copyright 2007 Partner Software, Inc.
| Constructor and Description |
|---|
AbstractScript(VfsFile file) |
| Modifier and Type | Method and Description |
|---|---|
VfsFile |
getFile()
If the script is associated with a file, return the file.
|
java.lang.String |
getName()
Returns the name of the script.
|
Log |
getScriptLog()
Returns the Log context for the script.
|
java.lang.Throwable |
getThrown()
If, during execution, the script terminates and throws an
otherwise-uncaught exception, that exception will be available here.
|
java.lang.Object |
getVariable(java.lang.String name)
Gets a single variable defined for the script.
|
Naming<java.lang.Object> |
getVariables()
Gets all defined variables in the script.
|
boolean |
isModified()
Returns true if the script has changed since the last time it was run.
|
boolean |
parse()
Parses the script, and returns true if it looks reasonably valid.
|
protected abstract void |
reloadImp()
Subclasses should implement this method to do any maintenance associated
with changes in the source file.
|
void |
run()
Executes the script exactly as in
Script.runScript(), but without
returning a result. |
java.lang.Object |
runScript()
Executes the script, and returns a result.
|
protected abstract java.lang.Object |
runScriptImp(Naming<java.lang.Object> variables)
Subclasses should implement this method with their actual script-running
implementation.
|
ScriptThread |
runThreaded()
Executes the script exactly as in
Script.run(), but in a separate thread
(specifically, a ScriptThread). |
protected void |
setThrown(java.lang.Throwable throwup)
Subclasses can use this to set the exception returned by getThrown().
|
void |
setVariable(java.lang.String name,
java.lang.Object value)
Sets a single variable in the script.
|
void |
setVariables(Naming<java.lang.Object> newVariables)
Sets all variables (except for predefined ones like "log") in one swell
foop.
|
java.lang.String |
toString() |
public AbstractScript(VfsFile file)
protected void setThrown(java.lang.Throwable throwup)
protected abstract void reloadImp()
throws java.lang.Exception
java.lang.Exceptionprotected abstract java.lang.Object runScriptImp(Naming<java.lang.Object> variables) throws java.lang.Exception
java.lang.Exceptionpublic ScriptThread runThreaded()
ScriptScript.run(), but in a separate thread
(specifically, a ScriptThread). Returns the thread.runThreaded in interface Scriptpublic boolean parse()
Scriptpublic java.lang.Object runScript()
ScriptScript.getThrown() method.public java.lang.String getName()
Scriptpublic java.lang.Throwable getThrown()
Scriptpublic java.lang.Object getVariable(java.lang.String name)
ScriptScript.setVariable(String, Object).getVariable in interface Scriptname - name of the variable in the scriptpublic Naming<java.lang.Object> getVariables()
ScriptgetVariables in interface Scriptpublic void run()
ScriptScript.runScript(), but without
returning a result. The sole purpose of this method is to implement the
Runnable interface, which makes threading etc. easier. Subclasses will
generally simply call runScript().public void setVariable(java.lang.String name,
java.lang.Object value)
ScriptsetVariable in interface Scriptname - name of the variable in the scriptvalue - value of the variable in the scriptpublic void setVariables(Naming<java.lang.Object> newVariables)
ScriptsetVariables in interface Scriptpublic Log getScriptLog()
Script
private static final Log log = LogFactory.getLog(FOOScript.class.getName()
+ "." + scriptPath);
getScriptLog in interface Scriptpublic java.lang.String toString()
toString in class java.lang.Objectpublic VfsFile getFile()
Scriptpublic boolean isModified()
ScriptisModified in interface Script