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 javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import jdbcadmin.web.ContexteManager;
26  import jdbcadmin.web.forms.SelectSchemaForm;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.apache.struts.action.ActionError;
31  import org.apache.struts.action.ActionErrors;
32  import org.apache.struts.action.ActionForm;
33  import org.apache.struts.action.ActionForward;
34  import org.apache.struts.action.ActionMapping;
35  
36  /***
37   * Select a schema.
38   * @struts.action
39   * name="selectSchemaForm"
40   * path="/selectSchema"
41   * @struts.action-forward
42   * name="main"
43   * path="/menu.jsp"
44   * @author Thomas Recloux (trecloux@norsys.fr)
45   */
46  public class SelectSchemaAction extends IndexedAction {
47  
48      /*** Logger */
49      private static Log logger = LogFactory.getLog(SelectSchemaAction.class);
50  
51  
52      /***
53      * Constructor
54      */
55      public SelectSchemaAction() {
56          super();
57      }
58  
59      /*** {@inheritDoc} */
60      public ActionForward indexedExec(
61          ActionMapping mapping,
62          ActionForm form,
63          HttpServletRequest request,
64          HttpServletResponse response)
65          throws Exception {
66  
67          ActionErrors errors = new ActionErrors();
68          ActionForward forward = new ActionForward();
69          String strFwd = "main";
70          SelectSchemaForm choixSchemaForm = (SelectSchemaForm) form;
71  
72          try {
73              ContexteManager.setCurrentSchema(request, choixSchemaForm.getSchema());
74          } catch (Exception e) {
75              if (logger.isErrorEnabled()) {
76                  logger.error("Unexpected error selecting current schema", e);
77              }
78              errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e));
79              strFwd = "error";
80          }
81  
82          // If a message is required, save the specified key(s)
83          // into the request for use by the <struts:errors> tag.
84  
85          if (!errors.isEmpty()) {
86              saveErrors(request, errors);
87          }
88          // Write logic determining how the user should be forwarded.
89          forward = mapping.findForward(strFwd);
90  
91          // Finish with
92          return (forward);
93  
94      }
95  }