1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package javax.faces.component; |
21 | |
|
22 | |
import javax.el.ELException; |
23 | |
import javax.el.ValueExpression; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.el.EvaluationException; |
26 | |
import javax.faces.el.PropertyNotFoundException; |
27 | |
import javax.faces.el.ValueBinding; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
@SuppressWarnings("deprecation") |
38 | |
class _ValueExpressionToValueBinding extends ValueBinding implements StateHolder |
39 | |
{ |
40 | |
|
41 | |
private ValueExpression _valueExpression; |
42 | |
|
43 | 0 | private boolean isTransient = false; |
44 | |
|
45 | |
|
46 | |
protected _ValueExpressionToValueBinding() |
47 | 0 | { |
48 | 0 | _valueExpression = null; |
49 | 0 | } |
50 | |
|
51 | |
@Override |
52 | |
public int hashCode() |
53 | |
{ |
54 | 0 | final int PRIME = 31; |
55 | 0 | int result = 1; |
56 | 0 | result = PRIME * result + ((_valueExpression == null) ? 0 : _valueExpression.hashCode()); |
57 | 0 | result = PRIME * result + (isTransient ? 1231 : 1237); |
58 | 0 | return result; |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public boolean equals(Object obj) |
63 | |
{ |
64 | 0 | if (this == obj) |
65 | 0 | return true; |
66 | 0 | if (obj == null) |
67 | 0 | return false; |
68 | 0 | if (getClass() != obj.getClass()) |
69 | 0 | return false; |
70 | 0 | final _ValueExpressionToValueBinding other = (_ValueExpressionToValueBinding) obj; |
71 | 0 | if (_valueExpression == null) |
72 | |
{ |
73 | 0 | if (other._valueExpression != null) |
74 | 0 | return false; |
75 | |
} |
76 | 0 | else if (!_valueExpression.equals(other._valueExpression)) |
77 | 0 | return false; |
78 | 0 | if (isTransient != other.isTransient) |
79 | 0 | return false; |
80 | 0 | return true; |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public ValueExpression getValueExpression() |
87 | |
{ |
88 | 0 | return getNotNullValueExpression(); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
private ValueExpression getNotNullValueExpression() |
95 | |
{ |
96 | 0 | if (_valueExpression == null) |
97 | |
{ |
98 | 0 | throw new IllegalStateException("value expression is null"); |
99 | |
} |
100 | 0 | return _valueExpression; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public String getExpressionString() |
105 | |
{ |
106 | 0 | return getNotNullValueExpression().getExpressionString(); |
107 | |
} |
108 | |
|
109 | |
|
110 | |
public _ValueExpressionToValueBinding(ValueExpression valueExpression) |
111 | 0 | { |
112 | 0 | if (valueExpression == null) |
113 | |
{ |
114 | 0 | throw new IllegalArgumentException("value expression must not be null."); |
115 | |
} |
116 | 0 | _valueExpression = valueExpression; |
117 | 0 | } |
118 | |
|
119 | |
@Override |
120 | |
public void setValue(FacesContext facesContext, Object value) throws EvaluationException, PropertyNotFoundException |
121 | |
{ |
122 | |
try |
123 | |
{ |
124 | 0 | getNotNullValueExpression().setValue(facesContext.getELContext(), value); |
125 | |
} |
126 | 0 | catch (javax.el.PropertyNotFoundException e) |
127 | |
{ |
128 | 0 | throw new javax.faces.el.PropertyNotFoundException(e); |
129 | |
} |
130 | 0 | catch (ELException e) |
131 | |
{ |
132 | 0 | throw new EvaluationException(e); |
133 | 0 | } |
134 | 0 | } |
135 | |
|
136 | |
@Override |
137 | |
public boolean isReadOnly(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException |
138 | |
{ |
139 | |
|
140 | |
try |
141 | |
{ |
142 | 0 | return getNotNullValueExpression().isReadOnly(facesContext.getELContext()); |
143 | |
} |
144 | 0 | catch (javax.el.PropertyNotFoundException e) |
145 | |
{ |
146 | 0 | throw new javax.faces.el.PropertyNotFoundException(e); |
147 | |
} |
148 | 0 | catch (ELException e) |
149 | |
{ |
150 | 0 | throw new EvaluationException(e); |
151 | |
} |
152 | |
|
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public Object getValue(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException |
157 | |
{ |
158 | |
try |
159 | |
{ |
160 | 0 | return getNotNullValueExpression().getValue(facesContext.getELContext()); |
161 | |
} |
162 | 0 | catch (javax.el.PropertyNotFoundException e) |
163 | |
{ |
164 | 0 | throw new javax.faces.el.PropertyNotFoundException(e); |
165 | |
} |
166 | 0 | catch (ELException e) |
167 | |
{ |
168 | 0 | throw new EvaluationException(e); |
169 | |
} |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public Class getType(FacesContext facesContext) throws EvaluationException, PropertyNotFoundException |
174 | |
{ |
175 | |
try |
176 | |
{ |
177 | 0 | return getNotNullValueExpression().getType(facesContext.getELContext()); |
178 | |
} |
179 | 0 | catch (javax.el.PropertyNotFoundException e) |
180 | |
{ |
181 | 0 | throw new javax.faces.el.PropertyNotFoundException(e); |
182 | |
} |
183 | 0 | catch (ELException e) |
184 | |
{ |
185 | 0 | throw new EvaluationException(e); |
186 | |
} |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
public void restoreState(FacesContext facesContext, Object state) |
192 | |
{ |
193 | 0 | if (state != null) |
194 | |
{ |
195 | 0 | if (state instanceof ValueExpression) |
196 | |
{ |
197 | 0 | _valueExpression = (ValueExpression) state; |
198 | |
} |
199 | |
else |
200 | |
{ |
201 | 0 | Object[] stateArray = (Object[]) state; |
202 | 0 | _valueExpression = (ValueExpression) _ClassUtils.newInstance((String) stateArray[0], |
203 | |
ValueExpression.class); |
204 | 0 | ((StateHolder) _valueExpression).restoreState(facesContext, stateArray[1]); |
205 | |
} |
206 | |
} |
207 | 0 | } |
208 | |
|
209 | |
public Object saveState(FacesContext context) |
210 | |
{ |
211 | 0 | if (!isTransient) |
212 | |
{ |
213 | 0 | if (_valueExpression instanceof StateHolder) |
214 | |
{ |
215 | 0 | Object[] state = new Object[2]; |
216 | 0 | state[0] = _valueExpression.getClass().getName(); |
217 | 0 | state[1] = ((StateHolder) _valueExpression).saveState(context); |
218 | 0 | return state; |
219 | |
} |
220 | |
else |
221 | |
{ |
222 | 0 | return _valueExpression; |
223 | |
} |
224 | |
} |
225 | 0 | return null; |
226 | |
} |
227 | |
|
228 | |
public void setTransient(boolean newTransientValue) |
229 | |
{ |
230 | 0 | isTransient = newTransientValue; |
231 | 0 | } |
232 | |
|
233 | |
public boolean isTransient() |
234 | |
{ |
235 | 0 | return isTransient; |
236 | |
} |
237 | |
|
238 | |
} |