64
64
* read-only access to properties via {@link DataBindingPropertyAccessor}. Similarly,
65
65
* {@link SimpleEvaluationContext#forReadWriteDataBinding()} enables read and write access
66
66
* to properties. Alternatively, configure custom accessors via
67
- * {@link SimpleEvaluationContext#forPropertyAccessors} and potentially activate method
68
- * resolution and/or a type converter through the builder.
67
+ * {@link SimpleEvaluationContext#forPropertyAccessors}, potentially
68
+ * {@linkplain Builder#withAssignmentDisabled() disable assignment}, and optionally
69
+ * activate method resolution and/or a type converter through the builder.
69
70
*
70
71
* <p>Note that {@code SimpleEvaluationContext} is typically not configured
71
72
* with a default root object. Instead it is meant to be created once and
@@ -264,9 +265,8 @@ public Object lookupVariable(String name) {
264
265
* ({@code ++}), and decrement ({@code --}) operators are disabled.
265
266
* @return {@code true} if assignment is enabled; {@code false} otherwise
266
267
* @since 5.3.38
267
- * @see #forPropertyAccessors(PropertyAccessor...)
268
268
* @see #forReadOnlyDataBinding()
269
- * @see #forReadWriteDataBinding ()
269
+ * @see Builder#withAssignmentDisabled ()
270
270
*/
271
271
@ Override
272
272
public boolean isAssignmentEnabled () {
@@ -275,15 +275,18 @@ public boolean isAssignmentEnabled() {
275
275
276
276
/**
277
277
* Create a {@code SimpleEvaluationContext} for the specified {@link PropertyAccessor}
278
- * delegates: typically a custom {@code PropertyAccessor} specific to a use case
279
- * (e.g. attribute resolution in a custom data structure), potentially combined with
280
- * a {@link DataBindingPropertyAccessor} if property dereferences are needed as well.
281
- * <p>Assignment is enabled within expressions evaluated by the context created via
282
- * this factory method.
278
+ * delegates: typically a custom {@code PropertyAccessor} specific to a use case —
279
+ * for example, for attribute resolution in a custom data structure — potentially
280
+ * combined with a {@link DataBindingPropertyAccessor} if property dereferences are
281
+ * needed as well.
282
+ * <p>By default, assignment is enabled within expressions evaluated by the context
283
+ * created via this factory method; however, assignment can be disabled via
284
+ * {@link Builder#withAssignmentDisabled()}.
283
285
* @param accessors the accessor delegates to use
284
286
* @see DataBindingPropertyAccessor#forReadOnlyAccess()
285
287
* @see DataBindingPropertyAccessor#forReadWriteAccess()
286
288
* @see #isAssignmentEnabled()
289
+ * @see Builder#withAssignmentDisabled()
287
290
*/
288
291
public static Builder forPropertyAccessors (PropertyAccessor ... accessors ) {
289
292
for (PropertyAccessor accessor : accessors ) {
@@ -292,7 +295,7 @@ public static Builder forPropertyAccessors(PropertyAccessor... accessors) {
292
295
"ReflectivePropertyAccessor. Consider using DataBindingPropertyAccessor or a custom subclass." );
293
296
}
294
297
}
295
- return new Builder (true , accessors );
298
+ return new Builder (accessors );
296
299
}
297
300
298
301
/**
@@ -303,22 +306,26 @@ public static Builder forPropertyAccessors(PropertyAccessor... accessors) {
303
306
* @see DataBindingPropertyAccessor#forReadOnlyAccess()
304
307
* @see #forPropertyAccessors
305
308
* @see #isAssignmentEnabled()
309
+ * @see Builder#withAssignmentDisabled()
306
310
*/
307
311
public static Builder forReadOnlyDataBinding () {
308
- return new Builder (false , DataBindingPropertyAccessor .forReadOnlyAccess ());
312
+ return new Builder (DataBindingPropertyAccessor .forReadOnlyAccess ()). withAssignmentDisabled ( );
309
313
}
310
314
311
315
/**
312
316
* Create a {@code SimpleEvaluationContext} for read-write access to
313
317
* public properties via {@link DataBindingPropertyAccessor}.
314
- * <p>Assignment is enabled within expressions evaluated by the context created via
315
- * this factory method.
318
+ * <p>By default, assignment is enabled within expressions evaluated by the context
319
+ * created via this factory method. Assignment can be disabled via
320
+ * {@link Builder#withAssignmentDisabled()}; however, it is preferable to use
321
+ * {@link #forReadOnlyDataBinding()} if you desire read-only access.
316
322
* @see DataBindingPropertyAccessor#forReadWriteAccess()
317
323
* @see #forPropertyAccessors
318
324
* @see #isAssignmentEnabled()
325
+ * @see Builder#withAssignmentDisabled()
319
326
*/
320
327
public static Builder forReadWriteDataBinding () {
321
- return new Builder (true , DataBindingPropertyAccessor .forReadWriteAccess ());
328
+ return new Builder (DataBindingPropertyAccessor .forReadWriteAccess ());
322
329
}
323
330
324
331
@@ -337,13 +344,22 @@ public static final class Builder {
337
344
@ Nullable
338
345
private TypedValue rootObject ;
339
346
340
- private final boolean assignmentEnabled ;
347
+ private boolean assignmentEnabled = true ;
341
348
342
- private Builder (boolean assignmentEnabled , PropertyAccessor ... accessors ) {
343
- this .assignmentEnabled = assignmentEnabled ;
349
+ private Builder (PropertyAccessor ... accessors ) {
344
350
this .accessors = Arrays .asList (accessors );
345
351
}
346
352
353
+ /**
354
+ * Disable assignment within expressions evaluated by this evaluation context.
355
+ * @since 5.3.38
356
+ * @see SimpleEvaluationContext#isAssignmentEnabled()
357
+ */
358
+ public Builder withAssignmentDisabled () {
359
+ this .assignmentEnabled = false ;
360
+ return this ;
361
+ }
362
+
347
363
/**
348
364
* Register the specified {@link MethodResolver} delegates for
349
365
* a combination of property access and method resolution.
0 commit comments