org.jboss.solder.el
Class Expressions

java.lang.Object
  extended by org.jboss.solder.el.Expressions

public class Expressions
extends Object

Provides various utility methods for working with EL expressions.

This utility can be used through injection:

 @Inject
 Expressions expressions;
 

Alternatively, if you aren't working in a CDI environment, it can be instantiated using the new keyword:

 Expressions expressions = new Expressions(context, expressionFactory);
 

Author:
Pete Muir, Dan Allen, Stuart Douglas

Constructor Summary
Expressions(javax.el.ELContext context, javax.el.ExpressionFactory expressionFactory)
          Create a new instance of the Expressions class, providing the ELContext and ExpressionFactory to be used.
 
Method Summary
<T> T
evaluateMethodExpression(String expression)
           Evaluate a MethodExpression with no parameters, inferring the return type.
<T> T
evaluateMethodExpression(String expression, Class<T> expectedReturnType)
           Evaluate a MethodExpression with no parameters.
<T> T
evaluateMethodExpression(String expression, Class<T> expectedReturnType, Object[] params, Class<?>[] expectedParamTypes)
           Evaluate a MethodExpression, passing arguments and argument types to the method.
<T> T
evaluateMethodExpression(String expression, Object... params)
           Evaluate a MethodExpression, passing arguments to the method.
<T> T
evaluateValueExpression(String expression)
           Evaluate a ValueExpression inferring the return type.
<T> T
evaluateValueExpression(String expression, Class<T> expectedType)
           Evaluate a ValueExpression.
 javax.el.ELContext getELContext()
          Obtain the ELContext that this instance of Expressions is using.
 javax.el.ExpressionFactory getExpressionFactory()
          Obtain the ExpressionFactory that this instance of Expressions is using.
 String toExpression(String name)
          Convert's a bean name to an EL expression string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Expressions

@Inject
public Expressions(javax.el.ELContext context,
                          javax.el.ExpressionFactory expressionFactory)
Create a new instance of the Expressions class, providing the ELContext and ExpressionFactory to be used.

Parameters:
context - the ELContext against which to operate
expressionFactory - the ExpressionFactory to use
Throws:
IllegalArgumentException - if context is null or expressionFactory is null
Method Detail

getELContext

public javax.el.ELContext getELContext()
Obtain the ELContext that this instance of Expressions is using.

Returns:
the ELContext in use

getExpressionFactory

public javax.el.ExpressionFactory getExpressionFactory()
Obtain the ExpressionFactory that this instance of Expressions is using.

Returns:
the ExpressionFactory in use

evaluateValueExpression

public <T> T evaluateValueExpression(String expression,
                                     Class<T> expectedType)

Evaluate a ValueExpression.

A ValueExpression is created by calling ExpressionFactory.createValueExpression(ELContext, String, Class) and then ValueExpression.getValue(ELContext) is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these classes and methods.

Type Parameters:
T - the type of the evaluated expression
Parameters:
expression - the expression to evaluate
expectedType - the expected type of the evaluated expression
Returns:
the result of evaluating the expression
Throws:
NullPointerException - if expectedType is null
javax.el.ELException - if there are syntactical errors in the provided expression or if an exception was thrown while performing property or variable resolution. The thrown exception will be included as the cause property of this exception, if available.
javax.el.PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
ClassCastException - if the result cannot be cast to the expected type
See Also:
ExpressionFactory.createValueExpression(ELContext, String, Class), ValueExpression.getValue(ELContext)

evaluateValueExpression

public <T> T evaluateValueExpression(String expression)

Evaluate a ValueExpression inferring the return type.

A ValueExpression is created by calling ExpressionFactory.createValueExpression(ELContext, String, Class) and then ValueExpression.getValue(ELContext) is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.

Type Parameters:
T - the type of the evaluated expression
Parameters:
expression - expression the expression to evaluate
Returns:
the result of evaluating the expression
Throws:
javax.el.ELException - if there are syntactical errors in the provided expression
javax.el.ELException - if an exception was thrown while performing property or variable resolution. The thrown exception will be included as the cause property of this exception, if available.
javax.el.PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable
ClassCastException - if the result cannot be cast to T
See Also:
ExpressionFactory.createValueExpression(ELContext, String, Class), ValueExpression.getValue(ELContext)

evaluateMethodExpression

