org.jfree.report.modules.misc.bsf
Class BSFExpression
java.lang.Object
|
+--org.jfree.report.function.AbstractExpression
|
+--org.jfree.report.modules.misc.bsf.BSFExpression
- public class BSFExpression
- extends AbstractExpression
- implements java.io.Serializable
An expression that uses the BeanShell scripting framework to perform a scripted
calculation. The expression itself is contained in a function called
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
An example in the XML format: (from report1.xml)
// you may import packages and classes or use the fully qualified name of the class
import org.jfree.report.*;
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());
}
- Author:
- Thomas Morgner
- See Also:
- Serialized Form
|
Constructor Summary |
BSFExpression()
default constructor, create a new BeanShellExpression. |
| Methods inherited from class org.jfree.report.function.AbstractExpression |
getDataRow,
getDependencyLevel,
getInstance,
getName,
getReportConfiguration,
getResourceBundleFactory,
getRuntime,
isActive,
setActive,
setDependencyLevel,
setName,
setRuntime |
| Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
BSFExpression
public BSFExpression()
- default constructor, create a new BeanShellExpression.
createInterpreter
protected org.apache.bsf.BSFManager createInterpreter()
initializeInterpreter
protected void initializeInterpreter(org.apache.bsf.BSFManager interpreter)
throws org.apache.bsf.BSFException
getValue
public java.lang.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 java.lang.Object clone()
throws java.lang.CloneNotSupportedException
- Clones the expression and reinitializes the script.
- Overrides:
- clone in class AbstractExpression
- Returns:
- a clone of the expression.
- Throws:
- java.lang.CloneNotSupportedException - this should never happen.
getExpression
public java.lang.String getExpression()
invalidate
protected void invalidate()
setExpression
public void setExpression(java.lang.String expression)
getLanguage
public java.lang.String getLanguage()
setLanguage
public void setLanguage(java.lang.String language)
getScript
public java.lang.String getScript()
setScript
public void setScript(java.lang.String script)