Class IndexedType
- java.lang.Object
-
- org.apache.commons.jexl3.internal.introspection.IndexedType
-
- All Implemented Interfaces:
JexlPropertyGet
public final class IndexedType extends java.lang.Object implements JexlPropertyGet
Abstract an indexed property container.This allows getting properties from expressions like
var.container.property. This stores the container name and class as well as the list of available getter and setter methods. It implements JexlPropertyGet since such a container can only be accessed from its owning instance (not set).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIndexedType.IndexedContainerA generic indexed property container, exposes get(key) and set(key, value) and solves method call dynamically based on arguments.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Class<?>clazzThe container class.(package private) java.lang.StringcontainerThe container name.private java.lang.reflect.MethodgetLast get method used.private java.lang.reflect.Method[]gettersThe array of getter methods.private java.lang.reflect.MethodsetLast set method used.private java.lang.reflect.Method[]settersThe array of setter methods.
-
Constructor Summary
Constructors Modifier Constructor Description privateIndexedType(java.lang.String name, java.lang.Class<?> c, java.lang.reflect.Method[] gets, java.lang.reflect.Method[] sets)Creates a new indexed property container type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JexlPropertyGetdiscover(Introspector is, java.lang.Object object, java.lang.String name)Attempts to find an indexed-property getter in an object.java.lang.Objectinvoke(java.lang.Object obj)Method used to get the property value of an object.(package private) java.lang.ObjectinvokeGet(java.lang.Object object, java.lang.Object key)Gets the value of a property from a container.(package private) java.lang.ObjectinvokeSet(java.lang.Object object, java.lang.Object key, java.lang.Object value)Sets the value of a property in a container.booleanisCacheable()Specifies if this JexlPropertyGet is cacheable and able to be reused for this class of object it was returned for.booleantryFailed(java.lang.Object val)Checks whether a tryInvoke failed or not.java.lang.ObjecttryInvoke(java.lang.Object obj, java.lang.Object key)Attempts to reuse this JexlPropertyGet, checking that it is compatible with the actual set of arguments.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.jexl3.introspection.JexlPropertyGet
isConstant
-
-
-
-
Field Detail
-
container
final java.lang.String container
The container name.
-
clazz
final java.lang.Class<?> clazz
The container class.
-
getters
private final java.lang.reflect.Method[] getters
The array of getter methods.
-
get
private volatile java.lang.reflect.Method get
Last get method used.
-
setters
private final java.lang.reflect.Method[] setters
The array of setter methods.
-
set
private volatile java.lang.reflect.Method set
Last set method used.
-
-
Constructor Detail
-
IndexedType
private IndexedType(java.lang.String name, java.lang.Class<?> c, java.lang.reflect.Method[] gets, java.lang.reflect.Method[] sets)Creates a new indexed property container type.- Parameters:
name- the container namec- the owning classgets- the array of getter methodssets- the array of setter methods
-
-
Method Detail
-
discover
public static JexlPropertyGet discover(Introspector is, java.lang.Object object, java.lang.String name)
Attempts to find an indexed-property getter in an object. The code attempts to find the list of methods getXXX() and setXXX(). Note that this is not equivalent to the strict bean definition of indexed properties; the type of the key is not necessarily an int and the set/get arrays are not resolved.- Parameters:
is- the introspectorobject- the objectname- the container name- Returns:
- a JexlPropertyGet is successful, null otherwise
-
invoke
public java.lang.Object invoke(java.lang.Object obj) throws java.lang.ExceptionDescription copied from interface:JexlPropertyGetMethod used to get the property value of an object.- Specified by:
invokein interfaceJexlPropertyGet- Parameters:
obj- the object to get the property value from.- Returns:
- the property value.
- Throws:
java.lang.Exception- on any error.
-
invokeGet
java.lang.Object invokeGet(java.lang.Object object, java.lang.Object key) throws java.lang.ExceptionGets the value of a property from a container.- Parameters:
object- the container instance (not null)key- the property key (not null)- Returns:
- the property value
- Throws:
java.lang.Exception- if invocation failed; IntrospectionException if a property getter could not be found
-
invokeSet
java.lang.Object invokeSet(java.lang.Object object, java.lang.Object key, java.lang.Object value) throws java.lang.ExceptionSets the value of a property in a container.- Parameters:
object- the container instance (not null)key- the property key (not null)value- the property value (not null)- Returns:
- the result of the method invocation (frequently null)
- Throws:
java.lang.Exception- if invocation failed; IntrospectionException if a property setter could not be found
-
isCacheable
public boolean isCacheable()
Description copied from interface:JexlPropertyGetSpecifies if this JexlPropertyGet is cacheable and able to be reused for this class of object it was returned for.- Specified by:
isCacheablein interfaceJexlPropertyGet- Returns:
- true if can be reused for this class, false if not
-
tryFailed
public boolean tryFailed(java.lang.Object val)
Description copied from interface:JexlPropertyGetChecks whether a tryInvoke failed or not.- Specified by:
tryFailedin interfaceJexlPropertyGet- Parameters:
val- the value returned by tryInvoke- Returns:
- true if tryInvoke failed, false otherwise
-
tryInvoke
public java.lang.Object tryInvoke(java.lang.Object obj, java.lang.Object key)Description copied from interface:JexlPropertyGetAttempts to reuse this JexlPropertyGet, checking that it is compatible with the actual set of arguments.- Specified by:
tryInvokein interfaceJexlPropertyGet- Parameters:
obj- the object to invoke the property get uponkey- the property key to get- Returns:
- the result of the method invocation that should be checked by tryFailed to determine if it succeeded or failed.
-
-