public class BSHExpression extends AbstractExpression
Object getValue()
and this function is defined in the expression
property. You have to overwrite the function
getValue()
to begin and to end your expression, but you are free to add your own functions to the
script.
By default, base Java core and extension packages are imported for you. They are:
java.lang
java.io
java.util
java.net
java.awt
java.awt.event
javax.swing
javax.swing.event
// you may import packages and classes or use the fully qualified name of the class import org.pentaho.reporting.engine.classic.core.*; String userdefinedFunction (String parameter, Date date) { return parameter + " - the current date is " + date); } // use simple java code to perform the expression. You may use all classes // available in your classpath as if you write "real" java code in your favourite // IDE. // See the www.beanshell.org site for more information ... // // A return value of type "Object" is alway implied ... getValue () { return userdefinedFunction ("Hello World :) ", new Date()); }
Modifier and Type | Field and Description |
---|---|
static String |
BSHHEADERFILE
The headerfile with the default initialisations.
|
Constructor and Description |
---|
BSHExpression()
default constructor, create a new BeanShellExpression.
|
Modifier and Type | Method and Description |
---|---|
protected bsh.Interpreter |
createInterpreter()
This method tries to create a new and fully initialized BeanShell interpreter.
|
String |
getExpression()
Sets the beanshell script as string.
|
Expression |
getInstance()
Return a new instance of this expression.
|
Object |
getValue()
Evaluates the defined expression.
|
protected void |
initializeInterpreter(bsh.Interpreter interpreter)
Initializes the bean-shell interpreter by executing the code in the BSHExpressionHeader.txt file.
|
void |
setExpression(String expression)
Sets the beanshell script that should be executed.
|
clone, getDataRow, getDependencyLevel, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setActive, setDependencyLevel, setName, setPreserve, setRuntime
public static final String BSHHEADERFILE
public BSHExpression()
protected bsh.Interpreter createInterpreter()
protected void initializeInterpreter(bsh.Interpreter interpreter) throws bsh.EvalError, IOException
interpreter
- the interpreter that should be initialized.bsh.EvalError
- if an BeanShell-Error occured.IOException
- if the beanshell file could not be read.public Object getValue()
public Expression getInstance()
getInstance
in interface Expression
getInstance
in class AbstractExpression
public String getExpression()
public void setExpression(String expression)
expression
- the script.Copyright © 2017 Hitachi Vantara. All rights reserved.