org.mule.expression
Class DefaultExpressionManager

java.lang.Object
  extended by org.mule.expression.DefaultExpressionManager
All Implemented Interfaces:
ExpressionManager

public class DefaultExpressionManager
extends Object
implements ExpressionManager

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
protected static Log logger
          logger used by this class
 
Fields inherited from interface org.mule.api.expression.ExpressionManager
DEFAULT_EXPRESSION_POSTFIX, DEFAULT_EXPRESSION_PREFIX
 
Constructor Summary
DefaultExpressionManager()
           
 
Method Summary
 void clearEvaluators()
          Clears all registered evaluators from the manager.
 Object evaluate(String expression, MuleMessage message)
          Evaluates the given expression.
 Object evaluate(String expression, MuleMessage message, boolean failIfNull)
          Evaluates the given expression.
 Object evaluate(String expression, String evaluator, MuleMessage message, boolean failIfNull)
          Evaluates the given expression.
 boolean isEvaluatorRegistered(String name)
          Checks whether an evaluator is registered with the manager
 boolean isValidExpression(String expression)
          Determines if the expression is valid or not.
 String parse(String expression, MuleMessage message)
          Evaluates expressions in a given string.
 String parse(String expression, MuleMessage message, boolean failIfNull)
          Evaluates expressions in a given string.
 void registerEvaluator(ExpressionEvaluator evaluator)
           
 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

logger

protected static final transient Log logger
logger used by this class

Constructor Detail

DefaultExpressionManager

public DefaultExpressionManager()
Method Detail

registerEvaluator

public void registerEvaluator(ExpressionEvaluator evaluator)
Specified by:
registerEvaluator in interface ExpressionManager

isEvaluatorRegistered

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

Specified by:
isEvaluatorRegistered in interface ExpressionManager
Parameters:
name - the name of the expression evaluator
Returns:
true if the evaluator is registered with the manager, false otherwise

unregisterEvaluator

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

Specified by:
unregisterEvaluator in interface ExpressionManager
Parameters:
name - the name of the evaluator to remove
Returns:
the evaluator that was removed. This will be null if the evaluator was not registered

evaluate

public Object evaluate(String expression,
                       MuleMessage message)
                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 ExpressionManager.parse(String,org.mule.api.MuleMessage,boolean) method should be used since it will iterate through all expressions in a string.

Specified by:
evaluate in interface ExpressionManager
Parameters:
expression - a single expression i.e. xpath://foo
message -
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 Object evaluate(String expression,
                       MuleMessage message,
                       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 ExpressionManager.parse(String,org.mule.api.MuleMessage,boolean) method should be used since it will iterate through all expressions in a string.

Specified by:
evaluate in interface ExpressionManager
Parameters:
expression - a single expression i.e. xpath://foo
message -
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null. @return 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.
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

evaluate

public Object evaluate(String expression,
                       String evaluator,
                       MuleMessage message,
                       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 ExpressionManager.parse(String,org.mule.api.MuleMessage,boolean) method should be used since it will iterate through all expressions in a string.

Specified by:
evaluate in interface ExpressionManager
Parameters:
expression - a single expression i.e. xpath://foo
evaluator - the evaluator to use when executing the expression
message -
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null. @return 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.
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

parse

public String parse(String expression,
                    MuleMessage message)
             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 ExpressionManager.evaluate(String,org.mule.api.MuleMessage,boolean).

Specified by:
parse in interface ExpressionManager
Parameters:
expression - a single expression i.e. xpath://foo
message -
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 String parse(String expression,
                    MuleMessage message,
                    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 ExpressionManager.evaluate(String,org.mule.api.MuleMessage,boolean).

Specified by:
parse in interface ExpressionManager
Parameters:
expression - a single expression i.e. xpath://foo
message -
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null. @return 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.
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

clearEvaluators

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

Specified by:
clearEvaluators in interface ExpressionManager

isValidExpression

public boolean isValidExpression(String expression)
Determines if the expression is valid or not. This method will validate a single expression or expressions embedded in a string. the expression must be well formed i.e. #[bean:user]

Specified by:
isValidExpression in interface ExpressionManager
Parameters:
expression - the expression to validate
Returns:
true if the expression evaluator is recognised


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