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