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