KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > host > HostAdmin


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.host;
31
32 import com.caucho.management.server.HostMXBean;
33 import com.caucho.management.server.WebAppMXBean;
34 import com.caucho.server.deploy.DeployControllerAdmin;
35 import com.caucho.server.deploy.DeployException;
36 import com.caucho.server.webapp.WebAppController;
37 import com.caucho.util.L10N;
38 import com.caucho.vfs.Path;
39
40 import java.util.ArrayList JavaDoc;
41
42 /**
43  * The admin implementation for a host.
44  */

45 public class HostAdmin extends DeployControllerAdmin<HostController>
46   implements HostMXBean
47 {
48   private static final L10N L = new L10N(HostAdmin.class);
49
50   /**
51    * Creates the admin.
52    */

53   public HostAdmin(HostController controller)
54   {
55     super(controller);
56   }
57
58   public String JavaDoc getName()
59   {
60     String JavaDoc name = getController().getName();
61
62     if (name == null || name.equals(""))
63       return "default";
64     else
65       return name;
66   }
67
68   public String JavaDoc getHostName()
69   {
70     return getController().getHostName();
71   }
72
73   public String JavaDoc getURL()
74   {
75     Host host = getHost();
76
77     if (host != null)
78       return host.getURL();
79     else
80       return null;
81   }
82
83   /**
84    * Returns the host's document directory.
85    */

86   public String JavaDoc getRootDirectory()
87   {
88     Path path = null;
89
90     Host host = getHost();
91
92     if (host != null)
93       path = host.getRootDirectory();
94
95     if (path != null)
96       return path.getNativePath();
97     else
98       return null;
99   }
100
101   /**
102    * Returns the host's document directory.
103    */

104   public String JavaDoc getDocumentDirectory()
105   {
106     Path path = null;
107
108     Host host = getHost();
109
110     if (host != null)
111       path = host.getDocumentDirectory();
112
113     if (path != null)
114       return path.getNativePath();
115     else
116       return null;
117   }
118
119   /**
120    * Returns the host's war directory.
121    */

122   public String JavaDoc getWarDirectory()
123   {
124     Path path = null;
125
126     Host host = getHost();
127
128     if (host != null)
129       path = host.getWarDir();
130
131     if (path != null)
132       return path.getNativePath();
133     else
134       return null;
135   }
136
137   public String JavaDoc getWarExpandDirectory()
138   {
139     Path path = null;
140
141     Host host = getHost();
142
143     if (host != null)
144       path = host.getWarExpandDir();
145
146     if (path != null)
147       return path.getNativePath();
148     else
149       return null;
150   }
151
152   /**
153    * Updates a .war deployment.
154    */

155   public void updateWebAppDeploy(String JavaDoc name)
156     throws DeployException
157   {
158     Host host = getHost();
159
160     try {
161       if (host != null)
162     host.updateWebAppDeploy(name);
163     } catch (Throwable JavaDoc e) {
164       throw new DeployException(e);
165     }
166   }
167
168   /**
169    * Updates a .ear deployment.
170    */

171   public void updateEarDeploy(String JavaDoc name)
172     throws DeployException
173   {
174     Host host = getHost();
175
176     try {
177       if (host != null)
178     host.updateEarDeploy(name);
179     } catch (Throwable JavaDoc e) {
180       throw new DeployException(e);
181     }
182   }
183
184   /**
185    * Expand a .ear deployment.
186    */

187   public void expandEarDeploy(String JavaDoc name)
188   {
189     Host host = getHost();
190
191     if (host != null)
192       host.expandEarDeploy(name);
193   }
194
195   /**
196    * Start a .ear deployment.
197    */

198   public void startEarDeploy(String JavaDoc name)
199   {
200     Host host = getHost();
201
202     if (host != null)
203       host.startEarDeploy(name);
204   }
205
206   /**
207    * Returns the webapps.
208    */

209   public WebAppMXBean []getWebApps()
210   {
211     Host host = getHost();
212
213     if (host == null)
214       return new WebAppMXBean[0];
215
216     ArrayList JavaDoc<WebAppController> webappList = host.getWebAppList();
217
218     WebAppMXBean []webapps = new WebAppMXBean[webappList.size()];
219
220     for (int i = 0; i < webapps.length; i++) {
221       WebAppController controller = webappList.get(i);
222
223       webapps[i] = controller.getAdmin();
224     }
225
226     return webapps;
227   }
228
229   /**
230    * Returns the host.
231    */

232   protected Host getHost()
233   {
234     return getController().getDeployInstance();
235   }
236
237   /**
238    * Returns a string view.
239    */

240   public String JavaDoc toString()
241   {
242     return "HostAdmin[" + getName() + "]";
243   }
244 }
245
Popular Tags