View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-shell Project
18  //
19  // TomcatServerConfiguration.java
20  // Since: May 7, 2009
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.shell.tomcat;
26  
27  import java.io.File;
28  
29  /**
30   * Configuration bean for the {@link TomcatServer}.
31   * 
32   * @author leo
33   * 
34   */
35  public class TomcatServerConfiguration {
36  	private int port = 8088; // default port number is set to 8088
37  	private int ajp13port = 8009; // proxy server
38  	private String catalinaBase; // 
39  
40  	public TomcatServerConfiguration() {
41  		String workDir = getSystemProperty("user.dir", "");
42  		// The default Tomcat base folder is set to workdir/target/tomcat
43  		this.catalinaBase = new File(getSystemProperty("catalina.base", workDir), "target/tomcat").getPath();
44  	}
45  
46  	public static TomcatServerConfiguration newInstance(int port) {
47  		TomcatServerConfiguration config = new TomcatServerConfiguration();
48  		config.setPort(port);
49  		return config;
50  	}
51  
52  	private static String getSystemProperty(String key, String defaultValue) {
53  		String value = System.getProperty("user.dir");
54  		return value != null ? value : defaultValue;
55  	}
56  
57  	public int getPort() {
58  		return port;
59  	}
60  
61  	public void setPort(int port) {
62  		if (port < 0)
63  			throw new IllegalArgumentException("invalid port number: " + port);
64  		this.port = port;
65  	}
66  
67  	public String getCatalinaBase() {
68  		return catalinaBase;
69  	}
70  
71  	public void setCatalinaBase(String catalinaBase) {
72  
73  		// File path = new File(catalinaBase);
74  		// if (!path.isAbsolute())
75  		// catalinaBase = path.getAbsolutePath();
76  
77  		this.catalinaBase = catalinaBase;
78  	}
79  
80  	public int getAjp13port() {
81  		return ajp13port;
82  	}
83  
84  	public void setAjp13port(int ajp13port) {
85  		this.ajp13port = ajp13port;
86  	}
87  
88  }