1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import org .springframework .expression .EvaluationException ;
22
22
import org .springframework .expression .Expression ;
23
23
import org .springframework .expression .TypedValue ;
24
+ import org .springframework .lang .Nullable ;
24
25
25
26
/**
26
27
* Represents a template expression broken into pieces. Each piece will be an Expression
@@ -58,6 +59,10 @@ public final String getExpressionString() {
58
59
return this .expressionString ;
59
60
}
60
61
62
+ public final Expression [] getExpressions () {
63
+ return this .expressions ;
64
+ }
65
+
61
66
@ Override
62
67
public String getValue () throws EvaluationException {
63
68
StringBuilder sb = new StringBuilder ();
@@ -70,6 +75,12 @@ public String getValue() throws EvaluationException {
70
75
return sb .toString ();
71
76
}
72
77
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
+
73
84
@ Override
74
85
public String getValue (Object rootObject ) throws EvaluationException {
75
86
StringBuilder sb = new StringBuilder ();
@@ -82,6 +93,12 @@ public String getValue(Object rootObject) throws EvaluationException {
82
93
return sb .toString ();
83
94
}
84
95
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
+
85
102
@ Override
86
103
public String getValue (EvaluationContext context ) throws EvaluationException {
87
104
StringBuilder sb = new StringBuilder ();
@@ -94,6 +111,14 @@ public String getValue(EvaluationContext context) throws EvaluationException {
94
111
return sb .toString ();
95
112
}
96
113
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
+
97
122
@ Override
98
123
public String getValue (EvaluationContext context , Object rootObject ) throws EvaluationException {
99
124
StringBuilder sb = new StringBuilder ();
@@ -107,8 +132,11 @@ public String getValue(EvaluationContext context, Object rootObject) throws Eval
107
132
}
108
133
109
134
@ 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 );
112
140
}
113
141
114
142
@ Override
@@ -117,73 +145,50 @@ public Class<?> getValueType() {
117
145
}
118
146
119
147
@ 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 ;
127
150
}
128
151
129
152
@ 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 ;
132
155
}
133
156
134
157
@ 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 ;
138
160
}
139
161
140
162
@ 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 );
144
165
}
145
166
146
167
@ 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 );
153
170
}
154
171
155
-
156
172
@ 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 );
160
175
}
161
176
162
177
@ Override
163
- public < T > T getValue (EvaluationContext context , Object rootObject , Class < T > desiredResultType )
178
+ public TypeDescriptor getValueTypeDescriptor (EvaluationContext context , Object rootObject )
164
179
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
- }
173
180
174
- @ Override
175
- public Class <?> getValueType (EvaluationContext context , Object rootObject ) throws EvaluationException {
176
- return String .class ;
181
+ return TypeDescriptor .valueOf (String .class );
177
182
}
178
183
179
184
@ 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 ;
182
187
}
183
188
184
189
@ 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 ;
187
192
}
188
193
189
194
@ Override
@@ -192,17 +197,17 @@ public boolean isWritable(EvaluationContext context, Object rootObject) throws E
192
197
}
193
198
194
199
@ Override
195
- public void setValue (EvaluationContext context , Object rootObject , Object value ) throws EvaluationException {
200
+ public void setValue (Object rootObject , @ Nullable Object value ) throws EvaluationException {
196
201
throw new EvaluationException (this .expressionString , "Cannot call setValue on a composite expression" );
197
202
}
198
203
199
204
@ 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" ) ;
202
207
}
203
208
204
209
@ Override
205
- public void setValue (Object rootObject , Object value ) throws EvaluationException {
210
+ public void setValue (EvaluationContext context , Object rootObject , @ Nullable Object value ) throws EvaluationException {
206
211
throw new EvaluationException (this .expressionString , "Cannot call setValue on a composite expression" );
207
212
}
208
213
0 commit comments