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   * $Id: Wizard.java 499272 2007-01-24 06:10:08Z craigmcc $
18   */
19  
20  package org.apache.shale.examples.test.dialog.scxml;
21  
22  import javax.faces.context.FacesContext;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.shale.dialog.Constants;
27  import org.apache.shale.dialog.DialogContext;
28  import org.apache.shale.dialog.DialogContextManager;
29  import org.apache.shale.dialog.DialogHelper;
30  
31  /***
32   * <p>Utility actions for the wizard dialog series of tests.</p>
33   */
34  public class Wizard {
35      
36  
37      // ------------------------------------------------------ Instance Variables
38  
39  
40      /***
41       * <p>Log instance for this class.</p>
42       */
43      private Log log = LogFactory.getLog(Wizard.class);
44  
45  
46      // ---------------------------------------------------------- Wizard Actions
47  
48  
49      /***
50       * <p>Log the fact that this wizard dialog was cancelled.</p>
51       */
52      public String cancel() {
53  
54          if (log.isInfoEnabled()) {
55              log.info("Wizard dialog was cancelled");
56          }
57          // Real apps would clean up things here
58          return "cancelled";
59  
60      }
61  
62  
63      /***
64       * <p>Log the fact that this wizard dialog was finished.</p>
65       */
66      public String finish() {
67  
68          if (log.isInfoEnabled()) {
69              log.info("Wizard dialog was finished");
70          }
71          // Real apps would store away database information here
72          return "finished";
73  
74      }
75  
76  
77      /***
78       * <p>Set up the wizard state information with dummy data.  This is an action
79       * state that is invoked by the dialog.</p>
80       */
81      public String setup() {
82  
83          FacesContext context = FacesContext.getCurrentInstance();
84          DialogContext dcontext = DialogHelper.getDialogContext(context);
85          if (log.isInfoEnabled()) {
86              log.info("Setting up WizardData for a new dialog context id " + dcontext.getId());
87          }
88  
89          WizardData data = (WizardData) dcontext.getData();
90          data.setUsername("initUsername");
91          data.setPassword("initPassword");
92          data.setName("initName");
93          data.setAddress1("initAddress1");
94          data.setAddress2("initAddress2");
95          data.setCity("initCity");
96          data.setState("initState");
97          data.setZipCode("initZipCode");
98          data.setAdministrator(false);
99          data.setEnabled(true);
100 
101         return "success";
102 
103     }
104 
105 
106     /***
107      * <p>Programmatically start an instance of the wizard dialog.</p>
108      */
109     public String start() {
110 
111         if (log.isInfoEnabled()) {
112             log.info("Starting a wizard dialog programmatically");
113         }
114 
115         FacesContext context = FacesContext.getCurrentInstance();
116         DialogContextManager manager =
117                 DialogHelper.getDialogContextManager(context);
118         DialogContext dcontext = manager.create(context, "wizard");
119         dcontext.start(context);
120         return null;
121 
122     }
123 
124 
125 }