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);
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
<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.
|
@Inject public Expressions(javax.el.ELContext context, javax.el.ExpressionFactory expressionFactory)
Expressions
class, providing the
ELContext
and ExpressionFactory
to be used.context
- the ELContext
against which to operateexpressionFactory
- the ExpressionFactory
to useIllegalArgumentException
- if context
is null or
expressionFactory
is nullpublic javax.el.ELContext getELContext()
ELContext
that this instance of Expressions
is
using.ELContext
in usepublic javax.el.ExpressionFactory getExpressionFactory()
ExpressionFactory
that this instance of
Expressions
is using.ExpressionFactory
in usepublic <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.
T
- the type of the evaluated expressionexpression
- the expression to evaluateexpectedType
- the expected type of the evaluated expressionNullPointerException
- 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
typeExpressionFactory.createValueExpression(ELContext, String, Class)
,
ValueExpression.getValue(ELContext)
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.
T
- the type of the evaluated expressionexpression
- expression the expression to evaluatejavax.el.ELException
- if there are syntactical errors in the provided
expressionjavax.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 readableClassCastException
- if the result cannot be cast to T
ExpressionFactory.createValueExpression(ELContext, String, Class)
,
ValueExpression.getValue(ELContext)
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.
T
- the type of the evaluated expressionexpression
- expression the expression to evaluateexpectedReturnType
- the expected return type of the evaluated
expressionparams
- arguments to the methodexpectedParamTypes
- of the arguments to the methodClassCastException
- 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.MethodExpression.invoke(ELContext, Object[])
,
ExpressionFactory.createMethodExpression(ELContext, String, Class,
Class[])
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.
T
- the type of the evaluated expressionexpression
- expression the expression to evaluateexpectedReturnType
- the expected return type of the evaluated
expressionClassCastException
- 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.MethodExpression.invoke(ELContext, Object[])
,
ExpressionFactory.createMethodExpression(ELContext, String, Class,
Class[])
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.
T
- the type of the evaluated expressionexpression
- expression the expression to evaluateClassCastException
- 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.MethodExpression.invoke(ELContext, Object[])
,
ExpressionFactory.createMethodExpression(ELContext, String, Class,
Class[])
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.
T
- the type of the evaluated expressionexpression
- expression the expression to evaluateparams
- arguments to the methodClassCastException
- 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.MethodExpression.invoke(ELContext, Object[])
,
ExpressionFactory.createMethodExpression(ELContext, String, Class,
Class[])
Copyright © 2008-2013 Seam Framework. All Rights Reserved.