1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.el;
20
21 import java.io.Externalizable;
22 import java.io.IOException;
23 import java.io.ObjectInput;
24 import java.io.ObjectOutput;
25
26 import javax.el.ELContext;
27 import javax.el.ELException;
28 import javax.el.PropertyNotFoundException;
29 import javax.el.PropertyNotWritableException;
30 import javax.el.ValueExpression;
31 import javax.faces.FacesWrapper;
32 import javax.faces.view.Location;
33 import javax.faces.view.facelets.TagAttribute;
34
35
36
37
38
39
40
41 public class ContextAwareTagValueExpression
42 extends ValueExpression
43 implements Externalizable, FacesWrapper<ValueExpression>, ContextAware
44 {
45
46 private static final long serialVersionUID = 1L;
47
48 private ValueExpression _wrapped;
49
50 private Location _location;
51
52 private String _qName;
53
54 public ContextAwareTagValueExpression()
55 {
56 super();
57 }
58
59 public ContextAwareTagValueExpression(TagAttribute tagAttribute, ValueExpression valueExpression)
60 {
61 _location = tagAttribute.getLocation();
62 _qName = tagAttribute.getQName();
63 _wrapped = valueExpression;
64 }
65
66 public Class<?> getExpectedType()
67 {
68 return _wrapped.getExpectedType();
69 }
70
71 public Class<?> getType(ELContext context)
72 {
73 try
74 {
75 return _wrapped.getType(context);
76 }
77 catch (PropertyNotFoundException pnfe)
78 {
79 throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
80 }
81 catch (ELException e)
82 {
83 throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
84 }
85
86
87
88
89
90 }
91
92 public Object getValue(ELContext context)
93 {
94 try
95 {
96 return _wrapped.getValue(context);
97 }
98 catch (PropertyNotFoundException pnfe)
99 {
100 throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
101 }
102 catch (ELException e)
103 {
104 throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
105 }
106
107
108
109
110
111 }
112
113 private String getLocalExpressionString()
114 {
115 String expressionString = null;
116 try
117 {
118 expressionString = getExpressionString();
119 }
120 catch (Throwable t)
121 {
122
123 }
124 return expressionString;
125 }
126
127 public boolean isReadOnly(ELContext context)
128 {
129 try
130 {
131 return _wrapped.isReadOnly(context);
132 }
133 catch (PropertyNotFoundException pnfe)
134 {
135 throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
136 }
137 catch (ELException e)
138 {
139 throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
140 }
141
142
143
144
145
146
147 }
148
149 public void setValue(ELContext context, Object value)
150 {
151 try
152 {
153 _wrapped.setValue(context, value);
154 }
155 catch (PropertyNotFoundException pnfe)
156 {
157 throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(),pnfe);
158 }
159 catch (PropertyNotWritableException pnwe)
160 {
161 throw new ContextAwarePropertyNotWritableException(getLocation(), getLocalExpressionString(),
162 getQName(), pnwe);
163 }
164 catch (ELException e)
165 {
166 throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
167 }
168
169
170
171
172
173 }
174
175 public boolean equals(Object obj)
176 {
177 return _wrapped.equals(obj);
178 }
179
180 public String getExpressionString()
181 {
182 return _wrapped.getExpressionString();
183 }
184
185 public int hashCode()
186 {
187 return _wrapped.hashCode();
188 }
189
190 public boolean isLiteralText()
191 {
192 return _wrapped.isLiteralText();
193 }
194
195 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
196 {
197 _wrapped = (ValueExpression) in.readObject();
198 _location = (Location) in.readObject();
199 _qName = in.readUTF();
200 }
201
202 public void writeExternal(ObjectOutput out) throws IOException
203 {
204 out.writeObject(_wrapped);
205 out.writeObject(_location);
206 out.writeUTF(_qName);
207 }
208
209 public String toString()
210 {
211 return _location + ": " + _wrapped;
212 }
213
214 public ValueExpression getWrapped()
215 {
216 return _wrapped;
217 }
218
219 public Location getLocation()
220 {
221 return _location;
222 }
223
224 public String getQName()
225 {
226 return _qName;
227 }
228 }