Class PropertySetExecutor
- java.lang.Object
-
- org.apache.commons.jexl3.internal.introspection.AbstractExecutor
-
- org.apache.commons.jexl3.internal.introspection.AbstractExecutor.Set
-
- org.apache.commons.jexl3.internal.introspection.PropertySetExecutor
-
- All Implemented Interfaces:
JexlPropertySet
public class PropertySetExecutor extends AbstractExecutor.Set
Specialized executor to set a property in an object.- Since:
- 2.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.jexl3.internal.introspection.AbstractExecutor
AbstractExecutor.Get, AbstractExecutor.Method, AbstractExecutor.Set
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
property
The property.private static int
SET_START_INDEX
Index of the first character of the set{p,P}roperty.protected java.lang.Class<?>
valueClass
The property value class.-
Fields inherited from class org.apache.commons.jexl3.internal.introspection.AbstractExecutor
method, objectClass, TRY_FAILED
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PropertySetExecutor(java.lang.Class<?> clazz, java.lang.reflect.Method method, java.lang.String key, java.lang.Object value)
Creates an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PropertySetExecutor
discover(Introspector is, java.lang.Class<?> clazz, java.lang.String property, java.lang.Object value)
Discovers a PropertySetExecutor.private static java.lang.reflect.Method
discoverSet(Introspector is, java.lang.Class<?> clazz, java.lang.String property, java.lang.Object arg)
Discovers the method for aJexlPropertySet
.java.lang.Object
getTargetProperty()
Gets the property targeted by this executor.java.lang.Object
invoke(java.lang.Object o, java.lang.Object argument)
Method used to set the property value of an object.private static boolean
isEmptyArray(java.lang.Object arg)
Checks whether an argument is an empty array.private static java.lang.reflect.Method
lookupSetEmptyArray(Introspector is, java.lang.Class<?> clazz, java.lang.String methodName)
Finds an empty array property setter method bymethodName
.java.lang.Object
tryInvoke(java.lang.Object o, java.lang.Object identifier, java.lang.Object value)
Attempts to reuse this JexlPropertySet, checking that it is compatible with the actual set of arguments.-
Methods inherited from class org.apache.commons.jexl3.internal.introspection.AbstractExecutor
castInteger, castString, classOf, equals, equals, getMethod, getMethodName, getTargetClass, hashCode, initMarker, isAlive, isCacheable, makeArgs, tryFailed
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.jexl3.introspection.JexlPropertySet
isCacheable, tryFailed
-
-
-
-
Field Detail
-
SET_START_INDEX
private static final int SET_START_INDEX
Index of the first character of the set{p,P}roperty.- See Also:
- Constant Field Values
-
property
protected final java.lang.String property
The property.
-
valueClass
protected final java.lang.Class<?> valueClass
The property value class.
-
-
Constructor Detail
-
PropertySetExecutor
protected PropertySetExecutor(java.lang.Class<?> clazz, java.lang.reflect.Method method, java.lang.String key, java.lang.Object value)
Creates an instance.- Parameters:
clazz
- the class the set method applies tomethod
- the method called through this executorkey
- the key to use as 1st argument to the set methodvalue
- the value
-
-
Method Detail
-
discover
public static PropertySetExecutor discover(Introspector is, java.lang.Class<?> clazz, java.lang.String property, java.lang.Object value)
Discovers a PropertySetExecutor.The method to be found should be named "set{P,p}property.
- Parameters:
is
- the introspectorclazz
- the class to find the get method fromproperty
- the property name to findvalue
- the value to assign to the property- Returns:
- the executor if found, null otherwise
-
discoverSet
private static java.lang.reflect.Method discoverSet(Introspector is, java.lang.Class<?> clazz, java.lang.String property, java.lang.Object arg)
Discovers the method for aJexlPropertySet
.The method to be found should be named "set{P,p}property. As a special case, any empty array will try to find a valid array-setting non-ambiguous method.
- Parameters:
is
- the introspectorclazz
- the class to find the get method fromproperty
- the name of the property to setarg
- the value to assign to the property- Returns:
- the method if found, null otherwise
-
isEmptyArray
private static boolean isEmptyArray(java.lang.Object arg)
Checks whether an argument is an empty array.- Parameters:
arg
- the argument- Returns:
- true if
arg
is an empty array
-
lookupSetEmptyArray
private static java.lang.reflect.Method lookupSetEmptyArray(Introspector is, java.lang.Class<?> clazz, java.lang.String methodName)
Finds an empty array property setter method bymethodName
.This checks only one method with that name accepts an array as sole parameter.
- Parameters:
is
- the introspectorclazz
- the class to find the get method frommethodName
- the method name to find- Returns:
- the sole method that accepts an array as parameter
-
getTargetProperty
public java.lang.Object getTargetProperty()
Description copied from class:AbstractExecutor
Gets the property targeted by this executor.- Overrides:
getTargetProperty
in classAbstractExecutor
- Returns:
- the target property
-
invoke
public java.lang.Object invoke(java.lang.Object o, java.lang.Object argument) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Description copied from interface:JexlPropertySet
Method used to set the property value of an object.- Parameters:
o
- Object on which the property setter will be called with the valueargument
- value to be set- Returns:
- the value returned from the set operation (impl specific)
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
tryInvoke
public java.lang.Object tryInvoke(java.lang.Object o, java.lang.Object identifier, java.lang.Object value)
Description copied from interface:JexlPropertySet
Attempts to reuse this JexlPropertySet, checking that it is compatible with the actual set of arguments.- Parameters:
o
- the object to invoke the get uponidentifier
- the property key to getvalue
- the property value to set- Returns:
- the result of the method invocation that should be checked by tryFailed to determine if it succeeded or failed.
-
-