Sync MapAccessor implementations
This commit is contained in:
parent
4fa9781549
commit
e547313fa6
|
|
@ -34,6 +34,27 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
class CompilableMapAccessor implements CompilablePropertyAccessor {
|
class CompilableMapAccessor implements CompilablePropertyAccessor {
|
||||||
|
|
||||||
|
private final boolean allowWrite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new map accessor for reading as well as writing.
|
||||||
|
* @since 6.2
|
||||||
|
* @see #CompilableMapAccessor(boolean)
|
||||||
|
*/
|
||||||
|
public CompilableMapAccessor() {
|
||||||
|
this(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new map accessor for reading and possibly also writing.
|
||||||
|
* @param allowWrite whether to allow write operations on a target instance
|
||||||
|
* @since 6.2
|
||||||
|
* @see #canWrite
|
||||||
|
*/
|
||||||
|
public CompilableMapAccessor(boolean allowWrite) {
|
||||||
|
this.allowWrite = allowWrite;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?>[] getSpecificTargetClasses() {
|
public Class<?>[] getSpecificTargetClasses() {
|
||||||
return new Class<?>[] {Map.class};
|
return new Class<?>[] {Map.class};
|
||||||
|
|
@ -57,7 +78,7 @@ class CompilableMapAccessor implements CompilablePropertyAccessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canWrite(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
|
public boolean canWrite(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
|
||||||
return true;
|
return (this.allowWrite && target instanceof Map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -65,7 +86,7 @@ class CompilableMapAccessor implements CompilablePropertyAccessor {
|
||||||
public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue)
|
public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue)
|
||||||
throws AccessException {
|
throws AccessException {
|
||||||
|
|
||||||
Assert.state(target instanceof Map, "Target must be a Map");
|
Assert.state(target instanceof Map, "Target must be of type Map");
|
||||||
Map<Object, Object> map = (Map<Object, Object>) target;
|
Map<Object, Object> map = (Map<Object, Object>) target;
|
||||||
map.put(name, newValue);
|
map.put(name, newValue);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue