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.e_app;
031:
032: import com.caucho.log.Log;
033: import com.caucho.management.j2ee.J2EEApplication;
034: import com.caucho.management.j2ee.J2EEManagedObject;
035: import com.caucho.server.deploy.DeployControllerAdmin;
036: import com.caucho.server.deploy.EnvironmentDeployController;
037: import com.caucho.server.webapp.WebAppContainer;
038: import com.caucho.server.webapp.WebAppController;
039: import com.caucho.util.L10N;
040: import com.caucho.vfs.Path;
041:
042: import javax.servlet.jsp.el.ELException;
043: import java.util.ArrayList;
044: import java.util.logging.Level;
045: import java.util.logging.Logger;
046:
047: /**
048: * A configuration entry for an Enterprise WebApp
049: */
050: public class EarDeployController extends
051: EnvironmentDeployController<EnterpriseApplication, EarConfig> {
052: private static final Logger log = Log
053: .open(EarDeployController.class);
054: private static final L10N L = new L10N(EarDeployController.class);
055:
056: private WebAppContainer _container;
057:
058: // private Var _hostVar = new Var();
059:
060: // root-dir as set by the resin.conf
061: private Path _earRootDir;
062:
063: private ArrayList<EarConfig> _eAppDefaults = new ArrayList<EarConfig>();
064:
065: private EarAdmin _admin = new EarAdmin(this );
066: private J2EEApplication _j2eeAdmin;
067:
068: EarDeployController(String name, WebAppContainer container,
069: EarConfig config) {
070: super (config);
071:
072: _container = container;
073:
074: if (container != null) {
075: _eAppDefaults.addAll(container.getEarDefaultList());
076: }
077: }
078:
079: EarDeployController(String name, Path rootDirectory,
080: WebAppContainer container) {
081: super (name, rootDirectory);
082:
083: _container = container;
084:
085: if (container != null) {
086: _eAppDefaults.addAll(container.getEarDefaultList());
087: }
088: }
089:
090: /**
091: * Sets the Resin host name.
092: */
093: public void setId(String name) {
094: getVariableMap().put("name", name);
095:
096: // XXX: super.setId(name);
097: }
098:
099: /**
100: * Returns the ear directory set by the hosts-directory.
101: */
102: public Path getEarRootDir() {
103: return _earRootDir;
104: }
105:
106: /**
107: * Sets the host directory by the resin.conf
108: */
109: public void setEarRootDir(Path rootDir) {
110: _earRootDir = rootDir;
111: }
112:
113: /**
114: * Returns the deploy admin.
115: */
116: @Override
117: protected DeployControllerAdmin getDeployAdmin() {
118: return _admin;
119: }
120:
121: @Override
122: protected void initEnd() {
123: super .initEnd();
124:
125: _j2eeAdmin = new J2EEApplication(this );
126: J2EEManagedObject.register(_j2eeAdmin);
127: }
128:
129: /**
130: * Finds any web-app in the ear matching the contextPath.
131: */
132: public WebAppController findWebAppController(String name) {
133: try {
134: EnterpriseApplication eApp = request();
135:
136: if (eApp != null)
137: return eApp.findWebAppEntry(name);
138: else
139: return null;
140: } catch (Throwable e) {
141: log.log(Level.FINER, e.toString(), e);
142:
143: return null;
144: }
145: }
146:
147: /**
148: * Creates the application.
149: */
150: protected EnterpriseApplication instantiateDeployInstance() {
151: return new EnterpriseApplication(_container, this , getId());
152: }
153:
154: protected Path calculateRootDirectory() throws ELException {
155: Path rootDir = getRootDirectory();
156: EnterpriseApplication eApp = getDeployInstance();
157:
158: if (rootDir == null && eApp != null)
159: rootDir = eApp.getRootDirectory();
160:
161: return rootDir;
162: }
163:
164: @Override
165: public boolean destroy() {
166: Thread thread = Thread.currentThread();
167: ClassLoader oldLoader = thread.getContextClassLoader();
168:
169: try {
170: thread.setContextClassLoader(getParentClassLoader());
171: J2EEManagedObject.unregister(_j2eeAdmin);
172: } finally {
173: thread.setContextClassLoader(oldLoader);
174: }
175:
176: return super .destroy();
177: }
178:
179: /**
180: * Returns equality.
181: */
182: public boolean equals(Object o) {
183: if (!(o instanceof EarDeployController))
184: return false;
185:
186: EarDeployController entry = (EarDeployController) o;
187:
188: return getId().equals(entry.getId());
189: }
190:
191: /**
192: * Returns a printable view.
193: */
194: public String toString() {
195: return "EarDeployController[" + getId() + "]";
196: }
197: }
|