org.kuali.rice.krad.uif.service.impl
Class ExpressionEvaluatorServiceImpl

java.lang.Object
  extended by org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl
All Implemented Interfaces:
ExpressionEvaluatorService

public class ExpressionEvaluatorServiceImpl
extends Object
implements ExpressionEvaluatorService

Evaluates expression language statements using the Spring EL engine

Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
 
Fields inherited from interface org.kuali.rice.krad.uif.service.ExpressionEvaluatorService
EMBEDDED_PROPERTY_NAME_ADD_INDICATOR
 
Constructor Summary
ExpressionEvaluatorServiceImpl()
           
 
Method Summary
protected  void addCustomFunctions(org.springframework.expression.spel.support.StandardEvaluationContext context)
          Registers custom functions for el expressions with the given context
 boolean containsElPlaceholder(String value)
          Indicates whether or not the given string contains the el placholder (begin and end delimiters)
 Object evaluateExpression(Object contextObject, Map<String,Object> evaluationParameters, String expressionStr)
          Evaluates the given el expression against the content object and parameters, and returns the result of the evaluation
 void evaluateExpressionsOnConfigurable(View view, UifDictionaryBean expressionConfigurable, Object contextObject, Map<String,Object> evaluationParameters)
          Evaluates any el expressions that are found as a string property value for the object
 String evaluateExpressionTemplate(Object contextObject, Map<String,Object> evaluationParameters, String expressionTemplate)
          Evaluates the given expression template string against the context object and map of parameters
protected  void evaluatePropertyExpressions(View view, UifDictionaryBean expressionConfigurable, Object contextObject, Map<String,Object> evaluationParameters)
          Retrieves the Map from the given object that containing the property expressions that should be evaluated.
protected  void evaluatePropertyReplacers(View view, UifDictionaryBean expressionConfigurable, Object contextObject, Map<String,Object> evaluationParameters)
          Iterates through any configured PropertyReplacer instances for the component and evaluates the given condition.
protected static String getLinePathPrefixValue(Component component)
          Determines the value for the UifConstants.LINE_PATH_BIND_ADJUST_PREFIX binding prefix based on collection group found in the component context
 String replaceBindingPrefixes(View view, Object object, String expression)
          Adjusts the property expressions for a given object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionEvaluatorServiceImpl

public ExpressionEvaluatorServiceImpl()
Method Detail

evaluateExpressionsOnConfigurable

public void evaluateExpressionsOnConfigurable(View view,
                                              UifDictionaryBean expressionConfigurable,
                                              Object contextObject,
                                              Map<String,Object> evaluationParameters)
Description copied from interface: ExpressionEvaluatorService
Evaluates any el expressions that are found as a string property value for the object

Using reflection the properties for the object are retrieved and if of String type the corresponding value is retrieved. If the value is not empty and contains the el placeholder see ExpressionEvaluatorService.containsElPlaceholder(String) then the expression is evaluated using the given context object and parameters. The evaluated string is then set as the new property value, or in the case of a template (expression contained within a literal string), the expression part is replaced in the property value.

In addition to evaluating any property expressions, any configured PropertyReplacer for the object are also evaluated and if a match occurs those property replacements are made

Specified by:
evaluateExpressionsOnConfigurable in interface ExpressionEvaluatorService
Parameters:
view - - view instance being rendered
expressionConfigurable - - object whose properties should be checked for expressions and evaluated
contextObject - - context object for the expression evaluations
evaluationParameters - - map of parameters that may appear in expressions, the map key gives the parameter name that may appear in the expression, and the map value is the object that expression should evaluate against when that name is found
See Also:
org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpressionsOnConfigurable(org.kuali.rice.krad.uif.view.View, org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean, java.lang.Object, java.util.Map)

evaluateExpressionTemplate

public String evaluateExpressionTemplate(Object contextObject,
                                         Map<String,Object> evaluationParameters,
                                         String expressionTemplate)
Description copied from interface: ExpressionEvaluatorService
Evaluates the given expression template string against the context object and map of parameters

If the template string contains one or more el placeholders (see ExpressionEvaluatorService.containsElPlaceholder(String)), the expression contained within the placeholder will be evaluated and the corresponding value will be substituted back into the property value where the placeholder occurred. If no placeholders are found, the string will be returned unchanged

