Skip to content

Commit 4187e04

Browse files
committed
Backport doc change
1 parent d512cca commit 4187e04

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/asciidoc/core-expressions.adoc

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,30 @@ create a boolean condition:
181181
=== `EvaluationContext`
182182

183183
The interface `EvaluationContext` is used when evaluating an expression to resolve
184-
properties, methods, fields, and to help perform type conversion. The out-of-the-box
185-
implementations, `SimpleEvalutationContext` and `StandardEvaluationContext`, use
186-
reflection to manipulate the object, caching `java.lang.reflect.Method`,
187-
`java.lang.reflect.Field`, and `java.lang.reflect.Constructor` instances for increased
188-
performance.
189-
190-
`SimpleEvaluationContext` exposes a subset of essential SpEL language features and
191-
configuration options. Certain categories of expressions, do not require the full extent
192-
of the SpEL language syntax and arguably should be meaningfully restricted. Examples
184+
properties, methods, fields, and to help perform type conversion. There are two
185+
out-of-the-box implementations.
186+
187+
* `SimpleEvaluationContext` -- exposes a subset of essential SpEL language features and
188+
configuration options, for categories of expressions that do not require the full extent
189+
of the SpEL language syntax and should be meaningfully restricted. Examples
193190
include but are not limited to data binding expressions, property-based filters, and
194-
others. To effect, `SimpleEvaluationContext` supports a subset of the SpEL language syntax
195-
that excludes references to Java types, constructors, and bean references.
191+
others.
196192

197-
`StandardEvaluationContext` exposes the full set of SpEL language features and
193+
* `StandardEvaluationContext` -- exposes the full set of SpEL language features and
198194
configuration options. You may use it to specify a default root object, and to configure
199195
every available evaluation-related strategy.
200196

197+
`SimpleEvaluationContext` is designed to support only a subset of the SpEL language syntax.
198+
It excludes Java type references, constructors, and bean references. It also requires
199+
explicit choosing the level of support for properties and methods in expressions.
200+
By default, the `create()` static factory method enables only read access to properties.
201+
You can also obtain a builder to configure the exact level of support needed, targeting
202+
one of, or some combination of the following:
203+
204+
. Custom {@code PropertyAccessor} only (no reflection).
205+
. Data binding properties for read-only access.
206+
. Data binding properties for read and write.
207+
201208

