org.mule.expression
Class DefaultExpressionManager

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

public class DefaultExpressionManager
extends Object
implements ExpressionManager, MuleContextAware, Initialisable

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
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Constructor Summary
DefaultExpressionManager()
           
 
Method Summary
 void clearEnrichers()
          Clears all registered enrichers from the manager.
 void clearEvaluators()
          Clears all registered evaluators from the manager.
protected  String createEnrichmentExpression(String expression)
           
 void enrich(String expression, MuleEvent event, Object object)
           
 void enrich(String expression, MuleMessage message, Object object)
          Enriches the current message using
 void enrich(String expression, String enricherName, MuleMessage message, Object object)
          Enriches the current message
 Object evaluate(String expression, MuleEvent event)
           
 Object evaluate(String expression, MuleEvent event, boolean failIfNull)
          Evaluates the given expression.
 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 evaluateBoolean(String expression, MuleEvent event)
           
 boolean evaluateBoolean(String expression, MuleEvent event, boolean nullReturnsTrue, boolean nonBooleanReturnsTrue)
           
 boolean evaluateBoolean(String expression, MuleMessage message)
          Evaluates the given expression resolving the result of the evaluation to a boolean.
 boolean evaluateBoolean(String expression, MuleMessage message, boolean nullReturnsTrue, boolean nonBooleanReturnsTrue)
          Evaluates the given expression resolving the result of the evaluation to a boolean.
 boolean evaluateBoolean(String expression, String evaluator, MuleMessage message)
          Evaluates the given expression resolving the result of the evaluation to a boolean.
 boolean evaluateBoolean(String expression, String evaluator, MuleMessage message, boolean nullReturnsTrue, boolean nonBooleanReturnsTrue)
          Evaluates the given expression resolving the result of the evaluation to a boolean.
 ExpressionLanguage getExpressionLanguage()
           
 void initialise()
          Method used to perform any initialisation work.
protected  boolean isEnricherExpression(String expression)
           
 boolean isEnricherRegistered(String name)
          Checks whether an enricher is registered with the manager
protected  boolean isEvaluatorExpression(String expression)
           
 boolean isEvaluatorRegistered(String name)
          Checks whether an evaluator is registered with the manager
 boolean isExpression(String string)
          Determines if the string is an expression.
 boolean isValidExpression(String expression)
          Determines if the expression is valid or not.
 String parse(String expression, MuleEvent event)
           
 String parse(String expression, MuleEvent event, boolean failIfNull)
           
 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.
protected  String preProcessExpression(String expression)
           
 void registerEnricher(ExpressionEnricher enricher)
           
 void registerEvaluator(ExpressionEvaluator evaluator)
           
protected  boolean resolveBoolean(Object result, boolean nullReturnsTrue, boolean nonBooleanReturnsTrue, String expression)
           
 void setExpressionLanguage(ExpressionLanguage expressionLanguage)
           
 void setMuleContext(MuleContext context)
           
 ExpressionEnricher unregisterEnricher(String name)
          Removes the evaluator with the given name
 ExpressionEvaluator unregisterEvaluator(String name)
          Removes the evaluator with the given name
 void validateExpression(String expression)
          Determines if the expression is valid or not.
 
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

setMuleContext

public void setMuleContext(MuleContext context)
Specified by:
setMuleContext in interface MuleContextAware

registerEvaluator

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

registerEnricher

public void registerEnricher(ExpressionEnricher enricher)
Specified by:
registerEnricher 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

isEnricherRegistered

public boolean isEnricherRegistered(String name)
Checks whether an enricher is registered with the manager

Specified by:
isEnricherRegistered in interface ExpressionManager
Parameters:
name - the name of the expression enricher
Returns:
true if the enricher 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

unregisterEnricher

public ExpressionEnricher unregisterEnricher(String name)
Removes the evaluator with the given name

Specified by:
unregisterEnricher in interface ExpressionManager
Parameters:
name - the name of the evaluator to remove
Returns:
the enricher that was removed. This will be null if the enricher 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. "context:serviceName" and "#[context: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 - the current message to process. The expression will evaluata on the message.
Returns:
the result of the evaluation. Expressions that return collection will return an empty collection, not null.
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,
                       MuleEvent event)
                throws ExpressionRuntimeException
