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.faces.FacesWrapper;
24  import javax.faces.context.FacesContext;
25  import javax.faces.view.Location;
26  
27  /**
28   * 
29   * @author Leonardo Uribe 
30   */
31  public class ResourceLocationValueExpression extends LocationValueExpression implements FacesWrapper<ValueExpression>
32  {
33      
34      private static final long serialVersionUID = -5636849184764526288L;
35      
36      public ResourceLocationValueExpression()
37      {
38          super();
39      }
40      
41      public ResourceLocationValueExpression(Location location, ValueExpression delegate)
42      {
43          super(location, delegate);
44      }
45      
46      @Override
47      public Class<?> getType(ELContext context)
48      {
49          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
50          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
51          try
52          {
53              return delegate.getType(context);
54          }
55          finally
56          {
57              ResourceELUtils.removeResourceLocationForResolver(facesContext);
58          }
59      }
60  
61      @Override
62      public Object getValue(ELContext context)
63      {
64          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
65          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
66          try
67          {
68              return delegate.getValue(context);
69          }
70          finally
71          {
72              ResourceELUtils.removeResourceLocationForResolver(facesContext);
73          }
74      }
75  
76      @Override
77      public boolean isReadOnly(ELContext context)
78      {
79          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
80          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
81          try
82          {
83              return delegate.isReadOnly(context);
84          }
85          finally
86          {
87              ResourceELUtils.removeResourceLocationForResolver(facesContext);
88          }
89      }
90  
91      @Override
92      public void setValue(ELContext context, Object value)
93      {
94          FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
95          ResourceELUtils.saveResourceLocationForResolver(facesContext, location);
96          try
97          {
98              delegate.setValue(context, value);
99          }
100         finally
101         {
102             ResourceELUtils.removeResourceLocationForResolver(facesContext);
103         }
104     }
105 
106     @Override
107     public boolean equals(Object obj)
108     {
109         return delegate.equals(obj);
110     }
111 
112     @Override
113     public String getExpressionString()
114     {
115         return delegate.getExpressionString();
116     }
117 
118     @Override
119     public int hashCode()
120     {
121         return delegate.hashCode();
122     }
123 
124     @Override
125     public boolean isLiteralText()
126     {
127         return delegate.isLiteralText();
128     }
129 
130     public ValueExpression getWrapped()
131     {
132         return delegate;
133     }
134 }