11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2017 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2121import org .springframework .expression .EvaluationException ;
2222import org .springframework .expression .Expression ;
2323import org .springframework .expression .TypedValue ;
24+ import org .springframework .lang .Nullable ;
2425
2526/**
2627 * Represents a template expression broken into pieces. Each piece will be an Expression
@@ -58,6 +59,10 @@ public final String getExpressionString() {
5859 return this .expressionString ;
5960 }
6061
62+ public final Expression [] getExpressions () {
63+ return this .expressions ;
64+ }
65+
6166 @ Override
6267 public String getValue () throws EvaluationException {
6368 StringBuilder sb = new StringBuilder ();
@@ -70,6 +75,12 @@ public String getValue() throws EvaluationException {
7075 return sb .toString ();
7176 }
7277
78+ @ Override
79+ public <T > T getValue (@ Nullable Class <T > expectedResultType ) throws EvaluationException {
80+ Object value = getValue ();
81+ return ExpressionUtils .convertTypedValue (null , new TypedValue (value ), expectedResultType );
82+ }
83+
7384 @ Override
7485 public String getValue (Object rootObject ) throws EvaluationException {
7586 StringBuilder sb = new StringBuilder ();
@@ -82,6 +93,12 @@ public String getValue(Object rootObject) throws EvaluationException {
8293 return sb .toString ();
8394 }
8495
96+ @ Override
97+ public <T > T getValue (Object rootObject , @ Nullable Class <T > desiredResultType ) throws EvaluationException {
98+ Object value = getValue (rootObject );
99+ return ExpressionUtils .convertTypedValue (null , new TypedValue (value ), desiredResultType );
100+ }
101+
85102 @ Override
86103 public String getValue (EvaluationContext context ) throws EvaluationException {
87104 StringBuilder sb = new StringBuilder ();
@@ -94,6 +111,14 @@ public String getValue(EvaluationContext context) throws EvaluationException {
94111 return sb .toString ();
95112 }
96113
114+ @ Override
115+ public <T > T getValue (EvaluationContext context , @ Nullable Class <T > expectedResultType )
116+ throws EvaluationException {
117+
118+ Object value = getValue (context );
119+ return ExpressionUtils .convertTypedValue (context , new TypedValue (value ), expectedResultType );
120+ }
121+
97122 @ Override
98123 public String getValue (EvaluationContext context , Object rootObject ) throws EvaluationException {
99124 StringBuilder sb = new StringBuilder ();
@@ -107,8 +132,11 @@ public String getValue(EvaluationContext context, Object rootObject) throws Eval
107132 }
108133
109134 @ Override
110- public Class <?> getValueType (EvaluationContext context ) {
111- return String .class ;
135+ public <T > T getValue (EvaluationContext context , Object rootObject , @ Nullable Class <T > desiredResultType )
136+ throws EvaluationException {
137+
138+ Object value = getValue (context ,rootObject );
139+ return ExpressionUtils .convertTypedValue (context , new TypedValue (value ), desiredResultType );
112140 }
113141
114142 @ Override
@@ -117,73 +145,50 @@ public Class<?> getValueType() {
117145 }
118146
119147 @ Override
120- public TypeDescriptor getValueTypeDescriptor (EvaluationContext context ) {
121- return TypeDescriptor .valueOf (String .class );
122- }
123-
124- @ Override
125- public TypeDescriptor getValueTypeDescriptor () {
126- return TypeDescriptor .valueOf (String .class );
148+ public Class <?> getValueType (EvaluationContext context ) {
149+ return String .class ;
127150 }
128151
129152 @ Override
130- public void setValue ( EvaluationContext context , Object value ) throws EvaluationException {
131- throw new EvaluationException ( this . expressionString , "Cannot call setValue on a composite expression" ) ;
153+ public Class <?> getValueType ( Object rootObject ) throws EvaluationException {
154+ return String . class ;
132155 }
133156
134157 @ Override
135- public <T > T getValue (EvaluationContext context , Class <T > expectedResultType ) throws EvaluationException {
136- Object value = getValue (context );
137- return ExpressionUtils .convertTypedValue (context , new TypedValue (value ), expectedResultType );
158+ public Class <?> getValueType (EvaluationContext context , Object rootObject ) throws EvaluationException {
159+ return String .class ;
138160 }
139161
140162 @ Override
141- public <T > T getValue (Class <T > expectedResultType ) throws EvaluationException {
142- Object value = getValue ();
143- return ExpressionUtils .convertTypedValue (null , new TypedValue (value ), expectedResultType );
163+ public TypeDescriptor getValueTypeDescriptor () {
164+ return TypeDescriptor .valueOf (String .class );
144165 }
145166
146167 @ Override
147- public boolean isWritable (EvaluationContext context ) {
148- return false ;
149- }
150-
151- public Expression [] getExpressions () {
152- return this .expressions ;
168+ public TypeDescriptor getValueTypeDescriptor (Object rootObject ) throws EvaluationException {
169+ return TypeDescriptor .valueOf (String .class );
153170 }
154171
155-
156172 @ Override
157- public <T > T getValue (Object rootObject , Class <T > desiredResultType ) throws EvaluationException {
158- Object value = getValue (rootObject );
159- return ExpressionUtils .convertTypedValue (null , new TypedValue (value ), desiredResultType );
173+ public TypeDescriptor getValueTypeDescriptor (EvaluationContext context ) {
174+ return TypeDescriptor .valueOf (String .class );
160175 }
161176
162177 @ Override
163- public < T > T getValue (EvaluationContext context , Object rootObject , Class < T > desiredResultType )
178+ public TypeDescriptor getValueTypeDescriptor (EvaluationContext context , Object rootObject )
164179 throws EvaluationException {
165- Object value = getValue (context ,rootObject );
166- return ExpressionUtils .convertTypedValue (context , new TypedValue (value ), desiredResultType );
167- }
168-
169- @ Override
170- public Class <?> getValueType (Object rootObject ) throws EvaluationException {
171- return String .class ;
172- }
173180
174- @ Override
175- public Class <?> getValueType (EvaluationContext context , Object rootObject ) throws EvaluationException {
176- return String .class ;
181+ return TypeDescriptor .valueOf (String .class );
177182 }
178183
179184 @ Override
180- public TypeDescriptor getValueTypeDescriptor (Object rootObject ) throws EvaluationException {
181- return TypeDescriptor . valueOf ( String . class ) ;
185+ public boolean isWritable (Object rootObject ) throws EvaluationException {
186+ return false ;
182187 }
183188
184189 @ Override
185- public TypeDescriptor getValueTypeDescriptor (EvaluationContext context , Object rootObject ) throws EvaluationException {
186- return TypeDescriptor . valueOf ( String . class ) ;
190+ public boolean isWritable (EvaluationContext context ) {
191+ return false ;
187192 }
188193
189194 @ Override
@@ -192,17 +197,17 @@ public boolean isWritable(EvaluationContext context, Object rootObject) throws E
192197 }
193198
194199 @ Override
195- public void setValue (EvaluationContext context , Object rootObject , Object value ) throws EvaluationException {
200+ public void setValue (Object rootObject , @ Nullable Object value ) throws EvaluationException {
196201 throw new EvaluationException (this .expressionString , "Cannot call setValue on a composite expression" );
197202 }
198203
199204 @ Override
200- public boolean isWritable ( Object rootObject ) throws EvaluationException {
201- return false ;
205+ public void setValue ( EvaluationContext context , @ Nullable Object value ) throws EvaluationException {
206+ throw new EvaluationException ( this . expressionString , "Cannot call setValue on a composite expression" ) ;
202207 }
203208
204209 @ Override
205- public void setValue (Object rootObject , Object value ) throws EvaluationException {
210+ public void setValue (EvaluationContext context , Object rootObject , @ Nullable Object value ) throws EvaluationException {
206211 throw new EvaluationException (this .expressionString , "Cannot call setValue on a composite expression" );
207212 }
208213
0 commit comments