Package org.apache.commons.ognl
Class OgnlRuntime
- java.lang.Object
-
- org.apache.commons.ognl.OgnlRuntime
-
public class OgnlRuntime extends java.lang.Object
Utility class used by internal OGNL API to do various things like:- Handles majority of reflection logic / caching.
- Utility methods for casting strings / various numeric types used by
OgnlExpressionCompiler
.Core runtime configuration point for setting/using globalTypeConverter
/OgnlExpressionCompiler
/NullHandler
instances / etc..
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static OgnlCache
cache
private static OgnlExpressionCompiler
compiler
Expression compiler used byOgnl.compileExpression(OgnlContext, Object, String)
calls.static java.lang.String
GET_PREFIX
Java beans standard get method prefix.private static int
HEX_LENGTH
private static java.util.Map<java.lang.Integer,java.lang.String>
HEX_PADDING
Prefix padding for hexadecimal numbers to HEX_LENGTH.static int
INDEXED_PROPERTY_INT
JavaBeans IndexedPropertystatic int
INDEXED_PROPERTY_NONE
Not an indexed propertystatic int
INDEXED_PROPERTY_OBJECT
OGNL ObjectIndexedPropertystatic java.lang.String
IS_PREFIX
Java beans standard isboolean getter prefix. static java.lang.Object[]
NoArguments
static java.lang.Object
NoConversionPossible
Token returned by TypeConverter for no conversion possiblestatic java.lang.Object
NotFound
Constant expression used to indicate that a given method / property couldn't be found during reflection operations.private static java.lang.String
NULL_OBJECT_STRING
Returned bygetUniqueDescriptor()
when the object isnull
.static java.lang.String
NULL_STRING
Constant string representation of null string.private static NumericCasts
numericCasts
Constant strings for casting different primitive types.private static NumericDefaults
numericDefaults
private static NumericLiterals
numericLiterals
Numeric primitive literal string expressions.private static NumericValues
numericValues
Constant strings for getting the primitive value of different native types on the genericNumber
object interface.private static PrimitiveDefaults
primitiveDefaults
private static PrimitiveTypes
primitiveTypes
private static PrimitiveWrapperClasses
primitiveWrapperClasses
Used to provide primitive type equivalent conversions into and out of native / object types.private static java.lang.SecurityManager
securityManager
static java.lang.String
SET_PREFIX
Java beans standard set method prefix.
-
Constructor Summary
Constructors Constructor Description OgnlRuntime()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
areArgsCompatible(java.lang.Object[] args, java.lang.Class<?>[] classes)
Tells whether the given array of objects is compatible with the given array of classes---that is, whether the given array of objects can be passed as arguments to a method or constructor whose parameter types are the given array of classes.static boolean
areArgsCompatible(java.lang.Object[] args, java.lang.Class<?>[] classes, java.lang.reflect.Method method)
static java.lang.Object
callAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String methodName, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args)
static java.lang.Object
callConstructor(OgnlContext context, java.lang.String className, java.lang.Object[] args)
static java.lang.Object
callMethod(OgnlContext context, java.lang.Object target, java.lang.String methodName, java.lang.Object[] args)
Invokes the specified method against the target object.static java.lang.Object
callStaticMethod(OgnlContext context, java.lang.String className, java.lang.String methodName, java.lang.Object[] args)
static java.lang.Class<?>
classForName(OgnlContext context, java.lang.String className)
static void
clearCache()
Clears all of the cached reflection information normally used to improve the speed of expressions that operate on the same classes or are executed multiple times.static void
compileExpression(OgnlContext context, Node expression, java.lang.Object root)
static java.lang.Class<?>[]
findParameterTypes(java.lang.Class<?> type, java.lang.reflect.Method method)
Finds the appropriate parameter types for the givenMethod
andClass
instance of the type the method is associated with.static java.lang.reflect.Method
getAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] actualArgs)
Gets the appropriate method to be called for the given target, method name and arguments.static java.lang.Class<?>
getArgClass(java.lang.Object arg)
Gets the class for a method argument that is appropriate for looking up methods by reflection, by looking for the standard primitive wrapper classes and exchanging for them their underlying primitive class objects.static java.lang.String
getBaseName(java.lang.Object o)
Returns the base name (the class name without the package name prepended) of the object given.static java.lang.String
getChildSource(OgnlContext context, java.lang.Object target, Node child)
Attempts to get the java source string represented by the specific child expression via theJavaSource.toGetSourceString(OgnlContext, Object)
interface method.static java.lang.String
getChildSource(OgnlContext context, java.lang.Object target, Node child, boolean forceConversion)
Attempts to get the java source string represented by the specific child expression via theJavaSource.toGetSourceString(OgnlContext, Object)
interface method.static java.lang.String
getClassBaseName(java.lang.Class<?> clazz)
Returns the base name (the class name without the package name prepended) of the class given.static java.lang.String
getClassName(java.lang.Class<?> clazz, boolean fullyQualified)
static java.lang.String
getClassName(java.lang.Object object, boolean fullyQualified)
static java.lang.String
getClassPackageName(java.lang.Class<?> clazz)
Returns the package name of the class given.static OgnlExpressionCompiler
getCompiler(OgnlContext ognlContext)
static java.util.List<java.lang.reflect.Constructor<?>>
getConstructors(java.lang.Class<?> targetClass)
static java.lang.reflect.Constructor<?>
getConvertedConstructorAndArgs(OgnlContext context, java.lang.Object target, java.util.List<java.lang.reflect.Constructor<?>> constructors, java.lang.Object[] args, java.lang.Object[] newArgs)
static java.lang.reflect.Method
getConvertedMethodAndArgs(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] newArgs)
static java.lang.Object
getConvertedType(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?> type)
static boolean
getConvertedTypes(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args, java.lang.Object[] newArgs)
static java.util.List<java.lang.reflect.Method>
getDeclaredMethods(java.lang.Class<?> targetClass, java.lang.String propertyName, boolean findSets)
static ElementsAccessor
getElementsAccessor(java.lang.Class<?> clazz)
static java.lang.reflect.Field
getField(java.lang.Class<?> inClass, java.lang.String name)
static java.util.Map<java.lang.String,java.lang.reflect.Field>
getFields(java.lang.Class<?> targetClass)
static java.lang.Object
getFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName)
static java.lang.Object
getFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, boolean checkAccessAndExistence)
static java.lang.reflect.Method
getGetMethod(OgnlContext unused, java.lang.Class<?> targetClass, java.lang.String propertyName)
static java.lang.Object
getIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index)
static int
getIndexedPropertyType(OgnlContext context, java.lang.Class<?> sourceClass, java.lang.String name)
Determines the index property type, if any.static java.lang.reflect.Method
getMethod(OgnlContext context, java.lang.Class<?> target, java.lang.String name, Node[] children, boolean includeStatic)
static MethodAccessor
getMethodAccessor(java.lang.Class<?> clazz)
static java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>
getMethods(java.lang.Class<?> targetClass, boolean staticMethods)
static java.util.List<java.lang.reflect.Method>
getMethods(java.lang.Class<?> targetClass, java.lang.String name, boolean staticMethods)
static java.lang.Object
getMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName)
static java.lang.Object
getMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, boolean checkAccessAndExistence)
If the checkAccessAndExistence flag is true this method will check to see if the method exists and if it is accessible according to the context's MemberAccess.static NullHandler
getNullHandler(java.lang.Class<?> clazz)
static java.lang.String
getNumericCast(java.lang.Class<? extends java.lang.Number> type)
static java.lang.Object
getNumericDefaultValue(java.lang.Class<?> forClass)
static java.lang.String
getNumericLiteral(java.lang.Class<? extends java.lang.Number> type)
static java.lang.String
getNumericValueGetter(java.lang.Class<?> type)
static java.lang.String
getPackageName(java.lang.Object object)
Returns the package name of the object's class.static java.lang.Class<?>[]
getParameterTypes(java.lang.reflect.Constructor<?> constructor)
Returns the parameter types of the given method.static java.lang.Class<?>[]
getParameterTypes(java.lang.reflect.Method method)
Returns the parameter types of the given method.static java.security.Permission
getPermission(java.lang.reflect.Method method)
Permission will be named "invoke.. ". static java.lang.String
getPointerString(int num)
Returns a "pointer" string in the usual format for these things - 0x. static java.lang.String
getPointerString(java.lang.Object object)
Returns a "pointer" string in the usual format for these things - 0xfor the object given. static java.lang.Object
getPrimitiveDefaultValue(java.lang.Class<?> forClass)
static java.lang.Class<?>
getPrimitiveWrapperClass(java.lang.Class<?> primitiveClass)
static java.beans.PropertyDescriptor
getProperty(java.lang.Class<?> target, java.lang.String name)
static java.lang.Object
getProperty(OgnlContext context, java.lang.Object source, java.lang.Object name)
static PropertyAccessor
getPropertyAccessor(java.lang.Class<?> clazz)
static java.beans.PropertyDescriptor
getPropertyDescriptor(java.lang.Class<?> targetClass, java.lang.String propertyName)
This method returns a PropertyDescriptor for the given class and property name using a Map lookup (using getPropertyDescriptorsMap()).static java.beans.PropertyDescriptor
getPropertyDescriptorFromArray(java.lang.Class<?> targetClass, java.lang.String name)
Gets the property descriptor with the given name for the target class given.static java.util.Map<java.lang.String,java.beans.PropertyDescriptor>
getPropertyDescriptors(java.lang.Class<?> targetClass)
This method returns the property descriptors for the given class as a Map.static java.beans.PropertyDescriptor[]
getPropertyDescriptorsArray(java.lang.Class<?> targetClass)
static java.lang.reflect.Method
getReadMethod(java.lang.Class<?> target, java.lang.String name)
Finds the best possible match for a method on the specified target class with a matching name.static java.lang.reflect.Method
getReadMethod(java.lang.Class<?> target, java.lang.String name, int numParms)
static java.lang.SecurityManager
getSecurityManager()
Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.static java.lang.reflect.Method
getSetMethod(OgnlContext context, java.lang.Class<?> targetClass, java.lang.String propertyName)
static java.lang.Object
getStaticField(OgnlContext context, java.lang.String className, java.lang.String fieldName)
static java.lang.Class<?>
getTargetClass(java.lang.Object o)
Gets the "target" class of an object for looking up accessors that are registered on the target.static java.lang.String
getUniqueDescriptor(java.lang.Object object)
Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.static java.lang.String
getUniqueDescriptor(java.lang.Object object, boolean fullyQualified)
Returns a unique descriptor string that includes the object's class and a unique integer identifier.static java.lang.reflect.Method
getWriteMethod(java.lang.Class<?> target, java.lang.String name)
static java.lang.reflect.Method
getWriteMethod(java.lang.Class<?> target, java.lang.String name, int numParms)
static boolean
hasField(OgnlContext context, java.lang.Object target, java.lang.Class<?> inClass, java.lang.String propertyName)
static boolean
hasGetMethod(OgnlContext context, java.lang.Object target, java.lang.Class<?> targetClass, java.lang.String propertyName)
static boolean
hasGetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname)
static boolean
hasSetMethod(OgnlContext context, java.lang.Object target, java.lang.Class<?> targetClass, java.lang.String propertyName)
static boolean
hasSetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname)
static java.lang.Object
invokeMethod(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] argsArray)
static boolean
isBoolean(java.lang.String expression)
static boolean
isFieldAccessible(OgnlContext context, java.lang.Object target, java.lang.Class<?> inClass, java.lang.String propertyName)
static boolean
isFieldAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Field field, java.lang.String propertyName)
static boolean
isInstance(OgnlContext context, java.lang.Object value, java.lang.String className)
static boolean
isMethodAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Method method, java.lang.String propertyName)
static boolean
isMethodCallable(java.lang.reflect.Method method)
Convenience used to check if a method is volatile or synthetic so as to avoid calling un-callable methods.static boolean
isMoreSpecific(java.lang.Class<?>[] classes1, java.lang.Class<?>[] classes2)
Tells whether the first array of classes is more specific than the second.static boolean
isTypeCompatible(java.lang.Object object, java.lang.Class<?> clazz)
Tells whether the given object is compatible with the given class ---that is, whether the given object can be passed as an argument to a method or constructor whose parameter type is the given class.static void
setClassCacheInspector(ClassCacheInspector inspector)
Registers the specifiedClassCacheInspector
with all class reflection based internal caches.static void
setCompiler(OgnlExpressionCompiler compiler)
static void
setElementsAccessor(java.lang.Class<?> clazz, ElementsAccessor accessor)
static boolean
setFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value)
static void
setIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index, java.lang.Object value)
static void
setMethodAccessor(java.lang.Class<?> clazz, MethodAccessor accessor)
static boolean
setMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value)
static boolean
setMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value, boolean checkAccessAndExistence)
static void
setNullHandler(java.lang.Class<?> clazz, NullHandler handler)
static void
setProperty(OgnlContext context, java.lang.Object target, java.lang.Object name, java.lang.Object value)
static void
setPropertyAccessor(java.lang.Class<?> clazz, PropertyAccessor accessor)
static void
setSecurityManager(java.lang.SecurityManager securityManager)
Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.static boolean
shouldConvertNumericTypes(OgnlContext context)
Compares theOgnlContext.getCurrentType()
andOgnlContext.getPreviousType()
class types on the stack to determine if a numeric expression should force object conversion.static <T> java.lang.Object[]
toArray(java.util.List<T> list)
Utility to convert a List into an Object[] array.
-
-
-
Field Detail
-
NotFound
public static final java.lang.Object NotFound
Constant expression used to indicate that a given method / property couldn't be found during reflection operations.
-
NoArguments
public static final java.lang.Object[] NoArguments
-
NoConversionPossible
public static final java.lang.Object NoConversionPossible
Token returned by TypeConverter for no conversion possible
-
INDEXED_PROPERTY_NONE
public static final int INDEXED_PROPERTY_NONE
Not an indexed property- See Also:
- Constant Field Values
-
INDEXED_PROPERTY_INT
public static final int INDEXED_PROPERTY_INT
JavaBeans IndexedProperty- See Also:
- Constant Field Values
-
INDEXED_PROPERTY_OBJECT
public static final int INDEXED_PROPERTY_OBJECT
OGNL ObjectIndexedProperty- See Also:
- Constant Field Values
-
NULL_STRING
public static final java.lang.String NULL_STRING
Constant string representation of null string.
-
SET_PREFIX
public static final java.lang.String SET_PREFIX
Java beans standard set method prefix.- See Also:
- Constant Field Values
-
GET_PREFIX
public static final java.lang.String GET_PREFIX
Java beans standard get method prefix.- See Also:
- Constant Field Values
-
IS_PREFIX
public static final java.lang.String IS_PREFIX
Java beans standard isboolean getter prefix. - See Also:
- Constant Field Values
-
HEX_PADDING
private static final java.util.Map<java.lang.Integer,java.lang.String> HEX_PADDING
Prefix padding for hexadecimal numbers to HEX_LENGTH.
-
HEX_LENGTH
private static final int HEX_LENGTH
- See Also:
- Constant Field Values
-
NULL_OBJECT_STRING
private static final java.lang.String NULL_OBJECT_STRING
Returned bygetUniqueDescriptor()
when the object isnull
.- See Also:
- Constant Field Values
-
cache
static OgnlCache cache
-
primitiveTypes
private static final PrimitiveTypes primitiveTypes
-
primitiveDefaults
private static final PrimitiveDefaults primitiveDefaults
-
securityManager
private static java.lang.SecurityManager securityManager
-
compiler
private static OgnlExpressionCompiler compiler
Expression compiler used byOgnl.compileExpression(OgnlContext, Object, String)
calls.
-
primitiveWrapperClasses
private static final PrimitiveWrapperClasses primitiveWrapperClasses
Used to provide primitive type equivalent conversions into and out of native / object types.
-
numericCasts
private static final NumericCasts numericCasts
Constant strings for casting different primitive types.
-
numericValues
private static final NumericValues numericValues
Constant strings for getting the primitive value of different native types on the genericNumber
object interface. (or the less generic BigDecimal/BigInteger types)
-
numericLiterals
private static final NumericLiterals numericLiterals
Numeric primitive literal string expressions.
-
numericDefaults
private static final NumericDefaults numericDefaults
-
-
Method Detail
-
clearCache
public static void clearCache()
Clears all of the cached reflection information normally used to improve the speed of expressions that operate on the same classes or are executed multiple times.Warning: Calling this too often can be a huge performance drain on your expressions - use with care.
-
getNumericValueGetter
public static java.lang.String getNumericValueGetter(java.lang.Class<?> type)
-
getPrimitiveWrapperClass
public static java.lang.Class<?> getPrimitiveWrapperClass(java.lang.Class<?> primitiveClass)
-
getNumericCast
public static java.lang.String getNumericCast(java.lang.Class<? extends java.lang.Number> type)
-
getNumericLiteral
public static java.lang.String getNumericLiteral(java.lang.Class<? extends java.lang.Number> type)
-
setCompiler
public static void setCompiler(OgnlExpressionCompiler compiler)
-
getCompiler
public static OgnlExpressionCompiler getCompiler(OgnlContext ognlContext)
-
compileExpression
public static void compileExpression(OgnlContext context, Node expression, java.lang.Object root) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getTargetClass
public static java.lang.Class<?> getTargetClass(java.lang.Object o)
Gets the "target" class of an object for looking up accessors that are registered on the target. If the object is a Class object this will return the Class itself, else it will return object's getClass() result.
-
getBaseName
public static java.lang.String getBaseName(java.lang.Object o)
Returns the base name (the class name without the package name prepended) of the object given.
-
getClassBaseName
public static java.lang.String getClassBaseName(java.lang.Class<?> clazz)
Returns the base name (the class name without the package name prepended) of the class given.
-
getClassName
public static java.lang.String getClassName(java.lang.Object object, boolean fullyQualified)
-
getClassName
public static java.lang.String getClassName(java.lang.Class<?> clazz, boolean fullyQualified)
-
getPackageName
public static java.lang.String getPackageName(java.lang.Object object)
Returns the package name of the object's class.
-
getClassPackageName
public static java.lang.String getClassPackageName(java.lang.Class<?> clazz)
Returns the package name of the class given.
-
getPointerString
public static java.lang.String getPointerString(int num)
Returns a "pointer" string in the usual format for these things - 0x.
-
getPointerString
public static java.lang.String getPointerString(java.lang.Object object)
Returns a "pointer" string in the usual format for these things - 0xfor the object given. This will always return a unique value for each object.
-
getUniqueDescriptor
public static java.lang.String getUniqueDescriptor(java.lang.Object object, boolean fullyQualified)
Returns a unique descriptor string that includes the object's class and a unique integer identifier. If fullyQualified is true then the class name will be fully qualified to include the package name, else it will be just the class' base name.
-
getUniqueDescriptor
public static java.lang.String getUniqueDescriptor(java.lang.Object object)
Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.
-
toArray
public static <T> java.lang.Object[] toArray(java.util.List<T> list)
Utility to convert a List into an Object[] array. If the list is zero elements this will return a constant array; toArray() on List always returns a new object and this is wasteful for our purposes.
-
getParameterTypes
public static java.lang.Class<?>[] getParameterTypes(java.lang.reflect.Method method) throws CacheException
Returns the parameter types of the given method.- Throws:
CacheException
-
findParameterTypes
public static java.lang.Class<?>[] findParameterTypes(java.lang.Class<?> type, java.lang.reflect.Method method) throws CacheException
Finds the appropriate parameter types for the givenMethod
andClass
instance of the type the method is associated with. Correctly finds generic types if running in >= 1.5 jre as well.- Parameters:
type
- The class type the method is being executed against.method
- The method to find types for.- Returns:
- Array of parameter types for the given method.
- Throws:
CacheException
-
getParameterTypes
public static java.lang.Class<?>[] getParameterTypes(java.lang.reflect.Constructor<?> constructor) throws CacheException
Returns the parameter types of the given method.- Parameters:
constructor
-- Returns:
- Throws:
CacheException
-
getSecurityManager
public static java.lang.SecurityManager getSecurityManager()
Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Returns:
- SecurityManager for OGNL
-
setSecurityManager
public static void setSecurityManager(java.lang.SecurityManager securityManager)
Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Parameters:
securityManager
- SecurityManager to set
-
getPermission
public static java.security.Permission getPermission(java.lang.reflect.Method method) throws CacheException
Permission will be named "invoke.. ". - Parameters:
method
-- Returns:
- Throws:
CacheException
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] argsArray) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException, CacheException
- Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
CacheException
-
getArgClass
public static java.lang.Class<?> getArgClass(java.lang.Object arg)
Gets the class for a method argument that is appropriate for looking up methods by reflection, by looking for the standard primitive wrapper classes and exchanging for them their underlying primitive class objects. Other classes are passed through unchanged.- Parameters:
arg
- an object that is being passed to a method- Returns:
- the class to use to look up the method
-
isTypeCompatible
public static boolean isTypeCompatible(java.lang.Object object, java.lang.Class<?> clazz)
Tells whether the given object is compatible with the given class ---that is, whether the given object can be passed as an argument to a method or constructor whose parameter type is the given class. If object is null this will return true because null is compatible with any type.
-
areArgsCompatible
public static boolean areArgsCompatible(java.lang.Object[] args, java.lang.Class<?>[] classes)
Tells whether the given array of objects is compatible with the given array of classes---that is, whether the given array of objects can be passed as arguments to a method or constructor whose parameter types are the given array of classes.
-
areArgsCompatible
public static boolean areArgsCompatible(java.lang.Object[] args, java.lang.Class<?>[] classes, java.lang.reflect.Method method)
-
isMoreSpecific
public static boolean isMoreSpecific(java.lang.Class<?>[] classes1, java.lang.Class<?>[] classes2)
Tells whether the first array of classes is more specific than the second. Assumes that the two arrays are of the same length.
-
classForName
public static java.lang.Class<?> classForName(OgnlContext context, java.lang.String className) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
isInstance
public static boolean isInstance(OgnlContext context, java.lang.Object value, java.lang.String className) throws OgnlException
- Throws:
OgnlException
-
getPrimitiveDefaultValue
public static java.lang.Object getPrimitiveDefaultValue(java.lang.Class<?> forClass)
-
getNumericDefaultValue
public static java.lang.Object getNumericDefaultValue(java.lang.Class<?> forClass)
-
getConvertedType
public static java.lang.Object getConvertedType(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?> type)
-
getConvertedTypes
public static boolean getConvertedTypes(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args, java.lang.Object[] newArgs)
-
getConvertedMethodAndArgs
public static java.lang.reflect.Method getConvertedMethodAndArgs(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] newArgs)
-
getConvertedConstructorAndArgs
public static java.lang.reflect.Constructor<?> getConvertedConstructorAndArgs(OgnlContext context, java.lang.Object target, java.util.List<java.lang.reflect.Constructor<?>> constructors, java.lang.Object[] args, java.lang.Object[] newArgs)
-
getAppropriateMethod
public static java.lang.reflect.Method getAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] actualArgs)
Gets the appropriate method to be called for the given target, method name and arguments. If successful this method will return the Method within the target that can be called and the converted arguments in actualArgs. If unsuccessful this method will return null and the actualArgs will be empty.- Parameters:
context
- The current execution context.source
- Target object to run against or method name.target
- Instance of object to be run against.propertyName
- Name of property to get method of.methods
- List of current known methods.args
- Arguments originally passed in.actualArgs
- Converted arguments.- Returns:
- Best method match or null if none could be found.
-
callAppropriateMethod
public static java.lang.Object callAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String methodName, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args) throws MethodFailedException
- Throws:
MethodFailedException
-
callStaticMethod
public static java.lang.Object callStaticMethod(OgnlContext context, java.lang.String className, java.lang.String methodName, java.lang.Object[] args) throws OgnlException
- Throws:
OgnlException
-
callMethod
public static java.lang.Object callMethod(OgnlContext context, java.lang.Object target, java.lang.String methodName, java.lang.Object[] args) throws OgnlException
Invokes the specified method against the target object.- Parameters:
context
- The current execution context.target
- The object to invoke the method on.methodName
- Name of the method - as in "getValue" or "add", etc..args
- Optional arguments needed for method.- Returns:
- Result of invoking method.
- Throws:
OgnlException
- For lots of different reasons.
-
callConstructor
public static java.lang.Object callConstructor(OgnlContext context, java.lang.String className, java.lang.Object[] args) throws OgnlException
- Throws:
OgnlException
-
getMethodValue
public static java.lang.Object getMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName) throws OgnlException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.beans.IntrospectionException
- Throws:
OgnlException
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.beans.IntrospectionException
-
getMethodValue
public static java.lang.Object getMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, boolean checkAccessAndExistence) throws OgnlException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.beans.IntrospectionException
If the checkAccessAndExistence flag is true this method will check to see if the method exists and if it is accessible according to the context's MemberAccess. If neither test passes this will return NotFound.- Throws:
OgnlException
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.beans.IntrospectionException
-
setMethodValue
public static boolean setMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value) throws OgnlException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.beans.IntrospectionException
- Throws:
OgnlException
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.beans.IntrospectionException
-
setMethodValue
public static boolean setMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value, boolean checkAccessAndExistence) throws OgnlException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException, java.beans.IntrospectionException
- Throws:
OgnlException
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.beans.IntrospectionException
-
getConstructors
public static java.util.List<java.lang.reflect.Constructor<?>> getConstructors(java.lang.Class<?> targetClass)
-
getMethods
public static java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> getMethods(java.lang.Class<?> targetClass, boolean staticMethods)
- Parameters:
targetClass
-staticMethods
- if true (false) returns only the (non-)static methods- Returns:
- Returns the map of methods for a given class
-
getMethods
public static java.util.List<java.lang.reflect.Method> getMethods(java.lang.Class<?> targetClass, java.lang.String name, boolean staticMethods)
-
getFields
public static java.util.Map<java.lang.String,java.lang.reflect.Field> getFields(java.lang.Class<?> targetClass)
-
getField
public static java.lang.reflect.Field getField(java.lang.Class<?> inClass, java.lang.String name)
-
getFieldValue
public static java.lang.Object getFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName) throws java.lang.NoSuchFieldException
- Throws:
java.lang.NoSuchFieldException
-
getFieldValue
public static java.lang.Object getFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, boolean checkAccessAndExistence) throws java.lang.NoSuchFieldException
- Throws:
java.lang.NoSuchFieldException
-
setFieldValue
public static boolean setFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value) throws OgnlException
- Throws:
OgnlException
-
isFieldAccessible
public static boolean isFieldAccessible(OgnlContext context, java.lang.Object target, java.lang.Class<?> inClass, java.lang.String propertyName)
-
isFieldAccessible
public static boolean isFieldAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Field field, java.lang.String propertyName)
-
hasField
public static boolean hasField(OgnlContext context, java.lang.Object target, java.lang.Class<?> inClass, java.lang.String propertyName)
-
getStaticField
public static java.lang.Object getStaticField(OgnlContext context, java.lang.String className, java.lang.String fieldName) throws OgnlException
- Throws:
OgnlException
-
getDeclaredMethods
public static java.util.List<java.lang.reflect.Method> getDeclaredMethods(java.lang.Class<?> targetClass, java.lang.String propertyName, boolean findSets)
- Parameters:
targetClass
-propertyName
-findSets
-- Returns:
- Returns the list of (g)setter of a class for a given property name
-
isMethodCallable
public static boolean isMethodCallable(java.lang.reflect.Method method)
Convenience used to check if a method is volatile or synthetic so as to avoid calling un-callable methods.- Parameters:
method
- The method to check.- Returns:
- True if the method should be callable, false otherwise.
-
getGetMethod
public static java.lang.reflect.Method getGetMethod(OgnlContext unused, java.lang.Class<?> targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
isMethodAccessible
public static boolean isMethodAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Method method, java.lang.String propertyName)
-
hasGetMethod
public static boolean hasGetMethod(OgnlContext context, java.lang.Object target, java.lang.Class<?> targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
getSetMethod
public static java.lang.reflect.Method getSetMethod(OgnlContext context, java.lang.Class<?> targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
hasSetMethod
public static boolean hasSetMethod(OgnlContext context, java.lang.Object target, java.lang.Class<?> targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
hasGetProperty
public static boolean hasGetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
hasSetProperty
public static boolean hasSetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
getPropertyDescriptors
public static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getPropertyDescriptors(java.lang.Class<?> targetClass) throws java.beans.IntrospectionException, OgnlException
This method returns the property descriptors for the given class as a Map.- Parameters:
targetClass
- The class to get the descriptors for.- Returns:
- Map map of property descriptors for class.
- Throws:
java.beans.IntrospectionException
- on errors usingIntrospector
.OgnlException
- On general errors.
-
getPropertyDescriptor
public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class<?> targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
This method returns a PropertyDescriptor for the given class and property name using a Map lookup (using getPropertyDescriptorsMap()).- Parameters:
targetClass
- a target class.propertyName
- a property name.- Returns:
- the PropertyDescriptor for the given targetClass and propertyName.
- Throws:
java.beans.IntrospectionException
OgnlException
-
getPropertyDescriptorsArray
public static java.beans.PropertyDescriptor[] getPropertyDescriptorsArray(java.lang.Class<?> targetClass) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionException
OgnlException
-
getPropertyDescriptorFromArray
public static java.beans.PropertyDescriptor getPropertyDescriptorFromArray(java.lang.Class<?> targetClass, java.lang.String name) throws java.beans.IntrospectionException, OgnlException
Gets the property descriptor with the given name for the target class given.- Parameters:
targetClass
- Class for which property descriptor is desiredname
- Name of property- Returns:
- PropertyDescriptor of the named property or null if the class has no property with the given name
- Throws:
java.beans.IntrospectionException
OgnlException
-
setMethodAccessor
public static void setMethodAccessor(java.lang.Class<?> clazz, MethodAccessor accessor)
-
getMethodAccessor
public static MethodAccessor getMethodAccessor(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
setPropertyAccessor
public static void setPropertyAccessor(java.lang.Class<?> clazz, PropertyAccessor accessor)
-
getPropertyAccessor
public static PropertyAccessor getPropertyAccessor(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
getElementsAccessor
public static ElementsAccessor getElementsAccessor(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
setElementsAccessor
public static void setElementsAccessor(java.lang.Class<?> clazz, ElementsAccessor accessor)
-
getNullHandler
public static NullHandler getNullHandler(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
setNullHandler
public static void setNullHandler(java.lang.Class<?> clazz, NullHandler handler)
-
getProperty
public static java.lang.Object getProperty(OgnlContext context, java.lang.Object source, java.lang.Object name) throws OgnlException
- Throws:
OgnlException
-
setProperty
public static void setProperty(OgnlContext context, java.lang.Object target, java.lang.Object name, java.lang.Object value) throws OgnlException
- Throws:
OgnlException
-
getIndexedPropertyType
public static int getIndexedPropertyType(OgnlContext context, java.lang.Class<?> sourceClass, java.lang.String name) throws OgnlException
Determines the index property type, if any. ReturnsINDEXED_PROPERTY_NONE
if the property is not index-accessible as determined by OGNL or JavaBeans. If it is indexable then this will return whether it is a JavaBeans indexed property, conforming to the indexed property patterns (returnsINDEXED_PROPERTY_INT
) or if it conforms to the OGNL arbitrary object indexable (returnsINDEXED_PROPERTY_OBJECT
).- Throws:
OgnlException
-
getIndexedProperty
public static java.lang.Object getIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index) throws OgnlException
- Throws:
OgnlException
-
setIndexedProperty
public static void setIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index, java.lang.Object value) throws OgnlException
- Throws:
OgnlException
-
setClassCacheInspector
public static void setClassCacheInspector(ClassCacheInspector inspector)
Registers the specifiedClassCacheInspector
with all class reflection based internal caches. This may have a significant performance impact so be careful using this in production scenarios.- Parameters:
inspector
- The inspector instance that will be registered with all internal cache instances.
-
getMethod
public static java.lang.reflect.Method getMethod(OgnlContext context, java.lang.Class<?> target, java.lang.String name, Node[] children, boolean includeStatic) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getReadMethod
public static java.lang.reflect.Method getReadMethod(java.lang.Class<?> target, java.lang.String name)
Finds the best possible match for a method on the specified target class with a matching name.The name matched will also try different combinations like
is + name, has + name, get + name, etc..
- Parameters:
target
- The class to find a matching method against.name
- The name of the method.- Returns:
- The most likely matching
Method
, or null if none could be found.
-
getReadMethod
public static java.lang.reflect.Method getReadMethod(java.lang.Class<?> target, java.lang.String name, int numParms)
-
getWriteMethod
public static java.lang.reflect.Method getWriteMethod(java.lang.Class<?> target, java.lang.String name)
-
getWriteMethod
public static java.lang.reflect.Method getWriteMethod(java.lang.Class<?> target, java.lang.String name, int numParms)
-
getProperty
public static java.beans.PropertyDescriptor getProperty(java.lang.Class<?> target, java.lang.String name)
-
isBoolean
public static boolean isBoolean(java.lang.String expression)
-
shouldConvertNumericTypes
public static boolean shouldConvertNumericTypes(OgnlContext context)
Compares theOgnlContext.getCurrentType()
andOgnlContext.getPreviousType()
class types on the stack to determine if a numeric expression should force object conversion. Normally used in conjunction with theforceConversion
parameter ofgetChildSource(OgnlContext, Object, Node, boolean)
.- Parameters:
context
- The current context.- Returns:
- True, if the class types on the stack wouldn't be comparable in a pure numeric expression such as
o1 >= o2
.
-
getChildSource
public static java.lang.String getChildSource(OgnlContext context, java.lang.Object target, Node child) throws OgnlException
Attempts to get the java source string represented by the specific child expression via theJavaSource.toGetSourceString(OgnlContext, Object)
interface method.- Parameters:
context
- The ognl context to pass to the child.target
- The current object target to use.child
- The child expression.- Returns:
- The result of calling
JavaSource.toGetSourceString(OgnlContext, Object)
plus additional enclosures ofOgnlOps.convertValue(Object, Class, boolean)
for conversions. - Throws:
OgnlException
- Mandatory exception throwing catching.. (blehh)
-
getChildSource
public static java.lang.String getChildSource(OgnlContext context, java.lang.Object target, Node child, boolean forceConversion) throws OgnlException
Attempts to get the java source string represented by the specific child expression via theJavaSource.toGetSourceString(OgnlContext, Object)
interface method.- Parameters:
context
- The ognl context to pass to the child.target
- The current object target to use.child
- The child expression.forceConversion
- If true, forcesOgnlOps.convertValue(Object, Class)
conversions on the objects.- Returns:
- The result of calling
JavaSource.toGetSourceString(OgnlContext, Object)
plus additional enclosures ofOgnlOps.convertValue(Object, Class, boolean)
for conversions. - Throws:
OgnlException
- Mandatory exception throwing catching.. (blehh)
-
-