From e73f504680a3d95e41f4093077904e194c3e363f Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Thu, 9 Apr 2009 01:56:34 +0000 Subject: [PATCH] Corrected some typos, code samples and changed a bit of wording. All code samples are now SpEL testcases. git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@953 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../src/expressions.xml | 43 ++++++++----------- spring-framework-reference/src/new-in-3.xml | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/spring-framework-reference/src/expressions.xml b/spring-framework-reference/src/expressions.xml index baca2051868..270b126d60f 100644 --- a/spring-framework-reference/src/expressions.xml +++ b/spring-framework-reference/src/expressions.xml @@ -25,7 +25,7 @@ While SpEL serves as the foundation for expression evaluation within the Spring portfolio, it is not directly tied to Spring and can be used independently. In order to be self contained, many of the examples in this - chatper use SpEL as if it was an independent expression language. This + chapter use SpEL as if it was an independent expression language. This requires creating a few boostrapping infrastructure classes such as the parser. Most Spring users will not need to deal with this infrastructure and will instead only author expression strings for evaluation. An example @@ -136,7 +136,7 @@ String message = (String) exp.getValue();The value of the can be thrown, ParseException and EvaluationException when calling 'parser.parseExpression' and - 'exp.getValue' respectfully. + 'exp.getValue' respectedly. SpEL supports a wide range of features, such a calling methods, accessing properties and calling constructors. @@ -145,7 +145,7 @@ String message = (String) exp.getValue();The value of the the string literal ExpressionParser parser = new SpelAntlrExpressionParser(); -Expression exp = parser.parseExpression("'Hello World'.concat(!)"); +Expression exp = parser.parseExpression("'Hello World'.concat('!')"); String message = (String) exp.getValue(); The value of message is now 'Hello World!'. @@ -223,9 +223,9 @@ boolean isEqual = exp.getValue(context, Boolean.class); // evaluates to true

The EvaluationContext interface The interface EvaluationContext is - used when evaluating an expression to resolve properties, methods - ,fields, and to help perform type conversion. The out-of-the-box - implementation, StandardEvaluationContext ,uses + used when evaluating an expression to resolve properties, methods, + fields, and to help perform type conversion. The out-of-the-box + implementation, StandardEvaluationContext, uses reflection to manipulate the object, caching java.lang.reflect's Method, Field, and Constructor @@ -502,14 +502,14 @@ boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue( standard operator notation. Support is not yet implemented for objects that implement the Comparable interface. - // evaluats to true -boolean isEqual = parser.parseExpression("2 == 2").getValue(Boolean.class); + // evaluates to true +boolean trueValue = parser.parseExpression("2 == 2").getValue(Boolean.class); // evaluates to false -boolean isEqual = parser.parseExpression("2 < -5.0").getValue(Boolean.class); +boolean falseValue = parser.parseExpression("2 < -5.0").getValue(Boolean.class); // evaluates to true -boolean isEqual = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);In +boolean trueValue = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);In addition to standard relational operators SpEL supports the 'instanceof' and regular expression based 'matches' operator. @@ -542,8 +542,8 @@ boolean trueValue = parser.parseExpression(expression).getValue(societyContext, // -- OR -- -// evaluates to false -boolean falseValue = parser.parseExpression("true or false").getValue(Boolean.class); +// evaluates to true +boolean trueValue = parser.parseExpression("true or false").getValue(Boolean.class); // evaluates to true String expression = "isMember('Nikola Tesla') or isMember('Albert Einstien')"; @@ -596,9 +596,6 @@ int one = parser.parseExpression("8 / 5 % 2").getValue(Integer.class); // 1 // Operator precedence int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class); // -21 - - - @@ -608,8 +605,8 @@ int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class); Setting of a property is done by using the assignment operator. This would typically be done within a call to - SetValue but can also be done inside a call to - GetValue + setValue but can also be done inside a call to + getValue Inventor inventor = new Inventor(); StandardEvaluationContext inventorContext = new StandardEvaluationContext(); @@ -620,7 +617,6 @@ parser.parseExpression("Name").setValue(inventorContext, "Alexander Seovic2"); // alternatively String aleks = parser.parseExpression("Name = 'Alexandar Seovic'").getValue(inventorContext, String.class); - @@ -636,7 +632,7 @@ String aleks = parser.parseExpression("Name = 'Alexandar Seovic'").getValue(inve Class dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class); -boolean isEqual = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class); +boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class); @@ -674,10 +670,10 @@ parser.parseExpression("Name = #newName").getValue(context); System.out.println(tesla.getName()) // "Mike Tesla"
- The #this variables + The #this variable - The variable #this is always defined and refers to the root - object that is currently being evaluated. + The variable #this is always defined and refers to the + current evaluation object (the object against which unqualified references will be resolved). // create an array of integers List<Integer> primes = new ArrayList<Integer>(); @@ -723,9 +719,6 @@ List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExp This method is then registered with the evaluation context and can be used within an expression string - used in To register this method with the evaluation context and - used in an expression string - ExpressionParser parser = new SpelAntlrExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); diff --git a/spring-framework-reference/src/new-in-3.xml b/spring-framework-reference/src/new-in-3.xml index 44a1aaf22b9..dab03ef4d20 100644 --- a/spring-framework-reference/src/new-in-3.xml +++ b/spring-framework-reference/src/new-in-3.xml @@ -196,7 +196,7 @@ Spring Expression Language Spring introduces an expression language which is similar to Unified - EL in its syntax but offers significantly more feature. The expression + EL in its syntax but offers significantly more features. The expression language can be used when defining XML and Annotation based bean definitions and also serves as the foundation for expression language support across the Spring portfolio. Details of this new functionality can