com.sun.electric.database.variable
Class EvalJavaBsh

java.lang.Object
  extended by com.sun.electric.database.variable.EvalJavaBsh

public class EvalJavaBsh
extends java.lang.Object

Used for evaluating Java expressions in Variables It is meant to be invoked from the Variable context; these methods should not be used from other contexts, and thus are declared protected.

This class is thread-safe, but be warned: if multiple threads are hammering the bean shell for evaluations, it will slow down a lot due to contested locks.

Author:
gainsley

Field Summary
static EvalJavaBsh evalJavaBsh
          the singleton object of this class.
 
Constructor Summary
EvalJavaBsh()
          the contructor
 
Method Summary
 java.lang.Object doEvalLine(java.lang.String line)
           
protected  java.lang.Object evalVarObject(CodeExpression ce, VarContext context, java.lang.Object info)
          Evaluate Object as if it were a String containing java code.
 VarContext getCurrentContext()
          See what the current context of eval is.
 java.lang.Object getCurrentInfo()
          See what the current info of eval is.
 java.lang.Object getVariable(java.lang.String name)
           
 boolean isValidJava(java.lang.String line)
          Method to determine whether a string is valid Java code.
 java.lang.Object P(java.lang.String name)
          Method to lookup a variable for evaluation.
 java.lang.Object PAR(java.lang.String name)
          Method to lookup a variable for evaluation.
static java.lang.String replace(java.lang.String expr)
          Replaces @var calls to P("var") Replaces P("var") calls to P("ATTR_var") Replaces PAR("var") calls to PAR("ATTR_var")
static void runScript(java.lang.String script)
          Run a Java Bean Shell script
static Job runScriptJob(java.lang.String script)
          Run a Java Bean Shell script
 void setVariable(java.lang.String name, java.lang.Object value)
          Set a variable in the Java Bean Shell
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

evalJavaBsh

public static final EvalJavaBsh evalJavaBsh
the singleton object of this class.

Constructor Detail

EvalJavaBsh

public EvalJavaBsh()
the contructor

Method Detail

getCurrentContext

public VarContext getCurrentContext()
See what the current context of eval is.

Returns:
a VarContext.

getCurrentInfo

public java.lang.Object getCurrentInfo()
See what the current info of eval is.

Returns:
an Object.

replace

public static java.lang.String replace(java.lang.String expr)
Replaces @var calls to P("var") Replaces P("var") calls to P("ATTR_var") Replaces PAR("var") calls to PAR("ATTR_var")

Parameters:
expr - the expression
Returns:
replaced expression

evalVarObject

protected java.lang.Object evalVarObject(CodeExpression ce,
                                         VarContext context,
                                         java.lang.Object info)
                                  throws VarContext.EvalException
Evaluate Object as if it were a String containing java code. Note that this function may call itself recursively.

Parameters:
ce - the CodeExpression to be evaluates.
context - the context in which the object will be evaluated.
info - used to pass additional info from Electric to the interpreter, if needed.
Returns:
the evaluated object.
Throws:
VarContext.EvalException

P

public java.lang.Object P(java.lang.String name)
                   throws VarContext.EvalException
Method to lookup a variable for evaluation. Finds that variable 1 level up the hierarchy.

Parameters:
name - the name of the variable to find.
Returns:
the value of the variable (null if not found).
Throws:
VarContext.EvalException

PAR

public java.lang.Object PAR(java.lang.String name)
                     throws VarContext.EvalException
Method to lookup a variable for evaluation. Finds that variable anywhere up the hierarchy.

Parameters:
name - the name of the variable to find.
Returns:
the value of the variable (null if not found).
Throws:
VarContext.EvalException

runScript

public static void runScript(java.lang.String script)
Run a Java Bean Shell script


runScriptJob

public static Job runScriptJob(java.lang.String script)
Run a Java Bean Shell script


setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value)
Set a variable in the Java Bean Shell

Parameters:
name - the name of the variable
value - the value to set the variable to

getVariable

public java.lang.Object getVariable(java.lang.String name)

doEvalLine

public java.lang.Object doEvalLine(java.lang.String line)

isValidJava

public boolean isValidJava(java.lang.String line)
Method to determine whether a string is valid Java code.

Parameters:
line - the string to test.
Returns:
true if the string is valid, evaluatable Java code.