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.MethodExpression;
29 import javax.el.MethodInfo;
30 import javax.el.MethodNotFoundException;
31 import javax.el.PropertyNotFoundException;
32 import javax.faces.FacesWrapper;
33 import javax.faces.view.Location;
34 import javax.faces.view.facelets.TagAttribute;
35
36
37
38
39
40
41
42 public final class ContextAwareTagMethodExpression extends MethodExpression implements Externalizable, FacesWrapper<MethodExpression>, ContextAware
43 {
44
45 private static final long serialVersionUID = 1L;
46
47 private MethodExpression _wrapped;
48
49 private Location _location;
50
51 private String _qName;
52
53 public ContextAwareTagMethodExpression()
54 {
55 super();
56 }
57
58 public ContextAwareTagMethodExpression(TagAttribute tagAttribute, MethodExpression methodExpression)
59 {
60 _location = tagAttribute.getLocation();
61 _qName = tagAttribute.getQName();
62 _wrapped = methodExpression;
63 }
64
65 public MethodInfo getMethodInfo(ELContext context)
66 {
67 try
68 {
69 return _wrapped.getMethodInfo(context);
70 }
71 catch (PropertyNotFoundException pnfe)
72 {
73 throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
74 }
75 catch (MethodNotFoundException mnfe)
76 {
77 throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
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 invoke(ELContext context, Object[] params)
91 {
92 try
93 {
94 return _wrapped.invoke(context, params);
95 }
96 catch (PropertyNotFoundException pnfe)
97 {
98 throw new ContextAwarePropertyNotFoundException(getLocation(), getLocalExpressionString(), getQName(), pnfe);
99 }
100 catch (MethodNotFoundException mnfe)
101 {
102 throw new ContextAwareMethodNotFoundException(getLocation(), getLocalExpressionString(), getQName(), mnfe);
103 }
104 catch (ELException e)
105 {
106 throw new ContextAwareELException(getLocation(), getLocalExpressionString(), getQName(), e);
107 }
108
109
110
111
112
113 }
114
115
116 private String getLocalExpressionString()
117 {
118 String expressionString = null;
119 try
120 {
121 expressionString = getExpressionString();
122 }
123 catch (Throwable t)
124 {
125
126 }
127 return expressionString;
128 }
129
130 public String getExpressionString()
131 {
132 return _wrapped.getExpressionString();
133 }
134
135 public boolean equals(Object obj)
136 {
137 return _wrapped.equals(obj);
138 }
139
140 public int hashCode()
141 {
142 return _wrapped.hashCode();
143 }
144
145 public boolean isLiteralText()
146 {
147 return _wrapped.isLiteralText();
148 }
149
150 public void writeExternal(ObjectOutput out) throws IOException
151 {
152 out.writeObject(_wrapped);
153 out.writeObject(_location);
154 out.writeUTF(_qName);
155 }
156
157 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
158 {
159 _wrapped = (MethodExpression) in.readObject();
160 _location = (Location) in.readObject();
161 _qName = in.readUTF();
162 }
163
164 public String toString()
165 {
166 return _location + ": " + _wrapped;
167 }
168
169 public Location getLocation() {
170 return _location;
171 }
172
173 public String getQName() {
174 return _qName;
175 }
176
177 public MethodExpression getWrapped() {
178 return _wrapped;
179 }
180
181 }