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