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.ValueExpression; |
28 | |
import javax.faces.FacesWrapper; |
29 | |
import javax.faces.context.FacesContext; |
30 | |
import javax.faces.view.Location; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class LocationValueExpression extends ValueExpression |
48 | |
implements FacesWrapper<ValueExpression>, Externalizable |
49 | |
{ |
50 | |
|
51 | |
private static final long serialVersionUID = -5636849184764526288L; |
52 | |
|
53 | |
|
54 | |
Location location; |
55 | |
ValueExpression delegate; |
56 | |
int ccLevel; |
57 | |
|
58 | |
public LocationValueExpression() |
59 | |
{ |
60 | 0 | super(); |
61 | 0 | } |
62 | |
|
63 | |
public LocationValueExpression(Location location, ValueExpression delegate) |
64 | 0 | { |
65 | 0 | this.location = location; |
66 | 0 | this.delegate = delegate; |
67 | 0 | this.ccLevel = 0; |
68 | 0 | } |
69 | |
|
70 | |
public LocationValueExpression(Location location, ValueExpression delegate, int ccLevel) |
71 | 0 | { |
72 | 0 | this.location = location; |
73 | 0 | this.delegate = delegate; |
74 | 0 | this.ccLevel = ccLevel; |
75 | 0 | } |
76 | |
|
77 | |
public Location getLocation() |
78 | |
{ |
79 | 0 | return location; |
80 | |
} |
81 | |
|
82 | |
public int getCCLevel() |
83 | |
{ |
84 | 0 | return ccLevel; |
85 | |
} |
86 | |
|
87 | |
public LocationValueExpression apply(int newCCLevel) |
88 | |
{ |
89 | 0 | if(this.ccLevel == newCCLevel) |
90 | |
{ |
91 | 0 | return this; |
92 | |
} |
93 | |
else |
94 | |
{ |
95 | 0 | return new LocationValueExpression(this.location, this.delegate, newCCLevel); |
96 | |
} |
97 | |
} |
98 | |
|
99 | |
public LocationValueExpression apply(int newCCLevel, Location newLocation) |
100 | |
{ |
101 | 0 | if(this.ccLevel == newCCLevel && this.location.getPath().equals(newLocation.getPath())) |
102 | |
{ |
103 | 0 | return this; |
104 | |
} |
105 | |
else |
106 | |
{ |
107 | 0 | return new LocationValueExpression(newLocation, this.delegate, newCCLevel); |
108 | |
} |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public Class<?> getExpectedType() |
113 | |
{ |
114 | 0 | return delegate.getExpectedType(); |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public Class<?> getType(ELContext context) |
119 | |
{ |
120 | 0 | FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class); |
121 | 0 | CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel); |
122 | |
try |
123 | |
{ |
124 | 0 | return delegate.getType(context); |
125 | |
} |
126 | |
finally |
127 | |
{ |
128 | 0 | CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext); |
129 | |
} |
130 | |
} |
131 | |
|
132 | |
@Override |
133 | |
public Object getValue(ELContext context) |
134 | |
{ |
135 | 0 | FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class); |
136 | 0 | CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel); |
137 | |
try |
138 | |
{ |
139 | 0 | return delegate.getValue(context); |
140 | |
} |
141 | |
finally |
142 | |
{ |
143 | 0 | CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext); |
144 | |
} |
145 | |
} |
146 | |
|
147 | |
@Override |
148 | |
public boolean isReadOnly(ELContext context) |
149 | |
{ |
150 | 0 | FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class); |
151 | 0 | CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel); |
152 | |
try |
153 | |
{ |
154 | 0 | return delegate.isReadOnly(context); |
155 | |
} |
156 | |
finally |
157 | |
{ |
158 | 0 | CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext); |
159 | |
} |
160 | |
} |
161 | |
|
162 | |
@Override |
163 | |
public void setValue(ELContext context, Object value) |
164 | |
{ |
165 | 0 | FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class); |
166 | 0 | CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel); |
167 | |
try |
168 | |
{ |
169 | 0 | delegate.setValue(context, value); |
170 | |
} |
171 | |
finally |
172 | |
{ |
173 | 0 | CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext); |
174 | 0 | } |
175 | 0 | } |
176 | |
|
177 | |
@Override |
178 | |
public boolean equals(Object obj) |
179 | |
{ |
180 | 0 | return delegate.equals(obj); |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public String getExpressionString() |
185 | |
{ |
186 | 0 | return delegate.getExpressionString(); |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public int hashCode() |
191 | |
{ |
192 | 0 | return delegate.hashCode(); |
193 | |
} |
194 | |
|
195 | |
@Override |
196 | |
public boolean isLiteralText() |
197 | |
{ |
198 | 0 | return delegate.isLiteralText(); |
199 | |
} |
200 | |
|
201 | |
public ValueExpression getWrapped() |
202 | |
{ |
203 | 0 | return delegate; |
204 | |
} |
205 | |
|
206 | |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException |
207 | |
{ |
208 | 0 | this.delegate = (ValueExpression) in.readObject(); |
209 | 0 | this.location = (Location) in.readObject(); |
210 | 0 | this.ccLevel = in.readInt(); |
211 | 0 | } |
212 | |
|
213 | |
public void writeExternal(ObjectOutput out) throws IOException |
214 | |
{ |
215 | 0 | out.writeObject(this.delegate); |
216 | 0 | out.writeObject(this.location); |
217 | 0 | out.writeInt(this.ccLevel); |
218 | 0 | } |
219 | |
} |