You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/14 15:18:36 UTC
svn commit: r1103095 [9/24] - in /incubator/ognl/trunk/src:
main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/
main/java/org/apache/commons/ognl/internal/
test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/t...
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Ognl.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Ognl.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Ognl.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Ognl.java Sat May 14 13:18:29 2011
@@ -29,49 +29,46 @@ import java.util.Map;
* This class provides static methods for parsing and interpreting OGNL expressions.
* </P>
* <P>
- * The simplest use of the Ognl class is to get the value of an expression from an object, without
- * extra context or pre-parsing.
+ * The simplest use of the Ognl class is to get the value of an expression from an object, without extra context or
+ * pre-parsing.
* </P>
- *
+ *
* <PRE>
- *
+ *
* import org.apache.commons.ognl.Ognl; import org.apache.commons.ognl.OgnlException; try { result = Ognl.getValue(expression, root); }
* catch (OgnlException ex) { // Report error or recover }
- *
+ *
* </PRE>
- *
* <P>
- * 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 {@link ognl.OgnlException OgnlException}.
+ * 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
+ * {@link ognl.OgnlException OgnlException}.
* </P>
* <P>
- * 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 <CODE>Object</CODE> 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 <CODE>AST</CODE> type.
+ * 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
+ * <CODE>Object</CODE> 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 <CODE>AST</CODE> type.
* </P>
* <P>
- * The Ognl class also takes a <I>context map</I> 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 <CODE>#root</CODE> and <CODE>#context</CODE>
- * keys, which are required to be present. The <CODE>addDefaultContext(Object, Map)</CODE> method
- * will alter an existing <CODE>Map</CODE> to put the defaults in. Here is an example that shows
- * how to extract the <CODE>documentName</CODE> property out of the root object and append a
- * string with the current user name in parens:
+ * The Ognl class also takes a <I>context map</I> 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
+ * <CODE>#root</CODE> and <CODE>#context</CODE> keys, which are required to be present. The
+ * <CODE>addDefaultContext(Object, Map)</CODE> method will alter an existing <CODE>Map</CODE> to put the defaults in.
+ * Here is an example that shows how to extract the <CODE>documentName</CODE> property out of the root object and append
+ * a string with the current user name in parens:
* </P>
- *
+ *
* <PRE>
- *
+ *
* 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 }
- *
+ *
* </PRE>
- *
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
* @version 27 June 1999
@@ -80,865 +77,691 @@ public abstract class Ognl
{
/**
- * Parses the given OGNL expression and returns a tree representation of the expression that can
- * be used by <CODE>Ognl</CODE> static methods.
- *
- * @param expression
- * the OGNL expression to be parsed
+ * Parses the given OGNL expression and returns a tree representation of the expression that can be used by
+ * <CODE>Ognl</CODE> static methods.
+ *
+ * @param expression the OGNL expression to be parsed
* @return a tree representation of the expression
- * @throws ExpressionSyntaxException
- * if the expression is malformed
- * @throws OgnlException
- * if there is a pathological environmental problem
+ * @throws ExpressionSyntaxException if the expression is malformed
+ * @throws OgnlException if there is a pathological environmental problem
*/
- public static Object parseExpression(String expression)
- throws OgnlException
+ public static Object parseExpression( String expression )
+ throws OgnlException
{
- try {
- OgnlParser parser = new OgnlParser(new StringReader(expression));
+ try
+ {
+ OgnlParser parser = new OgnlParser( new StringReader( expression ) );
return parser.topLevelExpression();
- } catch (ParseException e) {
- throw new ExpressionSyntaxException(expression, e);
- } catch (TokenMgrError e) {
- throw new ExpressionSyntaxException(expression, e);
+ }
+ catch ( ParseException e )
+ {
+ throw new ExpressionSyntaxException( expression, e );
+ }
+ catch ( TokenMgrError e )
+ {
+ throw new ExpressionSyntaxException( expression, e );
}
}
/**
- * Parses and compiles the given expression using the {@link ognl.enhance.OgnlExpressionCompiler} returned
- * from {@link ognl.OgnlRuntime#getCompiler()}.
- *
- * @param context
- * The context to use.
- * @param root
- * The root object for the given expression.
- * @param expression
- * The expression to compile.
- *
- * @return The node with a compiled accessor set on {@link ognl.Node#getAccessor()} if compilation
- * was successfull. In instances where compilation wasn't possible because of a partially null
- * expression the {@link ExpressionAccessor} instance may be null and the compilation of this expression
- * still possible at some as yet indertermined point in the future.
- *
+ * Parses and compiles the given expression using the {@link ognl.enhance.OgnlExpressionCompiler} returned from
+ * {@link ognl.OgnlRuntime#getCompiler()}.
+ *
+ * @param context The context to use.
+ * @param root The root object for the given expression.
+ * @param expression The expression to compile.
+ * @return The node with a compiled accessor set on {@link ognl.Node#getAccessor()} if compilation was successfull.
+ * In instances where compilation wasn't possible because of a partially null expression the
+ * {@link ExpressionAccessor} instance may be null and the compilation of this expression still possible at
+ * some as yet indertermined point in the future.
* @throws Exception If a compilation error occurs.
*/
- public static Node compileExpression(OgnlContext context, Object root, String expression)
- throws Exception
+ public static Node compileExpression( OgnlContext context, Object root, String expression )
+ throws Exception
{
- Node expr = (Node)Ognl.parseExpression(expression);
+ Node expr = (Node) Ognl.parseExpression( expression );
- OgnlRuntime.compileExpression(context, expr, root);
+ OgnlRuntime.compileExpression( context, expr, root );
return expr;
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
- *
- * @param root
- * the root of the object graph
- * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
+ *
+ * @param root the root of the object graph
+ * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
*/
- public static Map createDefaultContext(Object root)
+ public static Map createDefaultContext( Object root )
{
- return addDefaultContext(root, null, null, null, new OgnlContext());
+ return addDefaultContext( root, null, null, null, new OgnlContext() );
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
- *
- * @param root
- * The root of the object graph.
- * @param classResolver
- * The resolver used to instantiate {@link Class} instances referenced in the expression.
- *
- * @return a new OgnlContext with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
+ *
+ * @param root The root of the object graph.
+ * @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
+ * @return a new OgnlContext with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
*/
- public static Map createDefaultContext(Object root, ClassResolver classResolver)
+ public static Map createDefaultContext( Object root, ClassResolver classResolver )
{
- return addDefaultContext(root, classResolver, null, null, new OgnlContext());
+ return addDefaultContext( root, classResolver, null, null, new OgnlContext() );
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
- *
- * @param root
- * The root of the object graph.
- * @param classResolver
- * The resolver used to instantiate {@link Class} instances referenced in the expression.
- * @param converter
- * Converter used to convert return types of an expression in to their desired types.
- *
- * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
+ *
+ * @param root The root of the object graph.
+ * @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
+ * @param converter Converter used to convert return types of an expression in to their desired types.
+ * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
*/
- public static Map createDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter)
+ public static Map createDefaultContext( Object root, ClassResolver classResolver, TypeConverter converter )
{
- return addDefaultContext(root, classResolver, converter, null, new OgnlContext());
+ return addDefaultContext( root, classResolver, converter, null, new OgnlContext() );
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
- *
- * @param root
- * The root of the object graph.
- * @param classResolver
- * The resolver used to instantiate {@link Class} instances referenced in the expression.
- * @param converter
- * Converter used to convert return types of an expression in to their desired types.
- * @param memberAccess
- * Java security handling object to determine semantics for accessing normally private/protected
- * methods / fields.
- * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
- */
- public static Map createDefaultContext(Object root, ClassResolver classResolver,
- TypeConverter converter, MemberAccess memberAccess)
- {
- return addDefaultContext(root, classResolver, converter, memberAccess, new OgnlContext());
- }
-
- /**
- * Appends the standard naming context for evaluating an OGNL expression into the context given
- * so that cached maps can be used as a context.
- *
- * @param root
- * the root of the object graph
- * @param context
- * the context to which OGNL context will be added.
- * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
- */
- public static Map addDefaultContext(Object root, Map context)
- {
- return addDefaultContext(root, null, null, null, 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.
- *
- * @param root
- * The root of the object graph.
- * @param classResolver
- * The resolver used to instantiate {@link Class} instances referenced in the expression.
- * @param context
- * The context to which OGNL context will be added.
- *
- * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
- */
- public static Map addDefaultContext(Object root, ClassResolver classResolver, Map context)
- {
- return addDefaultContext(root, classResolver, null, null, 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.
- *
- * @param root
- * The root of the object graph.
- * @param classResolver
- * The resolver used to instantiate {@link Class} instances referenced in the expression.
- * @param converter
- * Converter used to convert return types of an expression in to their desired types.
- * @param context
- * The context to which OGNL context will be added.
- *
- * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
- */
- public static Map addDefaultContext(Object root, ClassResolver classResolver,
- TypeConverter converter, Map context)
- {
- return addDefaultContext(root, classResolver, converter, null, 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.
- *
- * @param root
- * the root of the object graph
- * @param classResolver
- * The class loading resolver that should be used to resolve class references.
- * @param converter
- * The type converter to be used by default.
- * @param memberAccess
- * Definition for handling private/protected access.
- * @param context
- * Default context to use, if not an {@link OgnlContext} will be dumped into
- * a new {@link OgnlContext} object.
- * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set
- * appropriately
+ *
+ * @param root The root of the object graph.
+ * @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
+ * @param converter Converter used to convert return types of an expression in to their desired types.
+ * @param memberAccess Java security handling object to determine semantics for accessing normally private/protected
+ * methods / fields.
+ * @return a new Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
+ */
+ public static Map createDefaultContext( Object root, ClassResolver classResolver, TypeConverter converter,
+ MemberAccess memberAccess )
+ {
+ return addDefaultContext( root, classResolver, converter, memberAccess, new OgnlContext() );
+ }
+
+ /**
+ * Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps
+ * can be used as a context.
+ *
+ * @param root the root of the object graph
+ * @param context the context to which OGNL context will be added.
+ * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
*/
- public static Map addDefaultContext(Object root, ClassResolver classResolver,
- TypeConverter converter, MemberAccess memberAccess, Map context)
+ public static Map addDefaultContext( Object root, Map context )
+ {
+ return addDefaultContext( root, null, null, null, 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.
+ *
+ * @param root The root of the object graph.
+ * @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
+ * @param context The context to which OGNL context will be added.
+ * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
+ */
+ public static Map addDefaultContext( Object root, ClassResolver classResolver, Map context )
+ {
+ return addDefaultContext( root, classResolver, null, null, 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.
+ *
+ * @param root The root of the object graph.
+ * @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
+ * @param converter Converter used to convert return types of an expression in to their desired types.
+ * @param context The context to which OGNL context will be added.
+ * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
+ */
+ public static Map addDefaultContext( Object root, ClassResolver classResolver, TypeConverter converter, Map context )
+ {
+ return addDefaultContext( root, classResolver, converter, null, 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.
+ *
+ * @param root the root of the object graph
+ * @param classResolver The class loading resolver that should be used to resolve class references.
+ * @param converter The type converter to be used by default.
+ * @param memberAccess Definition for handling private/protected access.
+ * @param context Default context to use, if not an {@link OgnlContext} will be dumped into a new
+ * {@link OgnlContext} object.
+ * @return Context Map with the keys <CODE>root</CODE> and <CODE>context</CODE> set appropriately
+ */
+ public static Map addDefaultContext( Object root, ClassResolver classResolver, TypeConverter converter,
+ MemberAccess memberAccess, Map context )
{
OgnlContext result;
- if (!(context instanceof OgnlContext)) {
+ if ( !( context instanceof OgnlContext ) )
+ {
result = new OgnlContext();
- result.setValues(context);
- } else {
+ result.setValues( context );
+ }
+ else
+ {
result = (OgnlContext) context;
}
- if (classResolver != null) {
- result.setClassResolver(classResolver);
+ if ( classResolver != null )
+ {
+ result.setClassResolver( classResolver );
}
- if (converter != null) {
- result.setTypeConverter(converter);
+ if ( converter != null )
+ {
+ result.setTypeConverter( converter );
}
- if (memberAccess != null) {
- result.setMemberAccess(memberAccess);
+ if ( memberAccess != null )
+ {
+ result.setMemberAccess( memberAccess );
}
- result.setRoot(root);
+ result.setRoot( root );
return result;
}
/**
- * Configures the {@link ClassResolver} to use for the given context. Will be used during
- * expression parsing / execution to resolve class names.
- *
- * @param context
- * The context to place the resolver.
- * @param classResolver
- * The resolver to use to resolve classes.
+ * Configures the {@link ClassResolver} to use for the given context. Will be used during expression parsing /
+ * execution to resolve class names.
+ *
+ * @param context The context to place the resolver.
+ * @param classResolver The resolver to use to resolve classes.
*/
- public static void setClassResolver(Map context, ClassResolver classResolver)
+ public static void setClassResolver( Map context, ClassResolver classResolver )
{
- context.put(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY, classResolver);
+ context.put( OgnlContext.CLASS_RESOLVER_CONTEXT_KEY, classResolver );
}
/**
* Gets the previously stored {@link ClassResolver} for the given context - if any.
- *
- * @param context
- * The context to get the configured resolver from.
- *
- * @return The resolver instance, or null if none found.
+ *
+ * @param context The context to get the configured resolver from.
+ * @return The resolver instance, or null if none found.
*/
- public static ClassResolver getClassResolver(Map context)
+ public static ClassResolver getClassResolver( Map context )
{
- return (ClassResolver) context.get(OgnlContext.CLASS_RESOLVER_CONTEXT_KEY);
+ return (ClassResolver) context.get( OgnlContext.CLASS_RESOLVER_CONTEXT_KEY );
}
/**
- * Configures the type converter to use for a given context. This will be used
- * to convert into / out of various java class types.
- *
- * @param context
- * The context to configure it for.
- * @param converter
- * The converter to use.
+ * Configures the type converter to use for a given context. This will be used to convert into / out of various java
+ * class types.
+ *
+ * @param context The context to configure it for.
+ * @param converter The converter to use.
*/
- public static void setTypeConverter(Map context, TypeConverter converter)
+ public static void setTypeConverter( Map context, TypeConverter converter )
{
- context.put(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY, converter);
+ context.put( OgnlContext.TYPE_CONVERTER_CONTEXT_KEY, converter );
}
/**
* Gets the currently configured {@link TypeConverter} for the given context - if any.
- *
- * @param context
- * The context to get the converter from.
- *
+ *
+ * @param context The context to get the converter from.
* @return The converter - or null if none found.
*/
- public static TypeConverter getTypeConverter(Map context)
+ public static TypeConverter getTypeConverter( Map context )
{
- return (TypeConverter) context.get(OgnlContext.TYPE_CONVERTER_CONTEXT_KEY);
+ return (TypeConverter) context.get( OgnlContext.TYPE_CONVERTER_CONTEXT_KEY );
}
/**
- * Configures the specified context with a {@link MemberAccess} instance for
- * handling field/method protection levels.
- *
- * @param context
- * The context to configure.
- * @param memberAccess
- * The access resolver to configure the context with.
+ * Configures the specified context with a {@link MemberAccess} instance for handling field/method protection
+ * levels.
+ *
+ * @param context The context to configure.
+ * @param memberAccess The access resolver to configure the context with.
*/
- public static void setMemberAccess(Map context, MemberAccess memberAccess)
+ public static void setMemberAccess( Map context, MemberAccess memberAccess )
{
- context.put(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY, memberAccess);
+ context.put( OgnlContext.MEMBER_ACCESS_CONTEXT_KEY, memberAccess );
}
/**
* Gets the currently stored {@link MemberAccess} object for the given context - if any.
- *
- * @param context
- * The context to get the object from.
*
+ * @param context The context to get the object from.
* @return The configured {@link MemberAccess} instance in the specified context - or null if none found.
*/
- public static MemberAccess getMemberAccess(Map context)
+ public static MemberAccess getMemberAccess( Map context )
{
- return (MemberAccess) context.get(OgnlContext.MEMBER_ACCESS_CONTEXT_KEY);
+ return (MemberAccess) context.get( OgnlContext.MEMBER_ACCESS_CONTEXT_KEY );
}
/**
- * Sets the root object to use for all expressions in the given context - doesn't necessarily replace
- * root object instances explicitly passed in to other expression resolving methods on this class.
- *
- * @param context
- * The context to store the root object in.
- * @param root
- * The root object.
+ * Sets the root object to use for all expressions in the given context - doesn't necessarily replace root object
+ * instances explicitly passed in to other expression resolving methods on this class.
+ *
+ * @param context The context to store the root object in.
+ * @param root The root object.
*/
- public static void setRoot(Map context, Object root)
+ public static void setRoot( Map context, Object root )
{
- context.put(OgnlContext.ROOT_CONTEXT_KEY, root);
+ context.put( OgnlContext.ROOT_CONTEXT_KEY, root );
}
/**
* Gets the stored root object for the given context - if any.
- *
- * @param context
- * The context to get the root object from.
*
+ * @param context The context to get the root object from.
* @return The root object - or null if none found.
*/
- public static Object getRoot(Map context)
+ public static Object getRoot( Map context )
{
- return context.get(OgnlContext.ROOT_CONTEXT_KEY);
+ return context.get( OgnlContext.ROOT_CONTEXT_KEY );
}
/**
* Gets the last {@link Evaluation} executed on the given context.
- *
- * @param context
- * The context to get the evaluation from.
*
+ * @param context The context to get the evaluation from.
* @return The {@link Evaluation} - or null if none was found.
*/
- public static Evaluation getLastEvaluation(Map context)
+ public static Evaluation getLastEvaluation( Map context )
{
- return (Evaluation) context.get(OgnlContext.LAST_EVALUATION_CONTEXT_KEY);
+ return (Evaluation) context.get( OgnlContext.LAST_EVALUATION_CONTEXT_KEY );
}
/**
- * 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 <CODE>addDefaultContext()</CODE>.
- *
- * @param tree
- * the OGNL expression tree to evaluate, as returned by parseExpression()
- * @param context
- * the naming context for the evaluation
- * @param root
- * the root object for the OGNL expression
+ * 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 <CODE>addDefaultContext()</CODE>.
+ *
+ * @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
+ * @param context the naming context for the evaluation
+ * @param root the root object for the OGNL expression
* @return 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
- */
- public static Object getValue(Object tree, Map context, Object root)
- throws OgnlException
- {
- return getValue(tree, context, root, null);
+ * @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
+ */
+ public static Object getValue( Object tree, Map context, Object root )
+ throws OgnlException
+ {
+ return getValue( tree, context, root, null );
}
/**
- * 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 <CODE>addDefaultContext()</CODE>.
- *
- * @param tree
- * the OGNL expression tree to evaluate, as returned by parseExpression()
- * @param context
- * the naming context for the evaluation
- * @param root
- * the root object for the OGNL expression
- * @param resultType
- * the converted type of the resultant object, using the context's type converter
+ * 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 <CODE>addDefaultContext()</CODE>.
+ *
+ * @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
+ * @param context the naming context for the evaluation
+ * @param root the root object for the OGNL expression
+ * @param resultType the converted type of the resultant object, using the context's type converter
* @return 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
+ * @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
*/
- public static Object getValue(Object tree, Map context, Object root, Class resultType)
- throws OgnlException
+ public static Object getValue( Object tree, Map context, Object root, Class resultType )
+ throws OgnlException
{
Object result;
- OgnlContext ognlContext = (OgnlContext) addDefaultContext(root, context);
+ OgnlContext ognlContext = (OgnlContext) addDefaultContext( root, context );
- Node node = (Node)tree;
+ Node node = (Node) tree;
- if (node.getAccessor() != null)
- result = node.getAccessor().get(ognlContext, root);
+ if ( node.getAccessor() != null )
+ result = node.getAccessor().get( ognlContext, root );
else
- result = node.getValue(ognlContext, root);
+ result = node.getValue( ognlContext, root );
- if (resultType != null) {
- result = getTypeConverter(context).convertValue(context, root, null, null, result, resultType);
+ if ( resultType != null )
+ {
+ result = getTypeConverter( context ).convertValue( context, root, null, null, result, resultType );
}
return result;
}
/**
- * Gets the value represented by the given pre-compiled expression on the specified root
- * object.
- *
- * @param expression
- * The pre-compiled expression, as found in {@link Node#getAccessor()}.
- * @param context
- * The ognl context.
- * @param root
- * The object to retrieve the expression value from.
- * @return
- * The value.
- */
- public static Object getValue(ExpressionAccessor expression, OgnlContext context, Object root)
- {
- return expression.get(context, root);
+ * Gets the value represented by the given pre-compiled expression on the specified root object.
+ *
+ * @param expression The pre-compiled expression, as found in {@link Node#getAccessor()}.
+ * @param context The ognl context.
+ * @param root The object to retrieve the expression value from.
+ * @return The value.
+ */
+ public static Object getValue( ExpressionAccessor expression, OgnlContext context, Object root )
+ {
+ return expression.get( context, root );
}
/**
- * Gets the value represented by the given pre-compiled expression on the specified root
- * object.
- *
- * @param expression
- * The pre-compiled expression, as found in {@link Node#getAccessor()}.
- * @param context
- * The ognl context.
- * @param root
- * The object to retrieve the expression value from.
- * @param resultType
- * The desired object type that the return value should be converted to using the {@link #getTypeConverter(java.util.Map)} }.
- * @return
- * The value.
- */
- public static Object getValue(ExpressionAccessor expression, OgnlContext context,
- Object root, Class resultType)
- {
- return getTypeConverter(context).convertValue(context, root, null, null, expression.get(context, root), resultType);
+ * Gets the value represented by the given pre-compiled expression on the specified root object.
+ *
+ * @param expression The pre-compiled expression, as found in {@link Node#getAccessor()}.
+ * @param context The ognl context.
+ * @param root The object to retrieve the expression value from.
+ * @param resultType The desired object type that the return value should be converted to using the
+ * {@link #getTypeConverter(java.util.Map)} .
+ * @return The value.
+ */
+ public static Object getValue( ExpressionAccessor expression, OgnlContext context, Object root, Class resultType )
+ {
+ return getTypeConverter( context ).convertValue( context, root, null, null, expression.get( context, root ),
+ resultType );
}
/**
- * Evaluates the given OGNL expression to extract a value from the given root object in a given
- * context
- *
+ * Evaluates the given OGNL expression to extract a value from the given root object in a given context
+ *
* @see #parseExpression(String)
* @see #getValue(Object,Object)
- * @param expression
- * the OGNL expression to be parsed
- * @param context
- * the naming context for the evaluation
- * @param root
- * the root object for the OGNL expression
+ * @param expression the OGNL expression to be parsed
+ * @param context the naming context for the evaluation
+ * @param root the root object for the OGNL expression
* @return 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
+ * @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
*/
- public static Object getValue(String expression, Map context, Object root)
- throws OgnlException
+ public static Object getValue( String expression, Map context, Object root )
+ throws OgnlException
{
- return getValue(expression, context, root, null);
+ return getValue( expression, context, root, null );
}
/**
- * Evaluates the given OGNL expression to extract a value from the given root object in a given
- * context
- *
+ * Evaluates the given OGNL expression to extract a value from the given root object in a given context
+ *
* @see #parseExpression(String)
* @see #getValue(Object,Object)
- * @param expression
- * the OGNL expression to be parsed
- * @param context
- * the naming context for the evaluation
- * @param root
- * the root object for the OGNL expression
- * @param resultType
- * the converted type of the resultant object, using the context's type converter
+ * @param expression the OGNL expression to be parsed
+ * @param context the naming context for the evaluation
+ * @param root the root object for the OGNL expression
+ * @param resultType the converted type of the resultant object, using the context's type converter
* @return 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
+ * @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
*/
- public static Object getValue(String expression, Map context, Object root, Class resultType)
- throws OgnlException
+ public static Object getValue( String expression, Map context, Object root, Class resultType )
+ throws OgnlException
{
- return getValue(parseExpression(expression), context, root, resultType);
+ return getValue( parseExpression( expression ), context, root, resultType );
}
/**
* Evaluates the given OGNL expression tree to extract a value from the given root object.
- *
- * @param tree
- * the OGNL expression tree to evaluate, as returned by parseExpression()
- * @param root
- * the root object for the OGNL expression
+ *
+ * @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
+ * @param root the root object for the OGNL expression
* @return 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
+ * @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
*/
- public static Object getValue(Object tree, Object root)
- throws OgnlException
+ public static Object getValue( Object tree, Object root )
+ throws OgnlException
{
- return getValue(tree, root, null);
+ return getValue( tree, root, null );
}
/**
* Evaluates the given OGNL expression tree to extract a value from the given root object.
- *
- * @param tree
- * the OGNL expression tree to evaluate, as returned by parseExpression()
- * @param root
- * the root object for the OGNL expression
- * @param resultType
- * the converted type of the resultant object, using the context's type converter
+ *
+ * @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
+ * @param root the root object for the OGNL expression
+ * @param resultType the converted type of the resultant object, using the context's type converter
* @return 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
+ * @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
*/
- public static Object getValue(Object tree, Object root, Class resultType)
- throws OgnlException
+ public static Object getValue( Object tree, Object root, Class resultType )
+ throws OgnlException
{
- return getValue(tree, createDefaultContext(root), root, resultType);
+ return getValue( tree, createDefaultContext( root ), root, resultType );
}
/**
- * Convenience method that combines calls to <code> parseExpression </code> and
- * <code> getValue</code>.
- *
+ * Convenience method that combines calls to <code> parseExpression </code> and <code> getValue</code>.
+ *
* @see #parseExpression(String)
* @see #getValue(Object,Object)
- * @param expression
- * the OGNL expression to be parsed
- * @param root
- * the root object for the OGNL expression
+ * @param expression the OGNL expression to be parsed
+ * @param root the root object for the OGNL expression
* @return the result of evaluating the expression
- * @throws ExpressionSyntaxException
- * if the expression is malformed
- * @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
- */
- public static Object getValue(String expression, Object root)
- throws OgnlException
- {
- return getValue(expression, root, null);
+ * @throws ExpressionSyntaxException if the expression is malformed
+ * @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
+ */
+ public static Object getValue( String expression, Object root )
+ throws OgnlException
+ {
+ return getValue( expression, root, null );
}
/**
- * Convenience method that combines calls to <code> parseExpression </code> and
- * <code> getValue</code>.
- *
+ * Convenience method that combines calls to <code> parseExpression </code> and <code> getValue</code>.
+ *
* @see #parseExpression(String)
* @see #getValue(Object,Object)
- * @param expression
- * the OGNL expression to be parsed
- * @param root
- * the root object for the OGNL expression
- * @param resultType
- * the converted type of the resultant object, using the context's type converter
+ * @param expression the OGNL expression to be parsed
+ * @param root the root object for the OGNL expression
+ * @param resultType the converted type of the resultant object, using the context's type converter
* @return the result of evaluating the expression
- * @throws ExpressionSyntaxException
- * if the expression is malformed
- * @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
- */
- public static Object getValue(String expression, Object root, Class resultType)
- throws OgnlException
- {
- return getValue(parseExpression(expression), root, resultType);
+ * @throws ExpressionSyntaxException if the expression is malformed
+ * @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
+ */
+ public static Object getValue( String expression, Object root, Class resultType )
+ throws OgnlException
+ {
+ return getValue( parseExpression( expression ), root, resultType );
}
/**
- * 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 <CODE>addDefaultContext()</CODE>.
- *
- * @param tree
- * the OGNL expression tree to evaluate, as returned by parseExpression()
- * @param context
- * the naming context for the evaluation
- * @param root
- * the root object for the OGNL expression
- * @param 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
+ * 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 <CODE>addDefaultContext()</CODE>.
+ *
+ * @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
+ * @param context the naming context for the evaluation
+ * @param root the root object for the OGNL expression
+ * @param 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
*/
- public static void setValue(Object tree, Map context, Object root, Object value)
- throws OgnlException
+ public static void setValue( Object tree, Map context, Object root, Object value )
+ throws OgnlException
{
- OgnlContext ognlContext = (OgnlContext) addDefaultContext(root, context);
+ OgnlContext ognlContext = (OgnlContext) addDefaultContext( root, context );
Node n = (Node) tree;
- if (n.getAccessor() != null) {
- n.getAccessor().set(ognlContext, root, value);
+ if ( n.getAccessor() != null )
+ {
+ n.getAccessor().set( ognlContext, root, value );
return;
}
- n.setValue(ognlContext, root, value);
+ n.setValue( ognlContext, root, value );
}
/**
- * Sets the value given using the pre-compiled expression on the specified root
- * object.
- *
- * @param expression
- * The pre-compiled expression, as found in {@link Node#getAccessor()}.
- * @param context
- * The ognl context.
- * @param root
- * The object to set the expression value on.
- * @param value
- * The value to set.
- */
- public static void setValue(ExpressionAccessor expression, OgnlContext context,
- Object root, Object value)
- {
- expression.set(context, root, value);
- }
-
- /**
- * Evaluates the given OGNL expression to insert a value into the object graph rooted at the
- * given root object given the context.
- *
- * @param expression
- * the OGNL expression to be parsed
- * @param root
- * the root object for the OGNL expression
- * @param context
- * the naming context for the evaluation
- * @param 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
- */
- public static void setValue(String expression, Map context, Object root, Object value)
- throws OgnlException
- {
- setValue(parseExpression(expression), context, root, value);
- }
-
- /**
- * Evaluates the given OGNL expression tree to insert a value into the object graph rooted at
- * the given root object.
- *
- * @param tree
- * the OGNL expression tree to evaluate, as returned by parseExpression()
- * @param root
- * the root object for the OGNL expression
- * @param 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
- */
- public static void setValue(Object tree, Object root, Object value)
- throws OgnlException
- {
- setValue(tree, createDefaultContext(root), root, value);
- }
-
- /**
- * Convenience method that combines calls to <code> parseExpression </code> and
- * <code> setValue</code>.
- *
+ * Sets the value given using the pre-compiled expression on the specified root object.
+ *
+ * @param expression The pre-compiled expression, as found in {@link Node#getAccessor()}.
+ * @param context The ognl context.
+ * @param root The object to set the expression value on.
+ * @param value The value to set.
+ */
+ public static void setValue( ExpressionAccessor expression, OgnlContext context, Object root, Object value )
+ {
+ expression.set( context, root, value );
+ }
+
+ /**
+ * Evaluates the given OGNL expression to insert a value into the object graph rooted at the given root object given
+ * the context.
+ *
+ * @param expression the OGNL expression to be parsed
+ * @param root the root object for the OGNL expression
+ * @param context the naming context for the evaluation
+ * @param 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
+ */
+ public static void setValue( String expression, Map context, Object root, Object value )
+ throws OgnlException
+ {
+ setValue( parseExpression( expression ), context, root, value );
+ }
+
+ /**
+ * Evaluates the given OGNL expression tree to insert a value into the object graph rooted at the given root object.
+ *
+ * @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
+ * @param root the root object for the OGNL expression
+ * @param 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
+ */
+ public static void setValue( Object tree, Object root, Object value )
+ throws OgnlException
+ {
+ setValue( tree, createDefaultContext( root ), root, value );
+ }
+
+ /**
+ * Convenience method that combines calls to <code> parseExpression </code> and <code> setValue</code>.
+ *
* @see #parseExpression(String)
* @see #setValue(Object,Object,Object)
- * @param expression
- * the OGNL expression to be parsed
- * @param root
- * the root object for the OGNL expression
- * @param value
- * the value to insert into the object graph
- * @throws ExpressionSyntaxException
- * if the expression is malformed
- * @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
- */
- public static void setValue(String expression, Object root, Object value)
- throws OgnlException
- {
- setValue(parseExpression(expression), root, value);
+ * @param expression the OGNL expression to be parsed
+ * @param root the root object for the OGNL expression
+ * @param value the value to insert into the object graph
+ * @throws ExpressionSyntaxException if the expression is malformed
+ * @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
+ */
+ public static void setValue( String expression, Object root, Object value )
+ throws OgnlException
+ {
+ setValue( parseExpression( expression ), root, value );
}
/**
- * Checks if the specified {@link Node} instance represents a constant
- * expression.
- *
- * @param tree
- * The {@link Node} to check.
- * @param context
- * The context to use.
- *
+ * Checks if the specified {@link Node} instance represents a constant expression.
+ *
+ * @param tree The {@link Node} to check.
+ * @param context The context to use.
* @return True if the node is a constant - false otherwise.
- * @throws OgnlException If an error occurs checking the expression.
+ * @throws OgnlException If an error occurs checking the expression.
*/
- public static boolean isConstant(Object tree, Map context)
- throws OgnlException
+ public static boolean isConstant( Object tree, Map context )
+ throws OgnlException
{
- return ((SimpleNode) tree).isConstant((OgnlContext) addDefaultContext(null, context));
+ return ( (SimpleNode) tree ).isConstant( (OgnlContext) addDefaultContext( null, context ) );
}
- /**
+ /**
* Checks if the specified expression represents a constant expression.
- *
- * @param expression
- * The expression to check.
- * @param context
- * The context to use.
- *
+ *
+ * @param expression The expression to check.
+ * @param context The context to use.
* @return True if the node is a constant - false otherwise.
- * @throws OgnlException If an error occurs checking the expression.
+ * @throws OgnlException If an error occurs checking the expression.
*/
- public static boolean isConstant(String expression, Map context)
- throws OgnlException
+ public static boolean isConstant( String expression, Map context )
+ throws OgnlException
{
- return isConstant(parseExpression(expression), context);
+ return isConstant( parseExpression( expression ), context );
}
/**
- * Same as {@link #isConstant(Object, java.util.Map)} - only the {@link Map} context
- * is created for you.
- *
- * @param tree
- * The {@link Node} to check.
+ * Same as {@link #isConstant(Object, java.util.Map)} - only the {@link Map} context is created for you.
*
+ * @param tree The {@link Node} to check.
* @return True if the node represents a constant expression - false otherwise.
* @throws OgnlException If an exception occurs.
*/
- public static boolean isConstant(Object tree)
- throws OgnlException
+ public static boolean isConstant( Object tree )
+ throws OgnlException
{
- return isConstant(tree, createDefaultContext(null));
+ return isConstant( tree, createDefaultContext( null ) );
}
/**
- * Same as {@link #isConstant(String, java.util.Map)} - only the {@link Map}
- * instance is created for you.
- *
- * @param expression
- * The expression to check.
- *
+ * Same as {@link #isConstant(String, java.util.Map)} - only the {@link Map} instance is created for you.
+ *
+ * @param expression The expression to check.
* @return True if the expression represents a constant - false otherwise.
* @throws OgnlException If an exception occurs.
*/
- public static boolean isConstant(String expression)
- throws OgnlException
+ public static boolean isConstant( String expression )
+ throws OgnlException
{
- return isConstant(parseExpression(expression), createDefaultContext(null));
+ return isConstant( parseExpression( expression ), createDefaultContext( null ) );
}
- public static boolean isSimpleProperty(Object tree, Map context)
- throws OgnlException
+ public static boolean isSimpleProperty( Object tree, Map context )
+ throws OgnlException
{
- return ((SimpleNode) tree).isSimpleProperty((OgnlContext) addDefaultContext(null, context));
+ return ( (SimpleNode) tree ).isSimpleProperty( (OgnlContext) addDefaultContext( null, context ) );
}
- public static boolean isSimpleProperty(String expression, Map context)
- throws OgnlException
+ public static boolean isSimpleProperty( String expression, Map context )
+ throws OgnlException
{
- return isSimpleProperty(parseExpression(expression), context);
+ return isSimpleProperty( parseExpression( expression ), context );
}
- public static boolean isSimpleProperty(Object tree)
- throws OgnlException
+ public static boolean isSimpleProperty( Object tree )
+ throws OgnlException
{
- return isSimpleProperty(tree, createDefaultContext(null));
+ return isSimpleProperty( tree, createDefaultContext( null ) );
}
- public static boolean isSimpleProperty(String expression)
- throws OgnlException
+ public static boolean isSimpleProperty( String expression )
+ throws OgnlException
{
- return isSimpleProperty(parseExpression(expression), createDefaultContext(null));
+ return isSimpleProperty( parseExpression( expression ), createDefaultContext( null ) );
}
- public static boolean isSimpleNavigationChain(Object tree, Map context)
- throws OgnlException
+ public static boolean isSimpleNavigationChain( Object tree, Map context )
+ throws OgnlException
{
- return ((SimpleNode) tree).isSimpleNavigationChain((OgnlContext) addDefaultContext(null, context));
+ return ( (SimpleNode) tree ).isSimpleNavigationChain( (OgnlContext) addDefaultContext( null, context ) );
}
- public static boolean isSimpleNavigationChain(String expression, Map context)
- throws OgnlException
+ public static boolean isSimpleNavigationChain( String expression, Map context )
+ throws OgnlException
{
- return isSimpleNavigationChain(parseExpression(expression), context);
+ return isSimpleNavigationChain( parseExpression( expression ), context );
}
- public static boolean isSimpleNavigationChain(Object tree)
- throws OgnlException
+ public static boolean isSimpleNavigationChain( Object tree )
+ throws OgnlException
{
- return isSimpleNavigationChain(tree, createDefaultContext(null));
+ return isSimpleNavigationChain( tree, createDefaultContext( null ) );
}
- public static boolean isSimpleNavigationChain(String expression)
- throws OgnlException
+ public static boolean isSimpleNavigationChain( String expression )
+ throws OgnlException
{
- return isSimpleNavigationChain(parseExpression(expression), createDefaultContext(null));
+ return isSimpleNavigationChain( parseExpression( expression ), createDefaultContext( null ) );
}
/** You can't make one of these. */
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java Sat May 14 13:18:29 2011
@@ -29,119 +29,153 @@ import java.util.*;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class OgnlContext extends Object implements Map
+public class OgnlContext
+ extends Object
+ implements Map
{
public static final String CONTEXT_CONTEXT_KEY = "context";
+
public static final String ROOT_CONTEXT_KEY = "root";
+
public static final String THIS_CONTEXT_KEY = "this";
+
public static final String TRACE_EVALUATIONS_CONTEXT_KEY = "_traceEvaluations";
+
public static final String LAST_EVALUATION_CONTEXT_KEY = "_lastEvaluation";
+
public static final String KEEP_LAST_EVALUATION_CONTEXT_KEY = "_keepLastEvaluation";
+
public static final String CLASS_RESOLVER_CONTEXT_KEY = "_classResolver";
+
public static final String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
+
public static final String MEMBER_ACCESS_CONTEXT_KEY = "_memberAccess";
private static final String PROPERTY_KEY_PREFIX = "ognl";
+
private static boolean DEFAULT_TRACE_EVALUATIONS = false;
+
private static boolean DEFAULT_KEEP_LAST_EVALUATION = false;
public static final ClassResolver DEFAULT_CLASS_RESOLVER = new DefaultClassResolver();
+
public static final TypeConverter DEFAULT_TYPE_CONVERTER = new DefaultTypeConverter();
- public static final MemberAccess DEFAULT_MEMBER_ACCESS = new DefaultMemberAccess(false);
-
- private static final Set<String> RESERVED_KEYS = new HashSet<String>(11);
-
+
+ public static final MemberAccess DEFAULT_MEMBER_ACCESS = new DefaultMemberAccess( false );
+
+ private static final Set<String> RESERVED_KEYS = new HashSet<String>( 11 );
+
private Object _root;
+
private Object _currentObject;
+
private Node _currentNode;
+
private boolean _traceEvaluations = DEFAULT_TRACE_EVALUATIONS;
+
private Evaluation _rootEvaluation;
+
private Evaluation _currentEvaluation;
+
private Evaluation _lastEvaluation;
+
private boolean _keepLastEvaluation = DEFAULT_KEEP_LAST_EVALUATION;
-
- private Map _values = new HashMap(23);
-
+
+ private Map _values = new HashMap( 23 );
+
private ClassResolver _classResolver = DEFAULT_CLASS_RESOLVER;
+
private TypeConverter _typeConverter = DEFAULT_TYPE_CONVERTER;
+
private MemberAccess _memberAccess = DEFAULT_MEMBER_ACCESS;
-
- static {
+
+ static
+ {
String s;
-
- RESERVED_KEYS.add(CONTEXT_CONTEXT_KEY);
- RESERVED_KEYS.add(ROOT_CONTEXT_KEY);
- RESERVED_KEYS.add(THIS_CONTEXT_KEY);
- RESERVED_KEYS.add(TRACE_EVALUATIONS_CONTEXT_KEY);
- RESERVED_KEYS.add(LAST_EVALUATION_CONTEXT_KEY);
- RESERVED_KEYS.add(KEEP_LAST_EVALUATION_CONTEXT_KEY);
- RESERVED_KEYS.add(CLASS_RESOLVER_CONTEXT_KEY);
- RESERVED_KEYS.add(TYPE_CONVERTER_CONTEXT_KEY);
- RESERVED_KEYS.add(MEMBER_ACCESS_CONTEXT_KEY);
-
- try {
- if ((s = System.getProperty(PROPERTY_KEY_PREFIX + ".traceEvaluations")) != null) {
- DEFAULT_TRACE_EVALUATIONS = Boolean.valueOf(s.trim()).booleanValue();
+
+ RESERVED_KEYS.add( CONTEXT_CONTEXT_KEY );
+ RESERVED_KEYS.add( ROOT_CONTEXT_KEY );
+ RESERVED_KEYS.add( THIS_CONTEXT_KEY );
+ RESERVED_KEYS.add( TRACE_EVALUATIONS_CONTEXT_KEY );
+ RESERVED_KEYS.add( LAST_EVALUATION_CONTEXT_KEY );
+ RESERVED_KEYS.add( KEEP_LAST_EVALUATION_CONTEXT_KEY );
+ RESERVED_KEYS.add( CLASS_RESOLVER_CONTEXT_KEY );
+ RESERVED_KEYS.add( TYPE_CONVERTER_CONTEXT_KEY );
+ RESERVED_KEYS.add( MEMBER_ACCESS_CONTEXT_KEY );
+
+ try
+ {
+ if ( ( s = System.getProperty( PROPERTY_KEY_PREFIX + ".traceEvaluations" ) ) != null )
+ {
+ DEFAULT_TRACE_EVALUATIONS = Boolean.valueOf( s.trim() ).booleanValue();
}
- if ((s = System.getProperty(PROPERTY_KEY_PREFIX + ".keepLastEvaluation")) != null) {
- DEFAULT_KEEP_LAST_EVALUATION = Boolean.valueOf(s.trim()).booleanValue();
+ if ( ( s = System.getProperty( PROPERTY_KEY_PREFIX + ".keepLastEvaluation" ) ) != null )
+ {
+ DEFAULT_KEEP_LAST_EVALUATION = Boolean.valueOf( s.trim() ).booleanValue();
}
- } catch (SecurityException ex) {
+ }
+ catch ( SecurityException ex )
+ {
// restricted access environment, just keep defaults
}
}
private Stack<Class<?>> _typeStack = new Stack<Class<?>>();
+
private Stack<Class<?>> _accessorStack = new Stack<Class<?>>();
private int _localReferenceCounter = 0;
+
private Map<String, LocalReference> _localReferenceMap = null;
/**
- * Constructs a new OgnlContext with the default class resolver, type converter and member
- * access.
+ * Constructs a new OgnlContext with the default class resolver, type converter and member access.
*/
public OgnlContext()
{
}
/**
- * Constructs a new OgnlContext with the given class resolver, type converter and member access.
- * If any of these parameters is null the default will be used.
+ * Constructs a new OgnlContext with the given class resolver, type converter and member access. If any of these
+ * parameters is null the default will be used.
*/
- public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess)
+ public OgnlContext( ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess )
{
this();
- if (classResolver != null) {
+ if ( classResolver != null )
+ {
this._classResolver = classResolver;
}
- if (typeConverter != null) {
+ if ( typeConverter != null )
+ {
this._typeConverter = typeConverter;
}
- if (memberAccess != null) {
+ if ( memberAccess != null )
+ {
this._memberAccess = memberAccess;
}
}
- public OgnlContext(Map values)
+ public OgnlContext( Map values )
{
super();
this._values = values;
}
- public OgnlContext(ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess, Map values)
+ public OgnlContext( ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess, Map values )
{
- this(classResolver, typeConverter, memberAccess);
+ this( classResolver, typeConverter, memberAccess );
this._values = values;
}
- public void setValues(Map value)
+ public void setValues( Map value )
{
- for(Iterator it = value.keySet().iterator(); it.hasNext();) {
+ for ( Iterator it = value.keySet().iterator(); it.hasNext(); )
+ {
Object k = it.next();
- _values.put(k, value.get(k));
+ _values.put( k, value.get( k ) );
}
}
@@ -150,9 +184,12 @@ public class OgnlContext extends Object
return _values;
}
- public void setClassResolver(ClassResolver value)
+ public void setClassResolver( ClassResolver value )
{
- if (value == null) { throw new IllegalArgumentException("cannot set ClassResolver to null"); }
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "cannot set ClassResolver to null" );
+ }
_classResolver = value;
}
@@ -161,9 +198,12 @@ public class OgnlContext extends Object
return _classResolver;
}
- public void setTypeConverter(TypeConverter value)
+ public void setTypeConverter( TypeConverter value )
{
- if (value == null) { throw new IllegalArgumentException("cannot set TypeConverter to null"); }
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "cannot set TypeConverter to null" );
+ }
_typeConverter = value;
}
@@ -172,9 +212,12 @@ public class OgnlContext extends Object
return _typeConverter;
}
- public void setMemberAccess(MemberAccess value)
+ public void setMemberAccess( MemberAccess value )
{
- if (value == null) { throw new IllegalArgumentException("cannot set MemberAccess to null"); }
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "cannot set MemberAccess to null" );
+ }
_memberAccess = value;
}
@@ -183,16 +226,16 @@ public class OgnlContext extends Object
return _memberAccess;
}
- public void setRoot(Object value)
+ public void setRoot( Object value )
{
_root = value;
_accessorStack.clear();
_typeStack.clear();
_currentObject = value;
- if (_currentObject != null)
+ if ( _currentObject != null )
{
- setCurrentType(_currentObject.getClass());
+ setCurrentType( _currentObject.getClass() );
}
}
@@ -206,7 +249,7 @@ public class OgnlContext extends Object
return _traceEvaluations;
}
- public void setTraceEvaluations(boolean value)
+ public void setTraceEvaluations( boolean value )
{
_traceEvaluations = value;
}
@@ -216,26 +259,25 @@ public class OgnlContext extends Object
return _lastEvaluation;
}
- public void setLastEvaluation(Evaluation value)
+ public void setLastEvaluation( Evaluation value )
{
_lastEvaluation = value;
}
/**
- * This method can be called when the last evaluation has been used and can be returned for
- * reuse in the free pool maintained by the runtime. This is not a necessary step, but is useful
- * for keeping memory usage down. This will recycle the last evaluation and then set the last
- * evaluation to null.
+ * This method can be called when the last evaluation has been used and can be returned for reuse in the free pool
+ * maintained by the runtime. This is not a necessary step, but is useful for keeping memory usage down. This will
+ * recycle the last evaluation and then set the last evaluation to null.
*/
public void recycleLastEvaluation()
{
- OgnlRuntime.getEvaluationPool().recycleAll(_lastEvaluation);
+ OgnlRuntime.getEvaluationPool().recycleAll( _lastEvaluation );
_lastEvaluation = null;
}
/**
- * Returns true if the last evaluation that was done on this context is retained and available
- * through <code>getLastEvaluation()</code>. The default is true.
+ * Returns true if the last evaluation that was done on this context is retained and available through
+ * <code>getLastEvaluation()</code>. The default is true.
*/
public boolean getKeepLastEvaluation()
{
@@ -243,48 +285,49 @@ public class OgnlContext extends Object
}
/**
- * Sets whether the last evaluation that was done on this context is retained and available
- * through <code>getLastEvaluation()</code>. The default is true.
+ * Sets whether the last evaluation that was done on this context is retained and available through
+ * <code>getLastEvaluation()</code>. The default is true.
*/
- public void setKeepLastEvaluation(boolean value)
+ public void setKeepLastEvaluation( boolean value )
{
_keepLastEvaluation = value;
}
- public void setCurrentObject(Object value)
+ public void setCurrentObject( Object value )
{
_currentObject = value;
}
-
+
public Object getCurrentObject()
{
return _currentObject;
}
-
- public void setCurrentAccessor(Class<?> type)
+
+ public void setCurrentAccessor( Class<?> type )
{
- _accessorStack.add(type);
+ _accessorStack.add( type );
}
-
+
public Class<?> getCurrentAccessor()
{
- if (_accessorStack.isEmpty())
+ if ( _accessorStack.isEmpty() )
{
return null;
}
return _accessorStack.peek();
}
-
+
public Class<?> getPreviousAccessor()
{
- if (_accessorStack.isEmpty())
+ if ( _accessorStack.isEmpty() )
{
return null;
}
- if (_accessorStack.size() > 1) {
- return _accessorStack.get(_accessorStack.size() - 2);
+ if ( _accessorStack.size() > 1 )
+ {
+ return _accessorStack.get( _accessorStack.size() - 2 );
}
return null;
@@ -292,12 +335,12 @@ public class OgnlContext extends Object
public Class<?> getFirstAccessor()
{
- if (_accessorStack.isEmpty())
+ if ( _accessorStack.isEmpty() )
{
return null;
}
- return _accessorStack.get(0);
+ return _accessorStack.get( 0 );
}
/**
@@ -307,61 +350,61 @@ public class OgnlContext extends Object
*/
public Class<?> getCurrentType()
{
- if (_typeStack.isEmpty())
+ if ( _typeStack.isEmpty() )
{
return null;
}
- return _typeStack.peek();
+ return _typeStack.peek();
}
-
- public void setCurrentType(Class<?> type)
+
+ public void setCurrentType( Class<?> type )
{
- _typeStack.add(type);
+ _typeStack.add( type );
}
-
+
/**
- * Represents the last known object type on the evaluation stack, will be the value of
- * the last known {@link #getCurrentType()}.
+ * Represents the last known object type on the evaluation stack, will be the value of the last known
+ * {@link #getCurrentType()}.
*
* @return The previous type of object on the stack, may be null.
*/
public Class<?> getPreviousType()
{
- if (_typeStack.isEmpty())
+ if ( _typeStack.isEmpty() )
{
return null;
}
- if (_typeStack.size() > 1)
+ if ( _typeStack.size() > 1 )
{
- return _typeStack.get(_typeStack.size() - 2);
+ return _typeStack.get( _typeStack.size() - 2 );
}
return null;
}
-
- public void setPreviousType(Class<?> type)
+
+ public void setPreviousType( Class<?> type )
{
- if (_typeStack.isEmpty() || _typeStack.size() < 2)
+ if ( _typeStack.isEmpty() || _typeStack.size() < 2 )
{
return;
}
- _typeStack.set(_typeStack.size() - 2, type);
+ _typeStack.set( _typeStack.size() - 2, type );
}
public Class<?> getFirstType()
{
- if (_typeStack.isEmpty())
+ if ( _typeStack.isEmpty() )
{
return null;
}
- return _typeStack.get(0);
+ return _typeStack.get( 0 );
}
- public void setCurrentNode(Node value)
+ public void setCurrentNode( Node value )
{
_currentNode = value;
}
@@ -372,45 +415,45 @@ public class OgnlContext extends Object
}
/**
- * Gets the current Evaluation from the top of the stack. This is the Evaluation that is in
- * process of evaluating.
+ * Gets the current Evaluation from the top of the stack. This is the Evaluation that is in process of evaluating.
*/
public Evaluation getCurrentEvaluation()
{
return _currentEvaluation;
}
- public void setCurrentEvaluation(Evaluation value)
+ public void setCurrentEvaluation( Evaluation value )
{
_currentEvaluation = value;
}
/**
- * Gets the root of the evaluation stack. This Evaluation contains the node representing the
- * root expression and the source is the root source object.
+ * Gets the root of the evaluation stack. This Evaluation contains the node representing the root expression and the
+ * source is the root source object.
*/
public Evaluation getRootEvaluation()
{
return _rootEvaluation;
}
- public void setRootEvaluation(Evaluation value)
+ public void setRootEvaluation( Evaluation value )
{
_rootEvaluation = value;
}
/**
- * Returns the Evaluation at the relative index given. This should be zero or a negative number
- * as a relative reference back up the evaluation stack. Therefore getEvaluation(0) returns the
- * current Evaluation.
+ * Returns the Evaluation at the relative index given. This should be zero or a negative number as a relative
+ * reference back up the evaluation stack. Therefore getEvaluation(0) returns the current Evaluation.
*/
- public Evaluation getEvaluation(int relativeIndex)
+ public Evaluation getEvaluation( int relativeIndex )
{
Evaluation result = null;
- if (relativeIndex <= 0) {
+ if ( relativeIndex <= 0 )
+ {
result = _currentEvaluation;
- while((++relativeIndex < 0) && (result != null)) {
+ while ( ( ++relativeIndex < 0 ) && ( result != null ) )
+ {
result = result.getParent();
}
}
@@ -418,33 +461,36 @@ public class OgnlContext extends Object
}
/**
- * Pushes a new Evaluation onto the stack. This is done before a node evaluates. When evaluation
- * is complete it should be popped from the stack via <code>popEvaluation()</code>.
+ * Pushes a new Evaluation onto the stack. This is done before a node evaluates. When evaluation is complete it
+ * should be popped from the stack via <code>popEvaluation()</code>.
*/
- public void pushEvaluation(Evaluation value)
+ public void pushEvaluation( Evaluation value )
{
- if (_currentEvaluation != null) {
- _currentEvaluation.addChild(value);
- } else {
- setRootEvaluation(value);
+ if ( _currentEvaluation != null )
+ {
+ _currentEvaluation.addChild( value );
}
- setCurrentEvaluation(value);
+ else
+ {
+ setRootEvaluation( value );
+ }
+ setCurrentEvaluation( value );
}
/**
- * Pops the current Evaluation off of the top of the stack. This is done after a node has
- * completed its evaluation.
+ * Pops the current Evaluation off of the top of the stack. This is done after a node has completed its evaluation.
*/
public Evaluation popEvaluation()
{
Evaluation result;
result = _currentEvaluation;
- setCurrentEvaluation(result.getParent());
- if (_currentEvaluation == null) {
- setLastEvaluation(getKeepLastEvaluation() ? result : null);
- setRootEvaluation(null);
- setCurrentNode(null);
+ setCurrentEvaluation( result.getParent() );
+ if ( _currentEvaluation == null )
+ {
+ setLastEvaluation( getKeepLastEvaluation() ? result : null );
+ setRootEvaluation( null );
+ setCurrentNode( null );
}
return result;
}
@@ -454,14 +500,14 @@ public class OgnlContext extends Object
return ++_localReferenceCounter;
}
- public void addLocalReference(String key, LocalReference reference)
+ public void addLocalReference( String key, LocalReference reference )
{
- if (_localReferenceMap == null)
+ if ( _localReferenceMap == null )
{
_localReferenceMap = new LinkedHashMap<String, LocalReference>();
}
- _localReferenceMap.put(key, reference);
+ _localReferenceMap.put( key, reference );
}
public Map<String, LocalReference> getLocalReferences()
@@ -480,17 +526,17 @@ public class OgnlContext extends Object
return _values.isEmpty();
}
- public boolean containsKey(Object key)
+ public boolean containsKey( Object key )
{
- return _values.containsKey(key);
+ return _values.containsKey( key );
}
- public boolean containsValue(Object value)
+ public boolean containsValue( Object value )
{
- return _values.containsValue(value);
+ return _values.containsValue( value );
}
- public Object get(Object key)
+ public Object get( Object key )
{
Object result = null;
@@ -609,8 +655,7 @@ public class OgnlContext extends Object
// FIXME: complexity is O(n)
if ( RESERVED_KEYS.contains( key ) )
{
- if ( CONTEXT_CONTEXT_KEY.equals( key )
- || TRACE_EVALUATIONS_CONTEXT_KEY.equals( key )
+ if ( CONTEXT_CONTEXT_KEY.equals( key ) || TRACE_EVALUATIONS_CONTEXT_KEY.equals( key )
|| KEEP_LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
throw new IllegalArgumentException( "can't remove " + key + " from context" );
@@ -654,12 +699,13 @@ public class OgnlContext extends Object
return result;
}
- public void putAll(Map t)
+ public void putAll( Map t )
{
- for(Iterator it = t.keySet().iterator(); it.hasNext();) {
+ for ( Iterator it = t.keySet().iterator(); it.hasNext(); )
+ {
Object k = it.next();
- put(k, t.get(k));
+ put( k, t.get( k ) );
}
}
@@ -670,20 +716,20 @@ public class OgnlContext extends Object
_accessorStack.clear();
_localReferenceCounter = 0;
- if (_localReferenceMap != null)
+ if ( _localReferenceMap != null )
{
_localReferenceMap.clear();
}
- setRoot(null);
- setCurrentObject(null);
- setRootEvaluation(null);
- setCurrentEvaluation(null);
- setLastEvaluation(null);
- setCurrentNode(null);
- setClassResolver(DEFAULT_CLASS_RESOLVER);
- setTypeConverter(DEFAULT_TYPE_CONVERTER);
- setMemberAccess(DEFAULT_MEMBER_ACCESS);
+ setRoot( null );
+ setCurrentObject( null );
+ setRootEvaluation( null );
+ setCurrentEvaluation( null );
+ setLastEvaluation( null );
+ setCurrentNode( null );
+ setClassResolver( DEFAULT_CLASS_RESOLVER );
+ setTypeConverter( DEFAULT_TYPE_CONVERTER );
+ setMemberAccess( DEFAULT_MEMBER_ACCESS );
}
public Set keySet()
@@ -705,9 +751,9 @@ public class OgnlContext extends Object
}
@Override
- public boolean equals(Object o)
+ public boolean equals( Object o )
{
- return _values.equals(o);
+ return _values.equals( o );
}
@Override