org.mule.util.expression
Class ExpressionEvaluatorManager

java.lang.Object
  extended by org.mule.util.expression.ExpressionEvaluatorManager

public class ExpressionEvaluatorManager
extends Object

Provides universal access for evaluating expressions embedded in Mule configurations, such as Xml, Java, scripting and annotations. Users can register or unregister ExpressionEvaluator through this interface.


Field Summary
static String DEFAULT_EXPRESSION_PREFIX
           
 
Constructor Summary
ExpressionEvaluatorManager()
           
 
Method Summary
static void clearEvaluators()
          Clears all registered evaluators from the manager.
static Object evaluate(String expression, Object object)
          Evaluates the given expression.
static Object evaluate(String expression, Object object, boolean failIfNull)
          Evaluates the given expression.
static Object evaluate(String expression, Object object, String expressionPrefix, boolean failIfNull)
          Evaluates the given expression.
static Object evaluate(String expression, String evaluator, Object object, boolean failIfNull)
          Evaluates the given expression.
static boolean isEvaluatorRegistered(String name)
          Checks whether an evaluator is registered with the manager
static boolean isValidExpression(String expression)
          Determines if the expression is valid or not.
static boolean isValidExpression(String expression, String expressionPrefix)
          Determines if the expression is valid or not.
static String parse(String expression, Object object)
          Evaluates expressions in a given string.
static String parse(String expression, Object object, boolean failIfNull)
          Evaluates expressions in a given string.
static void registerEvaluator(ExpressionEvaluator extractor)
           
static ExpressionEvaluator unregisterEvaluator(String name)
          Removes the evaluator with the given name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXPRESSION_PREFIX

public static final String DEFAULT_EXPRESSION_PREFIX
See Also:
Constant Field Values
Constructor Detail

ExpressionEvaluatorManager

public ExpressionEvaluatorManager()
Method Detail

registerEvaluator

public static void registerEvaluator(ExpressionEvaluator extractor)

isEvaluatorRegistered

public static boolean isEvaluatorRegistered(String name)
Checks whether an evaluator is registered with the manager

Parameters:
name - the name of the expression evaluator
Returns:
true if the evaluator is registered with the manager, false otherwise

unregisterEvaluator

public static ExpressionEvaluator unregisterEvaluator(String name)
Removes the evaluator with the given name

Parameters:
name - the name of the evaluator to remove

evaluate

public static Object evaluate(String expression,
                              Object object)
                       throws ExpressionRuntimeException
Evaluates the given expression. The expression should be a single expression definition with or without enclosing braces. i.e. "mule:serviceName" and "${mule:serviceName}" are both valid. For situations where one or more expressions need to be parsed within a single text, the parse(String, Object, boolean) method should be used since it will iterate through all expressions in a string.

Parameters:
expression - a single expression i.e. xpath://foo
object - The object (usually MuleMessage) to evaluate the expression on.
Returns:
the result of the evaluation
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

evaluate

public static Object evaluate(String expression,
                              Object object,
                              boolean failIfNull)
                       throws ExpressionRuntimeException
Evaluates the given expression. The expression should be a single expression definition with or without enclosing braces. i.e. "mule:serviceName" and "${mule:serviceName}" are both valid. For situations where one or more expressions need to be parsed within a single text, the parse(String, Object, boolean) method should be used since it will iterate through all expressions in a string.

Parameters:
expression - a single expression i.e. xpath://foo
object - The object (usually MuleMessage) to evaluate the expression on.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null.
Returns:
the result of the evaluation
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

evaluate

public static Object evaluate(String expression,
                              String evaluator,
                              Object object,
                              boolean failIfNull)
                       throws ExpressionRuntimeException
Evaluates the given expression. The expression should be a single expression definition with or without enclosing braces. i.e. "mule:serviceName" and "${mule:serviceName}" are both valid. For situations where one or more expressions need to be parsed within a single text, the parse(String, Object, boolean) method should be used since it will iterate through all expressions in a string.

Parameters:
expression - a single expression i.e. xpath://foo
evaluator - the evaluator to use when executing the expression
object - The object (usually MuleMessage) to evaluate the expression on. It is unlikely that users will want to change this execpt maybe to use "[" instead.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null.
Returns:
the result of the evaluation
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

evaluate

public static Object evaluate(String expression,
                              Object object,
                              String expressionPrefix,
                              boolean failIfNull)
                       throws ExpressionRuntimeException
Evaluates the given expression. The expression should be a single expression definition with or without enclosing braces. i.e. "mule:serviceName" and "${mule:serviceName}" are both valid. For situations where one or more expressions need to be parsed within a single text, the parse(String, Object, boolean) method should be used since it will iterate through all expressions in a string.

Parameters:
expression - a single expression i.e. xpath://foo
object - The object (usually MuleMessage) to evaluate the expression on.
expressionPrefix - the expression prefix to use. The default is "${" but any character is valid. It is unlikely that users will want to change this except maybe to use "[" instead.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null.
Returns:
the result of the evaluation
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

parse

public static String parse(String expression,
                           Object object)
                    throws ExpressionRuntimeException
Evaluates expressions in a given string. This method will iterate through each expression and evaluate it. If a user needs to evaluate a single expression they can use evaluate(String, Object, boolean).

Parameters:
expression - a single expression i.e. xpath://foo
object - The object (usually MuleMessage) to evaluate the expression on.
Returns:
the result of the evaluation
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

parse

public static String parse(String expression,
                           Object object,
                           boolean failIfNull)
                    throws ExpressionRuntimeException
Evaluates expressions in a given string. This method will iterate through each expression and evaluate it. If a user needs to evaluate a single expression they can use evaluate(String, Object, boolean).

Parameters:
expression - a single expression i.e. xpath://foo
object - The object (usually MuleMessage) to evaluate the expression on.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null.
Returns:
the result of the evaluation
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

clearEvaluators

public static void clearEvaluators()
Clears all registered evaluators from the manager.


isValidExpression

public static boolean isValidExpression(String expression)
Determines if the expression is valid or not. This only validates single expressions.

Parameters:
expression - the expression to validate
Returns:
true if the expression evaluator is recognised

isValidExpression

public static boolean isValidExpression(String expression,
                                        String expressionPrefix)
Determines if the expression is valid or not. This only validates single expressions.

Parameters:
expression - the expression to validate
expressionPrefix - the prefix used for this expression. if the expression is ${bean:msg.header} the prefix is "${"
Returns:
true if the expression evaluator is recognised


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.