|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import org.springframework.lang.Nullable;
|
21 | 21 |
|
22 | 22 | /**
|
23 |
| - * A index accessor is able to read from (and possibly write to) an array's elements. |
| 23 | + * An index accessor is able to read from (and possibly write to) an indexed |
| 24 | + * structure of an object. |
24 | 25 | *
|
25 |
| - * <p>This interface places no restrictions, and so implementors are free to access elements |
26 |
| - * directly as fields or through getters or in any other way they see as appropriate. |
| 26 | + * <p>This interface places no restrictions on what constitutes an indexed |
| 27 | + * structure. Implementors are therefore free to access indexed values any way |
| 28 | + * they deem appropriate. |
27 | 29 | *
|
28 |
| - * <p>A resolver can optionally specify an array of target classes for which it should be |
29 |
| - * called. However, if it returns {@code null} from {@link #getSpecificTargetClasses()}, |
30 |
| - * it will be called for all property references and given a chance to determine if it |
31 |
| - * can read or write them. |
| 30 | + * <p>An index accessor can optionally specify an array of target classes for |
| 31 | + * which it should be called. However, if it returns {@code null} or an empty |
| 32 | + * array from {@link #getSpecificTargetClasses()}, it will be called for all |
| 33 | + * indexing operations and given a chance to determine if it can read from or |
| 34 | + * write to the indexed structure. |
32 | 35 | *
|
33 |
| - * <p>Property resolvers are considered to be ordered, and each will be called in turn. |
34 |
| - * The only rule that affects the call order is that any resolver naming the target |
35 |
| - * class directly in {@link #getSpecificTargetClasses()} will be called first, before |
36 |
| - * the general resolvers. |
| 36 | + * <p>Index accessors are considered to be ordered, and each will be called in |
| 37 | + * turn. The only rule that affects the call order is that any index accessor |
| 38 | + * which specifies explicit support for the target class via |
| 39 | + * {@link #getSpecificTargetClasses()} will be called first, before other |
| 40 | + * generic index accessors. |
37 | 41 | *
|
38 |
| - * @author jackmiking lee |
39 |
| - * @since 3.0 |
| 42 | + * @author Jackmiking Lee |
| 43 | + * @author Sam Brannen |
| 44 | + * @since 6.2 |
| 45 | + * @see PropertyAccessor |
40 | 46 | */
|
41 |
| -public interface IndexAccessor { |
| 47 | +public interface IndexAccessor extends TargetedAccessor { |
| 48 | + |
42 | 49 | /**
|
43 |
| - * Return an array of classes for which this resolver should be called. |
44 |
| - * <p>Returning {@code null} indicates this is a general resolver that |
45 |
| - * can be called in an attempt to resolve a property on any type. |
46 |
| - * @return an array of classes that this resolver is suitable for |
47 |
| - * (or {@code null} if a general resolver) |
| 50 | + * Get the set of classes for which this index accessor should be called. |
| 51 | + * <p>Returning {@code null} or an empty array indicates this is a generic |
| 52 | + * index accessor that can be called in an attempt to access an index on any |
| 53 | + * type. |
| 54 | + * @return an array of classes that this index accessor is suitable for |
| 55 | + * (or {@code null} or an empty array if a generic index accessor) |
48 | 56 | */
|
| 57 | + @Override |
49 | 58 | @Nullable
|
50 | 59 | Class<?>[] getSpecificTargetClasses();
|
51 | 60 |
|
52 | 61 | /**
|
53 |
| - * Called to determine if a resolver instance is able to access a specified property |
54 |
| - * on a specified target object. |
| 62 | + * Called to determine if this index accessor is able to read a specified |
| 63 | + * index on a specified target object. |
55 | 64 | * @param context the evaluation context in which the access is being attempted
|
56 |
| - * @param target the target object upon which the property is being accessed |
57 |
| - * @param index the index of the array being accessed |
58 |
| - * @return true if this resolver is able to read the property |
59 |
| - * @throws AccessException if there is any problem determining whether the property can be read |
| 65 | + * @param target the target object upon which the index is being accessed |
| 66 | + * @param index the index being accessed |
| 67 | + * @return true if this index accessor is able to read the index |
| 68 | + * @throws AccessException if there is any problem determining whether the |
| 69 | + * index can be read |
60 | 70 | */
|
61 | 71 | boolean canRead(EvaluationContext context, @Nullable Object target, Object index) throws AccessException;
|
62 | 72 |
|
63 | 73 | /**
|
64 |
| - * Called to read a property from a specified target object. |
65 |
| - * Should only succeed if {@link #canRead} also returns {@code true}. |
| 74 | + * Called to read an index from a specified target object. |
| 75 | + * <p>Should only succeed if {@link #canRead} also returns {@code true}. |
66 | 76 | * @param context the evaluation context in which the access is being attempted
|
67 |
| - * @param target the target object upon which the property is being accessed |
68 |
| - * @param index the index of the array being accessed |
69 |
| - * @return a TypedValue object wrapping the property value read and a type descriptor for it |
70 |
| - * @throws AccessException if there is any problem accessing the property value |
| 77 | + * @param target the target object upon which the index is being accessed |
| 78 | + * @param index the index being accessed |
| 79 | + * @return a TypedValue object wrapping the index value read and a type |
| 80 | + * descriptor for it |
| 81 | + * @throws AccessException if there is any problem reading the index value |
71 | 82 | */
|
72 |
| - ValueRef read(EvaluationContext context, @Nullable Object target,Object index) throws AccessException; |
| 83 | + // TODO Change return type to TypedValue to avoid package cycle. |
| 84 | + ValueRef read(EvaluationContext context, @Nullable Object target, Object index) throws AccessException; |
73 | 85 |
|
74 | 86 | /**
|
75 |
| - * Called to determine if a resolver instance is able to write to a specified |
76 |
| - * property on a specified target object. |
| 87 | + * Called to determine if this index accessor is able to write to a specified |
| 88 | + * index on a specified target object. |
77 | 89 | * @param context the evaluation context in which the access is being attempted
|
78 |
| - * @param target the target object upon which the property is being accessed |
79 |
| - * @param index the index of the array being accessed |
80 |
| - * @return true if this resolver is able to write to the property |
| 90 | + * @param target the target object upon which the index is being accessed |
| 91 | + * @param index the index being accessed |
| 92 | + * @return true if this index accessor is able to write to the index |
81 | 93 | * @throws AccessException if there is any problem determining whether the
|
82 |
| - * property can be written to |
| 94 | + * index can be written to |
83 | 95 | */
|
84 | 96 | boolean canWrite(EvaluationContext context, @Nullable Object target, Object index) throws AccessException;
|
85 | 97 |
|
86 | 98 | /**
|
87 |
| - * Called to write to a property on a specified target object. |
88 |
| - * Should only succeed if {@link #canWrite} also returns {@code true}. |
| 99 | + * Called to write to an index on a specified target object. |
| 100 | + * <p>Should only succeed if {@link #canWrite} also returns {@code true}. |
89 | 101 | * @param context the evaluation context in which the access is being attempted
|
90 |
| - * @param target the target object upon which the property is being accessed |
91 |
| - * @param index the index of the array being accessed |
92 |
| - * @param newValue the new value for the property |
93 |
| - * @throws AccessException if there is any problem writing to the property value |
| 102 | + * @param target the target object upon which the index is being accessed |
| 103 | + * @param index the index being accessed |
| 104 | + * @param newValue the new value for the index |
| 105 | + * @throws AccessException if there is any problem writing to the index value |
94 | 106 | */
|
95 | 107 | void write(EvaluationContext context, @Nullable Object target, Object index, @Nullable Object newValue)
|
96 | 108 | throws AccessException;
|
| 109 | + |
97 | 110 | }
|
0 commit comments