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;
19  
20  import javax.faces.context.FacesContext;
21  
22  /***
23   * <p>Helper class that provides static accessor methods for key objects
24   * provided by the Dialog Manager module.</p>
25   *
26   * @since 1.1.0
27   */
28  public final class DialogHelper {
29      
30  
31      /***
32       * <p>Private constructor to prevent instantiation.</p>
33       */
34      private DialogHelper() {
35          ;
36      }
37  
38      /***
39       * <p>Return the <code>data</code> property of the active
40       * {@link DialogContext} instance for the current request, if any;
41       * otherwise, return <code>null</code>.</p>
42       */
43      public static Object getDialogData() {
44  
45          return getDialogData(FacesContext.getCurrentInstance());
46  
47      }
48  
49  
50      /***
51       * <p>Return the <code>data</code> property of the active
52       * {@link DialogContext} instance for the current request, if any;
53       * otherwise, return <code>null</code>.</p>
54       *
55       * @param context <code>FacesContext</code> for the current request
56       */
57      public static Object getDialogData(FacesContext context) {
58  
59          DialogContext dcontext = getDialogContext(context);
60          if (dcontext != null) {
61              return dcontext.getData();
62          } else {
63              return null;
64          }
65  
66      }
67  
68      /***
69       * <p>Return the active {@link DialogContext} instance for the current
70       * request, if any; otherwise, return <code>null</code>.</p>
71       */
72      public static DialogContext getDialogContext() {
73  
74          return getDialogContext(FacesContext.getCurrentInstance());
75  
76      }
77  
78  
79      /***
80       * <p>Return the active {@link DialogContext} instance for the current
81       * request, if any; otherwise, return <code>null</code>.</p>
82       *
83       * @param context <code>FacesContext</code> for the current request
84       */
85      public static DialogContext getDialogContext(FacesContext context) {
86  
87          DialogContextManager manager = getDialogContextManager(context);
88          if (manager != null) {
89              return manager.getActiveDialogContext(context);
90          } else {
91              return null;
92          }
93  
94      }
95  
96  
97      /***
98       * <p>Return the {@link DialogContextManager} instance for the current
99       * user, creating it first if necessary.</p>
100      */
101     public static DialogContextManager getDialogContextManager() {
102 
103         return getDialogContextManager(FacesContext.getCurrentInstance());
104 
105     }
106 
107 
108     /***
109      * <p>Return the {@link DialogContextManager} instance for the current
110      * user, creating it first if necessary.</p>
111      *
112      * @param context <code>FacesContext</code> for the current request
113      */
114     public static DialogContextManager getDialogContextManager(FacesContext context) {
115 
116         DialogContextManager manager = (DialogContextManager)
117           context.getApplication().getVariableResolver().
118           resolveVariable(context, Constants.MANAGER_BEAN);
119         return manager;
120 
121     }
122 
123 
124 }