Specified by:
evaluate in interface ExpressionManager
Throws:
ExpressionRuntimeException

evaluate

public Object evaluate(String expression,
                       MuleEvent event,
                       boolean failIfNull)
                throws ExpressionRuntimeException
Evaluates the given expression. The expression should be a single expression definition with or without enclosing braces. i.e. "context:serviceName" and "#[context: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 - the current message to process. The expression will evaluata on the message.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null.
Returns:
the result of the evaluation. Expressions that return collection will return an empty collection, not null.
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)
Description copied from interface: ExpressionManager
Evaluates the given expression. The expression should be a single expression definition with or without enclosing braces. i.e. "context:serviceName" and "#[context: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 - 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

enrich

public void enrich(String expression,
                   MuleMessage message,
                   Object object)
            throws ExpressionRuntimeException
Description copied from interface: ExpressionManager
Enriches the current message using

Specified by:
enrich in interface ExpressionManager
Parameters:
expression - a single expression i.e. header://foo that defines how the message shoud be enriched
message - The current message being processed that will be enriched
object - The object that will be used to enrich the message
Throws:
ExpressionRuntimeException

enrich

public void enrich(String expression,
                   MuleEvent event,
                   Object object)
Specified by:
enrich in interface ExpressionManager

enrich

public void enrich(String expression,
                   String enricherName,
                   MuleMessage message,
                   Object object)
Description copied from interface: ExpressionManager
Enriches the current message

Specified by:
enrich in interface ExpressionManager
Parameters:
expression - a single expression i.e. header://foo that defines how the message shoud be enriched
enricherName - the enricher to use when executing the expression
message - The current message being processed that will be enriched
object - The object that will be used to enrich the message

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. "context:serviceName" and "#[context: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 - the current message to process. The expression will evaluata on the message.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null or if an exception should be thrown if an empty collection is returned.
Returns:
the result of the evaluation. Expressions that return collection will return an empty collection, not null.
Throws:
ExpressionRuntimeException - if the expression is invalid, or a null is found for the expression and 'failIfNull is set to true.

evaluateBoolean

public boolean evaluateBoolean(String expression,
                               String evaluator,
                               MuleMessage message)
                        throws ExpressionRuntimeException
Description copied from interface: ExpressionManager
Evaluates the given expression resolving the result of the evaluation to a boolean. The expression should be a single expression definition with or without enclosing braces. i.e. "context:serviceName" and "#[context:serviceName]" are both valid.

Specified by:
evaluateBoolean in interface ExpressionManager
Parameters:
expression - a single expression i.e. header:foo=bar
evaluator - the evaluator to use when executing the expression
message - The current message being processed
Throws:
ExpressionRuntimeException

evaluateBoolean

public boolean evaluateBoolean(String expression,
                               MuleMessage message)
                        throws ExpressionRuntimeException
Description copied from interface: ExpressionManager
Evaluates the given expression resolving the result of the evaluation to a boolean. The expression should be a single expression definition with or without enclosing braces. i.e. "context:serviceName" and "#[context:serviceName]" are both valid.

Specified by:
evaluateBoolean in interface ExpressionManager
Parameters:
expression - a single expression i.e. header:foo=bar
message - The current message being processed
Throws:
ExpressionRuntimeException

evaluateBoolean

public boolean evaluateBoolean(String expression,
                               String evaluator,
                               MuleMessage message,
                               boolean nullReturnsTrue,
                               boolean nonBooleanReturnsTrue)
                        throws ExpressionRuntimeException
Description copied from interface: ExpressionManager
Evaluates the given expression resolving the result of the evaluation to a boolean. The expression should be a single expression definition with or without enclosing braces. i.e. "context:serviceName" and "#[context:serviceName]" are both valid.

Specified by:
evaluateBoolean in interface ExpressionManager
Parameters:
expression - a single expression i.e. header:foo=bar
evaluator - the evaluator to use when executing the expression
message - The current message being processed
nullReturnsTrue - determines if true should be returned if the result of the evaluation is null
nonBooleanReturnsTrue - determines if true should returned if the result is not null but isn't recognised as a boolean
Throws:
ExpressionRuntimeException

evaluateBoolean

