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
@@ -234,9 +235,8 @@ public Object lookupVariable(String name) {
234
235
* ({@code ++}), and decrement ({@code --}) operators are disabled.
235
236
* @return {@code true} if assignment is enabled; {@code false} otherwise
236
237
* @since 5.3.38
237
- * @see #forPropertyAccessors(PropertyAccessor...)
238
238
* @see #forReadOnlyDataBinding()
239
- * @see #forReadWriteDataBinding ()
239
+ * @see Builder#withAssignmentDisabled ()
240
240
*/
241
241
@ Override
242
242
public boolean isAssignmentEnabled () {
@@ -245,15 +245,18 @@ public boolean isAssignmentEnabled() {
245
245
246
246
/**
247
247
* Create a {@code SimpleEvaluationContext} for the specified {@link PropertyAccessor}
248
- * delegates: typically a custom {@code PropertyAccessor} specific to a use case
249
- * (e.g. attribute resolution in a custom data structure), potentially combined with
250
- * a {@link DataBindingPropertyAccessor} if property dereferences are needed as well.
251
- * <p>Assignment is enabled within expressions evaluated by the context created via
252
- * this factory method.
248
+ * delegates: typically a custom {@code PropertyAccessor} specific to a use case —
249
+ * for example, for attribute resolution in a custom data structure — potentially
250
+ * combined with a {@link DataBindingPropertyAccessor} if property dereferences are
251
+ * needed as well.
252
+ * <p>By default, assignment is enabled within expressions evaluated by the context
253
+ * created via this factory method; however, assignment can be disabled via
254
+ * {@link Builder#withAssignmentDisabled()}.
253
255
* @param accessors the accessor delegates to use
254
256
* @see DataBindingPropertyAccessor#forReadOnlyAccess()
255
257
* @see DataBindingPropertyAccessor#forReadWriteAccess()
256
258
* @see #isAssignmentEnabled()
259
+ * @see Builder#withAssignmentDisabled()
257
260
*/
258
261
public static Builder forPropertyAccessors (PropertyAccessor ... accessors ) {
259
262
for (PropertyAccessor accessor : accessors ) {
@@ -262,7 +265,7 @@ public static Builder forPropertyAccessors(PropertyAccessor... accessors) {
262
265
"ReflectivePropertyAccessor. Consider using DataBindingPropertyAccessor or a custom subclass." );
263
266
}
264
267
}
265
- return new Builder (true , accessors );
268
+ return new Builder (accessors );
266
269
}
267
270
268
271
/**
@@ -273,22 +276,26 @@ public static Builder forPropertyAccessors(PropertyAccessor... accessors) {
273
276
* @see DataBindingPropertyAccessor#forReadOnlyAccess()
274
277
* @see #forPropertyAccessors
275
278
* @see #isAssignmentEnabled()
279
+ * @see Builder#withAssignmentDisabled()
276
280
*/
277
281
public static Builder forReadOnlyDataBinding () {
278
- return new Builder (false , DataBindingPropertyAccessor .forReadOnlyAccess ());
282
+ return new Builder (DataBindingPropertyAccessor .forReadOnlyAccess ()). withAssignmentDisabled ( );
279
283
}
280
284
281
285
/**
282
286
* Create a {@code SimpleEvaluationContext} for read-write access to
283
287
* public properties via {@link DataBindingPropertyAccessor}.
284
- * <p>Assignment is enabled within expressions evaluated by the context created via
285
- * this factory method.
288
+ * <p>By default, assignment is enabled within expressions evaluated by the context
289
+ * created via this factory method. Assignment can be disabled via
290
+ * {@link Builder#withAssignmentDisabled()}; however, it is preferable to use
291
+ * {@link #forReadOnlyDataBinding()} if you desire read-only access.
286
292
* @see DataBindingPropertyAccessor#forReadWriteAccess()
287
293
* @see #forPropertyAccessors
288
294
* @see #isAssignmentEnabled()
295
+ * @see Builder#withAssignmentDisabled()
289
296
*/
290
297
public static Builder forReadWriteDataBinding () {
291
- return new Builder (true , DataBindingPropertyAccessor .forReadWriteAccess ());
298
+ return new Builder (DataBindingPropertyAccessor .forReadWriteAccess ());
292
299
}
293
300
294
301
@@ -307,15 +314,24 @@ public static final class Builder {
307
314
@ Nullable
308
315
private TypedValue rootObject ;
309
316
310
- private final boolean assignmentEnabled ;
317
+ private boolean assignmentEnabled = true ;
311
318
312
319
313
- private Builder (boolean assignmentEnabled , PropertyAccessor ... accessors ) {
314
- this .assignmentEnabled = assignmentEnabled ;
320
+ private Builder (PropertyAccessor ... accessors ) {
315
321
this .accessors = Arrays .asList (accessors );
316
322
}
317
323
318
324
325
+ /**
326
+ * Disable assignment within expressions evaluated by this evaluation context.
327
+ * @since 5.3.38
328
+ * @see SimpleEvaluationContext#isAssignmentEnabled()
329
+ */
330
+ public Builder withAssignmentDisabled () {
331
+ this .assignmentEnabled = false ;
332
+ return this ;
333
+ }
334
+
319
335
/**
320
336
* Register the specified {@link MethodResolver} delegates for
321
337
* a combination of property access and method resolution.
@@ -347,7 +363,6 @@ public Builder withInstanceMethods() {
347
363
return this ;
348
364
}
349
365
350
-
351
366
/**
352
367
* Register a custom {@link ConversionService}.
353
368
* <p>By default a {@link StandardTypeConverter} backed by a
@@ -359,6 +374,7 @@ public Builder withConversionService(ConversionService conversionService) {
359
374
this .typeConverter = new StandardTypeConverter (conversionService );
360
375
return this ;
361
376
}
377
+
362
378
/**
363
379
* Register a custom {@link TypeConverter}.
364
380
* <p>By default a {@link StandardTypeConverter} backed by a
0 commit comments