001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.host;
031:
032: import com.caucho.management.server.HostMXBean;
033: import com.caucho.management.server.WebAppMXBean;
034: import com.caucho.server.deploy.DeployControllerAdmin;
035: import com.caucho.server.deploy.DeployException;
036: import com.caucho.server.webapp.WebAppController;
037: import com.caucho.util.L10N;
038: import com.caucho.vfs.Path;
039:
040: import java.util.ArrayList;
041:
042: /**
043: * The admin implementation for a host.
044: */
045: public class HostAdmin extends DeployControllerAdmin<HostController>
046: implements HostMXBean {
047: private static final L10N L = new L10N(HostAdmin.class);
048:
049: /**
050: * Creates the admin.
051: */
052: public HostAdmin(HostController controller) {
053: super (controller);
054: }
055:
056: public String getName() {
057: String name = getController().getName();
058:
059: if (name == null || name.equals(""))
060: return "default";
061: else
062: return name;
063: }
064:
065: public String getHostName() {
066: return getController().getHostName();
067: }
068:
069: public String getURL() {
070: Host host = getHost();
071:
072: if (host != null)
073: return host.getURL();
074: else
075: return null;
076: }
077:
078: /**
079: * Returns the host's document directory.
080: */
081: public String getRootDirectory() {
082: Path path = null;
083:
084: Host host = getHost();
085:
086: if (host != null)
087: path = host.getRootDirectory();
088:
089: if (path != null)
090: return path.getNativePath();
091: else
092: return null;
093: }
094:
095: /**
096: * Returns the host's document directory.
097: */
098: public String getDocumentDirectory() {
099: Path path = null;
100:
101: Host host = getHost();
102:
103: if (host != null)
104: path = host.getDocumentDirectory();
105:
106: if (path != null)
107: return path.getNativePath();
108: else
109: return null;
110: }
111:
112: /**
113: * Returns the host's war directory.
114: */
115: public String getWarDirectory() {
116: Path path = null;
117:
118: Host host = getHost();
119:
120: if (host != null)
121: path = host.getWarDir();
122:
123: if (path != null)
124: return path.getNativePath();
125: else
126: return null;
127: }
128:
129: public String getWarExpandDirectory() {
130: Path path = null;
131:
132: Host host = getHost();
133:
134: if (host != null)
135: path = host.getWarExpandDir();
136:
137: if (path != null)
138: return path.getNativePath();
139: else
140: return null;
141: }
142:
143: /**
144: * Updates a .war deployment.
145: */
146: public void updateWebAppDeploy(String name) throws DeployException {
147: Host host = getHost();
148:
149: try {
150: if (host != null)
151: host.updateWebAppDeploy(name);
152: } catch (Throwable e) {
153: throw new DeployException(e);
154: }
155: }
156:
157: /**
158: * Updates a .ear deployment.
159: */
160: public void updateEarDeploy(String name) throws DeployException {
161: Host host = getHost();
162:
163: try {
164: if (host != null)
165: host.updateEarDeploy(name);
166: } catch (Throwable e) {
167: throw new DeployException(e);
168: }
169: }
170:
171: /**
172: * Expand a .ear deployment.
173: */
174: public void expandEarDeploy(String name) {
175: Host host = getHost();
176:
177: if (host != null)
178: host.expandEarDeploy(name);
179: }
180:
181: /**
182: * Start a .ear deployment.
183: */
184: public void startEarDeploy(String name) {
185: Host host = getHost();
186:
187: if (host != null)
188: host.startEarDeploy(name);
189: }
190:
191: /**
192: * Returns the webapps.
193: */
194: public WebAppMXBean[] getWebApps() {
195: Host host = getHost();
196:
197: if (host == null)
198: return new WebAppMXBean[0];
199:
200: ArrayList<WebAppController> webappList = host.getWebAppList();
201:
202: WebAppMXBean[] webapps = new WebAppMXBean[webappList.size()];
203:
204: for (int i = 0; i < webapps.length; i++) {
205: WebAppController controller = webappList.get(i);
206:
207: webapps[i] = controller.getAdmin();
208: }
209:
210: return webapps;
211: }
212:
213: /**
214: * Returns the host.
215: */
216: protected Host getHost() {
217: return getController().getDeployInstance();
218: }
219:
220: /**
221: * Returns a string view.
222: */
223: public String toString() {
224: return "HostAdmin[" + getName() + "]";
225: }
226: }
|