Package ognl
Class OgnlRuntime
- java.lang.Object
-
- ognl.OgnlRuntime
-
public class OgnlRuntime extends java.lang.ObjectUtility 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 global
TypeConverter/OgnlExpressionCompiler/NullHandlerinstances / etc..
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOgnlRuntime.ArgsCompatbilityReportTells 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.private static classOgnlRuntime.ClassPropertyMethodCacheprivate static classOgnlRuntime.MatchingMethod
-
Field Summary
Fields Modifier and Type Field Description private static AccessibleObjectHandler_accessibleObjectHandler(package private) static ClassCacheInspector_cacheInspectorprivate static OgnlExpressionCompiler_compilerExpression compiler used byOgnl.compileExpression(OgnlContext, Object, String)calls.(package private) static ClassCache_constructorCache(package private) static java.util.Map_ctorParameterTypesCache(package private) static ClassCache[]_declaredMethodsprivate static boolean_disableOgnlSecurityManagerOnInitHold environment flag state associated with OGNL_SECURITY_MANAGER.(package private) static ClassCache_elementsAccessors(package private) static EvaluationPool_evaluationPool(package private) static ClassCache_fieldCache(package private) static java.util.Map_genericMethodParameterTypesCache(package private) static ClassCache_instanceMethodCache(package private) static ClassCache_invokePermissionCacheprivate static boolean_jdk15Used to store the result of determining if current jvm is 1.5 language compatible.private static boolean_jdk9Plusprivate static boolean_jdkCheckedprivate static int_majorJavaVersion(package private) static java.util.Map<java.lang.reflect.Method,java.lang.Boolean>_methodAccessCache(package private) static ClassCache_methodAccessors(package private) static java.util.Map_methodParameterTypesCache(package private) static java.util.Map<java.lang.reflect.Method,java.lang.Boolean>_methodPermCache(package private) static ClassCache_nullHandlers(package private) static ObjectArrayPool_objectArrayPool(package private) static ClassCache_primitiveDefaults(package private) static java.util.Map_primitiveTypes(package private) static ClassCache_propertyAccessors(package private) static ClassCache_propertyDescriptorCache(package private) static java.lang.SecurityManager_securityManager(package private) static ClassCache_staticMethodCache(package private) static java.util.List_superclassesprivate static boolean_useFirstMatchGetSetLookupHold environment flag state associated with USE_FIRSTMATCH_GETSET_LOOKUP.private static boolean_useJDK9PlusAccessHandlerHold environment flag state associated with USE_JDK9PLUS_ACESS_HANDLER.private static boolean_useStricterInvocationHold environment flag state associated with USE_STRICTER_INVOCATION.private static java.lang.reflect.MethodAO_SETACCESSIBLE_ARR_REFprivate static java.lang.reflect.MethodAO_SETACCESSIBLE_REF(package private) static OgnlRuntime.ClassPropertyMethodCachecacheGetMethod(package private) static OgnlRuntime.ClassPropertyMethodCachecacheSetMethodprivate static java.lang.Class[]EMPTY_CLASS_ARRAYprivate static java.lang.StringGET_PREFIXJava beans standard get method prefix.private static intHEX_LENGTHprivate static java.util.MapHEX_PADDINGPrefix padding for hexadecimal numbers to HEX_LENGTH.static intINDEXED_PROPERTY_INTJavaBeans IndexedPropertystatic intINDEXED_PROPERTY_NONENot an indexed propertystatic intINDEXED_PROPERTY_OBJECTOGNL ObjectIndexedPropertyprivate static java.lang.StringIS_PREFIXJava beans standard isboolean getter prefix. static OgnlRuntime.ArgsCompatbilityReportNoArgsReportstatic java.lang.Object[]NoArgumentsstatic java.lang.Class[]NoArgumentTypesstatic java.lang.ObjectNoConversionPossibleToken returned by TypeConverter for no conversion possiblestatic java.lang.ObjectNotFoundConstant expression used to indicate that a given method / property couldn't be found during reflection operations.static java.util.ListNotFoundListstatic java.util.MapNotFoundMapprivate static java.lang.StringNULL_OBJECT_STRINGReturned bygetUniqueDescriptor()when the object isnull.static java.lang.StringNULL_STRINGConstant string representation of null string.private static java.util.MapNUMERIC_CASTSprivate static java.util.MapNUMERIC_DEFAULTSprivate static java.util.MapNUMERIC_LITERALSprivate static java.util.MapNUMERIC_VALUES(package private) static java.lang.StringOGNL_SECURITY_MANAGERControl usage of the OGNL Security Manager using the JVM option: -Dognl.security.manager=true (or any non-null value other than 'disable') Omit '-Dognl.security.manager=' or nullify the property to disable the feature.(package private) static java.lang.StringOGNL_SM_FORCE_DISABLE_ON_INITprivate static java.util.IdentityHashMapPRIMITIVE_WRAPPER_CLASSESprivate static java.lang.StringSET_PREFIXJava beans standard set method prefix.private static java.lang.reflect.MethodSYS_CONSOLE_REFPrivate references for use in blocking direct invocation by invokeMethod().private static java.lang.reflect.MethodSYS_EXIT_REF(package private) static java.lang.StringUSE_FIRSTMATCH_GETSET_LOOKUPAllow users to revert to the old "first match" lookup for getters/setters by OGNL using the JVM options: -Dognl.UseFirstMatchGetSetLookup=true -Dognl.UseFirstMatchGetSetLookup=false Note: Using the "false" value has the same effect as omitting the option completely.(package private) static java.lang.StringUSE_JDK9PLUS_ACESS_HANDLERControl usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=false Note: Set to "true" to allow the new JDK9 and later behaviour, provided a newer JDK9+ is detected.(package private) static java.lang.StringUSE_STRICTER_INVOCATIONControl usage of "stricter" invocation processing by invokeMethod() using the JVM options: -Dognl.UseStricterInvocation=true -Dognl.UseStricterInvocation=false Note: Using the "true" value has the same effect as omitting the option completely.
-
Constructor Summary
Constructors Constructor Description OgnlRuntime()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static java.lang.reflect.Method_getGetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName)Returns a qualifying get (getter) method, if one is available for the given targetClass and propertyName.private static java.lang.reflect.Method_getSetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName)Returns a qualifying set (setter) method, if one is available for the given targetClass and propertyName.private static voidaddIfAccessor(java.util.List result, java.lang.reflect.Method method, java.lang.String baseName, boolean findSets)private static voidaddMethodToResult(java.util.Map result, java.lang.reflect.Method method)static OgnlRuntime.ArgsCompatbilityReportareArgsCompatible(java.lang.Class[] args, java.lang.Class[] classes, java.lang.reflect.Method m)static booleanareArgsCompatible(java.lang.Object[] args, java.lang.Class[] classes)static java.lang.ObjectcallAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String methodName, java.lang.String propertyName, java.util.List methods, java.lang.Object[] args)static java.lang.ObjectcallConstructor(OgnlContext context, java.lang.String className, java.lang.Object[] args)static java.lang.ObjectcallMethod(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.ObjectcallMethod(OgnlContext context, java.lang.Object target, java.lang.String methodName, java.lang.String propertyName, java.lang.Object[] args)Deprecated.UsecallMethod(OgnlContext, Object, String, Object[])instead.static java.lang.ObjectcallStaticMethod(OgnlContext context, java.lang.String className, java.lang.String methodName, java.lang.Object[] args)private static java.lang.StringcapitalizeBeanPropertyName(java.lang.String propertyName)static java.lang.ClassclassForName(OgnlContext context, java.lang.String className)static voidclearAdditionalCache()Clears some additional caches used by OgnlRuntime.static voidclearCache()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.private static voidcollectAccessors(java.lang.Class c, java.lang.String baseName, java.util.List result, boolean findSets)private static voidcollectMethods(java.lang.Class c, java.util.Map result, boolean staticMethods)static voidcompileExpression(OgnlContext context, Node expression, java.lang.Object root)(package private) static intdetectMajorJavaVersion()Detect the (reported) Major Java version running OGNL.private static OgnlRuntime.MatchingMethodfindBestMethod(java.util.List methods, java.lang.Class typeClass, java.lang.String name, java.lang.Class[] argClasses)(package private) static java.lang.reflect.MethodfindClosestMatchingMethod(java.lang.Class targetClass, java.lang.reflect.Method m, java.lang.String propertyName, java.lang.Class propertyType, boolean isReadMethod)(package private) static voidfindObjectIndexedPropertyDescriptors(java.lang.Class targetClass, java.util.Map intoMap)static java.lang.Class[]findParameterTypes(java.lang.Class type, java.lang.reflect.Method m)Finds the appropriate parameter types for the givenMethodandClassinstance of the type the method is associated with.(package private) static java.lang.ClassfindType(java.lang.reflect.Type[] types, java.lang.Class type)static java.util.MapgetAllMethods(java.lang.Class targetClass, boolean staticMethods)static java.util.ListgetAllMethods(java.lang.Class targetClass, java.lang.String name, boolean staticMethods)static java.lang.reflect.MethodgetAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String propertyName, java.lang.String methodName, java.util.List 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.ClassgetArgClass(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.Class[]getArgClasses(java.lang.Object[] args)static java.lang.StringgetBaseName(java.lang.Object o)Returns the base name (the class name without the package name prepended) of the object given.static java.lang.StringgetChildSource(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.StringgetChildSource(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.StringgetClassBaseName(java.lang.Class c)Returns the base name (the class name without the package name prepended) of the class given.static java.lang.StringgetClassName(java.lang.Class c, boolean fullyQualified)static java.lang.StringgetClassName(java.lang.Object o, boolean fullyQualified)static java.lang.StringgetClassPackageName(java.lang.Class c)Returns the package name of the class given.static OgnlExpressionCompilergetCompiler()static java.util.ListgetConstructors(java.lang.Class targetClass)static java.lang.reflect.ConstructorgetConvertedConstructorAndArgs(OgnlContext context, java.lang.Object target, java.util.List constructors, java.lang.Object[] args, java.lang.Object[] newArgs)static java.lang.reflect.MethodgetConvertedMethodAndArgs(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.util.List methods, java.lang.Object[] args, java.lang.Object[] newArgs)static java.lang.ObjectgetConvertedType(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName, java.lang.Object value, java.lang.Class type)static booleangetConvertedTypes(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.ListgetDeclaredMethods(java.lang.Class targetClass, java.lang.String propertyName, boolean findSets)static booleangetDisableOgnlSecurityManagerOnInitValue()Returns the value of the flag indicating whether the OGNL SecurityManager was disabled on initialization or not.static ElementsAccessorgetElementsAccessor(java.lang.Class cls)static EvaluationPoolgetEvaluationPool()static java.lang.reflect.FieldgetField(java.lang.Class inClass, java.lang.String name)static java.util.MapgetFields(java.lang.Class targetClass)static java.lang.ObjectgetFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName)Deprecated.static java.lang.ObjectgetFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, boolean checkAccessAndExistence)static java.lang.reflect.MethodgetGetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName)cache get methodsprivate static java.lang.ObjectgetHandler(java.lang.Class forClass, ClassCache handlers)static java.lang.ObjectgetIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index)static intgetIndexedPropertyType(OgnlContext context, java.lang.Class sourceClass, java.lang.String name)Determines the index property type, if any.static intgetMajorJavaVersion()Get the Major Java Version detected by OGNL.static java.lang.reflect.MethodgetMethod(OgnlContext context, java.lang.Class target, java.lang.String name, Node[] children, boolean includeStatic)static MethodAccessorgetMethodAccessor(java.lang.Class cls)static java.util.MapgetMethods(java.lang.Class targetClass, boolean staticMethods)static java.util.ListgetMethods(java.lang.Class targetClass, java.lang.String name, boolean staticMethods)static java.lang.ObjectgetMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName)Deprecated.static java.lang.ObjectgetMethodValue(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 java.lang.StringgetModifierString(int modifiers)static NullHandlergetNullHandler(java.lang.Class cls)static java.lang.StringgetNumericCast(java.lang.Class type)static java.lang.ObjectgetNumericDefaultValue(java.lang.Class forClass)static java.lang.StringgetNumericLiteral(java.lang.Class type)static java.lang.StringgetNumericValueGetter(java.lang.Class type)static ObjectArrayPoolgetObjectArrayPool()static java.lang.StringgetPackageName(java.lang.Object o)Returns the package name of the object's class.static java.lang.Class[]getParameterTypes(java.lang.reflect.Constructor c)Returns the parameter types of the given method.static java.lang.Class[]getParameterTypes(java.lang.reflect.Method m)Returns the parameter types of the given method.static java.security.PermissiongetPermission(java.lang.reflect.Method method)Permission will be named "invoke.<declaring-class>.<method-name>".static java.lang.StringgetPointerString(int num)Returns a "pointer" string in the usual format for these things - 0x<hex digits>.static java.lang.StringgetPointerString(java.lang.Object o)Returns a "pointer" string in the usual format for these things - 0x<hex digits> for the object given.static java.lang.ObjectgetPrimitiveDefaultValue(java.lang.Class forClass)static java.lang.ClassgetPrimitiveWrapperClass(java.lang.Class primitiveClass)static java.beans.PropertyDescriptorgetProperty(java.lang.Class target, java.lang.String name)static java.lang.ObjectgetProperty(OgnlContext context, java.lang.Object source, java.lang.Object name)static PropertyAccessorgetPropertyAccessor(java.lang.Class cls)static java.beans.PropertyDescriptorgetPropertyDescriptor(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.PropertyDescriptorgetPropertyDescriptorFromArray(java.lang.Class targetClass, java.lang.String name)Gets the property descriptor with the given name for the target class given.static java.util.MapgetPropertyDescriptors(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.MethodgetReadMethod(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.MethodgetReadMethod(java.lang.Class target, java.lang.String name, java.lang.Class[] argClasses)static java.lang.SecurityManagergetSecurityManager()Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.static java.lang.reflect.MethodgetSetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName)cache set methods methodstatic java.lang.ObjectgetStaticField(OgnlContext context, java.lang.String className, java.lang.String fieldName)Method name is getStaticField(), but actually behaves more like "getStaticFieldValue()".static java.lang.ClassgetTargetClass(java.lang.Object o)Gets the "target" class of an object for looking up accessors that are registered on the target.static java.lang.StringgetUniqueDescriptor(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.StringgetUniqueDescriptor(java.lang.Object object, boolean fullyQualified)Returns a unique descriptor string that includes the object's class and a unique integer identifier.static booleangetUseFirstMatchGetSetLookupValue()Returns the value of the flag indicating whether the old "first match" lookup for getters/setters is in effect or not.static booleangetUseJDK9PlusAccessHandlerValue()Returns the value of the flag indicating whether the JDK9+ access handler has been been requested (it can then be used if the Major Java Version number is 9+).static booleangetUseStricterInvocationValue()Returns the value of the flag indicating whether "stricter" invocation is in effect or not.static java.lang.reflect.MethodgetWriteMethod(java.lang.Class target, java.lang.String name)static java.lang.reflect.MethodgetWriteMethod(java.lang.Class target, java.lang.String name, java.lang.Class[] argClasses)static booleanhasField(OgnlContext context, java.lang.Object target, java.lang.Class inClass, java.lang.String propertyName)static booleanhasGetMethod(OgnlContext context, java.lang.Object target, java.lang.Class targetClass, java.lang.String propertyName)static booleanhasGetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname)static booleanhasSetMethod(OgnlContext context, java.lang.Object target, java.lang.Class targetClass, java.lang.String propertyName)static booleanhasSetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname)private static booleanindexMethodCheck(java.util.List methods)static java.lang.ObjectinvokeMethod(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] argsArray)private static java.lang.ObjectinvokeMethodInsideSandbox(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] argsArray)static booleanisBoolean(java.lang.String expression)private static booleanisDefaultMethod(java.lang.reflect.Method method)Backport of java.lang.reflect.Method#isDefault() JDK8+ supports Default Methods for interfaces.static booleanisFieldAccessible(OgnlContext context, java.lang.Object target, java.lang.Class inClass, java.lang.String propertyName)static booleanisFieldAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Field field, java.lang.String propertyName)static booleanisInstance(OgnlContext context, java.lang.Object value, java.lang.String className)static booleanisJdk9Plus()Check if the detected Major Java Version is 9 or higher (JDK 9+).static booleanisMethodAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Method method, java.lang.String propertyName)(package private) static booleanisMethodCallable(java.lang.reflect.Method m)Convenience used to check if a method is a synthetic method so as to avoid calling un-callable methods.(package private) static booleanisMethodCallable_BridgeOrNonSynthetic(java.lang.reflect.Method m)Convenience used to check if a method is either a non-synthetic method or a bridge method.static booleanisMoreSpecific(java.lang.Class[] classes1, java.lang.Class[] classes2)Tells whether the first array of classes is more specific than the second.private static booleanisNonDefaultPublicInterfaceMethod(java.lang.reflect.Method method)Determine if the provided Method is a non-Default public Interface method.static booleanisTypeCompatible(java.lang.Class parameterClass, java.lang.Class methodArgumentClass, int index, OgnlRuntime.ArgsCompatbilityReport report)static booleanisTypeCompatible(java.lang.Object object, java.lang.Class c)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.(package private) static intparseMajorJavaVersion(java.lang.String versionString)Parse a Java version string to determine the Major Java version.(package private) static java.lang.ClassresolveType(java.lang.reflect.ParameterizedType param, java.lang.reflect.TypeVariable var, java.lang.reflect.TypeVariable[] declaredTypes)static voidsetClassCacheInspector(ClassCacheInspector inspector)Registers the specifiedClassCacheInspectorwith all class reflection based internal caches.static voidsetCompiler(OgnlExpressionCompiler compiler)static voidsetElementsAccessor(java.lang.Class cls, ElementsAccessor accessor)static booleansetFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value)static voidsetIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index, java.lang.Object value)static voidsetMethodAccessor(java.lang.Class cls, MethodAccessor accessor)static booleansetMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value)Deprecated.static booleansetMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value, boolean checkAccessAndExistence)static voidsetNullHandler(java.lang.Class cls, NullHandler handler)static voidsetProperty(OgnlContext context, java.lang.Object target, java.lang.Object name, java.lang.Object value)static voidsetPropertyAccessor(java.lang.Class cls, PropertyAccessor accessor)static voidsetSecurityManager(java.lang.SecurityManager value)Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.static booleanshouldConvertNumericTypes(OgnlContext context)Compares theOgnlContext.getCurrentType()andOgnlContext.getPreviousType()class types on the stack to determine if a numeric expression should force object conversion.static java.lang.Object[]toArray(java.util.List list)Utility to convert a List into an Object[] array.static booleanusingJDK9PlusAccessHandler()Returns an indication as to whether the current state indicates the JDK9+ (9 and later) access handler is being used / should be used.
-
-
-
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.
-
NotFoundList
public static final java.util.List NotFoundList
-
NotFoundMap
public static final java.util.Map NotFoundMap
-
NoArguments
public static final java.lang.Object[] NoArguments
-
NoArgumentTypes
public static final java.lang.Class[] NoArgumentTypes
-
NoConversionPossible
public static final java.lang.Object NoConversionPossible
Token returned by TypeConverter for no conversion possible
-
INDEXED_PROPERTY_NONE
public static int INDEXED_PROPERTY_NONE
Not an indexed property
-
INDEXED_PROPERTY_INT
public static int INDEXED_PROPERTY_INT
JavaBeans IndexedProperty
-
INDEXED_PROPERTY_OBJECT
public static int INDEXED_PROPERTY_OBJECT
OGNL ObjectIndexedProperty
-
NULL_STRING
public static final java.lang.String NULL_STRING
Constant string representation of null string.
-
SET_PREFIX
private static final java.lang.String SET_PREFIX
Java beans standard set method prefix.- See Also:
- Constant Field Values
-
GET_PREFIX
private static final java.lang.String GET_PREFIX
Java beans standard get method prefix.- See Also:
- Constant Field Values
-
IS_PREFIX
private 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 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
-
_jdk15
private static boolean _jdk15
Used to store the result of determining if current jvm is 1.5 language compatible.
-
_jdkChecked
private static boolean _jdkChecked
-
USE_JDK9PLUS_ACESS_HANDLER
static final java.lang.String USE_JDK9PLUS_ACESS_HANDLER
Control usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=false Note: Set to "true" to allow the new JDK9 and later behaviour, provided a newer JDK9+ is detected. By default the standard pre-JDK9 AccessHandler will be used even when running on JDK9+, so users must "opt-in" in order to enable the alternate JDK9+ AccessHandler. Using the JDK9PlusAccessHandler may avoid / mask JDK9+ warnings of the form: "WARNING: Illegal reflective access by ognl.OgnlRuntime" or provide an alternative when running in environments set with "--illegal-access=deny". Note: The default behaviour is to use the standard pre-JDK9 access handler. Using the "false" value has the same effect as omitting the option completely. Warning: Users are strongly advised to review their code and confirm they really need the AccessHandler modifying access levels, looking at alternatives to avoid that need.- See Also:
- Constant Field Values
-
USE_STRICTER_INVOCATION
static final java.lang.String USE_STRICTER_INVOCATION
Control usage of "stricter" invocation processing by invokeMethod() using the JVM options: -Dognl.UseStricterInvocation=true -Dognl.UseStricterInvocation=false Note: Using the "true" value has the same effect as omitting the option completely. The default behaviour is to use the "stricter" invocation processing. Using the "false" value reverts to the older "less strict" invocation processing (in the event the "stricter" processing causes issues for existing applications).- See Also:
- Constant Field Values
-
_useJDK9PlusAccessHandler
private static final boolean _useJDK9PlusAccessHandler
Hold environment flag state associated with USE_JDK9PLUS_ACESS_HANDLER. Default: false (if not set)
-
_useStricterInvocation
private static final boolean _useStricterInvocation
Hold environment flag state associated with USE_STRICTER_INVOCATION. Default: true (if not set)
-
_majorJavaVersion
private static final int _majorJavaVersion
-
_jdk9Plus
private static final boolean _jdk9Plus
-
_accessibleObjectHandler
private static final AccessibleObjectHandler _accessibleObjectHandler
-
SYS_CONSOLE_REF
private static final java.lang.reflect.Method SYS_CONSOLE_REF
Private references for use in blocking direct invocation by invokeMethod().
-
SYS_EXIT_REF
private static final java.lang.reflect.Method SYS_EXIT_REF
-
AO_SETACCESSIBLE_REF
private static final java.lang.reflect.Method AO_SETACCESSIBLE_REF
-
AO_SETACCESSIBLE_ARR_REF
private static final java.lang.reflect.Method AO_SETACCESSIBLE_ARR_REF
-
OGNL_SECURITY_MANAGER
static final java.lang.String OGNL_SECURITY_MANAGER
Control usage of the OGNL Security Manager using the JVM option: -Dognl.security.manager=true (or any non-null value other than 'disable') Omit '-Dognl.security.manager=' or nullify the property to disable the feature. To forcibly disable the feature (only possible at OGNL Library initialization, use the option: -Dognl.security.manager=forceDisableOnInit Users that have their own Security Manager implementations and no intention to use the OGNL SecurityManager sandbox may choose to use the 'forceDisableOnInit' flag option for performance reasons (avoiding overhead involving the system property security checks - when that feature will not be used).- See Also:
- Constant Field Values
-
OGNL_SM_FORCE_DISABLE_ON_INIT
static final java.lang.String OGNL_SM_FORCE_DISABLE_ON_INIT
- See Also:
- Constant Field Values
-
_disableOgnlSecurityManagerOnInit
private static final boolean _disableOgnlSecurityManagerOnInit
Hold environment flag state associated with OGNL_SECURITY_MANAGER. SeeOGNL_SECURITY_MANAGERfor more details. Default: false (if not set).
-
USE_FIRSTMATCH_GETSET_LOOKUP
static final java.lang.String USE_FIRSTMATCH_GETSET_LOOKUP
Allow users to revert to the old "first match" lookup for getters/setters by OGNL using the JVM options: -Dognl.UseFirstMatchGetSetLookup=true -Dognl.UseFirstMatchGetSetLookup=false Note: Using the "false" value has the same effect as omitting the option completely. The default behaviour is to use the "best match" lookup for getters/setters. Using the "true" value reverts to the older "first match" lookup for getters/setters (in the event the "best match" processing causes issues for existing applications).- See Also:
- Constant Field Values
-
_useFirstMatchGetSetLookup
private static final boolean _useFirstMatchGetSetLookup
Hold environment flag state associated with USE_FIRSTMATCH_GETSET_LOOKUP. Default: false (if not set)
-
_methodAccessors
static final ClassCache _methodAccessors
-
_propertyAccessors
static final ClassCache _propertyAccessors
-
_elementsAccessors
static final ClassCache _elementsAccessors
-
_nullHandlers
static final ClassCache _nullHandlers
-
_propertyDescriptorCache
static final ClassCache _propertyDescriptorCache
-
_constructorCache
static final ClassCache _constructorCache
-
_staticMethodCache
static final ClassCache _staticMethodCache
-
_instanceMethodCache
static final ClassCache _instanceMethodCache
-
_invokePermissionCache
static final ClassCache _invokePermissionCache
-
_fieldCache
static final ClassCache _fieldCache
-
_superclasses
static final java.util.List _superclasses
-
_declaredMethods
static final ClassCache[] _declaredMethods
-
_primitiveTypes
static final java.util.Map _primitiveTypes
-
_primitiveDefaults
static final ClassCache _primitiveDefaults
-
_methodParameterTypesCache
static final java.util.Map _methodParameterTypesCache
-
_genericMethodParameterTypesCache
static final java.util.Map _genericMethodParameterTypesCache
-
_ctorParameterTypesCache
static final java.util.Map _ctorParameterTypesCache
-
_securityManager
static java.lang.SecurityManager _securityManager
-
_evaluationPool
static final EvaluationPool _evaluationPool
-
_objectArrayPool
static final ObjectArrayPool _objectArrayPool
-
_methodAccessCache
static final java.util.Map<java.lang.reflect.Method,java.lang.Boolean> _methodAccessCache
-
_methodPermCache
static final java.util.Map<java.lang.reflect.Method,java.lang.Boolean> _methodPermCache
-
cacheSetMethod
static final OgnlRuntime.ClassPropertyMethodCache cacheSetMethod
-
cacheGetMethod
static final OgnlRuntime.ClassPropertyMethodCache cacheGetMethod
-
_cacheInspector
static ClassCacheInspector _cacheInspector
-
_compiler
private static OgnlExpressionCompiler _compiler
Expression compiler used byOgnl.compileExpression(OgnlContext, Object, String)calls.
-
EMPTY_CLASS_ARRAY
private static final java.lang.Class[] EMPTY_CLASS_ARRAY
-
PRIMITIVE_WRAPPER_CLASSES
private static java.util.IdentityHashMap PRIMITIVE_WRAPPER_CLASSES
-
NUMERIC_CASTS
private static final java.util.Map NUMERIC_CASTS
-
NUMERIC_VALUES
private static final java.util.Map NUMERIC_VALUES
-
NUMERIC_LITERALS
private static final java.util.Map NUMERIC_LITERALS
-
NUMERIC_DEFAULTS
private static final java.util.Map NUMERIC_DEFAULTS
-
NoArgsReport
public static final OgnlRuntime.ArgsCompatbilityReport NoArgsReport
-
-
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.
-
clearAdditionalCache
public static void clearAdditionalCache()
Clears some additional caches used by OgnlRuntime. The existingclearCache()clears the standard reflection-related caches, but some applications may have need to clear the additional caches as well. Clearing the additional caches may have greater impact than theclearCache()method so it should only be used when the normal cache clear is insufficient.Warning: Calling this method too often can be a huge performance drain on your expressions - use with care.
- Since:
- 3.1.25
-
getMajorJavaVersion
public static int getMajorJavaVersion()
Get the Major Java Version detected by OGNL.- Returns:
- Detected Major Java Version, or 5 (minimum supported version for OGNL) if unable to detect.
-
isJdk9Plus
public static boolean isJdk9Plus()
Check if the detected Major Java Version is 9 or higher (JDK 9+).- Returns:
- Return true if the Detected Major Java version is 9 or higher, otherwise false.
-
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 type)
-
getNumericLiteral
public static java.lang.String getNumericLiteral(java.lang.Class type)
-
setCompiler
public static void setCompiler(OgnlExpressionCompiler compiler)
-
getCompiler
public static OgnlExpressionCompiler getCompiler()
-
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.- Parameters:
o- the Object from which to retrieve its Class.- Returns:
- the Class of o.
-
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.- Parameters:
o- the Object from which to retrieve its base classname.- Returns:
- the base classname of o's Class.
-
getClassBaseName
public static java.lang.String getClassBaseName(java.lang.Class c)
Returns the base name (the class name without the package name prepended) of the class given.- Parameters:
c- the Class from which to retrieve its name.- Returns:
- the base classname of c.
-
getClassName
public static java.lang.String getClassName(java.lang.Object o, boolean fullyQualified)
-
getClassName
public static java.lang.String getClassName(java.lang.Class c, boolean fullyQualified)
-
getPackageName
public static java.lang.String getPackageName(java.lang.Object o)
Returns the package name of the object's class.- Parameters:
o- the Object from which to retrieve its Class package name.- Returns:
- the package name of o's Class.
-
getClassPackageName
public static java.lang.String getClassPackageName(java.lang.Class c)
Returns the package name of the class given.- Parameters:
c- the Class from which to retrieve its package name.- Returns:
- the package name of c.
-
getPointerString
public static java.lang.String getPointerString(int num)
Returns a "pointer" string in the usual format for these things - 0x<hex digits>.- Parameters:
num- the int to convert into a "pointer" string in hex format.- Returns:
- the String representing num as a "pointer" string in hex format.
-
getPointerString
public static java.lang.String getPointerString(java.lang.Object o)
Returns a "pointer" string in the usual format for these things - 0x<hex digits> for the object given. This will always return a unique value for each object.- Parameters:
o- the Object to convert into a "pointer" string in hex format.- Returns:
- the String representing o as a "pointer" string in hex format.
-
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.- Parameters:
object- the Object for which a unique descriptor string is desired.fullyQualified- true if the descriptor string is fully-qualified (package name), false for just the Class' base name.- Returns:
- the unique descriptor String for the object, qualified as per fullyQualified parameter.
-
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.- Parameters:
object- the Object for which a unique descriptor string is desired.- Returns:
- the unique descriptor String for the object, NOT fully-qualified.
-
toArray
public static java.lang.Object[] toArray(java.util.List 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.- Parameters:
list- the List to convert into an Object array.- Returns:
- the array of Objects from the list.
-
getParameterTypes
public static java.lang.Class[] getParameterTypes(java.lang.reflect.Method m)
Returns the parameter types of the given method.- Parameters:
m- the Method whose parameter types are being queried.- Returns:
- the array of Class elements representing m's parameters. May be null if m does not utilize parameters.
-
findParameterTypes
public static java.lang.Class[] findParameterTypes(java.lang.Class type, java.lang.reflect.Method m)Finds the appropriate parameter types for the givenMethodandClassinstance 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.m- The method to find types for.- Returns:
- Array of parameter types for the given method.
-
resolveType
static java.lang.Class resolveType(java.lang.reflect.ParameterizedType param, java.lang.reflect.TypeVariable var, java.lang.reflect.TypeVariable[] declaredTypes)
-
findType
static java.lang.Class findType(java.lang.reflect.Type[] types, java.lang.Class type)
-
getParameterTypes
public static java.lang.Class[] getParameterTypes(java.lang.reflect.Constructor c)
Returns the parameter types of the given method.- Parameters:
c- the Constructor whose parameter types are being queried.- Returns:
- the array of Class elements representing c's parameters. May be null if c does not utilize parameters.
-
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 value)
Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Parameters:
value- SecurityManager to set
-
getPermission
public static java.security.Permission getPermission(java.lang.reflect.Method method)
Permission will be named "invoke.<declaring-class>.<method-name>".- Parameters:
method- the Method whose Permission is being requested.- Returns:
- the Permission for method named "invoke.<declaring-class>.<method-name>".
-
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- Throws:
java.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
invokeMethodInsideSandbox
private static java.lang.Object invokeMethodInsideSandbox(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] argsArray) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException- Throws:
java.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
getArgClass
public static final 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
-
getArgClasses
public static java.lang.Class[] getArgClasses(java.lang.Object[] args)
-
isTypeCompatible
public static final boolean isTypeCompatible(java.lang.Object object, java.lang.Class c)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.- Parameters:
object- the Object to check for type-compatibility with Class c.c- the Class for which object's type-compatibility is being checked.- Returns:
- true if object is type-compatible with c.
-
isTypeCompatible
public static final boolean isTypeCompatible(java.lang.Class parameterClass, java.lang.Class methodArgumentClass, int index, OgnlRuntime.ArgsCompatbilityReport report)
-
areArgsCompatible
public static boolean areArgsCompatible(java.lang.Object[] args, java.lang.Class[] classes)
-
areArgsCompatible
public static OgnlRuntime.ArgsCompatbilityReport areArgsCompatible(java.lang.Class[] args, java.lang.Class[] classes, java.lang.reflect.Method m)
-
isMoreSpecific
public static final 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.- Parameters:
classes1- the Class array being checked to see if it is "more specific" than classes2.classes2- the Class array that classes1 is being checked against to see if classes1 is "more specific" than classes2.- Returns:
- true if the classes1 Class contents are "more specific" than classes2 Class contents, false otherwise.
-
getModifierString
public static java.lang.String getModifierString(int modifiers)
-
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)
-
getConvertedConstructorAndArgs
public static java.lang.reflect.Constructor getConvertedConstructorAndArgs(OgnlContext context, java.lang.Object target, java.util.List 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.lang.String methodName, java.util.List 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.methodName- Name of the method to get from known methods.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.
-
getConvertedMethodAndArgs
public static java.lang.reflect.Method getConvertedMethodAndArgs(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.util.List methods, java.lang.Object[] args, java.lang.Object[] newArgs)
-
findBestMethod
private static OgnlRuntime.MatchingMethod findBestMethod(java.util.List methods, java.lang.Class typeClass, java.lang.String name, java.lang.Class[] argClasses)
-
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 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.String propertyName, java.lang.Object[] args) throws OgnlException
Deprecated.UsecallMethod(OgnlContext, Object, String, Object[])instead.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..propertyName- Name of the property to call instead?args- Optional arguments needed for method.- Returns:
- Result of invoking method.
- Throws:
OgnlException- For lots of different reasons.
-
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
@Deprecated public static final 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
Deprecated.Don't use this method as it doesn't check member access rights viaMemberAccessinterface- Parameters:
context- the current execution context.target- the object to invoke the property name get on.propertyName- the name of the property to be retrieved from target.- Returns:
- the result invoking property retrieval of propertyName for target.
- Throws:
OgnlException- for lots of different reasons.java.lang.IllegalAccessException- if access not permitted.java.lang.NoSuchMethodException- if no property accessor exists.java.beans.IntrospectionException- on errors usingIntrospector.
-
getMethodValue
public static final 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.- Parameters:
context- the current execution context.target- the object to invoke the property name get on.propertyName- the name of the property to be retrieved from target.checkAccessAndExistence- true if this method should check access levels and existence for propertyName of target, false otherwise.- Returns:
- the result invoking property retrieval of propertyName for target.
- Throws:
OgnlException- for lots of different reasons.java.lang.IllegalAccessException- if access not permitted.java.lang.NoSuchMethodException- if no property accessor exists.java.beans.IntrospectionException- on errors usingIntrospector.
-
setMethodValue
@Deprecated 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
Deprecated.Don't use this method as it doesn't check member access rights viaMemberAccessinterface- Parameters:
context- the current execution context.target- the object to invoke the property name get on.propertyName- the name of the property to be set for target.value- the value to set for propertyName of target.- Returns:
- true if the operation succeeded, false otherwise.
- Throws:
OgnlException- for lots of different reasons.java.lang.IllegalAccessException- if access not permitted.java.lang.NoSuchMethodException- if no property accessor exists.java.beans.IntrospectionException- on errors usingIntrospector.
-
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:
OgnlExceptionjava.lang.IllegalAccessExceptionjava.lang.NoSuchMethodExceptionjava.beans.IntrospectionException
-
getConstructors
public static java.util.List getConstructors(java.lang.Class targetClass)
-
getMethods
public static java.util.Map getMethods(java.lang.Class targetClass, boolean staticMethods)
-
collectMethods
private static void collectMethods(java.lang.Class c, java.util.Map result, boolean staticMethods)
-
addMethodToResult
private static void addMethodToResult(java.util.Map result, java.lang.reflect.Method method)
-
isDefaultMethod
private static boolean isDefaultMethod(java.lang.reflect.Method method)
Backport of java.lang.reflect.Method#isDefault() JDK8+ supports Default Methods for interfaces. Default Methods are defined as: public, non-abstract and declared within an interface (must also be non-static).- Parameters:
method- The Method to check against the requirements for a Default Method.- Returns:
- true If the Method qualifies as a Default Method, false otherwise.
-
isNonDefaultPublicInterfaceMethod
private static boolean isNonDefaultPublicInterfaceMethod(java.lang.reflect.Method method)
Determine if the provided Method is a non-Default public Interface method. Public non-Default Methods are defined as: public, abstract, non-static and declared within an interface.- Parameters:
method- The Method to check against the requirements for a non-Default Method.- Returns:
- true If method qualifies as a non-Default public Interface method, false otherwise.
- Since:
- 3.1.25
-
getAllMethods
public static java.util.Map getAllMethods(java.lang.Class targetClass, boolean staticMethods)
-
getMethods
public static java.util.List getMethods(java.lang.Class targetClass, java.lang.String name, boolean staticMethods)
-
getAllMethods
public static java.util.List getAllMethods(java.lang.Class targetClass, java.lang.String name, boolean staticMethods)
-
getFields
public static java.util.Map getFields(java.lang.Class targetClass)
-
getField
public static java.lang.reflect.Field getField(java.lang.Class inClass, java.lang.String name)
-
getFieldValue
@Deprecated public static java.lang.Object getFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName) throws java.lang.NoSuchFieldException
Deprecated.Don't use this method as it doesn't check member access rights viaMemberAccessinterface- Parameters:
context- the current execution context.target- the object to invoke the property name get on.propertyName- the name of the property to be set for target.- Returns:
- the result invoking field retrieval of propertyName for target.
- Throws:
java.lang.NoSuchFieldException- if the field does not exist.
-
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
Method name is getStaticField(), but actually behaves more like "getStaticFieldValue()".Typical usage: Returns the value (not the actual
Field) for the given (static) fieldName. May return theEnumconstant value for the given fieldName when className is anEnum. May return aClassinstance when the given fieldName is "class".- Parameters:
context- The current ognl contextclassName- The name of the class which contains the fieldfieldName- The name of the field whose value should be returned- Returns:
- The value of the (static) fieldName
- Throws:
OgnlException- for lots of different reasons.
-
capitalizeBeanPropertyName
private static java.lang.String capitalizeBeanPropertyName(java.lang.String propertyName)
-
getDeclaredMethods
public static java.util.List getDeclaredMethods(java.lang.Class targetClass, java.lang.String propertyName, boolean findSets)
-
collectAccessors
private static void collectAccessors(java.lang.Class c, java.lang.String baseName, java.util.List result, boolean findSets)
-
addIfAccessor
private static void addIfAccessor(java.util.List result, java.lang.reflect.Method method, java.lang.String baseName, boolean findSets)
-
isMethodCallable
static boolean isMethodCallable(java.lang.reflect.Method m)
Convenience used to check if a method is a synthetic method so as to avoid calling un-callable methods. These methods are not considered callable by OGNL in almost all circumstances. This method considers any synthetic method (even bridge methods) as being un-callable. Even though synthetic and bridge methods can technically be called, by default OGNL excludes them from consideration. Synthetic methods should be excluded in general, since calling such methods could introduce unanticipated risks.- Parameters:
m- The method to check.- Returns:
- True if the method should be callable (non-synthetic), false otherwise.
-
isMethodCallable_BridgeOrNonSynthetic
static boolean isMethodCallable_BridgeOrNonSynthetic(java.lang.reflect.Method m)
Convenience used to check if a method is either a non-synthetic method or a bridge method. Warning: This method should NOT be used as a direct replacement forisMethodCallable(Method). Almost all OGNL processing assumes the exlcusion of synthetic methods in order to process correctly. Only use this method to determine method callability for any OGNL processing after careful consideration. This method considers synthetic methods that are not also bridge methods as being un-callable. Synthetic methods should be excluded in general, since calling such methods could introduce unanticipated risks.- Parameters:
m- The method to check.- Returns:
- True if the method should be callable (non-synethetic or bridge), false otherwise.
- Since:
- 3.2.16
-
getGetMethod
public static java.lang.reflect.Method getGetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
cache get methods- Parameters:
context- the current execution context.targetClass- the Class to invoke the property name "getter" retrieval on.propertyName- the name of the property for which a "getter" is sought.- Returns:
- the Method representing a "getter" for propertyName of targetClass.
- Throws:
OgnlException- for lots of different reasons.java.beans.IntrospectionException- on errors usingIntrospector.
-
_getGetMethod
private static java.lang.reflect.Method _getGetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
Returns a qualifying get (getter) method, if one is available for the given targetClass and propertyName. Note: From OGNL 3.1.25 onward, this method will attempt to find the first get getter method(s) that match: 1) First get (getter) method, whether public or not. 2) First public get (getter) method, provided the method's declaring class is also public. This may be the same as 1), if 1) is also public and its declaring class is also public. 3) First public non-Default interface get (getter) method, provided the method's declaring class is also public. The order of preference (priority) for the above matches will be 2 (1st public getter), 3 (1st public non-Default interface getter), 1 (1st getter of any kind). This updated methodology should help limit the need to modify method accessibility levels in some circumstances.- Parameters:
context- The current execution context.targetClass- Class to search for a get method (getter).propertyName- Name of the property for the get method (getter).- Returns:
- Throws:
java.beans.IntrospectionExceptionOgnlException
-
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.IntrospectionExceptionOgnlException
-
getSetMethod
public static java.lang.reflect.Method getSetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
cache set methods method- Parameters:
context- the current execution context.targetClass- the Class to invoke the property name "setter" retrieval on.propertyName- the name of the property for which a "setter" is sought.- Returns:
- the Method representing a "setter" for propertyName of targetClass.
- Throws:
java.beans.IntrospectionException- on errors usingIntrospector.OgnlException- for lots of different reasons.
-
_getSetMethod
private static java.lang.reflect.Method _getSetMethod(OgnlContext context, java.lang.Class targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
Returns a qualifying set (setter) method, if one is available for the given targetClass and propertyName. Note: From OGNL 3.1.25 onward, this method will attempt to find the first set setter method(s) that match: 1) First set (setter) method, whether public or not. 2) First public set (setter) method, provided the method's declaring class is also public. This may be the same as 1), if 1) is also public and its declaring class is also public. 3) First public non-Default interface set (setter) method, provided the method's declaring class is also public. The order of preference (priority) for the above matches will be 2 (1st public setter), 3 (1st public non-Default interface setter), 1 (1st setter of any kind). This updated methodology should help limit the need to modify method accessibility levels in some circumstances.- Parameters:
context- The current execution context.targetClass- Class to search for a set method (setter).propertyName- Name of the property for the set method (setter).- Returns:
- Throws:
java.beans.IntrospectionExceptionOgnlException
-
hasSetMethod
public static final boolean hasSetMethod(OgnlContext context, java.lang.Object target, java.lang.Class targetClass, java.lang.String propertyName) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionExceptionOgnlException
-
hasGetProperty
public static final boolean hasGetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionExceptionOgnlException
-
hasSetProperty
public static final boolean hasSetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname) throws java.beans.IntrospectionException, OgnlException
- Throws:
java.beans.IntrospectionExceptionOgnlException
-
indexMethodCheck
private static final boolean indexMethodCheck(java.util.List methods)
-
findObjectIndexedPropertyDescriptors
static void findObjectIndexedPropertyDescriptors(java.lang.Class targetClass, java.util.Map intoMap) throws OgnlException- Throws:
OgnlException
-
getPropertyDescriptors
public static java.util.Map getPropertyDescriptors(java.lang.Class targetClass) throws java.beans.IntrospectionException, OgnlExceptionThis 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, OgnlExceptionThis method returns a PropertyDescriptor for the given class and property name using a Map lookup (using getPropertyDescriptorsMap()).- Parameters:
targetClass- the class to get the descriptors for.propertyName- the property name of targetClass for which a Descriptor is requested.- Returns:
- the PropertyDescriptor for propertyName of targetClass.
- Throws:
java.beans.IntrospectionException- on errors usingIntrospector.OgnlException- On general errors.
-
findClosestMatchingMethod
static java.lang.reflect.Method findClosestMatchingMethod(java.lang.Class targetClass, java.lang.reflect.Method m, java.lang.String propertyName, java.lang.Class propertyType, boolean isReadMethod)
-
getPropertyDescriptorsArray
public static java.beans.PropertyDescriptor[] getPropertyDescriptorsArray(java.lang.Class targetClass) throws java.beans.IntrospectionException- Throws:
java.beans.IntrospectionException
-
getPropertyDescriptorFromArray
public static java.beans.PropertyDescriptor getPropertyDescriptorFromArray(java.lang.Class targetClass, java.lang.String name) throws java.beans.IntrospectionExceptionGets 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- on errors usingIntrospector.
-
setMethodAccessor
public static void setMethodAccessor(java.lang.Class cls, MethodAccessor accessor)
-
getMethodAccessor
public static MethodAccessor getMethodAccessor(java.lang.Class cls) throws OgnlException
- Throws:
OgnlException
-
setPropertyAccessor
public static void setPropertyAccessor(java.lang.Class cls, PropertyAccessor accessor)
-
getPropertyAccessor
public static PropertyAccessor getPropertyAccessor(java.lang.Class cls) throws OgnlException
- Throws:
OgnlException
-
getElementsAccessor
public static ElementsAccessor getElementsAccessor(java.lang.Class cls) throws OgnlException
- Throws:
OgnlException
-
setElementsAccessor
public static void setElementsAccessor(java.lang.Class cls, ElementsAccessor accessor)
-
getNullHandler
public static NullHandler getNullHandler(java.lang.Class cls) throws OgnlException
- Throws:
OgnlException
-
setNullHandler
public static void setNullHandler(java.lang.Class cls, NullHandler handler)
-
getHandler
private static java.lang.Object getHandler(java.lang.Class forClass, ClassCache handlers)
-
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_NONEif 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).- Parameters:
context- the current execution context.sourceClass- the Class to invoke indexed property type retrieval on.name- the name of the property for which an indexed property type is sought.- Returns:
- the indexed property type (int) for the property name of sourceClass. Returns
INDEXED_PROPERTY_NONEif name is not an indexed property. - Throws:
OgnlException- for lots of different reasons.
-
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
-
getEvaluationPool
public static EvaluationPool getEvaluationPool()
-
getObjectArrayPool
public static ObjectArrayPool getObjectArrayPool()
-
setClassCacheInspector
public static void setClassCacheInspector(ClassCacheInspector inspector)
Registers the specifiedClassCacheInspectorwith 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, java.lang.Class[] argClasses)
-
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, java.lang.Class[] argClasses)
-
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 the
forceConversionparameter 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)
-
detectMajorJavaVersion
static int detectMajorJavaVersion()
Detect the (reported) Major Java version running OGNL. Should support naming conventions of pre-JDK9 and JDK9+. See JEP 223: New Version-String Scheme for details.- Returns:
- Detected Major Java Version, or 5 (minimum supported version for OGNL) if unable to detect.
- Since:
- 3.1.25
-
parseMajorJavaVersion
static int parseMajorJavaVersion(java.lang.String versionString)
Parse a Java version string to determine the Major Java version. Should support naming conventions of pre-JDK9 and JDK9+. See JEP 223: New Version-String Scheme for details.- Returns:
- Detected Major Java Version, or 5 (minimum supported version for OGNL) if unable to detect.
- Since:
- 3.1.25
-
getUseJDK9PlusAccessHandlerValue
public static boolean getUseJDK9PlusAccessHandlerValue()
Returns the value of the flag indicating whether the JDK9+ access handler has been been requested (it can then be used if the Major Java Version number is 9+). Note: Value is controlled by a Java option flagUSE_JDK9PLUS_ACESS_HANDLER.- Returns:
- true if a request to use the JDK9+ access handler is requested, false otherwise (always use pre-JDK9 handler).
- Since:
- 3.1.25
-
getUseStricterInvocationValue
public static boolean getUseStricterInvocationValue()
Returns the value of the flag indicating whether "stricter" invocation is in effect or not. Note: Value is controlled by a Java option flagUSE_STRICTER_INVOCATION.- Returns:
- true if stricter invocation is in effect, false otherwise.
- Since:
- 3.1.25
-
getDisableOgnlSecurityManagerOnInitValue
public static boolean getDisableOgnlSecurityManagerOnInitValue()
Returns the value of the flag indicating whether the OGNL SecurityManager was disabled on initialization or not. Note: Value is controlled by a Java option flagOGNL_SECURITY_MANAGERusing the valueOGNL_SM_FORCE_DISABLE_ON_INIT.- Returns:
- true if OGNL SecurityManager was disabled on initialization, false otherwise.
- Since:
- 3.1.25
-
usingJDK9PlusAccessHandler
public static boolean usingJDK9PlusAccessHandler()
Returns an indication as to whether the current state indicates the JDK9+ (9 and later) access handler is being used / should be used. This is based on a combination of the detected Major Java Version and the Java option flagUSE_JDK9PLUS_ACESS_HANDLER.- Returns:
- true if the JDK9 and later access handler is being used / should be used, false otherwise.
- Since:
- 3.1.25
-
getUseFirstMatchGetSetLookupValue
public static boolean getUseFirstMatchGetSetLookupValue()
Returns the value of the flag indicating whether the old "first match" lookup for getters/setters is in effect or not. Note: Value is controlled by a Java option flagUSE_FIRSTMATCH_GETSET_LOOKUP.- Returns:
- true if the old "first match" lookup is in effect, false otherwise.
- Since:
- 3.1.25
-
-