202209
[[expressions-type-conversion]]
203210
==== Type conversion
@@ -225,7 +232,7 @@ being placed in it. A simple example:
225232
Simple simple = new Simple();
226233
simple.booleanList.add(true);
227234
228-
SimpleEvaluationContext context = new SimpleEvaluationContext();
235+
SimpleEvaluationContext context = SimpleEvaluationContext().create();
229236
230237
// false is passed in here as a string. SpEL and the conversion service will
231238
// correctly recognize that it needs to be a Boolean and convert it
@@ -602,7 +609,7 @@ arrays and lists are obtained using square bracket notation.
602609
[subs="verbatim,quotes"]
603610
----
604611
ExpressionParser parser = new SpelExpressionParser();
605-
SimpleEvaluationContext context = new SimpleEvaluationContext();
612+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
606613
607614
// Inventions Array
608615
@@ -885,7 +892,7 @@ done within a call to `setValue` but can also be done inside a call to `getValue
885892
[subs="verbatim,quotes"]
886893
----
887894
Inventor inventor = new Inventor();
888-
SimpleEvaluationContext context = new SimpleEvaluationContext();
895+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
889896
890897
parser.parseExpression("Name").setValue(context, inventor, "Alexander Seovic2");
891898
@@ -953,7 +960,7 @@ are set using the method setVariable on `EvaluationContext` implementations.
953960
[subs="verbatim,quotes"]
954961
----
955962
Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
956-
SimpleEvaluationContext context = new SimpleEvaluationContext();
963+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
957964
context.setVariable("newName", "Mike Tesla");
958965
959966
parser.parseExpression("Name = #newName").getValue(context, tesla);
@@ -979,7 +986,7 @@ an expression are evaluated, #root always refers to the root.
979986
980987
// create parser and set variable 'primes' as the array of integers
981988
ExpressionParser parser = new SpelExpressionParser();
982-
SimpleEvaluationContext context = new SimpleEvaluationContext();
989+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
983990
context.setVariable("primes",primes);
984991
985992
// all prime numbers > 10 from the list (using selection ?{...})
@@ -1001,7 +1008,7 @@ expression string. The function is registered through the `EvaluationContext`.
10011008
----
10021009
Method method = ...;
10031010
1004-
SimpleEvaluationContext context = new SimpleEvaluationContext();
1011+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
10051012
context.setVariable("myFunction", method);
10061013
----
10071014

@@ -1028,7 +1035,7 @@ The above method can then be registered and used as follows:
10281035
[subs="verbatim,quotes"]
10291036
----
10301037
ExpressionParser parser = new SpelExpressionParser();
1031-
SimpleEvaluationContext context = new SimpleEvaluationContext();
1038+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
10321039
10331040
context.setVariable("reverseString",
10341041
StringUtils.class.getDeclaredMethod("reverseString", String.class));
@@ -1049,7 +1056,7 @@ lookup beans from an expression using the (@) symbol.
10491056
[subs="verbatim,quotes"]
10501057
----
10511058
ExpressionParser parser = new SpelExpressionParser();
1052-
StandardEvaluationContext context = new StandardEvaluationContext();
1059+
StandardEvaluationContext context = StandardEvaluationContext.create();
10531060
context.setBeanResolver(new MyBeanResolver());
10541061
10551062
// This will end up calling resolve(context,"foo") on MyBeanResolver during evaluation
@@ -1062,7 +1069,7 @@ To access a factory bean itself, the bean name should instead be prefixed with a
10621069
[subs="verbatim,quotes"]
10631070
----
10641071
ExpressionParser parser = new SpelExpressionParser();
1065-
StandardEvaluationContext context = new StandardEvaluationContext();
1072+
StandardEvaluationContext context = StandardEvaluationContext.create();
10661073
context.setBeanResolver(new MyBeanResolver());
10671074
10681075
// This will end up calling resolve(context,"&foo") on MyBeanResolver during evaluation
@@ -1140,7 +1147,7 @@ Here is a more complex example.
11401147
ExpressionParser parser = new SpelExpressionParser();
11411148
11421149
Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
1143-
SimpleEvaluationContext context = new SimpleEvaluationContext();
1150+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
11441151
11451152
String name = parser.parseExpression("Name?:'Elvis Presley'").getValue(context, tesla, String.class);
11461153
@@ -1172,7 +1179,7 @@ safe navigation operator will simply return null instead of throwing an exceptio
11721179
Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
11731180
tesla.setPlaceOfBirth(new PlaceOfBirth("Smiljan"));
11741181
1175-
SimpleEvaluationContext context = new SimpleEvaluationContext();
1182+
SimpleEvaluationContext context = SimpleEvaluationContext.create();
11761183
11771184
String city = parser.parseExpression("PlaceOfBirth?.City").getValue(context, tesla, String.class);
11781185
System.out.println(city); // Smiljan
@@ -1240,6 +1247,7 @@ first or the last value. To obtain the first entry matching the selection the sy
12401247

12411248
[[expressions-collection-projection]]
12421249
=== Collection Projection
1250+
12431251
Projection allows a collection to drive the evaluation of a sub-expression and the
12441252
result is a new collection. The syntax for projection is `![projectionExpression]`. Most
12451253
easily understood by example, suppose we have a list of inventors but want the list of
@@ -1262,6 +1270,7 @@ expression against each map entry.
12621270

12631271
[[expressions-templating]]
12641272
=== Expression templating
1273+
12651274
Expression templates allow a mixing of literal text with one or more evaluation blocks.
12661275
Each evaluation block is delimited with prefix and suffix characters that you can
12671276
define, a common choice is to use `#{ }` as the delimiters. For example,
@@ -1307,6 +1316,7 @@ The definition of `TemplateParserContext` is shown below.
13071316

13081317
[[expressions-example-classes]]
13091318
== Classes used in the examples
1319+
13101320
Inventor.java
13111321

13121322
[source,java,indent=0]

0 commit comments

Comments
 (0)