KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > e_app > EarDeployController


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.e_app;
31
32 import com.caucho.log.Log;
33 import com.caucho.management.j2ee.J2EEApplication;
34 import com.caucho.management.j2ee.J2EEManagedObject;
35 import com.caucho.server.deploy.DeployControllerAdmin;
36 import com.caucho.server.deploy.EnvironmentDeployController;
37 import com.caucho.server.webapp.WebAppContainer;
38 import com.caucho.server.webapp.WebAppController;
39 import com.caucho.util.L10N;
40 import com.caucho.vfs.Path;
41
42 import javax.servlet.jsp.el.ELException JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.logging.Level JavaDoc;
45 import java.util.logging.Logger JavaDoc;
46
47 /**
48  * A configuration entry for an Enterprise WebApp
49  */

50 public class EarDeployController
51   extends EnvironmentDeployController<EnterpriseApplication,EarConfig> {
52   private static final Logger JavaDoc log = Log.open(EarDeployController.class);
53   private static final L10N L = new L10N(EarDeployController.class);
54
55   private WebAppContainer _container;
56
57   // private Var _hostVar = new Var();
58

59   // root-dir as set by the resin.conf
60
private Path _earRootDir;
61
62   private ArrayList JavaDoc<EarConfig> _eAppDefaults = new ArrayList JavaDoc<EarConfig>();
63
64   private EarAdmin _admin = new EarAdmin(this);
65   private J2EEApplication _j2eeAdmin;
66
67   EarDeployController(String JavaDoc name,
68                       WebAppContainer container, EarConfig config)
69   {
70     super(config);
71
72     _container = container;
73
74     if (container != null) {
75       _eAppDefaults.addAll(container.getEarDefaultList());
76     }
77   }
78
79   EarDeployController(String JavaDoc name, Path rootDirectory,
80                       WebAppContainer container)
81   {
82     super(name, rootDirectory);
83
84     _container = container;
85
86     if (container != null) {
87       _eAppDefaults.addAll(container.getEarDefaultList());
88     }
89   }
90
91   /**
92    * Sets the Resin host name.
93    */

94   public void setId(String JavaDoc name)
95   {
96     getVariableMap().put("name", name);
97
98     // XXX: super.setId(name);
99
}
100
101   /**
102    * Returns the ear directory set by the hosts-directory.
103    */

104   public Path getEarRootDir()
105   {
106     return _earRootDir;
107   }
108
109   /**
110    * Sets the host directory by the resin.conf
111    */

112   public void setEarRootDir(Path rootDir)
113   {
114     _earRootDir = rootDir;
115   }
116
117   /**
118    * Returns the deploy admin.
119    */

120   @Override JavaDoc
121   protected DeployControllerAdmin getDeployAdmin()
122   {
123     return _admin;
124   }
125
126   @Override JavaDoc
127   protected void initEnd()
128   {
129     super.initEnd();
130
131     _j2eeAdmin = new J2EEApplication(this);
132     J2EEManagedObject.register(_j2eeAdmin);
133   }
134
135   /**
136    * Finds any web-app in the ear matching the contextPath.
137    */

138   public WebAppController findWebAppController(String JavaDoc name)
139   {
140     try {
141       EnterpriseApplication eApp = request();
142
143       if (eApp != null)
144         return eApp.findWebAppEntry(name);
145       else
146         return null;
147     } catch (Throwable JavaDoc e) {
148       log.log(Level.FINER, e.toString(), e);
149
150       return null;
151     }
152   }
153
154   /**
155    * Creates the application.
156    */

157   protected EnterpriseApplication instantiateDeployInstance()
158   {
159     return new EnterpriseApplication(_container, this, getId());
160   }
161
162   protected Path calculateRootDirectory()
163     throws ELException JavaDoc
164   {
165     Path rootDir = getRootDirectory();
166     EnterpriseApplication eApp = getDeployInstance();
167
168     if (rootDir == null && eApp != null)
169       rootDir = eApp.getRootDirectory();
170
171     return rootDir;
172   }
173
174   @Override JavaDoc
175   public boolean destroy()
176   {
177     Thread JavaDoc thread = Thread.currentThread();
178     ClassLoader JavaDoc oldLoader = thread.getContextClassLoader();
179
180     try {
181       thread.setContextClassLoader(getParentClassLoader());
182       J2EEManagedObject.unregister(_j2eeAdmin);
183     } finally {
184       thread.setContextClassLoader(oldLoader);
185     }
186     
187     return super.destroy();
188   }
189
190   /**
191    * Returns equality.
192    */

193   public boolean equals(Object JavaDoc o)
194   {
195     if (! (o instanceof EarDeployController))
196       return false;
197
198     EarDeployController entry = (EarDeployController) o;
199
200     return getId().equals(entry.getId());
201   }
202     
203
204   /**
205    * Returns a printable view.
206    */

207   public String JavaDoc toString()
208   {
209     return "EarDeployController[" + getId() + "]";
210   }
211 }
212
Popular Tags