Interface IndexAccessor
- All Superinterfaces:
TargetedAccessor
- All Known Subinterfaces:
CompilableIndexAccessor
- All Known Implementing Classes:
ReflectiveIndexAccessor
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 Summary
Modifier and TypeMethodDescriptionboolean
canRead
(EvaluationContext context, Object target, Object index) Determine if this index accessor is able to read a specified index on a specified target object.boolean
canWrite
(EvaluationContext context, Object target, Object index) Determine if this index accessor is able to write to a specified index on a specified target object.read
(EvaluationContext context, Object target, Object index) Read an index from a specified target object.void
write
(EvaluationContext context, Object target, Object index, Object newValue) Write to an index on a specified target object.Methods inherited from interface org.springframework.expression.TargetedAccessor
getSpecificTargetClasses
-
Method Details
-
canRead
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 attemptedtarget
- the target object upon which the index is being accessedindex
- 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
Read an index from a specified target object.Should only be invoked if
canRead(org.springframework.expression.EvaluationContext, java.lang.Object, java.lang.Object)
returnstrue
for the same arguments.- Parameters:
context
- the evaluation context in which the access is being attemptedtarget
- the target object upon which the index is being accessedindex
- 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
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 attemptedtarget
- the target object upon which the index is being accessedindex
- 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)
returnstrue
for the same arguments.- Parameters:
context
- the evaluation context in which the access is being attemptedtarget
- the target object upon which the index is being accessedindex
- the index being accessednewValue
- the new value for the index- Throws:
AccessException
- if there is any problem writing to the index
-