net.sf.jasperreports.engine.fill

## Class JREvaluator

- java.lang.Object
- - net.sf.jasperreports.engine.fill.JREvaluator

- All Implemented Interfaces:
    DatasetExpressionEvaluator
  Direct Known Subclasses:
    GroovyEvaluator, JavaScriptCompiledEvaluator, JavaScriptEvaluator, JRBshEvaluator

      public abstract class JREvaluator
      extends java.lang.Object
      implements DatasetExpressionEvaluator

  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 the `this` 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 a `java.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.
  Version:
    $Id: JREvaluator.java 7045 2014-04-24 14:20:46Z shertage $
  Author:
    Lucian Chirita (lucianc@users.sourceforge.net)

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `JREvaluator()` Default constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `customizedInit(java.util.Map<java.lang.String,JRFillParameter> parametersMap, java.util.Map<java.lang.String,JRFillField> fieldsMap, java.util.Map<java.lang.String,JRFillVariable> variablesMap)` Initializes the parameters, fields and variables of the evaluator.
    `protected abstract java.lang.Object` | `evaluate(int id)` Evaluates an expression using current fields and variables values.
    `java.lang.Object` | `evaluate(JRExpression expression)`
    `protected abstract java.lang.Object` | `evaluateEstimated(int id)` Evaluates an expression using estimated variables values.
    `java.lang.Object` | `evaluateEstimated(JRExpression expression)`
    `protected abstract java.lang.Object` | `evaluateOld(int id)` Evaluates an expression using old fields and variables values.
    `java.lang.Object` | `evaluateOld(JRExpression expression)`
    `<T extends FunctionSupport> T` | `getFunctionSupport(java.lang.Class<T> clazz)`
    `protected java.lang.String` | `handleMissingResource(java.lang.String key, java.lang.Exception e)` Handles the case when a resource is missing.
    `void` | `init(java.util.Map<java.lang.String,JRFillParameter> parametersMap, java.util.Map<java.lang.String,JRFillField> fieldsMap, java.util.Map<java.lang.String,JRFillVariable> variablesMap, WhenResourceMissingTypeEnum resourceMissingType)` Initializes the evaluator by setting the parameter, field and variable objects.
    `java.lang.String` | `msg(java.lang.String pattern, java.lang.Object arg0)` Constructs a message using a pattern with one parameter.
    `java.lang.String` | `msg(java.lang.String pattern, java.lang.Object[] args)` Constructs a message using a pattern with an Object array parameter.
    `java.lang.String` | `msg(java.lang.String pattern, java.lang.Object arg0, java.lang.Object arg1)` Constructs a message using a pattern with two parameters.
    `java.lang.String` | `msg(java.lang.String pattern, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)` Constructs a message using a pattern with three parameters.
    `java.lang.String` | `str(java.lang.String key)` Returns a string for a given key from the resource bundle associated with the evaluator.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JREvaluator

          protected JREvaluator()

      Default constructor.

  - ### Method Detail

    - #### init

          public void init(java.util.Map<java.lang.String,JRFillParameter> parametersMap,
                  java.util.Map<java.lang.String,JRFillField> fieldsMap,
                  java.util.Map<java.lang.String,JRFillVariable> variablesMap,
                  WhenResourceMissingTypeEnum resourceMissingType)
                    throws JRException

      Initializes the evaluator by setting the parameter, field and variable objects.
      Specified by:
        `init` in interface `DatasetExpressionEvaluator`
      Parameters:
        `parametersMap` - the parameters indexed by name
        `fieldsMap` - the fields indexed by name
        `variablesMap` - the variables indexed by name
        `resourceMissingType` - the resource missing type
      Throws:
        `JRException`

    - #### getFunctionSupport

          public <T extends FunctionSupport> T getFunctionSupport(java.lang.Class<T> clazz)

    - #### msg

          public java.lang.String msg(java.lang.String pattern,
                             java.lang.Object arg0)

      Constructs a message using a pattern with one parameter.
      Parameters:
        `pattern` - the message pattern
        `arg0` - the message parameter
      Returns:
        the constructed message
      See Also:
        `MessageFormat.format(java.lang.Object[],java.lang.StringBuffer, java.text.FieldPosition)`

    - #### msg

          public java.lang.String msg(java.lang.String pattern,
                             java.lang.Object arg0,
                             java.lang.Object arg1)

      Constructs a message using a pattern with two parameters.
      Parameters:
        `pattern` - the message pattern
        `arg0` - the first message parameter
        `arg1` - the second message parameter
      Returns:
        the constructed message
      See Also:
        `MessageFormat.format(java.lang.Object[],java.lang.StringBuffer, java.text.FieldPosition)`

    - #### msg

          public java.lang.String msg(java.lang.String pattern,
                             java.lang.Object arg0,
                             java.lang.Object arg1,
                             java.lang.Object arg2)

      Constructs a message using a pattern with three parameters.
      Parameters:
        `pattern` - the message pattern
        `arg0` - the first message parameter
        `arg1` - the second message parameter
        `arg2` - the third parameter
      Returns:
        the constructed message
      See Also:
        `MessageFormat.format(java.lang.Object[],java.lang.StringBuffer, java.text.FieldPosition)`

    - #### msg

          public java.lang.String msg(java.lang.String pattern,
                             java.lang.Object[] args)

      Constructs a message using a pattern with an Object array parameter.
      Parameters:
        `pattern` - the message pattern
        `args` - the parameter Object array
      Returns:
        the constructed message
      See Also:
        `MessageFormat.format(java.lang.Object[],java.lang.StringBuffer, java.text.FieldPosition)`

    - #### str

          public java.lang.String str(java.lang.String key)

      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:
        `ResourceBundle.getString(java.lang.String)`

    - #### evaluate

          public java.lang.Object evaluate(JRExpression expression)
                                    throws JRExpressionEvalException

      Specified by:
        `evaluate` in interface `DatasetExpressionEvaluator`
      Throws:
        `JRExpressionEvalException`

    - #### evaluateOld

          public java.lang.Object evaluateOld(JRExpression expression)
                                       throws JRExpressionEvalException

      Specified by:
        `evaluateOld` in interface `DatasetExpressionEvaluator`
      Throws:
        `JRExpressionEvalException`

    - #### evaluateEstimated

          public java.lang.Object evaluateEstimated(JRExpression expression)
                                             throws JRExpressionEvalException

      Specified by:
        `evaluateEstimated` in interface `DatasetExpressionEvaluator`
      Throws:
        `JRExpressionEvalException`

    - #### handleMissingResource

          protected java.lang.String handleMissingResource(java.lang.String key,
                                               java.lang.Exception e)
                                                    throws JRRuntimeException

      Handles the case when a resource is missing.
      Parameters:
        `key` - the resource key
        `e` - 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(java.util.Map<java.lang.String,JRFillParameter> parametersMap,
                            java.util.Map<java.lang.String,JRFillField> fieldsMap,
                            java.util.Map<java.lang.String,JRFillVariable> variablesMap)
                                          throws JRException

      Initializes the parameters, fields and variables of the evaluator.
      Parameters:
        `parametersMap` - the parameters indexed by name
        `fieldsMap` - the fields indexed by name
        `variablesMap` - the variables indexed by name
      Throws:
        `JRException`

    - #### evaluate

          protected abstract java.lang.Object evaluate(int id)
                                                throws java.lang.Throwable

      Evaluates an expression using current fields and variables values.
      Parameters:
        `id` - the expression id
      Returns:
        the result of the evaluation
      Throws:
        `java.lang.Throwable`
      See Also:
        `JRExpression.EVALUATION_DEFAULT`, `JRFillVariable.getValue()`, `JRFillField.getValue()`

    - #### evaluateOld

          protected abstract java.lang.Object evaluateOld(int id)
                                                   throws java.lang.Throwable

      Evaluates an expression using old fields and variables values.
      Parameters:
        `id` - the expression id
      Returns:
        the result of the evaluation
      Throws:
        `java.lang.Throwable`
      See Also:
        `JRExpression.EVALUATION_OLD`, `JRFillVariable.getOldValue()`, `JRFillField.getOldValue()`

    - #### evaluateEstimated

          protected abstract java.lang.Object evaluateEstimated(int id)
                                                         throws java.lang.Throwable

      Evaluates an expression using estimated variables values.
      Parameters:
        `id` - the expression id
      Returns:
        the result of the evaluation
      Throws:
        `java.lang.Throwable`
      See Also:
        `JRExpression.EVALUATION_ESTIMATED`, `JRFillVariable.getEstimatedValue()`

© 2001-2010 Jaspersoft Corporation www.jaspersoft.com