1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package jdbcadmin.web.actions;
21
22 import java.util.List;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import jdbcadmin.core.data.Schema;
28 import jdbcadmin.web.ContexteManager;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.struts.action.ActionError;
33 import org.apache.struts.action.ActionErrors;
34 import org.apache.struts.action.ActionForm;
35 import org.apache.struts.action.ActionForward;
36 import org.apache.struts.action.ActionMapping;
37
38 /***
39 * List schemas.
40 * @struts.action path="/listSchema"
41 * @struts.action-forward name="main" path="/main.do" redirect="true"
42 * @struts.action-forward name="list" path="/main.do" redirect="true"
43 * @author Thomas Recloux (trecloux@norsys.fr)
44 */
45 public class SchemaListAction extends IndexedAction {
46
47 /*** Logger */
48 private static Log logger = LogFactory.getLog(SchemaListAction.class);
49
50 /***
51 * Constructor
52 */
53 public SchemaListAction() {
54 super();
55 }
56
57 /***
58 * {@inheritDoc}
59 */
60 public ActionForward indexedExec(ActionMapping mapping, ActionForm form,
61 HttpServletRequest request, HttpServletResponse response)
62 throws Exception {
63
64 ActionErrors errors = new ActionErrors();
65 String forward = "list";
66
67 try {
68
69 List schemas = ContexteManager.getInspector(request).getSchemas();
70 if (schemas.size() > 1) {
71 ContexteManager.setSchemas(request, schemas);
72 } else if (schemas.size() == 1) {
73 ContexteManager.setCurrentSchema(request, ((Schema) schemas
74 .get(0)).getName());
75 forward = "main";
76 } else {
77 ContexteManager.setCurrentSchema(request, "");
78 forward = "main";
79 }
80
81 } catch (Exception e) {
82 if (logger.isErrorEnabled()) {
83 logger.error("Unexepected error getting the schema list", e);
84 }
85 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
86 "error.generic", e));
87 forward = "error";
88 }
89
90
91
92
93 if (!errors.isEmpty()) {
94 saveErrors(request, errors);
95 }
96
97 return (mapping.findForward(forward));
98
99 }
100 }