public <T> T evaluateMethodExpression(String expression,
                                      Class<T> expectedReturnType,
                                      Object[] params,
                                      Class<?>[] expectedParamTypes)

Evaluate a MethodExpression, passing arguments and argument types to the method.

A MethodExpression is created by calling ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[]) and then MethodExpression.invoke(ELContext, Object[]) is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.

Type Parameters:
T - the type of the evaluated expression
Parameters:
expression - expression the expression to evaluate
expectedReturnType - the expected return type of the evaluated expression
params - arguments to the method
expectedParamTypes - of the arguments to the method
Returns:
the result of evaluating the expression
Throws:
ClassCastException - if the result cannot be cast to expectedReturnType
javax.el.ELException - if there are syntactical errors in the provided expression.
NullPointerException - if expectedParamTypes is null.
javax.el.PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
javax.el.MethodNotFoundException - if no suitable method can be found.
javax.el.ELException - if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").
javax.el.ELException - if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is an InvocationTargetException, extract its cause and pass it to the ELException constructor.
See Also:
MethodExpression.invoke(ELContext, Object[]), ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])

evaluateMethodExpression

public <T> T evaluateMethodExpression(String expression,
                                      Class<T> expectedReturnType)

Evaluate a MethodExpression with no parameters.

A MethodExpression is created by calling ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[]) and then MethodExpression.invoke(ELContext, Object[]) is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.

Type Parameters:
T - the type of the evaluated expression
Parameters:
expression - expression the expression to evaluate
expectedReturnType - the expected return type of the evaluated expression
Returns:
the result of evaluating the expression
Throws:
ClassCastException - if the result cannot be cast to expectedReturnType
javax.el.ELException - if there are syntactical errors in the provided expression.
NullPointerException - if expectedParamTypes is null.
javax.el.PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
javax.el.MethodNotFoundException - if no suitable method can be found.
javax.el.ELException - if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").
javax.el.ELException - if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is an InvocationTargetException, extract its cause and pass it to the ELException constructor.
See Also:
MethodExpression.invoke(ELContext, Object[]), ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])

evaluateMethodExpression

public <T> T evaluateMethodExpression(String expression)

Evaluate a MethodExpression with no parameters, inferring the return type.

A MethodExpression is created by calling ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[]) and then MethodExpression.invoke(ELContext, Object[]) is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.

Type Parameters:
T - the type of the evaluated expression
Parameters:
expression - expression the expression to evaluate
Returns:
the result of evaluating the expression
Throws:
ClassCastException - if the result cannot be cast to T
javax.el.ELException - if there are syntactical errors in the provided expression.
NullPointerException - if expectedParamTypes is null.
javax.el.PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
javax.el.MethodNotFoundException - if no suitable method can be found.
javax.el.ELException - if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").
javax.el.ELException - if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is an InvocationTargetException, extract its cause and pass it to the ELException constructor.
See Also:
MethodExpression.invoke(ELContext, Object[]), ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])

evaluateMethodExpression

public <T> T evaluateMethodExpression(String expression,
                                      Object... params)

Evaluate a MethodExpression, passing arguments to the method. The types of the arguments are discoverted from the arguments, and the return type is inferred.

A MethodExpression is created by calling ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[]) and then MethodExpression.invoke(ELContext, Object[]) is called to obtain the value. For more details on the semantics of EL, refer to the javadoc for these methods.

Type Parameters:
T - the type of the evaluated expression
Parameters:
expression - expression the expression to evaluate
params - arguments to the method
Returns:
the result of evaluating the expression
Throws:
ClassCastException - if the result cannot be cast to T
javax.el.ELException - if there are syntactical errors in the provided expression.
NullPointerException - if expectedParamTypes is null.
javax.el.PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
javax.el.MethodNotFoundException - if no suitable method can be found.
javax.el.ELException - if a String literal is specified and expectedReturnType of the MethodExpression is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.18 Type Conversion").
javax.el.ELException - if an exception was thrown while performing property or variable resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is an InvocationTargetException, extract its cause and pass it to the ELException constructor.
See Also:
MethodExpression.invoke(ELContext, Object[]), ExpressionFactory.createMethodExpression(ELContext, String, Class, Class[])

toExpression

public String toExpression(String name)
Convert's a bean name to an EL expression string.

Parameters:
name - the name of the bean to convert
Returns:
the expression string


Copyright © 2008-2011 Seam Framework. All Rights Reserved.