public class ScriptManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
ScriptManager.ScriptFunctionImpl |
static class |
ScriptManager.UndefinedFunctionException |
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log |
Constructor and Description |
---|
ScriptManager(java.lang.String contextName)
Initializes ScriptManager without a path to 3rd party system Python modules.
|
ScriptManager(java.lang.String contextName,
java.lang.String pathToExternalLibs) |
Modifier and Type | Method and Description |
---|---|
void |
addGlobalVariable(java.lang.String name,
org.python.core.PyObject value) |
void |
addScriptModule(java.lang.String path,
java.lang.Class<?> javaFunctionClass)
Expose all static methods of javaFunctionClass as scripting functions.
|
void |
addScriptModule(java.lang.String path,
java.lang.Class<?> javaFunctionClass,
ScriptFunctionDocProvider docProvider)
Expose all static methods of javaFunctionClass as scripting functions.
|
void |
addScriptModule(java.lang.String path,
java.lang.Object obj)
Expose all static and instance methods of obj as scripting functions.
|
void |
addScriptModule(java.lang.String path,
java.lang.Object obj,
ScriptFunctionDocProvider docProvider)
Expose all static and instance methods of obj as scripting functions.
|
void |
addScriptModule(java.lang.String path,
java.lang.String moduleCode)
Adds a script module on the given path (e.g.
|
void |
addScriptModule(java.lang.String path,
java.lang.String moduleCode,
ScriptScopeStyle scopeStyle) |
void |
addStaticFields(java.lang.String path,
java.lang.Class<?> clazz)
Adds all public static final fields defined by this class as python variables in the given path.
|
void |
addStdErrStream(java.io.OutputStream os) |
void |
addStdOutStream(java.io.OutputStream os) |
static void |
asynchInit() |
static void |
asynchInit(java.lang.String pathToExternalLibs)
Initialize the Jython System.
|
void |
clearAppModule() |
void |
clearModule(java.lang.String moduleName)
Clears the given module's internal mapping
|
void |
clearThirdPartyModules() |
ScriptFunction |
compileFunction(java.lang.String code)
Compiles a function definition (normally generated through the Extension Function style scripting system), and
returns a compiled function that can be used and reused.
|
ScriptFunction |
compileFunction(java.lang.String id,
java.lang.String functionName,
java.lang.String code)
Overload of compileFunction that allows the caller to define the identifier used for the compiled object, and the
method to extract from the code.
|
protected void |
configureScriptContext() |
org.python.core.PyStringMap |
createLocalsMap()
Creates a new local namespace with the 'system', ['app'], 'shared', and 'project' packages imported
automatically.
|
org.python.core.PyStringMap |
getGlobals()
Provides programmatic access to the global map
|
java.util.Map<java.lang.String,java.util.List<ScriptFunctionHint>> |
getHintsMap()
Maps the first element of hint path to the entire path, e.g.:
|
java.util.UUID |
getUUID() |
static void |
main(java.lang.String[] args) |
void |
removeModule(java.lang.String moduleName)
Removes the module mapping from sys.modules
|
void |
removeStdErrStream(java.io.OutputStream os) |
void |
removeStdOutStream(java.io.OutputStream os) |
void |
runCode(org.python.core.PyCode code,
org.python.core.PyObject locals)
Runs compiled python code with the given locals map.
|
void |
runCode(org.python.core.PyCode code,
org.python.core.PyObject locals,
org.python.core.PyObject globals)
Runs compiled python code with the given locals map and globals map.
|
void |
runCode(java.lang.String code,
org.python.core.PyObject locals,
org.python.core.PyObject globals,
java.lang.String filename)
Compiles and then runs some python code with the given locals map and globals map.
|
void |
runCode(java.lang.String code,
org.python.core.PyObject locals,
java.lang.String filename)
Compiles and then runs some python code with the given locals map.
|
org.python.core.PyObject |
runFunction(org.python.core.PyObject function,
org.python.core.PyObject... arguments) |
void |
setContextName(java.lang.String name)
Resets this script manager's context name, which only affects logging
|
void |
setPaused(boolean paused)
Sets the script manager to be 'paused'.
|
protected void |
setState()
Sets the python thread state to our PySystemState
|
public ScriptManager(java.lang.String contextName)
public ScriptManager(java.lang.String contextName, java.lang.String pathToExternalLibs)
public void addStdOutStream(java.io.OutputStream os)
public void removeStdOutStream(java.io.OutputStream os)
public void addStdErrStream(java.io.OutputStream os)
public void removeStdErrStream(java.io.OutputStream os)
public void setContextName(java.lang.String name)
protected void setState()
public static void asynchInit(java.lang.String pathToExternalLibs)
public static void asynchInit()
public void addScriptModule(java.lang.String path, java.lang.String moduleCode)
public void addScriptModule(java.lang.String path, java.lang.String moduleCode, ScriptScopeStyle scopeStyle)
public void addScriptModule(java.lang.String path, java.lang.Class<?> javaFunctionClass)
Expose all static methods of javaFunctionClass as scripting functions. Also exposes all static fields.
These functions will be part of the auto-complete system, but will not have any documentation provided. To
provide documentation as well use addScriptModule(String, Class, ScriptFunctionDocProvider)
.
path
- The namespace to add these functions to i.e. "system.net".javaFunctionClass
- The Class
to search for static methods.public void addScriptModule(java.lang.String path, java.lang.Class<?> javaFunctionClass, ScriptFunctionDocProvider docProvider)
Expose all static methods of javaFunctionClass as scripting functions. Also exposes all static fields.
path
- The namespace to add these functions to i.e. "system.net".javaFunctionClass
- The Class
to search for static methods.docProvider
- A ScriptFunctionDocProvider
that can produce documentation for use in the hints system.public void addScriptModule(java.lang.String path, java.lang.Object obj)
Expose all static and instance methods of obj as scripting functions. Also exposes all static fields.
These functions will be part of the auto-complete system, but will not have any documentation provided. To
provide documentation as well use addScriptModule(String, Class, ScriptFunctionDocProvider)
.
path
- The namespace to add these functions to i.e. "system.net".obj
- The Object
to search for static methods.public void addScriptModule(java.lang.String path, java.lang.Object obj, ScriptFunctionDocProvider docProvider)
Expose all static and instance methods of obj as scripting functions. Also exposes all static fields.
path
- The namespace to add these functions to i.e. "system.net".obj
- The Object
to search for static methods.docProvider
- A ScriptFunctionDocProvider
that can produce documentation for use in the hints system.public void addStaticFields(java.lang.String path, java.lang.Class<?> clazz)
public void clearAppModule()
public void clearModule(java.lang.String moduleName)
public void removeModule(java.lang.String moduleName)
public void clearThirdPartyModules()
public org.python.core.PyStringMap createLocalsMap()
public org.python.core.PyStringMap getGlobals()
public void addGlobalVariable(java.lang.String name, org.python.core.PyObject value)
public void runCode(java.lang.String code, org.python.core.PyObject locals, java.lang.String filename) throws JythonExecException
code
- the python scriptlocals
- locals mapfilename
- source file nameJythonExecException
- exScriptScopeStyle.Python21
public void runCode(org.python.core.PyCode code, org.python.core.PyObject locals) throws JythonExecException
code
- the compiled python codelocals
- locals mapJythonExecException
- exScriptScopeStyle.Python21
public void runCode(java.lang.String code, org.python.core.PyObject locals, org.python.core.PyObject globals, java.lang.String filename) throws JythonExecException
code
- the python scriptlocals
- locals mapglobals
- globals mapfilename
- source file nameJythonExecException
- exScriptScopeStyle.Python21
,
ScriptScopeStyle.Python25
public void runCode(org.python.core.PyCode code, org.python.core.PyObject locals, org.python.core.PyObject globals) throws JythonExecException
code
- the compiled python codelocals
- locals mapglobals
- globals map. If null, Python21 style scoping is used (shared global namespace).JythonExecException
- exprotected void configureScriptContext()
public org.python.core.PyObject runFunction(org.python.core.PyObject function, org.python.core.PyObject... arguments) throws JythonExecException
JythonExecException
public ScriptFunction compileFunction(java.lang.String code) throws org.python.core.PyException, JythonExecException, ScriptManager.UndefinedFunctionException
org.python.core.PyException
- exJythonExecException
- exScriptManager.UndefinedFunctionException
- expublic ScriptFunction compileFunction(java.lang.String id, java.lang.String functionName, java.lang.String code) throws org.python.core.PyException, JythonExecException, ScriptManager.UndefinedFunctionException
org.python.core.PyException
- exJythonExecException
- exScriptManager.UndefinedFunctionException
- expublic void setPaused(boolean paused)
public java.util.Map<java.lang.String,java.util.List<ScriptFunctionHint>> getHintsMap()
"path" -> ["path.to.autocomplete", "path.for.somethingelse"]
public java.util.UUID getUUID()
public static void main(java.lang.String[] args)