|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.scripting.AbstractScript
public abstract class AbstractScript
Abstract implementation of Script. Provides a standard framework for reloadable, "compileable" scripts.
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 Summary | |
|---|---|
AbstractScript(VfsFile file)
|
|
| Method Summary | |
|---|---|
VfsFile |
getFile()
|
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()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractScript(VfsFile file)
| Method Detail |
|---|
protected void setThrown(java.lang.Throwable throwup)
protected abstract void reloadImp()
throws java.lang.Exception
java.lang.Exception
protected 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()
Script
parse in interface Scriptpublic java.lang.Object runScript()
ScriptScript.getThrown() method.
runScript in interface Scriptpublic java.lang.String getName()
Script
getName in interface Scriptpublic java.lang.Throwable getThrown()
Script
getThrown in interface Scriptpublic java.lang.Object getVariable(java.lang.String name)
ScriptScript.setVariable(String, Object).
getVariable in interface Scriptname - name of the variable in the script
public Naming<java.lang.Object> getVariables()
Script
getVariables 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().
run in interface Scriptrun in interface java.lang.Runnable
public void setVariable(java.lang.String name,
java.lang.Object value)
Script
setVariable in interface Scriptname - name of the variable in the scriptvalue - value of the variable in the scriptpublic void setVariables(Naming<java.lang.Object> newVariables)
Script
setVariables 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()
public boolean isModified()
Script
isModified in interface Script
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||