View Javadoc

1   /*
2   Copyright (C) 2000 - 2007 Grid Systems, S.A.
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2, as
6   published by the Free Software Foundation.
7   
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17  package com.gridsystems.config.modules.tomcat;
18  
19  import java.io.File;
20  
21  import com.gridsystems.config.Configurator;
22  import com.gridsystems.config.ConfiguratorModel;
23  import com.gridsystems.config.ConsoleConfiguratorView;
24  import com.gridsystems.config.SwingConfiguratorView;
25  
26  /**
27   * Tomcat Configurator implementation.
28   *
29   * @author Rodrigo Ruiz
30   * @version 1.0
31   */
32  public final class TomcatConfigurator extends Configurator {
33    /**
34     * Resource bundle to use.
35     */
36    static final String BUNDLE = "com/gridsystems/config/modules/tomcat/config_tomcat";
37  
38    /**
39     * Singleton instance.
40     */
41    private static TomcatConfigurator instance = new TomcatConfigurator();
42  
43    /**
44     * Swing view.
45     */
46    private TomcatSwingView swingView = null;
47  
48    /**
49     * Console view.
50     */
51    private TomcatConsoleView consoleView = null;
52  
53    /**
54     * Hidden constructor to enforce the singleton pattern.
55     */
56    private TomcatConfigurator() {
57      super(BUNDLE, "config");
58      setModel(new TomcatConfigModel());
59  
60      // Checks Tomcat is present
61      File f = new File("../server/lib/catalina.jar");
62      if (!f.exists()) {
63        throw new IllegalStateException("Catalina server not found");
64      }
65  
66      String kernelContext = System.getProperty("context.dir");
67      if (kernelContext == null) {
68        System.setProperty("context.dir", "../webapps/kernel");
69      }
70    }
71  
72    /**
73     * Gets a singleton instance of this class.
74     *
75     * @return a singleton instance
76     */
77    public static TomcatConfigurator getInstance() {
78      return instance;
79    }
80  
81    /**
82     * {@inheritDoc}
83     */
84    protected SwingConfiguratorView getSwingView() {
85      if (swingView == null) {
86        swingView = new TomcatSwingView(this);
87      }
88      return swingView;
89    }
90  
91    /**
92     * {@inheritDoc}
93     */
94    protected ConsoleConfiguratorView getConsoleView() {
95      if (consoleView == null) {
96        consoleView = new TomcatConsoleView(this);
97      }
98      return consoleView;
99    }
100 
101   /**
102    * {@inheritDoc}
103    */
104   @Override protected ConfiguratorModel createModel() {
105     return new TomcatConfigModel((TomcatConfigModel)this.getModel());
106   }
107 
108   /**
109    * {@inheritDoc}
110    */
111   public void apply() throws Exception {
112     TomcatConfigModel oldModel = (TomcatConfigModel)this.getModel();
113     super.apply();
114     WindowsFirewallManager.closePorts(oldModel.getConnectors());
115   }
116 }