|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.actf.validation.valdoc.codeproc.AbstractCodeProcessor
org.eclipse.actf.validation.valdoc.scripting.AbstractCodeInterpreter
public abstract class AbstractCodeInterpreter
used to evaluate expressions and execute scripts given in the XML document. By default, all text content of elements and expressions within curly braces {...} will be evaluated by the interpreter.
Note: Although this class provides the full implementation of the
CodeInterpreter
interface, it is recommended that the
AbstractCodeInterpreter class be extended by those wishing to use scripting
languages not currently supported by or packaged with this application.
Field Summary | |
---|---|
protected org.apache.bsf.BSFManager |
manager
|
Fields inherited from class org.eclipse.actf.validation.valdoc.codeproc.AbstractCodeProcessor |
---|
classpath, configuration, language, model |
Fields inherited from interface org.eclipse.actf.validation.valdoc.codeproc.ICodeProcessor |
---|
DEFAULT_CODEPROCESSOR_FACTORY, FACTORY_PROCESSOR_KEY, SCRIPTLANG_ID |
Constructor Summary | |
---|---|
AbstractCodeInterpreter(String language,
IModel model)
create a code interpreter for processing scripts and expressions in the specified language. |
Method Summary | |
---|---|
void |
addScript(String code)
execute the script code specified. |
void |
addScript(String scriptName,
String scriptCode)
add the script code with the specified script name to this interpreter for later execution |
Object |
evaluateArguments(String code,
Class returnType)
attempt to evaluate the given string as an argument of the specified type. |
Object[] |
evaluateArguments(String code,
Class[] paramTypes)
attempt to evaluate the given code and return an array of objects corresponding to the specified types. |
protected abstract String |
formatPackageImport(String packageName)
|
Object |
getEnvironment()
used to retreave the environment of this interpreter so as to be passed to the setEnvironment(Object) of a newly instantiated
interpreter |
char |
getExpressionDelimiter()
the expression delimiter is always a semicolon (;) unless getLanguageSupportsTuples() returns true |
String |
getInitCode()
get the initialization code for this interpreter |
boolean |
getLanguageSupportsTuples()
return whether or not the language of this interpreter supports "tuples". |
protected String |
getNullValue()
return the equivalent of a null value |
String |
getScript(String scriptName)
get the code associated with the given script name |
protected void |
initClasspath()
initializes the underlying scripting engine with the classpath supplied via setClasspath . |
boolean |
isCompilerProcessor()
tests whether or not this processor is a compiler. |
protected void |
postInit()
perform initialization after instantiating underlying interpreter. |
protected void |
preInit()
perform initialization prior to instantiating the underlying script interpreter. |
boolean |
processCode(String[] params)
execute the code in params[0]. |
void |
setClasspath(String cp)
set the classpath for this processor. The classpath is used in one of two ways, depending upon the type of processor being used:
The classpath for a processor isnot necessarily the same as that used by ACTF validation engines. A default value is supplied in the ValidationConstants.CODE_PROCESSOR_CLASSPATH_KEY property in the raven.xml file. |
void |
setEnvironment(Object env)
set the environment for this interpreter. |
protected void |
setLanguageSupportsTuples(boolean b)
set whether or not the scripting language supports tuples |
void |
setLocal(String name,
Object obj,
String vParam)
declare a new identifier to this interpreter for use in scripts |
protected abstract Object |
toJavaObject(Object o,
Class c)
overwritten by those interpreters that wrap the results of evaluations in API-specific instances |
protected abstract Object[] |
toJavaObjects(Object o,
Class[] paramTypes)
convert the given object to an array of objects of the specified types. |
Methods inherited from class org.eclipse.actf.validation.valdoc.codeproc.AbstractCodeProcessor |
---|
addScript, addScripts, getClasspath, getFileContents, getLanguage, getModel, isIdVisible, makeExpressionList, prepareCode, setIdVisibility, setLanguage, setModel |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.apache.bsf.BSFManager manager
Constructor Detail |
---|
public AbstractCodeInterpreter(String language, IModel model)
Note: this constructor calls initClasspath()
if a
scripting engine for the specified language can be found.
language
- --
language of scripts in the document to be processedmodel
- --
model to be usedMethod Detail |
---|
protected void preInit() throws Exception
Exception
protected void postInit() throws Exception
Exception
public void setClasspath(String cp)
import
statements.
The classpath for a processor isnot necessarily the same as that used by ACTF validation engines. A default value is supplied in the ValidationConstants.CODE_PROCESSOR_CLASSPATH_KEY property in the raven.xml file.
setClasspath
in interface ICodeProcessor
setClasspath
in class AbstractCodeProcessor
cp
- -
classpath to usepublic void setEnvironment(Object env)
getEnvironment()
env
- --
environment of another interpreter retreaved via
getEnvironment()
public Object getEnvironment()
setEnvironment(Object)
of a newly instantiated
interpreter
setEnvironment(Object)
protected void initClasspath()
setClasspath
. This will be the classpath referenced
from within actual script code.
setClasspath(String)
public boolean getLanguageSupportsTuples()
true
if language supports primitive tuple data
type, false
otherwisepublic char getExpressionDelimiter()
getLanguageSupportsTuples()
returns true
protected void setLanguageSupportsTuples(boolean b)
b
- --
true
if language does, in fact, support tuplespublic void addScript(String code)
code
- --
code to be executedpublic void addScript(String scriptName, String scriptCode)
scriptName
- --
name or id of scriptscriptCode
- --
code to be executedpublic String getScript(String scriptName)
scriptName
- --
name of script for which code is desired
null
if name is
not validpublic String getInitCode()
protected abstract String formatPackageImport(String packageName)
public void setLocal(String name, Object obj, String vParam)
name
- --
identifier for this objectobj
- --
object being declared (this may not be null
vParam
- --
visibility parameterICodeProcessor.setIdVisibility(String)
public boolean processCode(String[] params)
params
- --
name of script to be executed in [0] (the remainder of the
array is ignored)
true
for success,
false
otherwise)public Object evaluateArguments(String code, Class returnType) throws EvaluationException
code
- --
argument to be evaluatedreturnType
- --
desired type of returned object
EvaluationException
- if evaluation was not successfulpublic Object[] evaluateArguments(String code, Class[] paramTypes) throws EvaluationException
languageSupportsTuples()
returns true
code
- --
code to be evaluatedparamTypes
- --
desired types of returned objects
EvaluationException
- if evaluation was not successfulgetLanguageSupportsTuples()
public boolean isCompilerProcessor()
ICodeProcessor
false
protected abstract Object toJavaObject(Object o, Class c)
o
- --
wrapped objectc
- --
desired type
protected abstract Object[] toJavaObjects(Object o, Class[] paramTypes)
languageSupportsTuples()
returns true
o
- --
API-dependent tuple objectparamTypes
- --
desired types of returned objects
null
if
conversion could not be performedgetLanguageSupportsTuples()
protected String getNullValue()
null
value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |