类 ReflectivePropertyAccessor
java.lang.Object
cn.taketoday.expression.spel.support.ReflectivePropertyAccessor
- 所有已实现的接口:
PropertyAccessor
- 直接已知子类:
DataBindingPropertyAccessor
A powerful
PropertyAccessor that uses reflection to access properties
for reading and possibly also for writing on a target instance.
A property can be referenced through a public getter method (when being read) or a public setter method (when being written), and also as a public field.
- 从以下版本开始:
- 4.0
- 作者:
- Andy Clement, Juergen Hoeller, Phillip Webb, Sam Brannen, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static classCaptures the member (method/field) to call reflectively to access a property value and the type descriptor for the value returned by the reflective call.static classAn optimized form of a PropertyAccessor that will use reflection but only knows how to access a particular property on a particular class.private static final class -
字段概要
字段修饰符和类型字段说明private final booleanprivate final Map<ReflectivePropertyAccessor.PropertyCacheKey,ReflectivePropertyAccessor.InvokerPair> private final Map<ReflectivePropertyAccessor.PropertyCacheKey,TypeDescriptor> private final Map<ReflectivePropertyAccessor.PropertyCacheKey,Member> -
构造器概要
构造器构造器说明Create a new property accessor for reading as well writing.ReflectivePropertyAccessor(boolean allowWrite) Create a new property accessor for reading and possibly also writing. -
方法概要
修饰符和类型方法说明booleancanRead(EvaluationContext context, Object target, String name) Called to determine if a resolver instance is able to access a specified property on a specified target object.booleancanWrite(EvaluationContext context, Object target, String name) Called to determine if a resolver instance is able to write to a specified property on a specified target object.createOptimalAccessor(EvaluationContext context, Object target, String name) Attempt to create an optimized property accessor tailored for a property of a particular name on a particular class.protected FieldFind a field of a certain name on a specified class.private Fieldprotected MethodfindGetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) Find a getter method for the specified property.private MethodfindGetterForProperty(String propertyName, Class<?> clazz, Object target) private MethodfindMethodForProperty(String[] methodSuffixes, String prefix, Class<?> clazz, boolean mustBeStatic, int numberOfParams, Set<Class<?>> requiredReturnTypes) protected MethodfindSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) Find a setter method for the specified property.private MethodfindSetterForProperty(String propertyName, Class<?> clazz, Object target) protected StringgetPropertyMethodSuffix(String propertyName) Return the method suffix for a given property name.protected String[]getPropertyMethodSuffixes(String propertyName) Return the method suffixes for a given property name.private Method[]getSortedMethods(Class<?> clazz) Return class methods ordered with non-bridge methods appearing higher.Class<?>[]Returnsnullwhich means this is a general purpose accessor.private TypeDescriptorgetTypeDescriptor(EvaluationContext context, Object target, String name) private TypeDescriptorgetTypeDescriptor(Method readMethod, Method writeMethod, Class<?> declaringClass) protected booleanisCandidateForProperty(Method method, Class<?> targetClass) Determine whether the givenMethodis a candidate for property access on an instance of the given target class.read(EvaluationContext context, Object target, String name) Called to read a property from a specified target object.voidwrite(EvaluationContext context, Object target, String name, Object newValue) Called to write to a property on a specified target object.
-
字段详细资料
-
ANY_TYPES
-
BOOLEAN_TYPES
-
allowWrite
private final boolean allowWrite -
readerCache
private final Map<ReflectivePropertyAccessor.PropertyCacheKey,ReflectivePropertyAccessor.InvokerPair> readerCache -
writerCache
-
typeDescriptorCache
-
sortedMethodsCache
-
-
构造器详细资料
-
ReflectivePropertyAccessor
public ReflectivePropertyAccessor()Create a new property accessor for reading as well writing. -
ReflectivePropertyAccessor
public ReflectivePropertyAccessor(boolean allowWrite) Create a new property accessor for reading and possibly also writing.- 参数:
allowWrite- whether to allow write operations on a target instance- 另请参阅:
-
-
方法详细资料
-
getSpecificTargetClasses
Returnsnullwhich means this is a general purpose accessor.- 指定者:
getSpecificTargetClasses在接口中PropertyAccessor- 返回:
- an array of classes that this resolver is suitable for
(or
nullif a general resolver)
-
canRead
public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException 从接口复制的说明:PropertyAccessorCalled to determine if a resolver instance is able to access a specified property on a specified target object.- 指定者:
canRead在接口中PropertyAccessor- 参数:
context- the evaluation context in which the access is being attemptedtarget- the target object upon which the property is being accessedname- the name of the property being accessed- 返回:
- true if this resolver is able to read the property
- 抛出:
AccessException- if there is any problem determining whether the property can be read
-
read
public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException 从接口复制的说明:PropertyAccessorCalled to read a property from a specified target object. Should only succeed ifPropertyAccessor.canRead(cn.taketoday.expression.EvaluationContext, java.lang.Object, java.lang.String)also returnstrue.- 指定者:
read在接口中PropertyAccessor- 参数:
context- the evaluation context in which the access is being attemptedtarget- the target object upon which the property is being accessedname- the name of the property being accessed- 返回:
- a TypedValue object wrapping the property value read and a type descriptor for it
- 抛出:
AccessException- if there is any problem accessing the property value
-
canWrite
public boolean canWrite(EvaluationContext context, @Nullable Object target, String name) throws AccessException 从接口复制的说明:PropertyAccessorCalled to determine if a resolver instance is able to write to a specified property on a specified target object.- 指定者:
canWrite在接口中PropertyAccessor- 参数:
context- the evaluation context in which the access is being attemptedtarget- the target object upon which the property is being accessedname- the name of the property being accessed- 返回:
- true if this resolver is able to write to the property
- 抛出:
AccessException- if there is any problem determining whether the property can be written to
-
getTypeDescriptor
-
write
public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) throws AccessException 从接口复制的说明:PropertyAccessorCalled to write to a property on a specified target object. Should only succeed ifPropertyAccessor.canWrite(cn.taketoday.expression.EvaluationContext, java.lang.Object, java.lang.String)also returnstrue.- 指定者:
write在接口中PropertyAccessor- 参数:
context- the evaluation context in which the access is being attemptedtarget- the target object upon which the property is being accessedname- the name of the property being accessednewValue- the new value for the property- 抛出:
AccessException- if there is any problem writing to the property value
-
getTypeDescriptor
@Nullable private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object target, String name) -
findGetterForProperty
-
findSetterForProperty
-
findGetterForProperty
@Nullable protected Method findGetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) Find a getter method for the specified property. -
findSetterForProperty
@Nullable protected Method findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) Find a setter method for the specified property. -
findMethodForProperty
-
getSortedMethods
Return class methods ordered with non-bridge methods appearing higher. -
isCandidateForProperty
Determine whether the givenMethodis 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
Objectbase class.- 参数:
method- the Method to evaluatetargetClass- the concrete target class that is being introspected- 从以下版本开始:
- 4.0
-
getPropertyMethodSuffixes
Return the method suffixes for a given property name. The default implementation uses JavaBean conventions with additional support for properties of the form 'xY' where the method 'getXY()' is used in preference to the JavaBean convention of 'getxY()'. -
getPropertyMethodSuffix
Return the method suffix for a given property name. The default implementation uses JavaBean conventions. -
findField
-
findField
Find a field of a certain name on a specified class. -
createOptimalAccessor
public PropertyAccessor createOptimalAccessor(EvaluationContext context, @Nullable Object target, 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.
-