org.mule.api.expression
Interface ExpressionManager

All Known Implementing Classes:
DefaultExpressionManager

public interface 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
static java.lang.String DEFAULT_EXPRESSION_POSTFIX
           
static java.lang.String DEFAULT_EXPRESSION_PREFIX
           
 
Method Summary
 void clearEvaluators()
          Clears all registered evaluators from the manager.
 java.lang.Object evaluate(java.lang.String expression, MuleMessage message)
          Evaluates the given expression.
 java.lang.Object evaluate(java.lang.String expression, MuleMessage message, boolean failIfNull)
          Evaluates the given expression.
 java.lang.Object evaluate(java.lang.String expression, java.lang.String evaluator, MuleMessage message, boolean failIfNull)
          Evaluates the given expression.
 boolean isEvaluatorRegistered(java.lang.String name)
          Checks whether an evaluator is registered with the manager
 boolean isExpression(java.lang.String string)
          Determines if the string is an expression.
 boolean isValidExpression(java.lang.String expression)
          Determines if the expression is valid or not.
 java.lang.String parse(java.lang.String expression, MuleMessage message)
          Evaluates expressions in a given string.
 java.lang.String parse(java.lang.String expression, MuleMessage message, boolean failIfNull)
          Evaluates expressions in a given string.
 void registerEvaluator(ExpressionEvaluator evaluator)
           
 ExpressionEvaluator unregisterEvaluator(java.lang.String name)
          Removes the evaluator with the given name
 void validateExpression(java.lang.String expression)
          Determines if the expression is valid or not.
 

Field Detail

DEFAULT_EXPRESSION_PREFIX

static final java.lang.String DEFAULT_EXPRESSION_PREFIX
See Also:
Constant Field Values

DEFAULT_EXPRESSION_POSTFIX

static final java.lang.String DEFAULT_EXPRESSION_POSTFIX
See Also:
Constant Field Values
Method Detail

registerEvaluator

void registerEvaluator(ExpressionEvaluator evaluator)

isEvaluatorRegistered

boolean isEvaluatorRegistered(java.lang.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

ExpressionEvaluator unregisterEvaluator(java.lang.String name)
Removes the evaluator with the given name

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

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

Parameters:
expression - a single expression i.e. xpath://foo
message - The current message being processed
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

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

Parameters:
expression - a single expression i.e. xpath://foo
message - The current message being processed
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null. @return the result of the evaluation
Returns:
the parsered expression string
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

evaluate

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

Parameters:
expression - one or more expressions ebedded in a literal string i.e. "Value is #[xpath://foo] other value is #[header:foo]."
evaluator - the evaluator to use when executing the expression
message - The current message bing processed
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null. @return the result of the evaluation
Returns:
the parsered expression string
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

parse

java.lang.String parse(java.lang.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 evaluate(String,org.mule.api.MuleMessage,boolean).

Parameters:
expression - one or more expressions ebedded in a literal string i.e. "Value is #[xpath://foo] other value is #[header:foo]."
message - The current message being processed
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

java.lang.String parse(java.lang.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 evaluate(String,org.mule.api.MuleMessage,boolean).

Parameters:
expression - one or more expressions ebedded in a literal string i.e. "Value is #[xpath://foo] other value is #[header:foo]."
message - The current message being processed
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null. @return the result of the evaluation
Returns:
the parsered expression string
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

clearEvaluators

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


isValidExpression

boolean isValidExpression(java.lang.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]

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

validateExpression

void validateExpression(java.lang.String expression)
                        throws InvalidExpressionException
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]

Parameters:
expression - the expression to validate
Throws:
InvalidExpressionException - if the expression is invalid, including information about the position and fault
Since:
3.0

isExpression

boolean isExpression(java.lang.String string)
Determines if the string is an expression. This method will validate that the string contains either the expression prefix (malformed) or a full expression. This isn't full proof but catches most error cases

Parameters:
string - is this string an expression string
Returns:
true if the string contains an expression
Since:
3.0


Copyright © 2003-2010 MuleSoft, Inc.. All Rights Reserved.