Class BSFExpression
- java.lang.Object
-
- org.pentaho.reporting.engine.classic.core.function.AbstractExpression
-
- org.pentaho.reporting.engine.classic.core.modules.misc.bsf.BSFExpression
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Expression
public class BSFExpression extends AbstractExpression
An expression that uses the Bean scripting framework to perform a scripted calculation.- Author:
- Thomas Morgner
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BSFExpression()
Default constructor, create a new BeanShellExpression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
clone()
Clones the expression and reinitializes the script.protected org.apache.bsf.BSFManager
createInterpreter()
Creates a new interpreter instance.String
getExpression()
Returns the script that gets evaluated every time the getValue() method is called.String
getLanguage()
Returns the programming language, in which the interpreter work.String
getScript()
Returns the script.Object
getValue()
Evaluates the defined expression.protected void
initializeInterpreter(org.apache.bsf.BSFManager interpreter)
Initializes the Bean-Scripting Framework manager.protected void
invalidate()
Invalidates the interpreter-cache and forces a reinterpretation of the script.void
setExpression(String expression)
Sets the script that should be executed.void
setLanguage(String language)
Defines the programming language of the script and expression.void
setScript(String script)
Defines the script.-
Methods inherited from class org.pentaho.reporting.engine.classic.core.function.AbstractExpression
getDataRow, getDependencyLevel, getInstance, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setActive, setDependencyLevel, setName, setPreserve, setRuntime
-
-
-
-
Method Detail
-
createInterpreter
protected org.apache.bsf.BSFManager createInterpreter()
Creates a new interpreter instance.- Returns:
- the interpreter or null, if there was an error.
-
initializeInterpreter
protected void initializeInterpreter(org.apache.bsf.BSFManager interpreter) throws org.apache.bsf.BSFException
Initializes the Bean-Scripting Framework manager.- Parameters:
interpreter
- the BSF-Manager that should be initialized.- Throws:
org.apache.bsf.BSFException
- if an error occured.
-
getValue
public Object getValue()
Evaluates the defined expression. If an exception or an evaluation error occures, the evaluation returns null and the error is logged. The current datarow and a copy of the expressions properties are set to script-internal variables. Changes to the properties will not alter the expressions original properties and will be lost when the evaluation is finished. Expressions do not maintain a state and no assumptions about the order of evaluation can be made.- Returns:
- the evaluated value or null.
-
clone
public Object clone() throws CloneNotSupportedException
Clones the expression and reinitializes the script.- Specified by:
clone
in interfaceExpression
- Overrides:
clone
in classAbstractExpression
- Returns:
- a clone of the expression.
- Throws:
CloneNotSupportedException
- this should never happen.
-
getExpression
public String getExpression()
Returns the script that gets evaluated every time the getValue() method is called.- Returns:
- the script.
-
invalidate
protected void invalidate()
Invalidates the interpreter-cache and forces a reinterpretation of the script.
-
setExpression
public void setExpression(String expression)
Sets the script that should be executed. Whats in the script depends on what langage is selected.- Parameters:
expression
- the script.
-
getLanguage
public String getLanguage()
Returns the programming language, in which the interpreter work.- Returns:
- the programming language, which must be one of the supported BSF-Languages.
-
setLanguage
public void setLanguage(String language)
Defines the programming language of the script and expression.- Parameters:
language
- the programming language of the script.
-
getScript
public String getScript()
Returns the script. The script is a predefined piece of code that gets executed once. It can (and should) be used to perform global initializations and to define functions.- Returns:
- the script (can be null).
-
setScript
public void setScript(String script)
Defines the script. The script is a predefined piece of code that gets executed once. It can (and should) be used to perform global initializations and to define functions.- Parameters:
script
- an initialization script.
-
-