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.dialog.faces;
19  
20  import javax.faces.context.FacesContext;
21  import javax.faces.el.EvaluationException;
22  import javax.faces.el.VariableResolver;
23  import org.apache.shale.dialog.Constants;
24  import org.apache.shale.dialog.DialogContext;
25  import org.apache.shale.dialog.DialogHelper;
26  
27  /***
28   * <p>Variable resolver that provides access to the instance data for a
29   * particular {@link DialogContext} instance with a single symbol.</p>
30   *
31   * @since 1.1
32   */
33  public final class DialogVariableResolver extends VariableResolver {
34  
35  
36      // ------------------------------------------------------------ Constructors
37  
38  
39      /***
40       * <p>Wrap the specified <code>VariableResolver</code> instance.</p>
41       *
42       * @param original Original instance to be wrapped
43       */
44      public DialogVariableResolver(VariableResolver original) {
45          this.original = original;
46      }
47  
48  
49      // ------------------------------------------------------ Instance Variables
50  
51  
52      /***
53       * <p>The <code>VariableResolver</code> to which we should delegate for
54       * variable names other than the one of interest.</p>
55       */
56      private VariableResolver original = null;
57  
58  
59      // ---------------------------------------------------------- Public Methods
60  
61  
62      /***
63       * <p>Resolve a reference to our dialog instance data (if requested), or
64       * delegate to the original <code>VariableResolver</code>.</p>
65       *
66       * @param context <code>FacesContext</code> for the current request
67       * @param name Name of the variable to resolve
68       */
69      public Object resolveVariable(FacesContext context, String name)
70        throws EvaluationException {
71  
72          // Delegate unless we are after a variable name of interest
73          if (!Constants.DIALOG_SCOPE.equals(name)) {
74              return original.resolveVariable(context, name);
75          }
76  
77          // Look up and return our instance data object (if any)
78          DialogContext dcontext = DialogHelper.getDialogContext(context);
79          if (dcontext != null) {
80              return dcontext.getData();
81          } else {
82              return null;
83          }
84  
85  
86      }
87  
88  
89  }