Specified by:
evaluateExpressionTemplate in interface ExpressionEvaluatorService
Parameters:
contextObject - - context object for the expression evaluations
evaluationParameters - - map of parameters that may appear in expressions, the map key gives the parameter name that may appear in the expression, and the map value is the object that expression should evaluate against when that name is found
expressionTemplate - - string that should be evaluated for el expressions
Returns:
String formed by replacing any el expressions in the original expression template with their corresponding evaluation results
See Also:
ExpressionEvaluatorService.evaluateExpressionTemplate(java.lang.Object, java.util.Map, java.lang.String)

evaluateExpression

public Object evaluateExpression(Object contextObject,
                                 Map<String,Object> evaluationParameters,
                                 String expressionStr)
Description copied from interface: ExpressionEvaluatorService
Evaluates the given el expression against the content object and parameters, and returns the result of the evaluation

The given expression string is assumed to be one el expression and should not contain the el placeholders. The returned result depends on the evaluation and what type is returns, for instance a boolean will be return for a boolean expression, or a string for string expression

Specified by:
evaluateExpression in interface ExpressionEvaluatorService
Parameters:
contextObject - - context object for the expression evaluations
evaluationParameters - - map of parameters that may appear in expressions, the map key gives the parameter name that may appear in the expression, and the map value is the object that expression should evaluate against when that name is found
expressionStr - - el expression to evaluate
Returns:
Object result of the expression evaluation
See Also:
ExpressionEvaluatorService.evaluateExpression(java.lang.Object, java.util.Map, java.lang.String)

addCustomFunctions

protected void addCustomFunctions(org.springframework.expression.spel.support.StandardEvaluationContext context)
Registers custom functions for el expressions with the given context

Parameters:
context - - context instance to register functions to

evaluatePropertyReplacers

protected void evaluatePropertyReplacers(View view,
                                         UifDictionaryBean expressionConfigurable,
                                         Object contextObject,
                                         Map<String,Object> evaluationParameters)
Iterates through any configured PropertyReplacer instances for the component and evaluates the given condition. If the condition is met, the replacement value is set on the corresponding property

Parameters:
view - - view instance being rendered
expressionConfigurable - - expressionConfigurable instance with property replacers list, should be either a component or layout manager
contextObject - - context for el evaluation
evaluationParameters - - parameters for el evaluation

evaluatePropertyExpressions

protected void evaluatePropertyExpressions(View view,
                                           UifDictionaryBean expressionConfigurable,
                                           Object contextObject,
                                           Map<String,Object> evaluationParameters)
Retrieves the Map from the given object that containing the property expressions that should be evaluated. Each expression is then evaluated and the result is used to set the property value

If the expression is an el template (part static text and part expression), only the expression part will be replaced with the result. More than one expressions may be contained within the template

Parameters:
view - - view instance that is being rendered
expressionConfigurable - - object instance to evaluate expressions for
contextObject - - object providing the default context for expressions
evaluationParameters - - map of additional parameters that may be used within the expressions

containsElPlaceholder

public boolean containsElPlaceholder(String value)
Description copied from interface: ExpressionEvaluatorService
Indicates whether or not the given string contains the el placholder (begin and end delimiters)

Specified by:
containsElPlaceholder in interface ExpressionEvaluatorService
Parameters:
value - - String to check for contained placeholders
Returns:
boolean true if the string contains one or more placeholders, false if it contains none
See Also:
ExpressionEvaluatorService.containsElPlaceholder(java.lang.String)

replaceBindingPrefixes

public String replaceBindingPrefixes(View view,
                                     Object object,
                                     String expression)
Description copied from interface: ExpressionEvaluatorService
Adjusts the property expressions for a given object

The UifConstants.NO_BIND_ADJUST_PREFIX prefix will be removed as this is a placeholder indicating that the property is directly on the form. The UifConstants.FIELD_PATH_BIND_ADJUST_PREFIX prefix will be replaced by the object's field path - this is only applicable to DataFields. The UifConstants.DEFAULT_PATH_BIND_ADJUST_PREFIX prefix will be replaced by the view's default path if it is set.

Specified by:
replaceBindingPrefixes in interface ExpressionEvaluatorService
Parameters:
view - - the parent view of the object
object - - Object to adjust property expressions on
expression - - The expression to adjust
Returns:
the adjusted expression String
See Also:
ExpressionEvaluatorService.replaceBindingPrefixes(org.kuali.rice.krad.uif.view.View, java.lang.Object, java.lang.String)

getLinePathPrefixValue

protected static String getLinePathPrefixValue(Component component)
Determines the value for the UifConstants.LINE_PATH_BIND_ADJUST_PREFIX binding prefix based on collection group found in the component context

Parameters:
component - - component instance for which the prefix is configured on
Returns:
String line binding path or empty string if path not found


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.