View Javadoc

1   /* ==============================================================================
2    *   JDBCAdmin, data management software.
3    *   Copyright (C) 2005  Norsys S.A
4    *
5    *   This library is free software; you can redistribute it and/or
6    *   modify it under the terms of the GNU Lesser General Public
7    *   License as published by the Free Software Foundation; either
8    *   version 2.1 of the License, or (at your option) any later version.
9    *
10   *   This library is distributed in the hope that it will be useful,
11   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *   Lesser General Public License for more details.
14   *
15   *   You should have received a copy of the GNU Lesser General Public
16   *   License along with this library; if not, write to the Free Software
17   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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              // recuperation de la liste des schemas
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          // If a message is required, save the specified key(s)
91          // into the request for use by the <struts:errors> tag.
92  
93          if (!errors.isEmpty()) {
94              saveErrors(request, errors);
95          }
96          // Finish with
97          return (mapping.findForward(forward));
98  
99      }
100 }