Interface IndexAccessor

All Superinterfaces:
TargetedAccessor
All Known Subinterfaces:
CompilableIndexAccessor
All Known Implementing Classes:
ReflectiveIndexAccessor

public interface IndexAccessor extends TargetedAccessor
An index accessor is able to read from and possibly write to an indexed structure of a target object.

This interface places no restrictions on what constitutes an indexed structure. Implementors are therefore free to access indexed values any way they deem appropriate.

An index accessor can optionally specify an array of target classes for which it should be called. However, if it returns null or an empty array from TargetedAccessor.getSpecificTargetClasses(), it will be called for all indexing operations and given a chance to determine if it can read from or write to the indexed structure.

Index accessors are considered to be ordered, and each will be called in turn. The only rule that affects the call order is that any index accessor which specifies explicit support for the target class via TargetedAccessor.getSpecificTargetClasses() will be called first, before other generic index accessors.

Since:
6.2
Author:
Jackmiking Lee, Sam Brannen
See Also:
  • Method Details

    • canRead

      boolean canRead(EvaluationContext context, Object target, Object index) throws AccessException
      Determine if this index accessor is able to read a specified index on a specified target object.
      Parameters:
      context - the evaluation context in which the access is being attempted
      target - the target object upon which the index is being accessed
      index - the index being accessed
      Returns:
      true if this index accessor is able to read the index
      Throws:
      AccessException - if there is any problem determining whether the index can be read
    • read

      TypedValue read(EvaluationContext context, Object target, Object index) throws AccessException
      Read an index from a specified target object.

      Should only be invoked if canRead(org.springframework.expression.EvaluationContext, java.lang.Object, java.lang.Object) returns true for the same arguments.

      Parameters:
      context - the evaluation context in which the access is being attempted
      target - the target object upon which the index is being accessed
      index - the index being accessed
      Returns:
      a TypedValue object wrapping the index value read and a type descriptor for the value
      Throws:
      AccessException - if there is any problem reading the index
    • canWrite

      boolean canWrite(EvaluationContext context, Object target, Object index) throws AccessException
      Determine if this index accessor is able to write to a specified index on a specified target object.
      Parameters:
      context - the evaluation context in which the access is being attempted
      target - the target object upon which the index is being accessed
      index - the index being accessed
      Returns:
      true if this index accessor is able to write to the index
      Throws:
      AccessException - if there is any problem determining whether the index can be written to
    • write

      void write(EvaluationContext context, Object target, Object index, @Nullable Object newValue) throws AccessException
      Write to an index on a specified target object.

      Should only be invoked if canWrite(org.springframework.expression.EvaluationContext, java.lang.Object, java.lang.Object) returns true for the same arguments.

      Parameters:
      context - the evaluation context in which the access is being attempted
      target - the target object upon which the index is being accessed
      index - the index being accessed
      newValue - the new value for the index
      Throws:
      AccessException - if there is any problem writing to the index