String message = (String) exp.getValue();</programlisting>The value of the
message variable is simply 'Hello World'. </para>
<para>The SpEL classes and interfaces you are most likely to use are
located in the packages <package>org.springframework.expression</package>
and its subpackages <package>spel.antlr</package> and
<package>spel.support</package>.</para>
<para>The expression language is based on a grammar and uses ANTLR to
construct the lexer and parser. The interface
<interfacename>ExpressionParser</interfacename> is responsible for parsing
an expression string, in this case a string literal denoted by the
surrounding single quotes. The interface
an expression string. In this example the expression string is a string
literal denoted by the surrounding single quotes. The interface
<interfacename>Expression</interfacename> is responsible for evaluating
the previously defined expression string. There are two exceptions that
can be thrown, <classname>ParseException</classname> and
@ -128,10 +133,10 @@ String message = (String) exp.getValue();</programlisting>The value of the
@@ -128,10 +133,10 @@ String message = (String) exp.getValue();</programlisting>The value of the
<para>SpEL supports a wide range of features, such a calling methods,
accessing properties and calling constructors. </para>
<para>As an example to method invocation, we call the 'concat' method on
<para>As an example of method invocation, we call the 'concat' method on
the string literal</para>
<programlisting>ExpressionParser parser = new SpelAntlrExpressionParser();
<programlistinglang=""language="java">ExpressionParser parser = new SpelAntlrExpressionParser();
@ -243,7 +261,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -243,7 +261,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>A property or constructor-arg value can be set using expressions
@ -252,7 +270,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -252,7 +270,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>The variable 'systemProperties' is predefined, so you can use it
@ -261,7 +279,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -261,7 +279,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>You can also refer to other bean properties by name, for
@ -278,13 +296,14 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -278,13 +296,14 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>The @Value annotation can be placed on fields, methods and
method/constructor parameters to specify a default value.</para>
<para>The <literal>@Value</literal> annotation can be placed on fields,
methods and method/constructor parameters to specify a default
value.</para>
<para>Here is an example to set the default value of a field
variable</para>
<programlisting>public static class FieldValueTestBean
<programlistinglanguage="java">public static class FieldValueTestBean
@Value("#{ systemProperties['user.region'] }")
private String defaultLocale;
@ -306,7 +325,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -306,7 +325,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>The equivalent but on a property setter method is shown
below</para>
<programlisting>public static class PropertyValueTestBean
<programlistinglanguage="java">public static class PropertyValueTestBean
private String defaultLocale;
@ -326,7 +345,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -326,7 +345,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>Autowired methods and constructors can also use the
<literal>@Value</literal> annotation.</para>
<programlisting>public class SimpleMovieLister {
<programlistinglanguage="java">public class SimpleMovieLister {
private MovieFinder movieFinder;
private String defaultLocale;
@ -341,7 +360,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -341,7 +360,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
// ...
}</programlisting>
<para><programlisting>public class MovieRecommender {
<para><programlistinglanguage="java">public class MovieRecommender {
private String defaultLocale;
@ -362,18 +381,55 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -362,18 +381,55 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<sectionid="expressions-language-ref">
<title>Language Reference</title>
<para></para>
<section>
<sectionid="expressions-ref-literal">
<title>Literal expressions</title>
<para>blah blah</para>
<para>The types of literal expressions supported are strings, dates,
numeric values (int, real, and hex), boolean and null. String are
delimited by single quotes. To put a single quote itself in a string use
the backslash character. The following listing shows simple usage of
literals. Typically they would not be used in isolation like this, but
as part of a more complex expression, for example using a literal on one
side of a logical comparison operator. </para>
<programlistinglanguage="java">ExpressionParser parser = new SpelAntlrExpressionParser();
<para>Navigating through properties is easy, just use a period to
indicate a nested property value. The instances of Inventor class, pupin
and tesla, were populated with data listed in section Section <link
linkend="expressions-examples-classes">Classes used in the
examples</link>. To navigate "down" and get Tesla's year of birth and
Pupin's city of birth the following expressions are used </para>
<programlistinglang=""language="java">int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context); // 1856
String city = (String) parser.parseExpression("placeOfBirth.City").getValue(context);</programlisting>
<para>Case insensitivty is allowed for the first letter of proprety
names. The contents of arrays and lists are obtained using square
bracket notation. </para>
<programlisting></programlisting>
</section>
<section>
@ -432,7 +488,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -432,7 +488,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
<para>blah blah</para>
</section>
<section>
<sectionid="expressions-ref-variables">
<title>Variables</title>
<para>blah blah</para>
@ -444,7 +500,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -444,7 +500,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
</section>
</section>
<section>
<sectionid="expressions-ref-functions">
<title>Functions</title>
<para>blah blah</para>
@ -457,7 +513,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last
@@ -457,7 +513,7 @@ String name = (String) exp.getValue(context);</programlisting>In the last