|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.helma.javascript.RhinoEngine
public class RhinoEngine
This class provides methods to create JavaScript objects from JavaScript files.
| Field Summary | |
|---|---|
static java.lang.Object[] |
EMPTY_ARGS
|
| Constructor Summary | |
|---|---|
RhinoEngine(java.util.List<Repository> repositories)
Create a RhinoEngine which loads scripts from directory dir. |
|
RhinoEngine(java.util.List<Repository> repositories,
java.lang.Class[] classes)
Create a RhinoEngine which loads scripts from directory dir
and defines the given classes as native host objects. |
|
| Method Summary | |
|---|---|
void |
addCallback(java.lang.String event,
java.lang.String name,
org.mozilla.javascript.Function func)
Register a callback. |
org.mozilla.javascript.Scriptable |
createThreadScope(org.mozilla.javascript.Context cx)
Create the per-thread top level javascript scope. |
void |
defineHostClass(java.lang.Class clazz)
Define a Javascript host object implemented by the given class. |
java.lang.Object |
evaluate(java.util.Map<java.lang.String,java.lang.Object> globals,
java.lang.String path)
Evaluate a module and return the result. |
Repository |
findRepository(java.lang.String path,
Repository localPath)
|
Resource |
findResource(java.lang.String path,
Repository localPath)
Search for a resource in a local path, or the main repository. |
HelmaClassLoader |
getClassLoader()
|
org.mozilla.javascript.ContextFactory |
getContextFactory()
|
ExtendedJavaClass |
getExtendedClass(java.lang.Class type)
|
protected Repository |
getRepository(org.mozilla.javascript.Scriptable scope)
Get the repository associated with the scope or one of its prototypes |
Repository |
getRepository(java.lang.String path)
Get a resource from our script repository |
Resource |
getResource(java.lang.String path)
Get a resource from our script repository |
java.util.List<Resource> |
getResources(java.lang.String path)
Get a list of all child resources for the given path relative to our script repository. |
ReloadableScript |
getScript(java.lang.String moduleName)
Resolves a type name to a script file within our script directory and returns a Scriptable evaluated to the file. |
ReloadableScript |
getScript(java.lang.String moduleName,
Repository localPath)
Resolves a type name to a script file within our script directory and returns a Scriptable evaluated to the file. |
ModuleScope |
getShellScope()
Return a shell scope for interactive evaluation |
org.mozilla.javascript.WrapFactory |
getWrapFactory()
|
protected void |
initGlobalsAndArguments(org.mozilla.javascript.Scriptable scope,
java.util.Map<java.lang.String,java.lang.Object> globals,
java.lang.Object[] args)
Initialize and normalize the global variables and arguments on a thread scope. |
java.lang.Object |
invoke(java.util.Map<java.lang.String,java.lang.Object> globals,
org.mozilla.javascript.Scriptable thisObj,
org.mozilla.javascript.Function function,
java.lang.Object[] args)
Invoke a javascript function. |
java.lang.Object |
invoke(java.util.Map<java.lang.String,java.lang.Object> globals,
java.lang.String path,
java.lang.String method,
java.lang.Object... args)
Invoke a javascript function. |
java.lang.Object |
invokeCallback(java.lang.String event,
java.lang.Object thisObj,
java.lang.Object... args)
Invoke a callback. |
org.mozilla.javascript.Scriptable |
loadModule(org.mozilla.javascript.Context cx,
java.lang.String moduleName,
org.mozilla.javascript.Scriptable parentScope,
org.mozilla.javascript.Scriptable loadingScope)
Load a Javascript module into a module scope. |
void |
removeCallback(java.lang.String event,
java.lang.String name)
Unregister a previously registered callback. |
protected java.lang.Object |
wrapArgument(java.lang.Object value,
org.mozilla.javascript.Scriptable scope)
Prepare a single property or argument value for use within rhino. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.Object[] EMPTY_ARGS
| Constructor Detail |
|---|
public RhinoEngine(java.util.List<Repository> repositories)
dir.
repositories - a list of code repositories
public RhinoEngine(java.util.List<Repository> repositories,
java.lang.Class[] classes)
dir
and defines the given classes as native host objects.
repositories - a list of code repositoriesclasses - the host classes to define| Method Detail |
|---|
public void defineHostClass(java.lang.Class clazz)
throws java.lang.reflect.InvocationTargetException,
java.lang.InstantiationException,
java.lang.IllegalAccessException
clazz - The Java class implementing the host object.
java.lang.IllegalAccessException - if access is not available
to a reflected class member
java.lang.InstantiationException - if unable to instantiate
the named class
java.lang.reflect.InvocationTargetException - if an exception is thrown
during execution of methods of the named class
public void addCallback(java.lang.String event,
java.lang.String name,
org.mozilla.javascript.Function func)
name - the callback namefunc - the callback function
public void removeCallback(java.lang.String event,
java.lang.String name)
name - the callback name
public java.lang.Object invokeCallback(java.lang.String event,
java.lang.Object thisObj,
java.lang.Object... args)
event - the callback eventargs - the arguments
public java.lang.Object evaluate(java.util.Map<java.lang.String,java.lang.Object> globals,
java.lang.String path)
throws java.io.IOException
globals - a map of global variablespath - the path of the module to evaluate
java.io.IOException - if an I/O related error occurred
public java.lang.Object invoke(java.util.Map<java.lang.String,java.lang.Object> globals,
java.lang.String path,
java.lang.String method,
java.lang.Object... args)
throws java.io.IOException,
java.lang.NoSuchMethodException
globals - map of global variables to set in the thread scopepath - the file path to the scriptmethod - the method name to call in the scriptargs - the arguments to pass to the method
java.lang.NoSuchMethodException - the method is not defined
java.io.IOException - an I/O related error occurredpublic ModuleScope getShellScope()
public java.lang.Object invoke(java.util.Map<java.lang.String,java.lang.Object> globals,
org.mozilla.javascript.Scriptable thisObj,
org.mozilla.javascript.Function function,
java.lang.Object[] args)
throws java.io.IOException,
java.lang.NoSuchMethodException
globals - map of global variables to set in the thread scopethisObj - the object to invoke the function onfunction - the function object to invokeargs - the arguments to pass to the method
java.lang.NoSuchMethodException - the method is not defined
java.io.IOException - an I/O related error occurredpublic org.mozilla.javascript.Scriptable createThreadScope(org.mozilla.javascript.Context cx)
cx - the current context
protected void initGlobalsAndArguments(org.mozilla.javascript.Scriptable scope,
java.util.Map<java.lang.String,java.lang.Object> globals,
java.lang.Object[] args)
scope - the thread local scopeglobals - the map of global objectsargs - the arguments
protected java.lang.Object wrapArgument(java.lang.Object value,
org.mozilla.javascript.Scriptable scope)
value - the property or argument valuescope - the scope
public ReloadableScript getScript(java.lang.String moduleName)
throws org.mozilla.javascript.JavaScriptException,
java.io.IOException
moduleName - the name of the module to load
org.mozilla.javascript.JavaScriptException - if an error occurred evaluating the script file
java.io.IOException - if an error occurred reading the script file
public ReloadableScript getScript(java.lang.String moduleName,
Repository localPath)
throws org.mozilla.javascript.JavaScriptException,
java.io.IOException
moduleName - the name of the module to loadlocalPath - the path of the resource issuing this call
org.mozilla.javascript.JavaScriptException - if an error occurred evaluating the script file
java.io.IOException - if an error occurred reading the script file
public org.mozilla.javascript.Scriptable loadModule(org.mozilla.javascript.Context cx,
java.lang.String moduleName,
org.mozilla.javascript.Scriptable parentScope,
org.mozilla.javascript.Scriptable loadingScope)
throws java.io.IOException
cx - the current contextmoduleName - the module nameparentScope - the parent scope to load the moduleloadingScope - the scope requesting the module
java.io.IOException - indicates that in input/output related error occurredprotected Repository getRepository(org.mozilla.javascript.Scriptable scope)
scope - the scope to get the repository from
public Resource getResource(java.lang.String path)
path - the resource path
public Repository getRepository(java.lang.String path)
path - the resource path
public java.util.List<Resource> getResources(java.lang.String path)
path - the repository path
public Resource findResource(java.lang.String path,
Repository localPath)
path - the resource namelocalPath - a repository to look first
public Repository findRepository(java.lang.String path,
Repository localPath)
public org.mozilla.javascript.ContextFactory getContextFactory()
public HelmaClassLoader getClassLoader()
public org.mozilla.javascript.WrapFactory getWrapFactory()
public ExtendedJavaClass getExtendedClass(java.lang.Class type)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||