|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Script
Generic interface for scripting language scripts.
Implementations must obey the following rules.
First, no exceptions may be thrown by runScript(). In fact, catching Throwable (so as to get RuntimeExceptions, OutOfMemoryError, etc.) is generally recommended. Often a running system can recover from a script's OutOfMemoryError. Instead of being thrown, uncaught Throwables should be logged as errors and made available via the getThrown() method. Note that this does not prevent the script itself from catching and handling its own exceptions; it only applies to exceptions that are not caught by the script.
Second, scripts should be cached and compiled for efficiency (whatever that
means for the given language). However, they should be reloaded and
recompiled whenever the backing file(s) change. Use methods like
VfsFile.getLastModifiedMillis() to determine
whether a file has changed efficiently.
Scripts should have their own logging context. In general this should correspond to the full classname of the Script implementation, plus the URL, file, or other location of the script itself. For example:
private static final Log log = LogFactory.getLog(FOOScript.class.getName()
+ ":" + scriptPath);
Most scripts require some kind of input; this is allowed through the use of
settable variables (setVariable(String, Object) and
setVariables(Naming)). The values of variables can be of any
appropriate type (assuming that the scripting language understands it of
course). All script implementations should provide "log" as a built-in
variable, set to the Log instance as described above, and "script", set to
the Script implementation itself. Generally "result" will be the variable
used to set a return value.
Copyright 2005-2006 Partner Software, Inc.
| Method Summary | |
|---|---|
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. |
void |
run()
Executes the script exactly as in runScript(), but without
returning a result. |
java.lang.Object |
runScript()
Executes the script, and returns a result. |
ScriptThread |
runThreaded()
Executes the script exactly as in run(), but in a separate thread
(specifically, a ScriptThread). |
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. |
| Method Detail |
|---|
java.lang.Object runScript()
getThrown() method.
void run()
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 java.lang.RunnableScriptThread runThreaded()
run(), but in a separate thread
(specifically, a ScriptThread). Returns the thread.
boolean parse()
java.lang.String getName()
void setVariable(java.lang.String name,
java.lang.Object value)
name - name of the variable in the scriptvalue - value of the variable in the scriptjava.lang.Object getVariable(java.lang.String name)
setVariable(String, Object).
name - name of the variable in the script
Naming<java.lang.Object> getVariables()
void setVariables(Naming<java.lang.Object> newVariables)
newVariables - java.lang.Throwable getThrown()
Log getScriptLog()
private static final Log log = LogFactory.getLog(FOOScript.class.getName()
+ "." + scriptPath);
boolean isModified()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||