| java.lang.Object ognl.Ognl
Ognl | abstract public class Ognl (Code) | | This class provides static methods for parsing and interpreting OGNL expressions.
The simplest use of the Ognl class is to get the value of an expression from
an object, without extra context or pre-parsing.
import ognl.Ognl;
import ognl.OgnlException;
try {
result = Ognl.getValue(expression, root);
} catch (OgnlException ex) {
// Report error or recover
}
This will parse the expression given and evaluate it against the root object
given, returning the result. If there is an error in the expression, such
as the property is not found, the exception is encapsulated into an
ognl.OgnlException OgnlException .
Other more sophisticated uses of Ognl can pre-parse expressions. This
provides two advantages: in the case of user-supplied expressions it
allows you to catch parse errors before evaluation and it allows you to
cache parsed expressions into an AST for better speed during repeated use.
The pre-parsed expression is always returned as an Object
to simplify use for programs that just wish to store the value for
repeated use and do not care that it is an AST. If it does care
it can always safely cast the value to an AST type.
The Ognl class also takes a context map as one of the parameters
to the set and get methods. This allows you to put your own variables
into the available namespace for OGNL expressions. The default context
contains only the #root and #context keys,
which are required to be present. The addDefaultContext(Object, Map)
method will alter an existing Map to put the defaults in.
Here is an example that shows how to extract the documentName
property out of the root object and append a string with the current user
name in parens:
private Map context = new HashMap();
public void setUserName(String value)
{
context.put("userName", value);
}
try {
// get value using our own custom context map
result = Ognl.getValue("documentName + \" (\" + ((#userName == null) ? \"<nobody>\" : #userName) + \")\"", context, root);
} catch (OgnlException ex) {
// Report error or recover
}
author: Luke Blanshard (blanshlu@netscape.net) author: Drew Davidson (drew@ognl.org) version: 27 June 1999 |
Method Summary | |
public static Map | addDefaultContext(Object root, Map context) Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. | public static Map | addDefaultContext(Object root, ClassResolver classResolver, Map context) Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. | public static Map | addDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter, Map context) Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. | public static Map | addDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess, Map context) Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. | public static Map | createDefaultContext(Object root) Creates and returns a new standard naming context for evaluating an OGNL
expression. | public static Map | createDefaultContext(Object root, ClassResolver classResolver) Creates and returns a new standard naming context for evaluating an OGNL
expression. | public static Map | createDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter) Creates and returns a new standard naming context for evaluating an OGNL
expression. | public static Map | createDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess) Creates and returns a new standard naming context for evaluating an OGNL
expression. | public static ClassResolver | getClassResolver(Map context) | public static Evaluation | getLastEvaluation(Map context) | public static MemberAccess | getMemberAccess(Map context) | public static Object | getRoot(Map context) | public static TypeConverter | getTypeConverter(Map context) | public static Object | getValue(Object tree, Map context, Object root) Evaluates the given OGNL expression tree to extract a value from the given root
object. | public static Object | getValue(Object tree, Map context, Object root, Class resultType) Evaluates the given OGNL expression tree to extract a value from the given root
object. | public static Object | getValue(String expression, Map context, Object root) | public static Object | getValue(String expression, Map context, Object root, Class resultType) | public static Object | getValue(Object tree, Object root) Evaluates the given OGNL expression tree to extract a value from the given root
object. | public static Object | getValue(Object tree, Object root, Class resultType) Evaluates the given OGNL expression tree to extract a value from the given root
object. | public static Object | getValue(String expression, Object root) Convenience method that combines calls to parseExpression and
getValue . | public static Object | getValue(String expression, Object root, Class resultType) Convenience method that combines calls to parseExpression and
getValue . | public static boolean | isConstant(Object tree, Map context) | public static boolean | isConstant(String expression, Map context) | public static boolean | isConstant(Object tree) | public static boolean | isConstant(String expression) | public static boolean | isSimpleNavigationChain(Object tree, Map context) | public static boolean | isSimpleNavigationChain(String expression, Map context) | public static boolean | isSimpleNavigationChain(Object tree) | public static boolean | isSimpleNavigationChain(String expression) | public static boolean | isSimpleProperty(Object tree, Map context) | public static boolean | isSimpleProperty(String expression, Map context) | public static boolean | isSimpleProperty(Object tree) | public static boolean | isSimpleProperty(String expression) | public static Object | parseExpression(String expression) Parses the given OGNL expression and returns a tree representation of the
expression that can be used by Ognl static methods. | public static void | setClassResolver(Map context, ClassResolver classResolver) | public static void | setMemberAccess(Map context, MemberAccess memberAccess) | public static void | setRoot(Map context, Object root) | public static void | setTypeConverter(Map context, TypeConverter converter) | public static void | setValue(Object tree, Map context, Object root, Object value) Evaluates the given OGNL expression tree to insert a value into the object graph
rooted at the given root object. | public static void | setValue(String expression, Map context, Object root, Object value) Evaluates the given OGNL expression to insert a value into the object graph
rooted at the given root object given the context. | public static void | setValue(Object tree, Object root, Object value) Evaluates the given OGNL expression tree to insert a value into the object graph
rooted at the given root object. | public static void | setValue(String expression, Object root, Object value) Convenience method that combines calls to parseExpression and
setValue . |
addDefaultContext | public static Map addDefaultContext(Object root, Map context)(Code) | | Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. Context Map with the keys root and context set appropriately |
addDefaultContext | public static Map addDefaultContext(Object root, ClassResolver classResolver, Map context)(Code) | | Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. Context Map with the keys root and context set appropriately |
addDefaultContext | public static Map addDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter, Map context)(Code) | | Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. Context Map with the keys root and context set appropriately |
addDefaultContext | public static Map addDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess, Map context)(Code) | | Appends the standard naming context for evaluating an OGNL expression
into the context given so that cached maps can be used as a context.
Parameters: root - the root of the object graph Parameters: context - the context to which OGNL context will be added. Context Map with the keys root and context set appropriately |
createDefaultContext | public static Map createDefaultContext(Object root)(Code) | | Creates and returns a new standard naming context for evaluating an OGNL
expression.
Parameters: root - the root of the object graph a new Map with the keys root and context set appropriately |
createDefaultContext | public static Map createDefaultContext(Object root, ClassResolver classResolver)(Code) | | Creates and returns a new standard naming context for evaluating an OGNL
expression.
Parameters: root - the root of the object graph a new OgnlContext with the keys root and context set appropriately |
createDefaultContext | public static Map createDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter)(Code) | | Creates and returns a new standard naming context for evaluating an OGNL
expression.
Parameters: root - the root of the object graph a new Map with the keys root and context set appropriately |
createDefaultContext | public static Map createDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess)(Code) | | Creates and returns a new standard naming context for evaluating an OGNL
expression.
Parameters: root - the root of the object graph a new Map with the keys root and context set appropriately |
getValue | public static Object getValue(Object tree, Map context, Object root) throws OgnlException(Code) | | Evaluates the given OGNL expression tree to extract a value from the given root
object. The default context is set for the given context and root via
addDefaultContext() .
Parameters: tree - the OGNL expression tree to evaluate, as returned by parseExpression() Parameters: context - the naming context for the evaluation Parameters: root - the root object for the OGNL expression the result of evaluating the expression throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
getValue | public static Object getValue(Object tree, Map context, Object root, Class resultType) throws OgnlException(Code) | | Evaluates the given OGNL expression tree to extract a value from the given root
object. The default context is set for the given context and root via
addDefaultContext() .
Parameters: tree - the OGNL expression tree to evaluate, as returned by parseExpression() Parameters: context - the naming context for the evaluation Parameters: root - the root object for the OGNL expression Parameters: resultType - the converted type of the resultant object, using the context's type converter the result of evaluating the expression throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
getValue | public static Object getValue(Object tree, Object root) throws OgnlException(Code) | | Evaluates the given OGNL expression tree to extract a value from the given root
object.
Parameters: tree - the OGNL expression tree to evaluate, as returned by parseExpression() Parameters: root - the root object for the OGNL expression the result of evaluating the expression throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
getValue | public static Object getValue(Object tree, Object root, Class resultType) throws OgnlException(Code) | | Evaluates the given OGNL expression tree to extract a value from the given root
object.
Parameters: tree - the OGNL expression tree to evaluate, as returned by parseExpression() Parameters: root - the root object for the OGNL expression Parameters: resultType - the converted type of the resultant object, using the context's type converter the result of evaluating the expression throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
parseExpression | public static Object parseExpression(String expression) throws OgnlException(Code) | | Parses the given OGNL expression and returns a tree representation of the
expression that can be used by Ognl static methods.
Parameters: expression - the OGNL expression to be parsed a tree representation of the expression throws: ExpressionSyntaxException - if the expression is malformed throws: OgnlException - if there is a pathological environmental problem |
setValue | public static void setValue(Object tree, Map context, Object root, Object value) throws OgnlException(Code) | | Evaluates the given OGNL expression tree to insert a value into the object graph
rooted at the given root object. The default context is set for the given
context and root via addDefaultContext() .
Parameters: tree - the OGNL expression tree to evaluate, as returned by parseExpression() Parameters: context - the naming context for the evaluation Parameters: root - the root object for the OGNL expression Parameters: value - the value to insert into the object graph throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
setValue | public static void setValue(String expression, Map context, Object root, Object value) throws OgnlException(Code) | | Evaluates the given OGNL expression to insert a value into the object graph
rooted at the given root object given the context.
Parameters: expression - the OGNL expression to be parsed Parameters: root - the root object for the OGNL expression Parameters: context - the naming context for the evaluation Parameters: value - the value to insert into the object graph throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
setValue | public static void setValue(Object tree, Object root, Object value) throws OgnlException(Code) | | Evaluates the given OGNL expression tree to insert a value into the object graph
rooted at the given root object.
Parameters: tree - the OGNL expression tree to evaluate, as returned by parseExpression() Parameters: root - the root object for the OGNL expression Parameters: value - the value to insert into the object graph throws: MethodFailedException - if the expression called a method which failed throws: NoSuchPropertyException - if the expression referred to a nonexistent property throws: InappropriateExpressionException - if the expression can't be used in this context throws: OgnlException - if there is a pathological environmental problem |
|
|