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