org.apache.commons.ognl
Class OgnlRuntime

java.lang.Object
  extended by org.apache.commons.ognl.OgnlRuntime

public class OgnlRuntime
extends Object

Utility class used by internal OGNL API to do various things like:

$Id: OgnlRuntime.java 1239219 2012-02-01 17:27:54Z mcucchiara $

Author:
Luke Blanshard (blanshlu@netscape.net), Drew Davidson (drew@ognl.org)

Field Summary
static String GET_PREFIX
          Java beans standard get method prefix.
static int INDEXED_PROPERTY_INT
          JavaBeans IndexedProperty
static int INDEXED_PROPERTY_NONE
          Not an indexed property
static int INDEXED_PROPERTY_OBJECT
          OGNL ObjectIndexedProperty
static String IS_PREFIX
          Java beans standard is boolean getter prefix.
static Object[] NoArguments
           
static Object NoConversionPossible
          Token returned by TypeConverter for no conversion possible
static Object NotFound
          Constant expression used to indicate that a given method / property couldn't be found during reflection operations.
static String NULL_STRING
          Constant string representation of null string.
static String SET_PREFIX
          Java beans standard set method prefix.
 
Constructor Summary
OgnlRuntime()
           
 
Method Summary
static boolean areArgsCompatible(Object[] args, 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(Object[] args, Class<?>[] classes, Method method)
           
static Object callAppropriateMethod(OgnlContext context, Object source, Object target, String methodName, String propertyName, List<Method> methods, Object[] args)
           
static Object callConstructor(OgnlContext context, String className, Object[] args)
           
static Object callMethod(OgnlContext context, Object target, String methodName, Object[] args)
          Invokes the specified method against the target object.
static Object callStaticMethod(OgnlContext context, String className, String methodName, Object[] args)
           
static Class<?> classForName(OgnlContext context, 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, Object root)
           
static Class<?>[] findParameterTypes(Class<?> type, Method method)
          Finds the appropriate parameter types for the given Method and Class instance of the type the method is associated with.
static Method getAppropriateMethod(OgnlContext context, Object source, Object target, String propertyName, List<Method> methods, Object[] args, Object[] actualArgs)
          Gets the appropriate method to be called for the given target, method name and arguments.
static Class<?> getArgClass(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 String getBaseName(Object o)
          Returns the base name (the class name without the package name prepended) of the object given.
static String getChildSource(OgnlContext context, Object target, Node child)
          Attempts to get the java source string represented by the specific child expression via the JavaSource.toGetSourceString(OgnlContext, Object) interface method.
static String getChildSource(OgnlContext context, Object target, Node child, boolean forceConversion)
          Attempts to get the java source string represented by the specific child expression via the JavaSource.toGetSourceString(OgnlContext, Object) interface method.
static String getClassBaseName(Class<?> clazz)
          Returns the base name (the class name without the package name prepended) of the class given.
static String getClassName(Class<?> clazz, boolean fullyQualified)
           
static String getClassName(Object object, boolean fullyQualified)
           
static String getClassPackageName(Class<?> clazz)
          Returns the package name of the class given.
static OgnlExpressionCompiler getCompiler()
          Deprecated. use getCompiler(OgnlContext) instead
static OgnlExpressionCompiler getCompiler(OgnlContext ognlContext)
           
static List<Constructor<?>> getConstructors(Class<?> targetClass)
           
static Constructor<?> getConvertedConstructorAndArgs(OgnlContext context, Object target, List<Constructor<?>> constructors, Object[] args, Object[] newArgs)
           
static Method getConvertedMethodAndArgs(OgnlContext context, Object target, String propertyName, List<Method> methods, Object[] args, Object[] newArgs)
           
static Object getConvertedType(OgnlContext context, Object target, Member member, String propertyName, Object value, Class<?> type)
           
static boolean getConvertedTypes(OgnlContext context, Object target, Member member, String propertyName, Class<?>[] parameterTypes, Object[] args, Object[] newArgs)
           
static List<Method> getDeclaredMethods(Class<?> targetClass, String propertyName, boolean findSets)
           
static ElementsAccessor getElementsAccessor(Class<?> clazz)
           
static EvaluationPool getEvaluationPool()
           
static Field getField(Class<?> inClass, String name)
           
static Map<String,Field> getFields(Class<?> targetClass)
           
static Object getFieldValue(OgnlContext context, Object target, String propertyName)
           
static Object getFieldValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence)
           
static Method getGetMethod(OgnlContext unused, Class<?> targetClass, String propertyName)
           
static Object getIndexedProperty(OgnlContext context, Object source, String name, Object index)
           
static int getIndexedPropertyType(OgnlContext context, Class<?> sourceClass, String name)
          Determines the index property type, if any.
static Method getMethod(OgnlContext context, Class<?> target, String name, Node[] children, boolean includeStatic)
           
static MethodAccessor getMethodAccessor(Class<?> clazz)
           
static Map<String,List<Method>> getMethods(Class<?> targetClass, boolean staticMethods)
           
static List<Method> getMethods(Class<?> targetClass, String name, boolean staticMethods)
           
static Object getMethodValue(OgnlContext context, Object target, String propertyName)
           
static Object getMethodValue(OgnlContext context, Object target, 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 String getModifierString(int modifiers)
          Deprecated. This method is no longer used.
static NullHandler getNullHandler(Class<?> clazz)
           
static String getNumericCast(Class<? extends Number> type)
           
static Object getNumericDefaultValue(Class<?> forClass)
           
static String getNumericLiteral(Class<? extends Number> type)
           
static String getNumericValueGetter(Class<?> type)
           
static ObjectArrayPool getObjectArrayPool()
           
static String getPackageName(Object object)
          Returns the package name of the object's class.
static Class<?>[] getParameterTypes(Constructor<?> constructor)
          Returns the parameter types of the given method.
static Class<?>[] getParameterTypes(Method method)
          Returns the parameter types of the given method.
static Permission getPermission(Method method)
          Permission will be named "invoke..".
static String getPointerString(int num)
          Returns a "pointer" string in the usual format for these things - 0x.
static String getPointerString(Object object)
          Returns a "pointer" string in the usual format for these things - 0x for the object given.
static Object getPrimitiveDefaultValue(Class<?> forClass)
           
static Class<?> getPrimitiveWrapperClass(Class<?> primitiveClass)
           
static PropertyDescriptor getProperty(Class<?> target, String name)
           
static Object getProperty(OgnlContext context, Object source, Object name)
           
static PropertyAccessor getPropertyAccessor(Class<?> clazz)
           
static PropertyDescriptor getPropertyDescriptor(Class<?> targetClass, String propertyName)
          This method returns a PropertyDescriptor for the given class and property name using a Map lookup (using getPropertyDescriptorsMap()).
static PropertyDescriptor getPropertyDescriptorFromArray(Class<?> targetClass, String name)
          Gets the property descriptor with the given name for the target class given.
static Map<String,PropertyDescriptor> getPropertyDescriptors(Class<?> targetClass)
          This method returns the property descriptors for the given class as a Map.
static PropertyDescriptor[] getPropertyDescriptorsArray(Class<?> targetClass)
           
static Method getReadMethod(Class<?> target, String name)
          Finds the best possible match for a method on the specified target class with a matching name.
static Method getReadMethod(Class<?> target, String name, int numParms)
           
static SecurityManager getSecurityManager()
          Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.
static Method getSetMethod(OgnlContext context, Class<?> targetClass, String propertyName)
           
static Object getStaticField(OgnlContext context, String className, String fieldName)
           
static Class<?> getTargetClass(Object o)
          Gets the "target" class of an object for looking up accessors that are registered on the target.
static String getUniqueDescriptor(Object object)
          Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.
static String getUniqueDescriptor(Object object, boolean fullyQualified)
          Returns a unique descriptor string that includes the object's class and a unique integer identifier.
static Method getWriteMethod(Class<?> target, String name)
           
static Method getWriteMethod(Class<?> target, String name, int numParms)
           
static boolean hasField(OgnlContext context, Object target, Class<?> inClass, String propertyName)
           
static boolean hasGetMethod(OgnlContext context, Object target, Class<?> targetClass, String propertyName)
           
static boolean hasGetProperty(OgnlContext context, Object target, Object oname)
           
static boolean hasSetMethod(OgnlContext context, Object target, Class<?> targetClass, String propertyName)
           
static boolean hasSetProperty(OgnlContext context, Object target, Object oname)
           
static Object invokeMethod(Object target, Method method, Object[] argsArray)
           
static boolean isBoolean(String expression)
           
static boolean isFieldAccessible(OgnlContext context, Object target, Class<?> inClass, String propertyName)
           
static boolean isFieldAccessible(OgnlContext context, Object target, Field field, String propertyName)
           
static boolean isInstance(OgnlContext context, Object value, String className)
           
static boolean isJdk15()
          Deprecated. This always returns true now since OGNL requires Java 1.5.
static boolean isMethodAccessible(OgnlContext context, Object target, Method method, String propertyName)
           
static boolean isMethodCallable(Method method)
          Convenience used to check if a method is volatile or synthetic so as to avoid calling un-callable methods.
static boolean isMoreSpecific(Class<?>[] classes1, Class<?>[] classes2)
          Tells whether the first array of classes is more specific than the second.
static boolean isTypeCompatible(Object object, 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 specified ClassCacheInspector with all class reflection based internal caches.
static void setCompiler(OgnlExpressionCompiler compiler)
           
static void setElementsAccessor(Class<?> clazz, ElementsAccessor accessor)
           
static boolean setFieldValue(OgnlContext context, Object target, String propertyName, Object value)
           
static void setIndexedProperty(OgnlContext context, Object source, String name, Object index, Object value)
           
static void setMethodAccessor(Class<?> clazz, MethodAccessor accessor)
           
static boolean setMethodValue(OgnlContext context, Object target, String propertyName, Object value)
           
static boolean setMethodValue(OgnlContext context, Object target, String propertyName, Object value, boolean checkAccessAndExistence)
           
static void setNullHandler(Class<?> clazz, NullHandler handler)
           
static void setProperty(OgnlContext context, Object target, Object name, Object value)
           
static void setPropertyAccessor(Class<?> clazz, PropertyAccessor accessor)
           
static void setSecurityManager(SecurityManager securityManager)
          Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.
static boolean shouldConvertNumericTypes(OgnlContext context)
          Compares the OgnlContext.getCurrentType() and OgnlContext.getPreviousType() class types on the stack to determine if a numeric expression should force object conversion.
static
<T> Object[]
toArray(List<T> list)
          Utility to convert a List into an Object[] array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NotFound

public static final Object NotFound
Constant expression used to indicate that a given method / property couldn't be found during reflection operations.


NoArguments

public static final Object[] NoArguments

NoConversionPossible

public static final 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 String NULL_STRING
Constant string representation of null string.


SET_PREFIX

public static final String SET_PREFIX
Java beans standard set method prefix.

See Also:
Constant Field Values

GET_PREFIX

public static final String GET_PREFIX
Java beans standard get method prefix.

See Also:
Constant Field Values

IS_PREFIX

public static final String IS_PREFIX
Java beans standard is boolean getter prefix.

See Also:
Constant Field Values
Constructor Detail

OgnlRuntime

public OgnlRuntime()
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.


isJdk15

public static boolean isJdk15()
Deprecated. This always returns true now since OGNL requires Java 1.5.

Returns:
Always returns true.

getNumericValueGetter

public static String getNumericValueGetter(Class<?> type)

getPrimitiveWrapperClass

public static Class<?> getPrimitiveWrapperClass(Class<?> primitiveClass)

getNumericCast

public static String getNumericCast(Class<? extends Number> type)

getNumericLiteral

public static String getNumericLiteral(Class<? extends Number> type)

setCompiler

public static void setCompiler(OgnlExpressionCompiler compiler)

getCompiler

public static OgnlExpressionCompiler getCompiler()
Deprecated. use getCompiler(OgnlContext) instead


getCompiler

public static OgnlExpressionCompiler getCompiler(OgnlContext ognlContext)

compileExpression

public static void compileExpression(OgnlContext context,
                                     Node expression,
                                     Object root)
                              throws Exception
Throws:
Exception

getTargetClass

public static Class<?> getTargetClass(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 String getBaseName(Object o)
Returns the base name (the class name without the package name prepended) of the object given.


getClassBaseName

public static String getClassBaseName(Class<?> clazz)
Returns the base name (the class name without the package name prepended) of the class given.


getClassName

public static String getClassName(Object object,
                                  boolean fullyQualified)

getClassName

public static String getClassName(Class<?> clazz,
                                  boolean fullyQualified)

getPackageName

public static String getPackageName(Object object)
Returns the package name of the object's class.


getClassPackageName

public static String getClassPackageName(Class<?> clazz)
Returns the package name of the class given.


getPointerString

public static String getPointerString(int num)
Returns a "pointer" string in the usual format for these things - 0x.


getPointerString

public static String getPointerString(Object object)
Returns a "pointer" string in the usual format for these things - 0x for the object given. This will always return a unique value for each object.


getUniqueDescriptor

public static String getUniqueDescriptor(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 String getUniqueDescriptor(Object object)
Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.


toArray

public static <T> Object[] toArray(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 Class<?>[] getParameterTypes(Method method)
                                    throws CacheException
Returns the parameter types of the given method.

Throws:
CacheException

findParameterTypes

public static Class<?>[] findParameterTypes(Class<?> type,
                                            Method method)
                                     throws CacheException
Finds the appropriate parameter types for the given Method and Class 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 Class<?>[] getParameterTypes(Constructor<?> constructor)
                                    throws CacheException
Returns the parameter types of the given method.

Parameters:
constructor -
Returns:
Throws:
CacheException

getSecurityManager

public static SecurityManager getSecurityManager()
Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.

Returns:
SecurityManager for OGNL

setSecurityManager

public static void setSecurityManager(SecurityManager securityManager)
Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.

Parameters:
securityManager - SecurityManager to set

getPermission

public static Permission getPermission(Method method)
                                throws CacheException
Permission will be named "invoke..".

Parameters:
method -
Returns:
Throws:
CacheException

invokeMethod

public static Object invokeMethod(Object target,
                                  Method method,
                                  Object[] argsArray)
                           throws InvocationTargetException,
                                  IllegalAccessException,
                                  CacheException
Throws:
InvocationTargetException
IllegalAccessException
CacheException

getArgClass

public static Class<?> getArgClass(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(Object object,
                                       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(Object[] args,
                                        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(Object[] args,
                                        Class<?>[] classes,
                                        Method method)

isMoreSpecific

public static boolean isMoreSpecific(Class<?>[] classes1,
                                     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.


getModifierString

public static String getModifierString(int modifiers)
Deprecated. This method is no longer used.

Parameters:
modifiers -
Returns:

classForName

public static Class<?> classForName(OgnlContext context,
                                    String className)
                             throws ClassNotFoundException
Throws:
ClassNotFoundException

isInstance

public static boolean isInstance(OgnlContext context,
                                 Object value,
                                 String className)
                          throws OgnlException
Throws:
OgnlException

getPrimitiveDefaultValue

public static Object getPrimitiveDefaultValue(Class<?> forClass)

getNumericDefaultValue

public static Object getNumericDefaultValue(Class<?> forClass)

getConvertedType

public static Object getConvertedType(OgnlContext context,
                                      Object target,
                                      Member member,
                                      String propertyName,
                                      Object value,
                                      Class<?> type)

getConvertedTypes

public static boolean getConvertedTypes(OgnlContext context,
                                        Object target,
                                        Member member,
                                        String propertyName,
                                        Class<?>[] parameterTypes,
                                        Object[] args,
                                        Object[] newArgs)

getConvertedMethodAndArgs

public static Method getConvertedMethodAndArgs(OgnlContext context,
                                               Object target,
                                               String propertyName,
                                               List<Method> methods,
                                               Object[] args,
                                               Object[] newArgs)

getConvertedConstructorAndArgs

public static Constructor<?> getConvertedConstructorAndArgs(OgnlContext context,
                                                            Object target,
                                                            List<Constructor<?>> constructors,
                                                            Object[] args,
                                                            Object[] newArgs)

getAppropriateMethod

public static Method getAppropriateMethod(OgnlContext context,
                                          Object source,
                                          Object target,
                                          String propertyName,
                                          List<Method> methods,
                                          Object[] args,
                                          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 Object callAppropriateMethod(OgnlContext context,
                                           Object source,
                                           Object target,
                                           String methodName,
                                           String propertyName,
                                           List<Method> methods,
                                           Object[] args)
                                    throws MethodFailedException
Throws:
MethodFailedException

callStaticMethod

public static Object callStaticMethod(OgnlContext context,
                                      String className,
                                      String methodName,
                                      Object[] args)
                               throws OgnlException
Throws:
OgnlException

callMethod

public static Object callMethod(OgnlContext context,
                                Object target,
                                String methodName,
                                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 Object callConstructor(OgnlContext context,
                                     String className,
                                     Object[] args)
                              throws OgnlException
Throws:
OgnlException

getMethodValue

public static Object getMethodValue(OgnlContext context,
                                    Object target,
                                    String propertyName)
                             throws OgnlException,
                                    IllegalAccessException,
                                    NoSuchMethodException,
                                    IntrospectionException
Throws:
OgnlException
IllegalAccessException
NoSuchMethodException
IntrospectionException

getMethodValue

public static Object getMethodValue(OgnlContext context,
                                    Object target,
                                    String propertyName,
                                    boolean checkAccessAndExistence)
                             throws OgnlException,
                                    IllegalAccessException,
                                    NoSuchMethodException,
                                    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
IllegalAccessException
NoSuchMethodException
IntrospectionException

setMethodValue

public static boolean setMethodValue(OgnlContext context,
                                     Object target,
                                     String propertyName,
                                     Object value)
                              throws OgnlException,
                                     IllegalAccessException,
                                     NoSuchMethodException,
                                     IntrospectionException
Throws:
OgnlException
IllegalAccessException
NoSuchMethodException
IntrospectionException

setMethodValue

public static boolean setMethodValue(OgnlContext context,
                                     Object target,
                                     String propertyName,
                                     Object value,
                                     boolean checkAccessAndExistence)
                              throws OgnlException,
                                     IllegalAccessException,
                                     NoSuchMethodException,
                                     IntrospectionException
Throws:
OgnlException
IllegalAccessException
NoSuchMethodException
IntrospectionException

getConstructors

public static List<Constructor<?>> getConstructors(Class<?> targetClass)

getMethods

public static Map<String,List<Method>> getMethods(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 List<Method> getMethods(Class<?> targetClass,
                                      String name,
                                      boolean staticMethods)

getFields

public static Map<String,Field> getFields(Class<?> targetClass)

getField

public static Field getField(Class<?> inClass,
                             String name)

getFieldValue

public static Object getFieldValue(OgnlContext context,
                                   Object target,
                                   String propertyName)
                            throws NoSuchFieldException
Throws:
NoSuchFieldException

getFieldValue

public static Object getFieldValue(OgnlContext context,
                                   Object target,
                                   String propertyName,
                                   boolean checkAccessAndExistence)
                            throws NoSuchFieldException
Throws:
NoSuchFieldException

setFieldValue

public static boolean setFieldValue(OgnlContext context,
                                    Object target,
                                    String propertyName,
                                    Object value)
                             throws OgnlException
Throws:
OgnlException

isFieldAccessible

public static boolean isFieldAccessible(OgnlContext context,
                                        Object target,
                                        Class<?> inClass,
                                        String propertyName)

isFieldAccessible

public static boolean isFieldAccessible(OgnlContext context,
                                        Object target,
                                        Field field,
                                        String propertyName)

hasField

public static boolean hasField(OgnlContext context,
                               Object target,
                               Class<?> inClass,
                               String propertyName)

getStaticField

public static Object getStaticField(OgnlContext context,
                                    String className,
                                    String fieldName)
                             throws OgnlException
Throws:
OgnlException

getDeclaredMethods

public static List<Method> getDeclaredMethods(Class<?> targetClass,
                                              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(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 Method getGetMethod(OgnlContext unused,
                                  Class<?> targetClass,
                                  String propertyName)
                           throws IntrospectionException,
                                  OgnlException
Throws:
IntrospectionException
OgnlException

isMethodAccessible

public static boolean isMethodAccessible(OgnlContext context,
                                         Object target,
                                         Method method,
                                         String propertyName)

hasGetMethod

public static boolean hasGetMethod(OgnlContext context,
                                   Object target,
                                   Class<?> targetClass,
                                   String propertyName)
                            throws IntrospectionException,
                                   OgnlException
Throws:
IntrospectionException
OgnlException

getSetMethod

public static Method getSetMethod(OgnlContext context,
                                  Class<?> targetClass,
                                  String propertyName)
                           throws IntrospectionException,
                                  OgnlException
Throws:
IntrospectionException
OgnlException

hasSetMethod

public static boolean hasSetMethod(OgnlContext context,
                                   Object target,
                                   Class<?> targetClass,
                                   String propertyName)
                            throws IntrospectionException,
                                   OgnlException
Throws:
IntrospectionException
OgnlException

hasGetProperty

public static boolean hasGetProperty(OgnlContext context,
                                     Object target,
                                     Object oname)
                              throws IntrospectionException,
                                     OgnlException
Throws:
IntrospectionException
OgnlException

hasSetProperty

public static boolean hasSetProperty(OgnlContext context,
                                     Object target,
                                     Object oname)
                              throws IntrospectionException,
                                     OgnlException
Throws:
IntrospectionException
OgnlException

getPropertyDescriptors

public static Map<String,PropertyDescriptor> getPropertyDescriptors(Class<?> targetClass)
                                                             throws 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:
IntrospectionException - on errors using Introspector.
OgnlException - On general errors.

getPropertyDescriptor

public static PropertyDescriptor getPropertyDescriptor(Class<?> targetClass,
                                                       String propertyName)
                                                throws 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:
IntrospectionException
OgnlException

getPropertyDescriptorsArray

public static PropertyDescriptor[] getPropertyDescriptorsArray(Class<?> targetClass)
                                                        throws IntrospectionException,
                                                               OgnlException
Throws:
IntrospectionException
OgnlException

getPropertyDescriptorFromArray

public static PropertyDescriptor getPropertyDescriptorFromArray(Class<?> targetClass,
                                                                String name)
                                                         throws IntrospectionException,
                                                                OgnlException
Gets the property descriptor with the given name for the target class given.

Parameters:
targetClass - Class for which property descriptor is desired
name - Name of property
Returns:
PropertyDescriptor of the named property or null if the class has no property with the given name
Throws:
IntrospectionException
OgnlException

setMethodAccessor

public static void setMethodAccessor(Class<?> clazz,
                                     MethodAccessor accessor)

getMethodAccessor

public static MethodAccessor getMethodAccessor(Class<?> clazz)
                                        throws OgnlException
Throws:
OgnlException

setPropertyAccessor

public static void setPropertyAccessor(Class<?> clazz,
                                       PropertyAccessor accessor)

getPropertyAccessor

public static PropertyAccessor getPropertyAccessor(Class<?> clazz)
                                            throws OgnlException
Throws:
OgnlException

getElementsAccessor

public static ElementsAccessor getElementsAccessor(Class<?> clazz)
                                            throws OgnlException
Throws:
OgnlException

setElementsAccessor

public static void setElementsAccessor(Class<?> clazz,
                                       ElementsAccessor accessor)

getNullHandler

public static NullHandler getNullHandler(Class<?> clazz)
                                  throws OgnlException
Throws:
OgnlException

setNullHandler

public static void setNullHandler(Class<?> clazz,
                                  NullHandler handler)

getProperty

public static Object getProperty(OgnlContext context,
                                 Object source,
                                 Object name)
                          throws OgnlException
Throws:
OgnlException

setProperty

public static void setProperty(OgnlContext context,
                               Object target,
                               Object name,
                               Object value)
                        throws OgnlException
Throws:
OgnlException

getIndexedPropertyType

public static int getIndexedPropertyType(OgnlContext context,
                                         Class<?> sourceClass,
                                         String name)
                                  throws OgnlException
Determines the index property type, if any. Returns INDEXED_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 (returns INDEXED_PROPERTY_INT) or if it conforms to the OGNL arbitrary object indexable (returns INDEXED_PROPERTY_OBJECT).

Throws:
OgnlException

getIndexedProperty

public static Object getIndexedProperty(OgnlContext context,
                                        Object source,
                                        String name,
                                        Object index)
                                 throws OgnlException
Throws:
OgnlException

setIndexedProperty

public static void setIndexedProperty(OgnlContext context,
                                      Object source,
                                      String name,
                                      Object index,
                                      Object value)
                               throws OgnlException
Throws:
OgnlException

getEvaluationPool

public static EvaluationPool getEvaluationPool()

getObjectArrayPool

public static ObjectArrayPool getObjectArrayPool()

setClassCacheInspector

public static void setClassCacheInspector(ClassCacheInspector inspector)
Registers the specified ClassCacheInspector 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 Method getMethod(OgnlContext context,
                               Class<?> target,
                               String name,
                               Node[] children,
                               boolean includeStatic)
                        throws Exception
Throws:
Exception

getReadMethod

public static Method getReadMethod(Class<?> target,
                                   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 Method getReadMethod(Class<?> target,
                                   String name,
                                   int numParms)

getWriteMethod

public static Method getWriteMethod(Class<?> target,
                                    String name)

getWriteMethod

public static Method getWriteMethod(Class<?> target,
                                    String name,
                                    int numParms)

getProperty

public static PropertyDescriptor getProperty(Class<?> target,
                                             String name)

isBoolean

public static boolean isBoolean(String expression)

shouldConvertNumericTypes

public static boolean shouldConvertNumericTypes(OgnlContext context)
Compares the OgnlContext.getCurrentType() and OgnlContext.getPreviousType() class types on the stack to determine if a numeric expression should force object conversion.

Normally used in conjunction with the forceConversion parameter of getChildSource(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 String getChildSource(OgnlContext context,
                                    Object target,
                                    Node child)
                             throws OgnlException
Attempts to get the java source string represented by the specific child expression via the JavaSource.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 of OgnlOps.convertValue(Object, Class, boolean) for conversions.
Throws:
OgnlException - Mandatory exception throwing catching.. (blehh)

getChildSource

public static String getChildSource(OgnlContext context,
                                    Object target,
                                    Node child,
                                    boolean forceConversion)
                             throws OgnlException
Attempts to get the java source string represented by the specific child expression via the JavaSource.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, forces OgnlOps.convertValue(Object, Class) conversions on the objects.
Returns:
The result of calling JavaSource.toGetSourceString(OgnlContext, Object) plus additional enclosures of OgnlOps.convertValue(Object, Class, boolean) for conversions.
Throws:
OgnlException - Mandatory exception throwing catching.. (blehh)


Copyright © 1997-2013 The Apache Software Foundation. All Rights Reserved.