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 class
IndexedType.IndexedContainer
A 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<?>
clazz
The container class.(package private) java.lang.String
container
The container name.private java.lang.reflect.Method
get
Last get method used.private java.lang.reflect.Method[]
getters
The array of getter methods.private java.lang.reflect.Method
set
Last set method used.private java.lang.reflect.Method[]
setters
The array of setter methods.
-
Constructor Summary
Constructors Modifier Constructor Description 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JexlPropertyGet
discover(Introspector is, java.lang.Object object, java.lang.String name)
Attempts to find an indexed-property getter in an object.java.lang.Object
invoke(java.lang.Object obj)
Method used to get the property value of an object.(package private) java.lang.Object
invokeGet(java.lang.Object object, java.lang.Object key)
Gets the value of a property from a container.(package private) java.lang.Object
invokeSet(java.lang.Object object, java.lang.Object key, java.lang.Object value)
Sets the value of a property in a container.boolean
isCacheable()
Specifies if this JexlPropertyGet is cacheable and able to be reused for this class of object it was returned for.boolean
tryFailed(java.lang.Object rval)
Checks whether a tryInvoke failed or not.java.lang.Object
tryInvoke(java.lang.Object obj, java.lang.Object key)
Attempts to reuse this JexlPropertyGet, checking that it is compatible with the actual set of arguments.
-
-
-
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.Exception
Description copied from interface:JexlPropertyGet
Method used to get the property value of an object.- Specified by:
invoke
in 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.Exception
Gets 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.Exception
Sets 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:JexlPropertyGet
Specifies if this JexlPropertyGet is cacheable and able to be reused for this class of object it was returned for.- Specified by:
isCacheable
in interfaceJexlPropertyGet
- Returns:
- true if can be reused for this class, false if not
-
tryFailed
public boolean tryFailed(java.lang.Object rval)
Description copied from interface:JexlPropertyGet
Checks whether a tryInvoke failed or not.- Specified by:
tryFailed
in interfaceJexlPropertyGet
- Parameters:
rval
- 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:JexlPropertyGet
Attempts to reuse this JexlPropertyGet, checking that it is compatible with the actual set of arguments.- Specified by:
tryInvoke
in 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.
-
-