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.MethodExpression; |
28 | |
import javax.el.MethodInfo; |
29 | |
import javax.faces.FacesWrapper; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
import javax.faces.view.Location; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | public class LocationMethodExpression extends MethodExpression |
49 | |
implements FacesWrapper<MethodExpression>, Externalizable, LocationAware |
50 | |
{ |
51 | |
|
52 | |
private static final long serialVersionUID = 1634644578979226893L; |
53 | |
|
54 | |
private Location location; |
55 | |
private MethodExpression delegate; |
56 | |
int ccLevel; |
57 | |
|
58 | |
public LocationMethodExpression() |
59 | |
{ |
60 | 0 | super(); |
61 | 0 | } |
62 | |
|
63 | |
public LocationMethodExpression(Location location, MethodExpression delegate) |
64 | 0 | { |
65 | 0 | this.location = location; |
66 | 0 | this.delegate = delegate; |
67 | 0 | this.ccLevel = 0; |
68 | 0 | } |
69 | |
|
70 | |
public LocationMethodExpression(Location location, MethodExpression 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 LocationMethodExpression apply(int newCCLevel) |
83 | |
{ |
84 | 0 | if(this.ccLevel == newCCLevel) |
85 | |
{ |
86 | 0 | return this; |
87 | |
} |
88 | |
else |
89 | |
{ |
90 | 0 | return new LocationMethodExpression(this.location, this.delegate, newCCLevel); |
91 | |
} |
92 | |
} |
93 | |
|
94 | |
public LocationMethodExpression apply(int newCCLevel, Location newLocation) |
95 | |
{ |
96 | 0 | if(this.ccLevel == newCCLevel && this.location.getPath().equals(newLocation.getPath())) |
97 | |
{ |
98 | 0 | return this; |
99 | |
} |
100 | |
else |
101 | |
{ |
102 | 0 | return new LocationMethodExpression(newLocation, this.delegate, newCCLevel); |
103 | |
} |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
public MethodInfo getMethodInfo(ELContext context) |
108 | |
{ |
109 | 0 | FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class); |
110 | 0 | CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel); |
111 | |
try |
112 | |
{ |
113 | 0 | return delegate.getMethodInfo(context); |
114 | |
} |
115 | |
finally |
116 | |
{ |
117 | 0 | CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext); |
118 | |
} |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public Object invoke(ELContext context, Object[] params) |
123 | |
{ |
124 | 0 | FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class); |
125 | 0 | CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel); |
126 | |
try |
127 | |
{ |
128 | 0 | return delegate.invoke(context, params); |
129 | |
} |
130 | |
finally |
131 | |
{ |
132 | 0 | CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext); |
133 | |
} |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public boolean equals(Object obj) |
138 | |
{ |
139 | 0 | return delegate.equals(obj); |
140 | |
} |
141 | |
|
142 | |
@Override |
143 | |
public String getExpressionString() |
144 | |
{ |
145 | 0 | return delegate.getExpressionString(); |
146 | |
} |
147 | |
|
148 | |
@Override |
149 | |
public int hashCode() |
150 | |
{ |
151 | 0 | return delegate.hashCode(); |
152 | |
} |
153 | |
|
154 | |
@Override |
155 | |
public boolean isLiteralText() |
156 | |
{ |
157 | 0 | return delegate.isLiteralText(); |
158 | |
} |
159 | |
|
160 | |
public MethodExpression getWrapped() |
161 | |
{ |
162 | 0 | return delegate; |
163 | |
} |
164 | |
|
165 | |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException |
166 | |
{ |
167 | 0 | this.delegate = (MethodExpression) in.readObject(); |
168 | 0 | this.location = (Location) in.readObject(); |
169 | 0 | this.ccLevel = in.readInt(); |
170 | 0 | } |
171 | |
|
172 | |
public void writeExternal(ObjectOutput out) throws IOException |
173 | |
{ |
174 | 0 | out.writeObject(this.delegate); |
175 | 0 | out.writeObject(this.location); |
176 | 0 | out.writeInt(this.ccLevel); |
177 | 0 | } |
178 | |
|
179 | |
} |