|
|||||||||
| Home >> All >> [ ognl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
ognl
Class Ognl

java.lang.Objectognl.Ognl
- public abstract class Ognl
- extends java.lang.Object
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 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
}
- Version:
- 27 June 1999
| Constructor Summary | |
private |
Ognl()
You can't make one of these. |
| Method Summary | |
static java.util.Map |
addDefaultContext(java.lang.Object root,
ClassResolver classResolver,
java.util.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. |
static java.util.Map |
addDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter,
java.util.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. |
static java.util.Map |
addDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter,
MemberAccess memberAccess,
java.util.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. |
static java.util.Map |
addDefaultContext(java.lang.Object root,
java.util.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. |
static java.util.Map |
createDefaultContext(java.lang.Object root)
Creates and returns a new standard naming context for evaluating an OGNL expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
ClassResolver classResolver)
Creates and returns a new standard naming context for evaluating an OGNL expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter)
Creates and returns a new standard naming context for evaluating an OGNL expression. |
static java.util.Map |
createDefaultContext(java.lang.Object root,
ClassResolver classResolver,
TypeConverter converter,
MemberAccess memberAccess)
Creates and returns a new standard naming context for evaluating an OGNL expression. |
static ClassResolver |
getClassResolver(java.util.Map context)
|
static Evaluation |
getLastEvaluation(java.util.Map context)
|
static MemberAccess |
getMemberAccess(java.util.Map context)
|
static java.lang.Object |
getRoot(java.util.Map context)
|
static TypeConverter |
getTypeConverter(java.util.Map context)
|
static java.lang.Object |
getValue(java.lang.Object tree,
java.util.Map context,
java.lang.Object root)
Evaluates the given OGNL expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.Object tree,
java.util.Map context,
java.lang.Object root,
java.lang.Class resultType)
Evaluates the given OGNL expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.Object tree,
java.lang.Object root)
Evaluates the given OGNL expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.Object tree,
java.lang.Object root,
java.lang.Class resultType)
Evaluates the given OGNL expression tree to extract a value from the given root object. |
static java.lang.Object |
getValue(java.lang.String expression,
java.util.Map context,
java.lang.Object root)
Evaluates the given OGNL expression to extract a value from the given root object in a given context |
static java.lang.Object |
getValue(java.lang.String expression,
java.util.Map context,
java.lang.Object root,
java.lang.Class resultType)
Evaluates the given OGNL expression to extract a value from the given root object in a given context |
static java.lang.Object |
getValue(java.lang.String expression,
java.lang.Object root)
Convenience method that combines calls to parseExpression and
getValue. |
static java.lang.Object |
getValue(java.lang.String expression,
java.lang.Object root,
java.lang.Class resultType)
Convenience method that combines calls to parseExpression and
getValue. |
static boolean |
isConstant(java.lang.Object tree)
|
static boolean |
isConstant(java.lang.Object tree,
java.util.Map context)
|
static boolean |
isConstant(java.lang.String expression)
|
static boolean |
isConstant(java.lang.String expression,
java.util.Map context)
|
static boolean |
isSimpleNavigationChain(java.lang.Object tree)
|
static boolean |
isSimpleNavigationChain(java.lang.Object tree,
java.util.Map context)
|
static boolean |
isSimpleNavigationChain(java.lang.String expression)
|
static boolean |
isSimpleNavigationChain(java.lang.String expression,
java.util.Map context)
|
static boolean |
isSimpleProperty(java.lang.Object tree)
|
static boolean |
isSimpleProperty(java.lang.Object tree,
java.util.Map context)
|
static boolean |
isSimpleProperty(java.lang.String expression)
|
static boolean |
isSimpleProperty(java.lang.String expression,
java.util.Map context)
|
static java.lang.Object |
parseExpression(java.lang.String expression)
Parses the given OGNL expression and returns a tree representation of the expression that can be used by Ognl static methods. |
static void |
setClassResolver(java.util.Map context,
ClassResolver classResolver)
|
static void |
setMemberAccess(java.util.Map context,
MemberAccess memberAccess)
|
static void |
setRoot(java.util.Map context,
java.lang.Object root)
|
static void |
setTypeConverter(java.util.Map context,
TypeConverter converter)
|
static void |
setValue(java.lang.Object tree,
java.util.Map context,
java.lang.Object root,
java.lang.Object value)
Evaluates the given OGNL expression tree to insert a value into the object graph rooted at the given root object. |
static void |
setValue(java.lang.Object tree,
java.lang.Object root,
java.lang.Object value)
Evaluates the given OGNL expression tree to insert a value into the object graph rooted at the given root object. |
static void |
setValue(java.lang.String expression,
java.util.Map context,
java.lang.Object root,
java.lang.Object value)
Evaluates the given OGNL expression to insert a value into the object graph rooted at the given root object given the context. |
static void |
setValue(java.lang.String expression,
java.lang.Object root,
java.lang.Object value)
Convenience method that combines calls to parseExpression and
setValue. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
Ognl
private Ognl()
- You can't make one of these.
| Method Detail |
parseExpression
public static java.lang.Object parseExpression(java.lang.String expression) throws OgnlException
- Parses the given OGNL expression and returns a tree representation of the
expression that can be used by
Ognlstatic methods.
createDefaultContext
public static java.util.Map createDefaultContext(java.lang.Object root)
- Creates and returns a new standard naming context for evaluating an OGNL
expression.
createDefaultContext
public static java.util.Map createDefaultContext(java.lang.Object root, ClassResolver classResolver)
- Creates and returns a new standard naming context for evaluating an OGNL
expression.
createDefaultContext
public static java.util.Map createDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter)
- Creates and returns a new standard naming context for evaluating an OGNL
expression.
createDefaultContext
public static java.util.Map createDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess)
- Creates and returns a new standard naming context for evaluating an OGNL
expression.
addDefaultContext
public static java.util.Map addDefaultContext(java.lang.Object root, java.util.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.
addDefaultContext
public static java.util.Map addDefaultContext(java.lang.Object root, ClassResolver classResolver, java.util.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.
addDefaultContext
public static java.util.Map addDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter, java.util.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.
addDefaultContext
public static java.util.Map addDefaultContext(java.lang.Object root, ClassResolver classResolver, TypeConverter converter, MemberAccess memberAccess, java.util.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.
setClassResolver
public static void setClassResolver(java.util.Map context, ClassResolver classResolver)
getClassResolver
public static ClassResolver getClassResolver(java.util.Map context)
setTypeConverter
public static void setTypeConverter(java.util.Map context, TypeConverter converter)
getTypeConverter
public static TypeConverter getTypeConverter(java.util.Map context)
setMemberAccess
public static void setMemberAccess(java.util.Map context, MemberAccess memberAccess)
getMemberAccess
public static MemberAccess getMemberAccess(java.util.Map context)
setRoot
public static void setRoot(java.util.Map context, java.lang.Object root)
getRoot
public static java.lang.Object getRoot(java.util.Map context)
getLastEvaluation
public static Evaluation getLastEvaluation(java.util.Map context)
getValue
public static java.lang.Object getValue(java.lang.Object tree, java.util.Map context, java.lang.Object root) throws OgnlException
- 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().
getValue
public static java.lang.Object getValue(java.lang.Object tree, java.util.Map context, java.lang.Object root, java.lang.Class resultType) throws OgnlException
- 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().
getValue
public static java.lang.Object getValue(java.lang.String expression, java.util.Map context, java.lang.Object root) throws OgnlException
- Evaluates the given OGNL expression to extract a value from the given root
object in a given context
getValue
public static java.lang.Object getValue(java.lang.String expression, java.util.Map context, java.lang.Object root, java.lang.Class resultType) throws OgnlException
- Evaluates the given OGNL expression to extract a value from the given root
object in a given context
getValue
public static java.lang.Object getValue(java.lang.Object tree, java.lang.Object root) throws OgnlException
- Evaluates the given OGNL expression tree to extract a value from the given root
object.
getValue
public static java.lang.Object getValue(java.lang.Object tree, java.lang.Object root, java.lang.Class resultType) throws OgnlException
- Evaluates the given OGNL expression tree to extract a value from the given root
object.
getValue
public static java.lang.Object getValue(java.lang.String expression, java.lang.Object root) throws OgnlException
- Convenience method that combines calls to
parseExpressionandgetValue.
getValue
public static java.lang.Object getValue(java.lang.String expression, java.lang.Object root, java.lang.Class resultType) throws OgnlException
- Convenience method that combines calls to
parseExpressionandgetValue.
setValue
public static void setValue(java.lang.Object tree, java.util.Map context, java.lang.Object root, java.lang.Object value) throws OgnlException
- 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().
setValue
public static void setValue(java.lang.String expression, java.util.Map context, java.lang.Object root, java.lang.Object value) throws OgnlException
- Evaluates the given OGNL expression to insert a value into the object graph
rooted at the given root object given the context.
setValue
public static void setValue(java.lang.Object tree, java.lang.Object root, java.lang.Object value) throws OgnlException
- Evaluates the given OGNL expression tree to insert a value into the object graph
rooted at the given root object.
setValue
public static void setValue(java.lang.String expression, java.lang.Object root, java.lang.Object value) throws OgnlException
- Convenience method that combines calls to
parseExpressionandsetValue.
isConstant
public static boolean isConstant(java.lang.Object tree, java.util.Map context) throws OgnlException
isConstant
public static boolean isConstant(java.lang.String expression, java.util.Map context) throws OgnlException
isConstant
public static boolean isConstant(java.lang.Object tree) throws OgnlException
isConstant
public static boolean isConstant(java.lang.String expression) throws OgnlException
isSimpleProperty
public static boolean isSimpleProperty(java.lang.Object tree, java.util.Map context) throws OgnlException
isSimpleProperty
public static boolean isSimpleProperty(java.lang.String expression, java.util.Map context) throws OgnlException
isSimpleProperty
public static boolean isSimpleProperty(java.lang.Object tree) throws OgnlException
isSimpleProperty
public static boolean isSimpleProperty(java.lang.String expression) throws OgnlException
isSimpleNavigationChain
public static boolean isSimpleNavigationChain(java.lang.Object tree, java.util.Map context) throws OgnlException
isSimpleNavigationChain
public static boolean isSimpleNavigationChain(java.lang.String expression, java.util.Map context) throws OgnlException
isSimpleNavigationChain
public static boolean isSimpleNavigationChain(java.lang.Object tree) throws OgnlException
isSimpleNavigationChain
public static boolean isSimpleNavigationChain(java.lang.String expression) throws OgnlException
|
|||||||||
| Home >> All >> [ ognl overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
ognl.Ognl