// --------------------------------------------------------------------------
// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// Neither the name of the Drew Davidson nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
// --------------------------------------------------------------------------
package ognl; import ognl.enhance.ExpressionAccessor; import java.io.StringReader;
import java.util.Map; /**
* <P>
* 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.
* </P>
*
* <PRE>
*
* import ognl.Ognl; import 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}.
* </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.
* </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:
* </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) ? \"&lt;nobody&gt;\" : #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
*/
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
* @return a tree representation of the expression
* @throws ExpressionSyntaxException
* if the expression is malformed
* @throws OgnlException
* if there is a pathological environmental problem
*/
public static Object parseExpression(String expression)
throws OgnlException
{
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);
}
} /**
* 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
{
Node expr = (Node)Ognl.parseExpression(expression); 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
*/
public static Map createDefaultContext(Object root)
{
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
*/
public static Map createDefaultContext(Object root, ClassResolver classResolver)
{
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
*/
public static Map createDefaultContext(Object root, ClassResolver classResolver, TypeConverter converter)
{
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
*/
public static Map addDefaultContext(Object root, ClassResolver classResolver,
TypeConverter converter, MemberAccess memberAccess, Map context)
{
OgnlContext result; if (!(context instanceof OgnlContext)) {
result = new OgnlContext();
result.setValues(context);
} else {
result = (OgnlContext) context;
}
if (classResolver != null) {
result.setClassResolver(classResolver);
}
if (converter != null) {
result.setTypeConverter(converter);
}
if (memberAccess != null) {
result.setMemberAccess(memberAccess);
} 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.
*/
public static void setClassResolver(Map context, ClassResolver 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.
*/
public static ClassResolver getClassResolver(Map context)
{
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.
*/
public static void setTypeConverter(Map context, TypeConverter 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.
*
* @return The converter - or null if none found.
*/
public static TypeConverter getTypeConverter(Map context)
{
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.
*/
public static void setMemberAccess(Map context, MemberAccess 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.
*
* @return The configured {@link MemberAccess} instance in the specified context - or null if none found.
*/
public static MemberAccess getMemberAccess(Map context)
{
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.
*/
public static void setRoot(Map context, Object 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.
*
* @return The root object - or null if none found.
*/
public static Object getRoot(Map context)
{
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.
*
* @return The {@link Evaluation} - or null if none was found.
*/
public static Evaluation getLastEvaluation(Map context)
{
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
* @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);
} /**
* 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
*/
public static Object getValue(Object tree, Map context, Object root, Class resultType)
throws OgnlException
{
Object result;
OgnlContext ognlContext = (OgnlContext) addDefaultContext(root, context); Node node = (Node)tree; if (node.getAccessor() != null)
result = node.getAccessor().get(ognlContext, root);
else
result = node.getValue(ognlContext, root); 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.
* @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
*
* @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
* @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(String expression, Map context, Object root)
throws OgnlException
{
return getValue(expression, context, root, null);
} /**
* 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
* @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(String expression, Map context, Object root, Class resultType)
throws OgnlException
{
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
* @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, Object root)
throws OgnlException
{
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
* @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, Object root, Class resultType)
throws OgnlException
{
return getValue(tree, createDefaultContext(root), root, resultType);
} /**
* 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
* @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);
} /**
* 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
* @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);
} /**
* 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
{
OgnlContext ognlContext = (OgnlContext) addDefaultContext(root, context);
Node n = (Node) tree; if (n.getAccessor() != null) {
n.getAccessor().set(ognlContext, root, value);
return;
} 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>.
*
* @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);
} /**
* 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.
*/
public static boolean isConstant(Object tree, Map context)
throws OgnlException
{
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.
*
* @return True if the node is a constant - false otherwise.
* @throws OgnlException If an error occurs checking the expression.
*/
public static boolean isConstant(String expression, Map context)
throws OgnlException
{
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.
*
* @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
{
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.
*
* @return True if the expression represents a constant - false otherwise.
* @throws OgnlException If an exception occurs.
*/
public static boolean isConstant(String expression)
throws OgnlException
{
return isConstant(parseExpression(expression), createDefaultContext(null));
} public static boolean isSimpleProperty(Object tree, Map context)
throws OgnlException
{
return ((SimpleNode) tree).isSimpleProperty((OgnlContext) addDefaultContext(null, context));
} public static boolean isSimpleProperty(String expression, Map context)
throws OgnlException
{
return isSimpleProperty(parseExpression(expression), context);
} public static boolean isSimpleProperty(Object tree)
throws OgnlException
{
return isSimpleProperty(tree, createDefaultContext(null));
} public static boolean isSimpleProperty(String expression)
throws OgnlException
{
return isSimpleProperty(parseExpression(expression), createDefaultContext(null));
} public static boolean isSimpleNavigationChain(Object tree, Map context)
throws OgnlException
{
return ((SimpleNode) tree).isSimpleNavigationChain((OgnlContext) addDefaultContext(null, context));
} public static boolean isSimpleNavigationChain(String expression, Map context)
throws OgnlException
{
return isSimpleNavigationChain(parseExpression(expression), context);
} public static boolean isSimpleNavigationChain(Object tree)
throws OgnlException
{
return isSimpleNavigationChain(tree, createDefaultContext(null));
} public static boolean isSimpleNavigationChain(String expression)
throws OgnlException
{
return isSimpleNavigationChain(parseExpression(expression), createDefaultContext(null));
} /** You can't make one of these. */
private Ognl()
{
}
}

Ognl对象图导航语言 源码的更多相关文章

  1. android通讯录导航栏源码(一)

    通讯录导航栏源码: 1.activity package com.anna.contact.activity; import java.util.ArrayList; import java.util ...

  2. 超详细Go语言源码目录说明

    开源项目「go home」聚焦Go语言技术栈与面试题,以协助Gopher登上更大的舞台,欢迎go home~ 导读 学习Go语言源码的第一步就是了解先了解它的目录结构,你对它的源码目录了解多少呢?今天 ...

  3. Go语言源码分析之unsafe

    Go语言源码分析之unsafe 1.什么是unsafe unsafe 库让 golang 可以像C语言一样操作计算机内存,但这并不是golang推荐使用的,能不用尽量不用,就像它的名字所表达的一样,它 ...

  4. 在linux操作系统上进行简单的C语言源码的gcc编译实验

    尝试在linux上用gcc 而非封装完好的codeblocks,vs等ide 来编译c和cpp源程序 首先查看我的gcc版本,我的是VM centos 自带的,没有的话得自行安装,安装上gcc就可以在 ...

  5. linux下c语言源码编译

    一.源码编译过程   源码  ---> 预处理 ---> 编译 ---> 汇编 ---> 链接 --->执行    我们可以把它分为三部分来完成: ./configure ...

  6. OGNL(对象图导航语言)学习

    一.关于OGNL(Object-Graph Navigation Language),一种可以方便地操作对象属性的开源表达式语言. 特点:  1)支持对象方法调用,形式如:objName.method ...

  7. Struts_OGNL(Object Graph Navigation Language) 对象图导航语言

    1.访问值栈中的action的普通属性: 请求: <a href="ognl.action?username=u&password=p">访问属性</a& ...

  8. linux平台进行c语言源码安装

    安装c源程序的步骤: 1. ./configure --prefix 执行编译检测 指定安装路径 2. make 编译 3. sudo make install 编译后安装 前两步可以合成一步(mak ...

  9. 曹工说Redis源码(2)-- redis server 启动过程解析及简单c语言基础知识补充

    文章导航 Redis源码系列的初衷,是帮助我们更好地理解Redis,更懂Redis,而怎么才能懂,光看是不够的,建议跟着下面的这一篇,把环境搭建起来,后续可以自己阅读源码,或者跟着我这边一起阅读.由于 ...

随机推荐

  1. 300行ABAP代码实现一个最简单的区块链原型

    不知从什么时候起,区块链在网上一下子就火了. 这里Jerry就不班门弄斧了,网上有太多的区块链介绍文章.我的这篇文章没有任何高大上的术语,就是300行ABAP代码,实现一个最简单的区块链原型. 我个人 ...

  2. IOS给图片增加水印(图片、文字)

    在网上发现很多人使用 CGContextDrawImage(context,CGRectMake(0,0,self.width,self.height),[image CGImage]); //原图  ...

  3. 【BZOJ3209】花神的数论题(数位DP)

    点此看题面 大致题意: 设\(sum(i)\)表示\(i\)二进制中1的个数,请求出\(\prod_{i=1}^n sum(i)\). 数位\(DP\) 很显然,这是一道数位\(DP\)题.我们可以先 ...

  4. 漫谈 Clustering (番外篇): Expectation Maximization

    Expectation Maximization (EM) 是一种以迭代的方式来解决一类特殊最大似然 (Maximum Likelihood) 问题的方法,这类问题通常是无法直接求得最优解,但是如果引 ...

  5. Bootstrap 历练实例 - 折叠(Collapse)插件方法

    方法 下面是一些折叠(Collapse)插件中有用的方法: 方法 描述 实例 Options:.collapse(options) 激活内容为可折叠元素.接受一个可选的 options 对象. $(' ...

  6. PAM认证机制

    PAM:Pluggable Authentication Modules 认证库:文本文件,MySQL,NIS,LDAP等 Sun公司于1995 年开发的一种与认证相关的通用框架机制 PAM 是关注如 ...

  7. Class:向传统类模式转变的构造函数

    前言 JS基于原型的'类',一直被转行前端的码僚们大呼惊奇,但接近传统模式使用class关键字定义的出现,却使得一些前端同行深感遗憾而纷纷留言:"还我独特的JS"."净搞 ...

  8. BootStrap下拉框搜索功能

    <!DOCTYPE html> <html> <head> <title>jQuery bootstrap-select可搜索多选下拉列表插件-www. ...

  9. 关于 composer 的一些坑

    发布自己的『包.库』至 https://packagist.org 却一直不能引入 网络上所有关于新建composer包的教程文章统统只提到了版本可能会影响无法 require 深深的坑哭了我们这些入 ...

  10. python爬虫的基本思路

    爬虫:请求网站并提取数据的自动化程序. 流程: 发送请求 -> 获取数据 -> 解析数据 -> 存储数据