org.eclipse.birt.core.script
Class ScriptContext

java.lang.Object
  extended by org.eclipse.birt.core.script.ScriptContext

public class ScriptContext
extends java.lang.Object

Wraps around the Rhino Script context


Field Summary
protected  java.util.Map<java.lang.String,org.mozilla.javascript.Script> compiledScripts
          a cache storing compiled script
protected  org.mozilla.javascript.Context context
          the JavaScript Context
protected  org.mozilla.javascript.ImporterTopLevel global
           
protected static java.util.logging.Logger logger
          for logging
protected  org.mozilla.javascript.NativeObject params
          for BIRT globel varible "params"
protected  org.mozilla.javascript.Scriptable scope
          The JavaScript scope used for script execution
protected  java.util.HashMap<java.lang.String,ScriptExpression> scriptExpressionCache
          a cache storing ScriptExpression
protected  org.mozilla.javascript.Scriptable sharedScope
           
 
Constructor Summary
ScriptContext()
          constructor
ScriptContext(org.mozilla.javascript.ScriptableObject root)
           
 
Method Summary
 org.mozilla.javascript.Scriptable enterScope()
          creates a new scripting scope
 org.mozilla.javascript.Scriptable enterScope(org.mozilla.javascript.Scriptable newScope)
          Use a new scope in the script context.
 java.lang.Object eval(ScriptExpression expr)
          evaluates a script
 java.lang.Object eval(java.lang.String source)
          evaluates a script
 java.lang.Object eval(java.lang.String source, org.mozilla.javascript.Scriptable scope)
          Evaluates a String with given scope.
 void exit()
          exit the scripting context
 void exitScope()
          exits from the current scripting scope.
 org.mozilla.javascript.Context getContext()
           
 org.mozilla.javascript.Scriptable getRootScope()
           
 org.mozilla.javascript.Scriptable getScope()
           
 org.mozilla.javascript.Scriptable getSharedScope()
           
 java.lang.Object javaToJs(java.lang.Object value)
           
 java.lang.Object jsToJava(java.lang.Object jsValue)
          converts a JS object to a Java object
 java.lang.Object lookupBean(java.lang.String name)
          checks if a property is available in the scope
 void registerBean(java.lang.String name, java.lang.Object value)
           
static void registerInitializer(IJavascriptInitializer initializer)
          Deprecated. BIRT 1.0.1
static void registerWrapper(IJavascriptWrapper wrapper)
          Deprecated. BIRT 1.0.1
 void setApplicationClassLoader(java.lang.ClassLoader appLoader)
           
 void setCompiledScripts(java.util.Map<java.lang.String,org.mozilla.javascript.Script> compiledScripts)
           
static void unregisterInitializer(IJavascriptInitializer initializer)
          Deprecated. BIRT 1.0.1
static void unregisterWrapper(IJavascriptWrapper wrapper)
          Deprecated. BIRT 1.0.1
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static java.util.logging.Logger logger
for logging


context

protected org.mozilla.javascript.Context context
the JavaScript Context


global

protected org.mozilla.javascript.ImporterTopLevel global

sharedScope

protected org.mozilla.javascript.Scriptable sharedScope

scope

protected org.mozilla.javascript.Scriptable scope
The JavaScript scope used for script execution


compiledScripts

protected java.util.Map<java.lang.String,org.mozilla.javascript.Script> compiledScripts
a cache storing compiled script


scriptExpressionCache

protected java.util.HashMap<java.lang.String,ScriptExpression> scriptExpressionCache
a cache storing ScriptExpression


params

protected org.mozilla.javascript.NativeObject params
for BIRT globel varible "params"

Constructor Detail

ScriptContext

public ScriptContext()
constructor


ScriptContext

public ScriptContext(org.mozilla.javascript.ScriptableObject root)
Method Detail

setCompiledScripts

public void setCompiledScripts(java.util.Map<java.lang.String,org.mozilla.javascript.Script> compiledScripts)

registerBean

public void registerBean(java.lang.String name,
                         java.lang.Object value)
Parameters:
name - the name of a property
value - the value of a property

exit

public void exit()
exit the scripting context


enterScope

public org.mozilla.javascript.Scriptable enterScope()
creates a new scripting scope


enterScope

public org.mozilla.javascript.Scriptable enterScope(org.mozilla.javascript.Scriptable newScope)
Use a new scope in the script context. The following script is evaluated in the new scope. You must call exitScope to return to the parent scope. The new scope is created automatically if the newScope is null.

Parameters:
newScope, - scope used for following evaluation. null means create a scope automatically.
Returns:
the scope used for following evaluation.

exitScope

public void exitScope()
exits from the current scripting scope. Must couple with the enterScope.


getScope

public org.mozilla.javascript.Scriptable getScope()
Returns:
the current scope

getSharedScope

public org.mozilla.javascript.Scriptable getSharedScope()

getRootScope

public org.mozilla.javascript.Scriptable getRootScope()

getContext

public org.mozilla.javascript.Context getContext()

lookupBean

public java.lang.Object lookupBean(java.lang.String name)
checks if a property is available in the scope

Parameters:
name -
Returns:

eval

public java.lang.Object eval(java.lang.String source)
                      throws BirtException
evaluates a script

Parameters:
source - script to be evaluated
Returns:
the evaluated value
Throws:
BirtException

eval

public java.lang.Object eval(java.lang.String source,
                             org.mozilla.javascript.Scriptable scope)
                      throws BirtException
Evaluates a String with given scope.

Parameters:
source -
scope -
Returns:
Throws:
BirtException

eval

public java.lang.Object eval(ScriptExpression expr)
                      throws BirtException
evaluates a script

Throws:
BirtException

jsToJava

public java.lang.Object jsToJava(java.lang.Object jsValue)
converts a JS object to a Java object

Parameters:
jsValue - javascript object
Returns:
Java object

javaToJs

public java.lang.Object javaToJs(java.lang.Object value)

registerInitializer

public static void registerInitializer(IJavascriptInitializer initializer)
Deprecated. BIRT 1.0.1

register a intializer which is called when construct a new script context. You can't reigster the same initializer more than once, otherwise the initailzier will be called multiple times.

Parameters:
initializer - initializer.

unregisterInitializer

public static void unregisterInitializer(IJavascriptInitializer initializer)
Deprecated. BIRT 1.0.1

remove a intialzier.

Parameters:
initializer - to be removed.

registerWrapper

public static void registerWrapper(IJavascriptWrapper wrapper)
Deprecated. BIRT 1.0.1

register a wrapper which should be called in WapperFactory.

Parameters:
wrapper - new wrapper.

unregisterWrapper

public static void unregisterWrapper(IJavascriptWrapper wrapper)
Deprecated. BIRT 1.0.1

remove the wapper.

Parameters:
wrapper - to be removed.

setApplicationClassLoader

public void setApplicationClassLoader(java.lang.ClassLoader appLoader)


Copyright © 2008 Actuate Corp. All rights reserved.