热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ognl对象图导航语言源码

--------------------------------------------------------------------------Copyright(c)19


// --------------------------------------------------------------------------
// 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;
/**
*


* This class provides static methods for parsing and interpreting OGNL expressions.
*


*


* The simplest use of the Ognl class is to get the value of an expression from an object, without
* extra context or pre-parsing.
*


*
*

*
* import ognl.Ognl; import ognl.OgnlException; try { result = Ognl.getValue(expression, root); }
* catch (OgnlException ex) { // Report error or recover }
*
*

*
*


* This will parse the expression given and evaluate it against the root object given, returning the
* result. If there is an error in the expression, such as the property is not found, the exception
* is encapsulated into an {@link ognl.OgnlException OgnlException}.
*


*


* Other more sophisticated uses of Ognl can pre-parse expressions. This provides two advantages: in
* the case of user-supplied expressions it allows you to catch parse errors before evaluation and
* it allows you to cache parsed expressions into an AST for better speed during repeated use. The
* pre-parsed expression is always returned as an Object to simplify use for programs
* that just wish to store the value for repeated use and do not care that it is an AST. If it does
* care it can always safely cast the value to an AST type.
*


*


* The Ognl class also takes a context map as one of the parameters to the set and get
* methods. This allows you to put your own variables into the available namespace for OGNL
* expressions. The default context contains only the #root and #context
* keys, which are required to be present. The addDefaultContext(Object, Map) method
* will alter an existing Map to put the defaults in. Here is an example that shows
* how to extract the documentName property out of the root object and append a
* string with the current user name in parens:
*


*
*

*
* private Map cOntext= new HashMap(); public void setUserName(String value) {
* context.put("userName", value); } try { // get value using our own custom context map result =
* Ognl.getValue("documentName + \" (\" + ((#userName == null) ? \"\" : #userName) +
* \")\"", context, root); } catch (OgnlException ex) { // Report error or recover }
*
*

*
* @author Luke Blanshard (blanshlu@netscape.net)
*
@author Drew Davidson (drew@ognl.org)
*
@version 27 June 1999
*/
public abstract class Ognl
{
/**
* Parses the given OGNL expression and returns a tree representation of the expression that can
* be used by Ognl 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 root and context 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 root and context 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 root and context 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 root and context 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 root and context 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 root and context 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 root and context 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 root and context 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 addDefaultContext().
*
*
@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 addDefaultContext().
*
*
@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 parseExpression and
* getValue.
*
*
@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 parseExpression and
* getValue.
*
*
@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 addDefaultContext().
*
*
@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 parseExpression and
* setValue.
*
*
@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对象图导航语言 源码,布布扣,bubuko.com


推荐阅读
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
author-avatar
空白画叶子
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有