1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.bean;
20
21 import java.io.Serializable;
22
23 import javax.el.ELException;
24 import javax.el.ValueExpression;
25
26 import javax.faces.component.StateHolder;
27 import javax.faces.context.FacesContext;
28 import javax.faces.el.EvaluationException;
29 import javax.faces.el.ValueBinding;
30
31 public class ValueExpressionValueBinding extends ValueBinding
32 {
33
34
35
36
37
38
39
40 public static ValueBinding getValueBinding(ValueExpression ve)
41 {
42
43
44 if (ve instanceof ValueBindingValueExpression)
45 return ((ValueBindingValueExpression)ve).getValueBinding();
46 else if (ve instanceof StateHolder)
47 {
48 if (ve instanceof Serializable)
49 return new SerializableStateHolderValueExpressionValueBinding(ve);
50 else
51 return new StateHolderValueExpressionValueBinding(ve);
52 }
53 else if (ve instanceof Serializable)
54 {
55 return new SerializableValueExpressionValueBinding(ve);
56 }
57 else
58 {
59 return new ValueExpressionValueBinding(ve);
60 }
61 }
62
63 @SuppressWarnings("deprecation")
64 private ValueExpressionValueBinding(ValueExpression ve)
65 {
66 if (ve == null)
67 throw new NullPointerException();
68
69 _ve = ve;
70 }
71
72 public ValueExpression getValueExpression()
73 {
74 return _ve;
75 }
76
77 @SuppressWarnings("deprecation")
78 public Object getValue(FacesContext facesContext)
79 {
80 try
81 {
82 return _ve.getValue(facesContext.getELContext());
83 }
84
85 catch (ELException ee)
86 {
87 throw new EvaluationException(ee.getMessage(), ee.getCause());
88 }
89 }
90
91 @SuppressWarnings("deprecation")
92 public void setValue(FacesContext facesContext, Object object)
93 {
94 try
95 {
96 _ve.setValue(facesContext.getELContext(), object);
97 }
98
99 catch (ELException ee)
100 {
101 throw new EvaluationException(ee.getMessage(), ee.getCause());
102 }
103 }
104
105 @SuppressWarnings("deprecation")
106 public boolean isReadOnly(FacesContext facesContext)
107 {
108 try
109 {
110 return _ve.isReadOnly(facesContext.getELContext());
111 }
112
113 catch (ELException ee)
114 {
115 throw new EvaluationException(ee.getMessage(), ee.getCause());
116 }
117 }
118
119 @SuppressWarnings("deprecation")
120 public Class getType(FacesContext facesContext)
121 {
122 try
123 {
124 return _ve.getType(facesContext.getELContext());
125 }
126
127 catch (ELException ee)
128 {
129 throw new EvaluationException(ee.getMessage(), ee.getCause());
130 }
131 }
132
133 public boolean equals(Object o)
134 {
135 if (o == this)
136 return true;
137
138 if (!(o instanceof ValueExpressionValueBinding))
139 return false;
140
141 ValueExpressionValueBinding that = (ValueExpressionValueBinding) o;
142 return that._ve.equals(_ve);
143 }
144
145 public int hashCode()
146 {
147 return _ve.hashCode();
148 }
149
150 public String toString()
151 {
152 return super.toString() + ", expression=" + _ve;
153 }
154
155 private static class SerializableValueExpressionValueBinding extends ValueExpressionValueBinding
156 implements Serializable
157 {
158 public SerializableValueExpressionValueBinding(ValueExpression ve)
159 {
160 super(ve);
161 }
162 private static final long serialVersionUID = 1L;
163 }
164
165 private static class StateHolderValueExpressionValueBinding extends ValueExpressionValueBinding
166 implements StateHolder
167 {
168 public StateHolderValueExpressionValueBinding(ValueExpression ve)
169 {
170 super(ve);
171 _stateHolder = (StateHolder)ve;
172 }
173
174 public Object saveState(FacesContext facesContext)
175 {
176 return _stateHolder.saveState(facesContext);
177 }
178
179 public void restoreState(FacesContext facesContext, Object object)
180 {
181 _stateHolder.restoreState(facesContext, object);
182 }
183
184 public boolean isTransient()
185 {
186 return _stateHolder.isTransient();
187 }
188
189 public void setTransient(boolean b)
190 {
191 _stateHolder.setTransient(b);
192 }
193
194 private final StateHolder _stateHolder;
195 private static final long serialVersionUID = 1L;
196 }
197
198 private static class SerializableStateHolderValueExpressionValueBinding extends
199 StateHolderValueExpressionValueBinding
200 implements Serializable
201 {
202 public SerializableStateHolderValueExpressionValueBinding(ValueExpression ve)
203 {
204 super(ve);
205 }
206 private static final long serialVersionUID = 1L;
207 }
208
209 private final ValueExpression _ve;
210 }