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 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 super();
61 }
62
63 public LocationValueExpression(Location location, ValueExpression delegate)
64 {
65 this.location = location;
66 this.delegate = delegate;
67 this.ccLevel = 0;
68 }
69
70 public LocationValueExpression(Location location, ValueExpression delegate, int ccLevel)
71 {
72 this.location = location;
73 this.delegate = delegate;
74 this.ccLevel = ccLevel;
75 }
76
77 public Location getLocation()
78 {
79 return location;
80 }
81
82 public int getCCLevel()
83 {
84 return ccLevel;
85 }
86
87 public LocationValueExpression apply(int newCCLevel)
88 {
89 if(this.ccLevel == newCCLevel)
90 {
91 return this;
92 }
93 else
94 {
95 return new LocationValueExpression(this.location, this.delegate, newCCLevel);
96 }
97 }
98
99 @Override
100 public Class<?> getExpectedType()
101 {
102 return delegate.getExpectedType();
103 }
104
105 @Override
106 public Class<?> getType(ELContext context)
107 {
108 FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
109 CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel);
110 try
111 {
112 return delegate.getType(context);
113 }
114 finally
115 {
116 CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext);
117 }
118 }
119
120 @Override
121 public Object getValue(ELContext context)
122 {
123 FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
124 CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel);
125 try
126 {
127 return delegate.getValue(context);
128 }
129 finally
130 {
131 CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext);
132 }
133 }
134
135 @Override
136 public boolean isReadOnly(ELContext context)
137 {
138 FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
139 CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel);
140 try
141 {
142 return delegate.isReadOnly(context);
143 }
144 finally
145 {
146 CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext);
147 }
148 }
149
150 @Override
151 public void setValue(ELContext context, Object value)
152 {
153 FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
154 CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location, ccLevel);
155 try
156 {
157 delegate.setValue(context, value);
158 }
159 finally
160 {
161 CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext);
162 }
163 }
164
165 @Override
166 public boolean equals(Object obj)
167 {
168 return delegate.equals(obj);
169 }
170
171 @Override
172 public String getExpressionString()
173 {
174 return delegate.getExpressionString();
175 }
176
177 @Override
178 public int hashCode()
179 {
180 return delegate.hashCode();
181 }
182
183 @Override
184 public boolean isLiteralText()
185 {
186 return delegate.isLiteralText();
187 }
188
189 public ValueExpression getWrapped()
190 {
191 return delegate;
192 }
193
194 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
195 {
196 this.delegate = (ValueExpression) in.readObject();
197 this.location = (Location) in.readObject();
198 this.ccLevel = in.readInt();
199 }
200
201 public void writeExternal(ObjectOutput out) throws IOException
202 {
203 out.writeObject(this.delegate);
204 out.writeObject(this.location);
205 out.writeInt(this.ccLevel);
206 }
207 }