Class 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()
      Returns null which means this is a general purpose accessor.
      protected boolean isCandidateForProperty​(java.lang.reflect.Method method, java.lang.Class<?> targetClass)
      Determine whether the given Method 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getSpecificTargetClasses

        @Nullable
        public java.lang.Class<?>[] getSpecificTargetClasses()
        Returns null which means this is a general purpose accessor.
        Specified by:
        getSpecificTargetClasses in interface org.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 interface org.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 interface org.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 interface org.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 interface org.springframework.expression.PropertyAccessor
        Throws:
        org.springframework.expression.AccessException
      • isCandidateForProperty

        protected boolean isCandidateForProperty​(java.lang.reflect.Method method,
                                                 java.lang.Class<?> targetClass)
        Determine whether the given Method 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 evaluate
        targetClass - 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.

        See Also:
        ReflectivePropertyAccessor.OptimalPropertyAccessor