2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.spring;
19  
20  import javax.faces.context.FacesContext;
21  import javax.faces.el.EvaluationException;
22  import javax.faces.el.VariableResolver;
23  
24  import org.springframework.web.jsf.FacesContextUtils;
25  
26  /***
27   * <p>Extended <code>VariableResolver</code> that exposes the Spring
28   * <code>WebApplicationContext</code> instance under a variable named
29   * with the specified manifest constant.</p>
30   *
31   * $Id: WebApplicationContextVariableResolver.java 464373 2006-10-16 04:21:54Z rahul $
32   */
33  public class WebApplicationContextVariableResolver extends VariableResolver {
34  
35  
36      // ------------------------------------------------------------- Constructor
37  
38  
39      /***
40       * <p>Construct a new {@link WebApplicationContextVariableResolver}
41       * instance.</p>
42       *
43       * @param original Original resolver to delegate to.
44       */
45      public WebApplicationContextVariableResolver(VariableResolver original) {
46  
47          this.original = original;
48  
49      }
50  
51  
52      // ------------------------------------------------------ Instance Variables
53  
54  
55      /***
56       * <p>The original <code>VariableResolver</code> passed to our constructor.</p>
57       */
58      private VariableResolver original = null;
59  
60  
61      // ------------------------------------------------------ Manifest Constants
62  
63  
64      /***
65       * <p>Variable name to be resoved to our web application context.</p>
66       */
67      private static final String WEB_APPLICATION_CONTEXT_VARIABLE_NAME =
68          "webApplicationContext";
69  
70  
71  
72  
73      // ------------------------------------------------ VariableResolver Methods
74  
75  
76      /***
77       * <p>Resolve variable names known to this resolver; otherwise, delegate to
78       * the original resolver passed to our constructor.</p>
79       *
80       * @param context FacesContext for the current request
81       * @param name Variable name to be resolved
82       *
83       * @exception EvaluationException if an evaluation error occurs
84       */
85      public Object resolveVariable(FacesContext context, String name)
86        throws EvaluationException {
87  
88          if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(name)) {
89              return FacesContextUtils.getWebApplicationContext(context);
90          } else {
91              return original.resolveVariable(context, name);
92          }
93  
94      }
95  
96  
97  }