public boolean evaluateBoolean(String expression,
                               MuleMessage message,
                               boolean nullReturnsTrue,
                               boolean nonBooleanReturnsTrue)
                        throws ExpressionRuntimeException
Description copied from interface: ExpressionManager
Evaluates the given expression resolving the result of the evaluation to a boolean. The expression should be a single expression definition with or without enclosing braces. i.e. "context:serviceName" and "#[context:serviceName]" are both valid.

Specified by:
evaluateBoolean in interface ExpressionManager
Parameters:
expression - a single expression i.e. header:foo=bar
message - The current message being processed
nullReturnsTrue - determines if true should be returned if the result of the evaluation is null
nonBooleanReturnsTrue - determines if true should returned if the result is not null but isn't recognised as a boolean
Throws:
ExpressionRuntimeException

evaluateBoolean

public boolean evaluateBoolean(String expression,
                               MuleEvent event,
                               boolean nullReturnsTrue,
                               boolean nonBooleanReturnsTrue)
                        throws ExpressionRuntimeException
Specified by:
evaluateBoolean in interface ExpressionManager
Throws:
ExpressionRuntimeException

resolveBoolean

protected boolean resolveBoolean(Object result,
                                 boolean nullReturnsTrue,
                                 boolean nonBooleanReturnsTrue,
                                 String expression)

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 - the current message to process. The expression will evaluata on the message.
Returns:
the result of the evaluation. Expressions that return collection will return an empty collection, not null.
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,
                    MuleEvent event)
             throws ExpressionRuntimeException
Specified by:
parse in interface ExpressionManager
Throws:
ExpressionRuntimeException

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 - the current message to process. The expression will evaluata on the message.
failIfNull - determines if an exception should be thrown if expression could not be evaluated or returns null.
Returns:
the result of the evaluation. Expressions that return collection will return an empty collection, not null.
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,
                    MuleEvent event,
                    boolean failIfNull)
             throws ExpressionRuntimeException
Specified by:
parse in interface ExpressionManager
Throws:
ExpressionRuntimeException

clearEvaluators

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

Specified by:
clearEvaluators in interface ExpressionManager

clearEnrichers

public void clearEnrichers()
Description copied from interface: ExpressionManager
Clears all registered enrichers from the manager.

Specified by:
clearEnrichers in interface ExpressionManager

isExpression

public boolean isExpression(String string)
Description copied from interface: ExpressionManager
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

Specified by:
isExpression in interface ExpressionManager
Parameters:
string - is this string an expression string
Returns:
true if the string contains an expression

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

validateExpression

public void validateExpression(String expression)
                        throws InvalidExpressionException
Description copied from interface: ExpressionManager
Determines if the expression is valid or not. This method will validate a single expression or expressions embedded in a string. The expression must either be a well formed expression evaluator i.e. #[bean:user] or must be a valid expression language expression.

Specified by:
validateExpression in interface ExpressionManager
Parameters:
expression - the expression to validate
Throws:
InvalidExpressionException - if the expression is invalid, including information about the position and fault

initialise

public void initialise()
                throws InitialisationException
Description copied from interface: Initialisable
Method used to perform any initialisation work. If a fatal error occurs during initialisation an InitialisationException should be thrown, causing the Mule instance to shutdown. If the error is recoverable, say by retrying to connect, a RecoverableException should be thrown. There is no guarantee that by throwing a Recoverable exception that the Mule instance will not shut down.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException - if a fatal error occurs causing the Mule instance to shutdown
RecoverableException - if an error occurs that can be recovered from

evaluateBoolean

public boolean evaluateBoolean(String expression,
                               MuleEvent event)
                        throws ExpressionRuntimeException
Specified by:
evaluateBoolean in interface ExpressionManager
Throws:
ExpressionRuntimeException

preProcessExpression

protected String preProcessExpression(String expression)

isEvaluatorExpression

protected boolean isEvaluatorExpression(String expression)

isEnricherExpression

protected boolean isEnricherExpression(String expression)

createEnrichmentExpression

protected String createEnrichmentExpression(String expression)

setExpressionLanguage

public void setExpressionLanguage(ExpressionLanguage expressionLanguage)

getExpressionLanguage

public ExpressionLanguage getExpressionLanguage()


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