KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > webapp > WebAppEarDeployGenerator


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.server.webapp;
30
31 import com.caucho.log.Log;
32 import com.caucho.server.deploy.DeployContainer;
33 import com.caucho.server.deploy.DeployGenerator;
34 import com.caucho.server.e_app.EarDeployController;
35 import com.caucho.server.e_app.EarDeployGenerator;
36
37 import java.util.logging.Logger JavaDoc;
38
39 /**
40  * The generator for the ear deploy
41  */

42 public class WebAppEarDeployGenerator extends DeployGenerator<WebAppController> {
43   private static final Logger JavaDoc log = Log.open(WebAppEarDeployGenerator.class);
44
45   private WebAppContainer _container;
46   
47   private String JavaDoc _urlPrefix = "";
48
49   private ClassLoader JavaDoc _parentLoader;
50   
51   private DeployContainer<EarDeployController> _earContainer;
52
53   private EarDeployGenerator _earDeploy;
54
55   /**
56    * Creates the new host deploy.
57    */

58   public WebAppEarDeployGenerator(DeployContainer<WebAppController> deployContainer,
59                   WebAppContainer container,
60                   EarDeployGenerator earDeploy)
61     throws Exception JavaDoc
62   {
63     super(deployContainer);
64     
65     setContainer(container);
66
67     _earDeploy = earDeploy;
68     _earContainer = earDeploy.getDeployContainer();
69   }
70
71   /**
72    * Gets the webApp container.
73    */

74   public WebAppContainer getContainer()
75   {
76     return _container;
77   }
78
79   /**
80    * Sets the webApp container.
81    */

82   public void setContainer(WebAppContainer container)
83   {
84     _container = container;
85
86     if (_parentLoader == null)
87       _parentLoader = container.getClassLoader();
88   }
89
90   /**
91    * Sets the parent loader.
92    */

93   public void setParentClassLoader(ClassLoader JavaDoc loader)
94   {
95     _parentLoader = loader;
96   }
97
98   /**
99    * Sets the url prefix.
100    */

101   public void setURLPrefix(String JavaDoc prefix)
102   {
103     while (prefix.endsWith("/")) {
104       prefix = prefix.substring(0, prefix.length() - 1);
105     }
106     
107     _urlPrefix = prefix;
108   }
109
110   /**
111    * Gets the url prefix.
112    */

113   public String JavaDoc getURLPrefix()
114   {
115     return _urlPrefix;
116   }
117
118   /**
119    * Returns the log.
120    */

121   protected Logger JavaDoc getLog()
122   {
123     return log;
124   }
125
126   /**
127    * Starts the deployment.
128    */

129   @Override JavaDoc
130   protected void startImpl()
131   {
132     super.startImpl();
133
134     _earContainer.start();
135   }
136
137   /**
138    * Return true if modified.
139    */

140   public boolean isModified()
141   {
142     return _earContainer.isModified();
143   }
144
145   /**
146    * Redeploys if modified.
147    */

148   public void update()
149   {
150     _earContainer.update();
151   }
152   
153   /**
154    * Returns the current array of webApp entries.
155    */

156   public WebAppController generateController(String JavaDoc name)
157   {
158     for (EarDeployController earController : _earContainer.getControllers()) {
159       WebAppController webAppController;
160
161       webAppController = earController.findWebAppController(name);
162
163       if (webAppController != null)
164     return webAppController;
165     }
166
167     return null;
168   }
169   
170   /**
171    * Destroy the deployment.
172    */

173   @Override JavaDoc
174   protected void stopImpl()
175   {
176     _earContainer.stop();
177
178     super.stopImpl();
179   }
180   
181   /**
182    * Destroy the deployment.
183    */

184   @Override JavaDoc
185   protected void destroyImpl()
186   {
187     _earContainer.destroy();
188
189     super.destroyImpl();
190   }
191
192   public String JavaDoc toString()
193   {
194     return "WebAppEarDeployGenerator[" + _earDeploy + "]";
195   }
196 }
197
Popular Tags