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
@@ -268,9 +269,8 @@ public Object lookupVariable(String name) {
268
269
* ({@code ++}), and decrement ({@code --}) operators are disabled.
269
270
* @return {@code true} if assignment is enabled; {@code false} otherwise
270
271
* @since 5.3.38
271
- * @see #forPropertyAccessors(PropertyAccessor...)
272
272
* @see #forReadOnlyDataBinding()
273
- * @see #forReadWriteDataBinding ()
273
+ * @see Builder#withAssignmentDisabled ()
274
274
*/
275
275
@ Override
276
276
public boolean isAssignmentEnabled () {
@@ -279,15 +279,18 @@ public boolean isAssignmentEnabled() {
279
279
280
280
/**
281
281
* Create a {@code SimpleEvaluationContext} for the specified {@link PropertyAccessor}
282
- * delegates: typically a custom {@code PropertyAccessor} specific to a use case
283
- * (e.g. attribute resolution in a custom data structure), potentially combined with
284
- * a {@link DataBindingPropertyAccessor} if property dereferences are needed as well.
285
- * <p>Assignment is enabled within expressions evaluated by the context created via
286
- * this factory method.
282
+ * delegates: typically a custom {@code PropertyAccessor} specific to a use case —
283
+ * for example, for attribute resolution in a custom data structure — potentially
284
+ * combined with a {@link DataBindingPropertyAccessor} if property dereferences are
285
+ * needed as well.
286
+ * <p>By default, assignment is enabled within expressions evaluated by the context
287
+ * created via this factory method; however, assignment can be disabled via
288
+ * {@link Builder#withAssignmentDisabled()}.
287
289
* @param accessors the accessor delegates to use
288
290
* @see DataBindingPropertyAccessor#forReadOnlyAccess()
289
291
* @see DataBindingPropertyAccessor#forReadWriteAccess()
290
292
* @see #isAssignmentEnabled()
293
+ * @see Builder#withAssignmentDisabled()
291
294
*/
292
295
public static Builder forPropertyAccessors (PropertyAccessor ... accessors ) {
293
296
for (PropertyAccessor accessor : accessors ) {
@@ -296,7 +299,7 @@ public static Builder forPropertyAccessors(PropertyAccessor... accessors) {
296
299
"ReflectivePropertyAccessor. Consider using DataBindingPropertyAccessor or a custom subclass." );
297
300
}
298
301
}
299
- return new Builder (true , accessors );
302
+ return new Builder (accessors );
300
303
}
301
304
302
305
/**
@@ -307,22 +310,26 @@ public static Builder forPropertyAccessors(PropertyAccessor... accessors) {
307
310
* @see DataBindingPropertyAccessor#forReadOnlyAccess()
308
311
* @see #forPropertyAccessors
309
312
* @see #isAssignmentEnabled()
313
+ * @see Builder#withAssignmentDisabled()
310
314
*/
311
315
public static Builder forReadOnlyDataBinding () {
312
- return new Builder (false , DataBindingPropertyAccessor .forReadOnlyAccess ());
316
+ return new Builder (DataBindingPropertyAccessor .forReadOnlyAccess ()). withAssignmentDisabled ( );
313
317
}
314
318
315
319
/**
316
320
* Create a {@code SimpleEvaluationContext} for read-write access to
317
321
* public properties via {@link DataBindingPropertyAccessor}.
318
- * <p>Assignment is enabled within expressions evaluated by the context created via
319
- * this factory method.
322
+ * <p>By default, assignment is enabled within expressions evaluated by the context
323
+ * created via this factory method. Assignment can be disabled via
324
+ * {@link Builder#withAssignmentDisabled()}; however, it is preferable to use
325
+ * {@link #forReadOnlyDataBinding()} if you desire read-only access.
320
326
* @see DataBindingPropertyAccessor#forReadWriteAccess()
321
327
* @see #forPropertyAccessors
322
328
* @see #isAssignmentEnabled()
329
+ * @see Builder#withAssignmentDisabled()
323
330
*/
324
331
public static Builder forReadWriteDataBinding () {
325
- return new Builder (true , DataBindingPropertyAccessor .forReadWriteAccess ());
332
+ return new Builder (DataBindingPropertyAccessor .forReadWriteAccess ());
326
333
}
327
334
328
335
@@ -343,15 +350,24 @@ public static final class Builder {
343
350
@ Nullable
344
351
private TypedValue rootObject ;
345
352
346
- private final boolean assignmentEnabled ;
353
+ private boolean assignmentEnabled = true ;
347
354
348
355
349
- private Builder (boolean assignmentEnabled , PropertyAccessor ... accessors ) {
350
- this .assignmentEnabled = assignmentEnabled ;
356
+ private Builder (PropertyAccessor ... accessors ) {
351
357
this .propertyAccessors = Arrays .asList (accessors );
352
358
}
353
359
354
360
361
+ /**
362
+ * Disable assignment within expressions evaluated by this evaluation context.
363
+ * @since 5.3.38
364
+ * @see SimpleEvaluationContext#isAssignmentEnabled()
365
+ */
366
+ public Builder withAssignmentDisabled () {
367
+ this .assignmentEnabled = false ;
368
+ return this ;
369
+ }
370
+
355
371
/**
356
372
* Register the specified {@link IndexAccessor} delegates.
357
373
* @param indexAccessors the index accessors to use
0 commit comments