org.springframework.expression.spel.support

Class ReflectivePropertyAccessor

  • java.lang.Object
    • org.springframework.expression.spel.support.ReflectivePropertyAccessor
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and 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 and 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 Deprecated Methods 
      Modifier and Type Method and Description
      boolean canRead(EvaluationContext context, java.lang.Object target, java.lang.String name)
      Called to determine if a resolver instance is able to access a specified property on a specified target object.
      boolean canWrite(EvaluationContext context, java.lang.Object target, java.lang.String name)
      Called to determine if a resolver instance is able to write to a specified property on a specified target object.
      PropertyAccessor createOptimalAccessor(EvaluationContext context, 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.
      protected java.lang.reflect.Method findGetterForProperty(java.lang.String propertyName, java.lang.Class<?> clazz, boolean mustBeStatic)
      Find a getter method for the specified property.
      protected java.lang.reflect.Method findSetterForProperty(java.lang.String propertyName, java.lang.Class<?> clazz, boolean mustBeStatic)
      Find a setter method for the specified property.
      java.lang.reflect.Member getLastReadInvokerPair()
      Deprecated. 
      as of 4.3.15 since it is not used within the framework anymore
      protected java.lang.String getPropertyMethodSuffix(java.lang.String propertyName)
      Return the method suffix for a given property name.
      protected java.lang.String[] getPropertyMethodSuffixes(java.lang.String propertyName)
      Return the method suffixes for a given property name.
      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.
      TypedValue read(EvaluationContext context, java.lang.Object target, java.lang.String name)
      Called to read a property from a specified target object.
      void write(EvaluationContext context, java.lang.Object target, java.lang.String name, java.lang.Object newValue)
      Called to write to a property on a specified target object.
      • 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 PropertyAccessor
        Returns:
        an array of classes that this resolver is suitable for (or null if a general resolver)
      • canRead

        public boolean canRead(EvaluationContext context,
                               @Nullable
                               java.lang.Object target,
                               java.lang.String name)
                        throws AccessException
        Description copied from interface: PropertyAccessor
        Called to determine if a resolver instance is able to access a specified property on a specified target object.
        Specified by:
        canRead in interface PropertyAccessor
        Parameters:
        context - the evaluation context in which the access is being attempted
        target - the target object upon which the property is being accessed
        name - the name of the property being accessed
        Returns:
        true if this resolver is able to read the property
        Throws:
        AccessException - if there is any problem determining whether the property can be read
      • canWrite

        public boolean canWrite(EvaluationContext context,
                                @Nullable
                                java.lang.Object target,
                                java.lang.String name)
                         throws AccessException
        Description copied from interface: PropertyAccessor
        Called to determine if a resolver instance is able to write to a specified property on a specified target object.
        Specified by:
        canWrite in interface PropertyAccessor
        Parameters:
        context - the evaluation context in which the access is being attempted
        target - the target object upon which the property is being accessed
        name - the name of the property being accessed
        Returns:
        true if this resolver is able to write to the property
        Throws:
        AccessException - if there is any problem determining whether the property can be written to
      • getLastReadInvokerPair

        @Deprecated
         @Nullable
        public java.lang.reflect.Member getLastReadInvokerPair()
        Deprecated. as of 4.3.15 since it is not used within the framework anymore
        Get the last read invoker pair.
      • findGetterForProperty

        @Nullable
        protected java.lang.reflect.Method findGetterForProperty(java.lang.String propertyName,
                                                                           java.lang.Class<?> clazz,
                                                                           boolean mustBeStatic)
        Find a getter method for the specified property.
      • findSetterForProperty

        @Nullable
        protected java.lang.reflect.Method findSetterForProperty(java.lang.String propertyName,
                                                                           java.lang.Class<?> clazz,
                                                                           boolean mustBeStatic)
        Find a setter method for the specified property.
      • 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
      • getPropertyMethodSuffixes

        protected java.lang.String[] getPropertyMethodSuffixes(java.lang.String propertyName)
        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

        protected java.lang.String getPropertyMethodSuffix(java.lang.String propertyName)
        Return the method suffix for a given property name. The default implementation uses JavaBean conventions.
      • 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 PropertyAccessor createOptimalAccessor(EvaluationContext context,
                                                      @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