KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > test > SimpleActionHandler


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.test;
8
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collections JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.apache.log4j.Logger;
15
16 import com.inversoft.beans.BeanException;
17 import com.inversoft.verge.mvc.controller.form.FormAction;
18 import com.inversoft.verge.mvc.controller.form.config.FormConfig;
19
20
21 /**
22  * <p>
23  * This class is a simple action handler
24  * </p>
25  *
26  * @author Brian Pontarelli
27  * @since 2.0
28  * @version 2.0
29  */

30 public class SimpleActionHandler {
31
32     /**
33      * This classes logger
34      */

35     private static final Logger logger = Logger.getLogger(SimpleActionHandler.class);
36
37
38     /**
39      * Constructor for SimpleActionHandler.
40      */

41     public SimpleActionHandler() {
42         super();
43     }
44
45
46     public String JavaDoc handleSetUpUser(FormAction action) {
47         logger.debug("Action: " + action.getAction());
48
49         FormConfig config = action.getFormConfig();
50         if (config != null) {
51             logger.debug("Form based MVC call");
52
53             Object JavaDoc bean = null;
54             try {
55                 bean = config.getFormBean("user").getInstance(action.getHttpServletRequest());
56             } catch (BeanException be) {
57                 logger.error(be);
58             }
59
60             if (bean != null) {
61                 logger.debug("bean: " + bean.toString());
62             }
63         }
64
65         return "success";
66     }
67
68     public String JavaDoc handleSetUpAddress(FormAction action) throws BeanException {
69         logger.debug("Action: " + action.getAction());
70
71         FormConfig config = action.getFormConfig();
72         if (config != null) {
73             logger.debug("Form based MVC call");
74
75             Address addr = (Address) action.getFormBean("address");
76
77             if (addr != null) {
78                 logger.debug("bean: " + addr.toString());
79             }
80
81             addr.setCity("Changed the city");
82         }
83
84         return "failure";
85     }
86
87     public String JavaDoc handleCountrySelect(FormAction action) throws BeanException {
88         Address addr = (Address) action.getFormBean("address");
89         if (addr.getCountry().equals("USA")) {
90             addr.setCities(new String JavaDoc[] {"Denver", "Chicago"});
91         } else if (addr.getCountry().equals("Canada")) {
92             addr.setCities(new String JavaDoc[] {"Ontario", "Quebec"});
93         } else {
94             addr.setCities(null);
95         }
96         return "success";
97     }
98
99     public String JavaDoc handleFinished(FormAction action) throws BeanException {
100         Address addr = (Address) action.getFormBean("address");
101         if (addr != null) {
102             logger.debug("Address: " + addr.toString());
103         }
104         return "success";
105     }
106
107     public String JavaDoc handleLongTxnAction(FormAction action) throws InterruptedException JavaDoc {
108         //Thread.sleep(10000);
109
List JavaDoc list = new ArrayList JavaDoc();
110
111         for (int i = 0; i < 10000; i++) {
112             String JavaDoc s = "" + i;
113             s += s + "" + i + "" + i;
114             list.add(s);
115             Collections.sort(list);
116         }
117         return "done";
118     }
119
120     public String JavaDoc handleGlobalAction1(FormAction action) throws BeanException {
121         return "globalMapping1";
122     }
123 }
Popular Tags