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_accessibleObjectHandlerprivate static OgnlExpressionCompiler_compilerExpression compiler used byOgnl.compileExpression(OgnlContext, Object, String)calls.private static boolean_disableOgnlSecurityManagerOnInitDeprecated.will be removed in 3.5.x(package private) static EvaluationPool_evaluationPoolprivate static boolean_jdk9Plusprivate static int_majorJavaVersion(package private) static java.util.Map<java.lang.reflect.Method,java.lang.Boolean>_methodAccessCache(package private) static java.util.Map<java.lang.reflect.Method,java.lang.Boolean>_methodPermCacheprivate 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 OgnlCachecache(package private) static OgnlRuntime.ClassPropertyMethodCachecacheGetMethod(package private) static OgnlRuntime.ClassPropertyMethodCachecacheSetMethodprivate static java.lang.Class<?>[]EMPTY_CLASS_ARRAYstatic java.lang.StringGET_PREFIXJava beans standard get method prefix.private static intHEX_LENGTHprivate static java.util.Map<java.lang.Integer,java.lang.String>HEX_PADDINGPrefix padding for hexadecimal numbers to HEX_LENGTH.static intINDEXED_PROPERTY_INTJavaBeans IndexedPropertystatic intINDEXED_PROPERTY_NONENot an indexed propertystatic intINDEXED_PROPERTY_OBJECTOGNL ObjectIndexedPropertystatic java.lang.StringIS_PREFIXJava beans standardis<Foo>boolean getter prefix.static OgnlRuntime.ArgsCompatbilityReportNoArgsReportstatic java.lang.Object[]NoArgumentsstatic 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.private static java.lang.StringNULL_OBJECT_STRINGReturned bygetUniqueDescriptor()when the object isnull.static java.lang.StringNULL_STRINGConstant string representation of null string.private static NumericCastsnumericCastsConstant strings for casting different primitive types.private static NumericDefaultsnumericDefaultsprivate static NumericLiteralsnumericLiteralsNumeric primitive literal string expressions.private static NumericValuesnumericValuesConstant strings for getting the primitive value of different native types on the genericNumberobject interface.(package private) static java.lang.StringOGNL_SECURITY_MANAGERDeprecated.will removed in 3.5.x(package private) static java.lang.StringOGNL_SM_FORCE_DISABLE_ON_INITprivate static PrimitiveDefaultsprimitiveDefaultsprivate static PrimitiveTypesprimitiveTypesprivate static PrimitiveWrapperClassesprimitiveWrapperClassesUsed to provide primitive type equivalent conversions into and out of native / object types.(package private) static java.lang.SecurityManagersecurityManagerDeprecated.will be removed in 3.5.xstatic 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(package private) static java.lang.StringUSE_JDK9PLUS_ACCESS_HANDLERControl usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=false(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
-
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(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.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<java.lang.reflect.Method> 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)static <T> java.lang.Class<T>classForName(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.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<java.lang.reflect.Method> methods, java.lang.Class<?> typeClass, java.lang.String name, java.lang.Class<?>[] argClasses)static java.lang.Class<?>[]findParameterTypes(java.lang.Class<?> type, java.lang.reflect.Method method)Finds the appropriate parameter types for the givenMethodandClassinstance of the type the method is associated with.static java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>getAllMethods(java.lang.Class<?> targetClass, boolean staticMethods)Deprecated.static java.util.List<java.lang.reflect.Method>getAllMethods(java.lang.Class<?> targetClass, java.lang.String name, boolean staticMethods)Deprecated.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<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] actualArgs)Gets the appropriate method to be called for the given target, method name and arguments.static java.lang.Class<?>getArgClass(java.lang.Object arg)Gets the class for a method argument that is appropriate for looking up methods by reflection, by looking for the standard primitive wrapper classes and exchanging for them their underlying primitive class objects.static java.lang.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.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.List<java.lang.reflect.Constructor<?>>getConstructors(java.lang.Class<?> targetClass)static java.lang.reflect.Constructor<?>getConvertedConstructorAndArgs(OgnlContext context, java.lang.Object target, java.util.List<java.lang.reflect.Constructor<?>> constructors, java.lang.Object[] args, java.lang.Object[] newArgs)static java.lang.reflect.MethodgetConvertedMethodAndArgs(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] newArgs)static java.lang.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.List<java.lang.reflect.Method>getDeclaredMethods(java.lang.Class<?> targetClass, java.lang.String propertyName, boolean findSets)static booleangetDisableOgnlSecurityManagerOnInitValue()Deprecated.will be removed in 3.5.xstatic ElementsAccessorgetElementsAccessor(java.lang.Class<?> clazz)static EvaluationPoolgetEvaluationPool()static java.lang.reflect.FieldgetField(java.lang.Class<?> inClass, java.lang.String name)static java.util.Map<java.lang.String,java.lang.reflect.Field>getFields(java.lang.Class<?> targetClass)static java.lang.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(java.lang.Class<?> targetClass, java.lang.String propertyName)cache get methodsstatic java.lang.ObjectgetIndexedProperty(OgnlContext context, java.lang.Object source, java.lang.String name, java.lang.Object index)static intgetIndexedPropertyType(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<?> clazz)static java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>getMethods(java.lang.Class<?> targetClass, boolean staticMethods)static java.util.List<java.lang.reflect.Method>getMethods(java.lang.Class<?> targetClass, java.lang.String name, boolean staticMethods)static java.lang.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<?> clazz)static java.lang.StringgetNumericCast(java.lang.Class<? extends java.lang.Number> 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 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<?> constructor)Returns the parameter types of the given method.static java.lang.Class<?>[]getParameterTypes(java.lang.reflect.Method method)Returns the parameter types of the given method.static java.security.PermissiongetPermission(java.lang.reflect.Method method)Deprecated.since 3.4.6, forRemoval = truestatic 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.Class<?>getPrimitiveWrapperClass(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<?> clazz)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.Map<java.lang.String,java.beans.PropertyDescriptor>getPropertyDescriptors(java.lang.Class<?> targetClass)This method returns the property descriptors for the given class as a Map.static java.beans.PropertyDescriptor[]getPropertyDescriptorsArray(java.lang.Class<?> targetClass)static java.lang.reflect.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()Deprecated.will be removed in 3.5.xstatic 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.Class<?>getTargetClass(java.lang.Object o)Gets the "target" class of an object for looking up accessors that are registered on the target.static java.lang.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)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)private static booleanisAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName)Returns true if the given member is accessible or can be made accessible by this object.static booleanisBoolean(java.lang.String expression)private static booleanisDefaultMethod(java.lang.reflect.Method method)Backport of java.lang.reflect.Method#isDefault()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()Deprecated.since 3.4.6, forRemoval = truestatic booleanisMethodAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Method method, java.lang.String propertyName)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.static voidsetClassCacheInspector(ClassCacheInspector inspector)Registers the specifiedClassCacheInspectorwith all class reflection based internal caches.static voidsetCompiler(OgnlExpressionCompiler compiler)static voidsetElementsAccessor(java.lang.Class<?> clazz, ElementsAccessor accessor)static booleansetFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value)Deprecated.static booleansetFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value, boolean checkAccessAndExistence)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<?> clazz, 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<?> clazz, NullHandler handler)static voidsetProperty(OgnlContext context, java.lang.Object target, java.lang.Object name, java.lang.Object value)static voidsetPropertyAccessor(java.lang.Class<?> clazz, PropertyAccessor accessor)static voidsetSecurityManager(java.lang.SecurityManager value)Deprecated.will be removed in 3.5.xstatic booleanshouldConvertNumericTypes(OgnlContext context)Compares theOgnlContext.getCurrentType()andOgnlContext.getPreviousType()class types on the stack to determine if a numeric expression should force object conversion.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.
-
NoArguments
public static final java.lang.Object[] NoArguments
-
NoConversionPossible
public static final java.lang.Object NoConversionPossible
Token returned by TypeConverter for no conversion possible
-
INDEXED_PROPERTY_NONE
public static 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
public static final java.lang.String SET_PREFIX
Java beans standard set method prefix.- See Also:
- Constant Field Values
-
GET_PREFIX
public static final java.lang.String GET_PREFIX
Java beans standard get method prefix.- See Also:
- Constant Field Values
-
IS_PREFIX
public static final java.lang.String IS_PREFIX
Java beans standardis<Foo>boolean getter prefix.- See Also:
- Constant Field Values
-
HEX_PADDING
private static final java.util.Map<java.lang.Integer,java.lang.String> HEX_PADDING
Prefix padding for hexadecimal numbers to HEX_LENGTH.
-
HEX_LENGTH
private static final int HEX_LENGTH
- See Also:
- Constant Field Values
-
NULL_OBJECT_STRING
private static final java.lang.String NULL_OBJECT_STRING
Returned bygetUniqueDescriptor()when the object isnull.- See Also:
- Constant Field Values
-
USE_JDK9PLUS_ACCESS_HANDLER
static final java.lang.String USE_JDK9PLUS_ACCESS_HANDLER
Control usage of JDK9+ access handler using the JVM option: -Dognl.UseJDK9PlusAccessHandler=true -Dognl.UseJDK9PlusAccessHandler=falseNote: 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=falseNote: 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
@Deprecated static final java.lang.String OGNL_SECURITY_MANAGER
Deprecated.will removed in 3.5.xControl 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
@Deprecated private static final boolean _disableOgnlSecurityManagerOnInit
Deprecated.will be removed in 3.5.xHold 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=falseNote: 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)
-
cache
static final OgnlCache cache
-
primitiveTypes
private static final PrimitiveTypes primitiveTypes
-
primitiveDefaults
private static final PrimitiveDefaults primitiveDefaults
-
securityManager
@Deprecated static java.lang.SecurityManager securityManager
Deprecated.will be removed in 3.5.x
-
_evaluationPool
static final EvaluationPool _evaluationPool
-
_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
-
_compiler
private static OgnlExpressionCompiler _compiler
Expression compiler used byOgnl.compileExpression(OgnlContext, Object, String)calls.
-
primitiveWrapperClasses
private static final PrimitiveWrapperClasses primitiveWrapperClasses
Used to provide primitive type equivalent conversions into and out of native / object types.
-
numericCasts
private static final NumericCasts numericCasts
Constant strings for casting different primitive types.
-
numericValues
private static final NumericValues numericValues
Constant strings for getting the primitive value of different native types on the genericNumberobject interface. (or the less generic BigDecimal/BigInteger types)
-
numericLiterals
private static final NumericLiterals numericLiterals
Numeric primitive literal string expressions.
-
numericDefaults
private static final NumericDefaults numericDefaults
-
EMPTY_CLASS_ARRAY
private static final java.lang.Class<?>[] EMPTY_CLASS_ARRAY
-
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 the
clearCache()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
@Deprecated public static boolean isJdk9Plus()
Deprecated.since 3.4.6, forRemoval = trueCheck 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<? extends java.lang.Number> 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.
-
getParameterTypes
public static java.lang.Class<?>[] getParameterTypes(java.lang.reflect.Method method) throws CacheExceptionReturns the parameter types of the given method.- Parameters:
method- 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.
- Throws:
CacheException
-
findParameterTypes
public static java.lang.Class<?>[] findParameterTypes(java.lang.Class<?> type, java.lang.reflect.Method method)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.method- The method to find types for.- Returns:
- Array of parameter types for the given method.
-
getParameterTypes
public static java.lang.Class<?>[] getParameterTypes(java.lang.reflect.Constructor<?> constructor) throws CacheExceptionReturns the parameter types of the given method.- Parameters:
constructor- 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.
- Throws:
CacheException
-
getSecurityManager
@Deprecated public static java.lang.SecurityManager getSecurityManager()
Deprecated.will be removed in 3.5.xGets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Returns:
- SecurityManager for OGNL
-
setSecurityManager
@Deprecated public static void setSecurityManager(java.lang.SecurityManager value)
Deprecated.will be removed in 3.5.xSets the SecurityManager that OGNL uses to determine permissions for invoking methods.- Parameters:
value- SecurityManager to set
-
getPermission
@Deprecated public static java.security.Permission getPermission(java.lang.reflect.Method method) throws CacheExceptionDeprecated.since 3.4.6, forRemoval = truePermission 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>".
- Throws:
CacheException
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] argsArray) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException- 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 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 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 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 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 <T> java.lang.Class<T> 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<java.lang.reflect.Constructor<?>> constructors, java.lang.Object[] args, java.lang.Object[] newArgs)
-
getAppropriateMethod
public static java.lang.reflect.Method getAppropriateMethod(OgnlContext context, java.lang.Object source, java.lang.Object target, java.lang.String propertyName, java.lang.String methodName, java.util.List<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] actualArgs)
Gets the appropriate method to be called for the given target, method name and arguments. If successful this method will return the Method within the target that can be called and the converted arguments in actualArgs. If unsuccessful this method will return null and the actualArgs will be empty.- Parameters:
context- The current execution context.source- Target object to run against or method name.target- Instance of object to be run against.propertyName- Name of property to get method of.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<java.lang.reflect.Method> methods, java.lang.Object[] args, java.lang.Object[] newArgs)
-
findBestMethod
private static OgnlRuntime.MatchingMethod findBestMethod(java.util.List<java.lang.reflect.Method> 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<java.lang.reflect.Method> methods, java.lang.Object[] args) throws MethodFailedException
- Throws:
MethodFailedException
-
callStaticMethod
public static java.lang.Object callStaticMethod(OgnlContext context, java.lang.String className, java.lang.String methodName, java.lang.Object[] args) throws OgnlException
- Throws:
OgnlException
-
callMethod
public static java.lang.Object callMethod(OgnlContext context, java.lang.Object target, java.lang.String methodName, java.lang.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 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 java.lang.Object getMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, boolean checkAccessAndExistence) throws OgnlException, java.lang.IllegalAccessException, java.lang.NoSuchMethodException
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.
-
setMethodValue
@Deprecated public static boolean setMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value) throws OgnlException
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.
-
setMethodValue
public static boolean setMethodValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value, boolean checkAccessAndExistence) throws OgnlException
- Throws:
OgnlException
-
getConstructors
public static java.util.List<java.lang.reflect.Constructor<?>> getConstructors(java.lang.Class<?> targetClass)
-
getMethods
public static java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> getMethods(java.lang.Class<?> targetClass, boolean staticMethods)
-
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
@Deprecated public static java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> getAllMethods(java.lang.Class<?> targetClass, boolean staticMethods)Deprecated.
-
getMethods
public static java.util.List<java.lang.reflect.Method> getMethods(java.lang.Class<?> targetClass, java.lang.String name, boolean staticMethods)
-
getAllMethods
@Deprecated public static java.util.List<java.lang.reflect.Method> getAllMethods(java.lang.Class<?> targetClass, java.lang.String name, boolean staticMethods)Deprecated.
-
getFields
public static java.util.Map<java.lang.String,java.lang.reflect.Field> getFields(java.lang.Class<?> targetClass)
-
getField
public static java.lang.reflect.Field getField(java.lang.Class<?> inClass, java.lang.String name)
-
getFieldValue
@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
@Deprecated public static boolean setFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value) throws OgnlException
Deprecated.Don't use this method as it doesn't check member access rights viaMemberAccessinterface- Throws:
OgnlException
-
setFieldValue
public static boolean setFieldValue(OgnlContext context, java.lang.Object target, java.lang.String propertyName, java.lang.Object value, boolean checkAccessAndExistence) 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.
-
getDeclaredMethods
public static java.util.List<java.lang.reflect.Method> getDeclaredMethods(java.lang.Class<?> targetClass, java.lang.String propertyName, boolean findSets)
-
isMethodCallable
public 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 for
isMethodCallable(Method). Almost all OGNL processing assumes the exclusion 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-synthetic or bridge), false otherwise.
- Since:
- 3.2.16
-
getGetMethod
public static java.lang.reflect.Method getGetMethod(java.lang.Class<?> targetClass, java.lang.String propertyName)cache get methods- Parameters:
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.
-
_getGetMethod
private static java.lang.reflect.Method _getGetMethod(java.lang.Class<?> targetClass, java.lang.String propertyName)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:
targetClass- Class to search for a get method (getter).propertyName- Name of the property for the get method (getter).
-
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)
-
getSetMethod
public static java.lang.reflect.Method getSetMethod(OgnlContext context, java.lang.Class<?> targetClass, java.lang.String propertyName)
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.
-
_getSetMethod
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.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).
-
hasSetMethod
public static boolean hasSetMethod(OgnlContext context, java.lang.Object target, java.lang.Class<?> targetClass, java.lang.String propertyName)
-
hasGetProperty
public static boolean hasGetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname) throws java.beans.IntrospectionException
- Throws:
java.beans.IntrospectionException
-
hasSetProperty
public static boolean hasSetProperty(OgnlContext context, java.lang.Object target, java.lang.Object oname) throws java.beans.IntrospectionException
- Throws:
java.beans.IntrospectionException
-
getPropertyDescriptors
public static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getPropertyDescriptors(java.lang.Class<?> targetClass)
This method returns the property descriptors for the given class as a Map.- Parameters:
targetClass- The class to get the descriptors for.- Returns:
- Map of property descriptors for class.
-
getPropertyDescriptor
public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class<?> targetClass, java.lang.String propertyName) throws 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:
OgnlException- On general errors.
-
getPropertyDescriptorsArray
public static java.beans.PropertyDescriptor[] getPropertyDescriptorsArray(java.lang.Class<?> targetClass)
-
getPropertyDescriptorFromArray
public static java.beans.PropertyDescriptor getPropertyDescriptorFromArray(java.lang.Class<?> targetClass, java.lang.String name)Gets the property descriptor with the given name for the target class given.- 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
-
setMethodAccessor
public static void setMethodAccessor(java.lang.Class<?> clazz, MethodAccessor accessor)
-
getMethodAccessor
public static MethodAccessor getMethodAccessor(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
setPropertyAccessor
public static void setPropertyAccessor(java.lang.Class<?> clazz, PropertyAccessor accessor)
-
getPropertyAccessor
public static PropertyAccessor getPropertyAccessor(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
getElementsAccessor
public static ElementsAccessor getElementsAccessor(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
setElementsAccessor
public static void setElementsAccessor(java.lang.Class<?> clazz, ElementsAccessor accessor)
-
getNullHandler
public static NullHandler getNullHandler(java.lang.Class<?> clazz) throws OgnlException
- Throws:
OgnlException
-
setNullHandler
public static void setNullHandler(java.lang.Class<?> clazz, NullHandler handler)
-
getProperty
public static java.lang.Object getProperty(OgnlContext context, java.lang.Object source, java.lang.Object name) throws OgnlException
- Throws:
OgnlException
-
setProperty
public static void setProperty(OgnlContext context, java.lang.Object target, java.lang.Object name, java.lang.Object value) throws OgnlException
- Throws:
OgnlException
-
getIndexedPropertyType
public static int getIndexedPropertyType(java.lang.Class<?> sourceClass, java.lang.String name) throws OgnlExceptionDetermines 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:
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()
-
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).- 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)
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.
-
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 flag
USE_JDK9PLUS_ACCESS_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 flag
USE_STRICTER_INVOCATION.- Returns:
- true if stricter invocation is in effect, false otherwise.
- Since:
- 3.1.25
-
getDisableOgnlSecurityManagerOnInitValue
@Deprecated public static boolean getDisableOgnlSecurityManagerOnInitValue()
Deprecated.will be removed in 3.5.xReturns the value of the flag indicating whether the OGNL SecurityManager was disabled on initialization or not.Note: Value is controlled by a Java option flag
OGNL_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_ACCESS_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 flag
USE_FIRSTMATCH_GETSET_LOOKUP.- Returns:
- true if the old "first match" lookup is in effect, false otherwise.
- Since:
- 3.1.25
-
isAccessible
private static boolean isAccessible(OgnlContext context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName)
Returns true if the given member is accessible or can be made accessible by this object.- Parameters:
context- the current execution context.target- the Object to test accessibility for.member- the Member to test accessibility for.propertyName- the property to test accessibility for.- Returns:
- true if the target/member/propertyName is accessible in the context, false otherwise.
-
-