Package com.redis.riot.core
Class ReflectivePropertyAccessor
- java.lang.Object
-
- com.redis.riot.core.ReflectivePropertyAccessor
-
- All Implemented Interfaces:
org.springframework.expression.PropertyAccessor
public class ReflectivePropertyAccessor extends java.lang.Object implements org.springframework.expression.PropertyAccessor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReflectivePropertyAccessor.OptimalPropertyAccessor
An optimized form of a PropertyAccessor that will use reflection but only knows how to access a particular property on a particular class.
-
Constructor Summary
Constructors Constructor Description ReflectivePropertyAccessor()
Create a new property accessor for reading as well writing.ReflectivePropertyAccessor(boolean allowWrite)
Create a new property accessor for reading and possibly writing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRead(org.springframework.expression.EvaluationContext context, java.lang.Object target, java.lang.String name)
boolean
canWrite(org.springframework.expression.EvaluationContext context, java.lang.Object target, java.lang.String name)
org.springframework.expression.PropertyAccessor
createOptimalAccessor(java.lang.Object target, java.lang.String name)
Attempt to create an optimized property accessor tailored for a property of a particular name on a particular class.protected java.lang.reflect.Field
findField(java.lang.String name, java.lang.Class<?> clazz, boolean mustBeStatic)
Find a field of a certain name on a specified class.java.lang.Class<?>[]
getSpecificTargetClasses()
Returnsnull
which means this is a general purpose accessor.protected boolean
isCandidateForProperty(java.lang.reflect.Method method, java.lang.Class<?> targetClass)
Determine whether the givenMethod
is a candidate for property access on an instance of the given target class.org.springframework.expression.TypedValue
read(org.springframework.expression.EvaluationContext context, java.lang.Object target, java.lang.String name)
void
write(org.springframework.expression.EvaluationContext context, java.lang.Object target, java.lang.String name, java.lang.Object newValue)
-
-
-
Constructor Detail
-
ReflectivePropertyAccessor
public ReflectivePropertyAccessor()
Create a new property accessor for reading as well writing.- See Also:
ReflectivePropertyAccessor(boolean)
-
ReflectivePropertyAccessor
public ReflectivePropertyAccessor(boolean allowWrite)
Create a new property accessor for reading and possibly writing.- Parameters:
allowWrite
- whether to also allow for write operations- Since:
- 4.3.15
- See Also:
canWrite(org.springframework.expression.EvaluationContext, java.lang.Object, java.lang.String)
-
-
Method Detail
-
getSpecificTargetClasses
@Nullable public java.lang.Class<?>[] getSpecificTargetClasses()
Returnsnull
which means this is a general purpose accessor.- Specified by:
getSpecificTargetClasses
in interfaceorg.springframework.expression.PropertyAccessor
-
canRead
public boolean canRead(org.springframework.expression.EvaluationContext context, @Nullable java.lang.Object target, java.lang.String name) throws org.springframework.expression.AccessException
- Specified by:
canRead
in interfaceorg.springframework.expression.PropertyAccessor
- Throws:
org.springframework.expression.AccessException
-
read
public org.springframework.expression.TypedValue read(org.springframework.expression.EvaluationContext context, @Nullable java.lang.Object target, java.lang.String name) throws org.springframework.expression.AccessException
- Specified by:
read
in interfaceorg.springframework.expression.PropertyAccessor
- Throws:
org.springframework.expression.AccessException
-
canWrite
public boolean canWrite(org.springframework.expression.EvaluationContext context, @Nullable java.lang.Object target, java.lang.String name) throws org.springframework.expression.AccessException
- Specified by:
canWrite
in interfaceorg.springframework.expression.PropertyAccessor
- Throws:
org.springframework.expression.AccessException
-
write
public void write(org.springframework.expression.EvaluationContext context, @Nullable java.lang.Object target, java.lang.String name, @Nullable java.lang.Object newValue) throws org.springframework.expression.AccessException
- Specified by:
write
in interfaceorg.springframework.expression.PropertyAccessor
- Throws:
org.springframework.expression.AccessException
-
isCandidateForProperty
protected boolean isCandidateForProperty(java.lang.reflect.Method method, java.lang.Class<?> targetClass)
Determine whether the givenMethod
is a candidate for property access on an instance of the given target class.The default implementation considers any method as a candidate, even for non-user-declared properties on the
Object
base class.- Parameters:
method
- the Method to evaluatetargetClass
- the concrete target class that is being introspected- Since:
- 4.3.15
-
findField
@Nullable protected java.lang.reflect.Field findField(java.lang.String name, java.lang.Class<?> clazz, boolean mustBeStatic)
Find a field of a certain name on a specified class.
-
createOptimalAccessor
public org.springframework.expression.PropertyAccessor createOptimalAccessor(@Nullable java.lang.Object target, java.lang.String name)
Attempt to create an optimized property accessor tailored for a property of a particular name on a particular class. The general ReflectivePropertyAccessor will always work but is not optimal due to the need to lookup which reflective member (method/field) to use each time read() is called. This method will just return the ReflectivePropertyAccessor instance if it is unable to build a more optimal accessor.Note: An optimal accessor is currently only usable for read attempts. Do not call this method if you need a read-write accessor.
-
-