View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.el;
20  
21  import javax.el.ELContext;
22  import javax.el.ValueExpression;
23  import javax.el.ValueReference;
24  import javax.faces.FacesWrapper;
25  import javax.faces.context.FacesContext;
26  import javax.faces.view.Location;
27  
28  /**
29   * 
30   * @author Leonardo Uribe 
31   */
32  public class ResourceLocationValueExpression extends LocationValueExpression implements FacesWrapper<ValueExpression>
33  {
34      
35      private static final long serialVersionUID = -5636849184764526288L;
36      
37      public ResourceLocationValueExpression()
38      {
39          super();
40      }
41      
42      public ResourceLocationValueExpression(Location location, ValueExpression delegate)
43      {
44          super(location, delegate);
45      }
46      
47      @Override
48      public Class<?> getType(ELContext context)
49      {
50          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
51          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
52          try
53          {
54              return delegate.getType(context);
55          }
56          finally
57          {
58              ResourceELUtils.removeResourceLocationForResolver(facesContext);
59          }
60      }
61  
62      @Override
63      public Object getValue(ELContext context)
64      {
65          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
66          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
67          try
68          {
69              return delegate.getValue(context);
70          }
71          finally
72          {
73              ResourceELUtils.removeResourceLocationForResolver(facesContext);
74          }
75      }
76  
77      @Override
78      public boolean isReadOnly(ELContext context)
79      {
80          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
81          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
82          try
83          {
84              return delegate.isReadOnly(context);
85          }
86          finally
87          {
88              ResourceELUtils.removeResourceLocationForResolver(facesContext);
89          }
90      }
91  
92      @Override
93      public void setValue(ELContext context, Object value)
94      {
95          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
96          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
97          try
98          {
99              delegate.setValue(context, value);
100         }
101         finally
102         {
103             ResourceELUtils.removeResourceLocationForResolver(facesContext);
104         }
105     }
106 
107     @Override
108     public boolean equals(Object obj)
109     {
110         return delegate.equals(obj);
111     }
112 
113     @Override
114     public String getExpressionString()
115     {
116         return delegate.getExpressionString();
117     }
118 
119     @Override
120     public int hashCode()
121     {
122         return delegate.hashCode();
123     }
124 
125     @Override
126     public boolean isLiteralText()
127     {
128         return delegate.isLiteralText();
129     }
130 
131     @Override
132     public ValueExpression getWrapped()
133     {
134         return delegate;
135     }
136     
137     @Override
138     public ValueReference getValueReference(ELContext context)
139     {
140         FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
141         ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
142         try
143         {
144             return delegate.getValueReference(context);
145         }
146         finally
147         {
148             ResourceELUtils.removeResourceLocationForResolver(facesContext);
149         }
150     }
151 }