Package net.sf.jasperreports.engine.fill
Class JREvaluator
java.lang.Object
net.sf.jasperreports.engine.fill.JREvaluator
- All Implemented Interfaces:
DatasetExpressionEvaluator
- Direct Known Subclasses:
DirectEvaluator
,GroovyEvaluator
,JavaScriptCompiledEvaluator
,JavaScriptEvaluator
Base class for the dynamically generated expression evaluator classes.
This class also provides some built-in functions that will be described next.
Built-in Functions
Report expressions can perform method calls on various objects that are available during report filling, such as parameters, fields, or variable values, but can also call methods on a special object that is already available as thethis
reference. This is the calculator
object. It has public utility methods that are ready to use inside report expressions.
Currently, there are only a few utility methods of the calculator object available as built-in functions inside report expressions. These are the following:
msg
- this function offers a convenient way to format messages based on the current report locale, just as you would normally do when using ajava.text.MessageFormat
instance. Furthermore, several signatures for this function take up to three message parameters in order to make the formatting functionality easier to use.str
- this function is the equivalent of the$R{}
syntax. It gives access to locale specific resources from the associated resource bundle.
- Author:
- Lucian Chirita (lucianc@users.sourceforge.net)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
customizedInit
(Map<String, JRFillParameter> parametersMap, Map<String, JRFillField> fieldsMap, Map<String, JRFillVariable> variablesMap) Initializes the parameters, fields and variables of the evaluator.protected abstract Object
evaluate
(int id) Evaluates an expression using current fields and variables values.evaluate
(JRExpression expression) protected abstract Object
evaluateEstimated
(int id) Evaluates an expression using estimated variables values.evaluateEstimated
(JRExpression expression) protected abstract Object
evaluateOld
(int id) Evaluates an expression using old fields and variables values.evaluateOld
(JRExpression expression) <T extends FunctionSupport>
TgetFunctionSupport
(Class<T> clazz) protected Object
handleEvaluationException
(JRExpression expression, Throwable e) protected String
handleMissingResource
(String key, Exception e) Handles the case when a resource is missing.void
init
(Map<String, JRFillParameter> parametersMap, Map<String, JRFillField> fieldsMap, Map<String, JRFillVariable> variablesMap, WhenResourceMissingTypeEnum resourceMissingType, boolean ignoreNPE) Initializes the evaluator by setting the parameter, field and variable objects.Constructs a message using a pattern with one parameter.Constructs a message using a pattern with any number of parameters.Constructs a message using a pattern with two parameters.Constructs a message using a pattern with three parameters.void
setDirectExpressionEvaluators
(DirectExpressionEvaluators directExpressionEvaluators) Returns a string for a given key from the resource bundle associated with the evaluator.
-
Field Details
-
EXCEPTION_MESSAGE_KEY_RESOURCE_NOT_FOUND
- See Also:
-
PROPERTY_IGNORE_NPE
The expression evaluation engine in JasperReports has always ignored java.lang.NullPointerException exceptions raised during expression evaluation. An expression raising NullPointerException is evaluated to null. However, in certain cases, users want to be able to track down the source of their NPE and this configuration property can be set to instruct the expression evaluation engine to treat NPEs just the way all other expression exceptions are treated. The default value of this configuration property is true, meaning NPEs are ignored. The property can be set globally, at report or at dataset level.- See Also:
-
ignoreNPE
protected boolean ignoreNPE
-
-
Constructor Details
-
JREvaluator
protected JREvaluator()Default constructor.
-
-
Method Details
-
setDirectExpressionEvaluators
-
init
public void init(Map<String, JRFillParameter> parametersMap, Map<String, throws JRExceptionJRFillField> fieldsMap, Map<String, JRFillVariable> variablesMap, WhenResourceMissingTypeEnum resourceMissingType, boolean ignoreNPE) Initializes the evaluator by setting the parameter, field and variable objects.- Specified by:
init
in interfaceDatasetExpressionEvaluator
- Parameters:
parametersMap
- the parameters indexed by namefieldsMap
- the fields indexed by namevariablesMap
- the variables indexed by nameresourceMissingType
- the resource missing type- Throws:
JRException
-
getFunctionSupport
-
msg
Constructs a message using a pattern with one parameter.- Parameters:
pattern
- the message patternarg0
- the message parameter- Returns:
- the constructed message
- See Also:
-
msg
Constructs a message using a pattern with two parameters.- Parameters:
pattern
- the message patternarg0
- the first message parameterarg1
- the second message parameter- Returns:
- the constructed message
- See Also:
-
msg
Constructs a message using a pattern with three parameters.- Parameters:
pattern
- the message patternarg0
- the first message parameterarg1
- the second message parameterarg2
- the third parameter- Returns:
- the constructed message
- See Also:
-
msg
Constructs a message using a pattern with any number of parameters.- Parameters:
pattern
- the message patternargs
- the message parameters- Returns:
- the constructed message
- See Also:
-
str
Returns a string for a given key from the resource bundle associated with the evaluator.- Parameters:
key
- the key- Returns:
- the string for the given key
- See Also:
-
handleEvaluationException
protected Object handleEvaluationException(JRExpression expression, Throwable e) throws JRExpressionEvalException - Throws:
JRExpressionEvalException
-
evaluate
- Specified by:
evaluate
in interfaceDatasetExpressionEvaluator
- Throws:
JRExpressionEvalException
-
evaluateOld
- Specified by:
evaluateOld
in interfaceDatasetExpressionEvaluator
- Throws:
JRExpressionEvalException
-
evaluateEstimated
- Specified by:
evaluateEstimated
in interfaceDatasetExpressionEvaluator
- Throws:
JRExpressionEvalException
-
handleMissingResource
Handles the case when a resource is missing.- Parameters:
key
- the resource keye
- the exception- Returns:
- the value to use for the resource
- Throws:
JRRuntimeException
- when the resource missing handling type is Error
-
customizedInit
protected abstract void customizedInit(Map<String, JRFillParameter> parametersMap, Map<String, throws JRExceptionJRFillField> fieldsMap, Map<String, JRFillVariable> variablesMap) Initializes the parameters, fields and variables of the evaluator.- Parameters:
parametersMap
- the parameters indexed by namefieldsMap
- the fields indexed by namevariablesMap
- the variables indexed by name- Throws:
JRException
-
evaluate
Evaluates an expression using current fields and variables values.- Parameters:
id
- the expression id- Returns:
- the result of the evaluation
- Throws:
Throwable
- See Also:
-
evaluateOld
Evaluates an expression using old fields and variables values.- Parameters:
id
- the expression id- Returns:
- the result of the evaluation
- Throws:
Throwable
- See Also:
-
evaluateEstimated
Evaluates an expression using estimated variables values.- Parameters:
id
- the expression id- Returns:
- the result of the evaluation
- Throws:
Throwable
- See Also:
-