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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.webapp;
030:
031: import com.caucho.log.Log;
032: import com.caucho.server.deploy.DeployContainer;
033: import com.caucho.server.deploy.DeployGenerator;
034: import com.caucho.server.e_app.EarDeployController;
035: import com.caucho.server.e_app.EarDeployGenerator;
036:
037: import java.util.logging.Logger;
038:
039: /**
040: * The generator for the ear deploy
041: */
042: public class WebAppEarDeployGenerator extends
043: DeployGenerator<WebAppController> {
044: private static final Logger log = Log
045: .open(WebAppEarDeployGenerator.class);
046:
047: private WebAppContainer _container;
048:
049: private String _urlPrefix = "";
050:
051: private ClassLoader _parentLoader;
052:
053: private DeployContainer<EarDeployController> _earContainer;
054:
055: private EarDeployGenerator _earDeploy;
056:
057: /**
058: * Creates the new host deploy.
059: */
060: public WebAppEarDeployGenerator(
061: DeployContainer<WebAppController> deployContainer,
062: WebAppContainer container, EarDeployGenerator earDeploy)
063: throws Exception {
064: super (deployContainer);
065:
066: setContainer(container);
067:
068: _earDeploy = earDeploy;
069: _earContainer = earDeploy.getDeployContainer();
070: }
071:
072: /**
073: * Gets the webApp container.
074: */
075: public WebAppContainer getContainer() {
076: return _container;
077: }
078:
079: /**
080: * Sets the webApp container.
081: */
082: public void setContainer(WebAppContainer container) {
083: _container = container;
084:
085: if (_parentLoader == null)
086: _parentLoader = container.getClassLoader();
087: }
088:
089: /**
090: * Sets the parent loader.
091: */
092: public void setParentClassLoader(ClassLoader loader) {
093: _parentLoader = loader;
094: }
095:
096: /**
097: * Sets the url prefix.
098: */
099: public void setURLPrefix(String prefix) {
100: while (prefix.endsWith("/")) {
101: prefix = prefix.substring(0, prefix.length() - 1);
102: }
103:
104: _urlPrefix = prefix;
105: }
106:
107: /**
108: * Gets the url prefix.
109: */
110: public String getURLPrefix() {
111: return _urlPrefix;
112: }
113:
114: /**
115: * Returns the log.
116: */
117: protected Logger getLog() {
118: return log;
119: }
120:
121: /**
122: * Starts the deployment.
123: */
124: @Override
125: protected void startImpl() {
126: super .startImpl();
127:
128: _earContainer.start();
129: }
130:
131: /**
132: * Return true if modified.
133: */
134: public boolean isModified() {
135: return _earContainer.isModified();
136: }
137:
138: /**
139: * Redeploys if modified.
140: */
141: public void update() {
142: _earContainer.update();
143: }
144:
145: /**
146: * Returns the current array of webApp entries.
147: */
148: public WebAppController generateController(String name) {
149: for (EarDeployController earController : _earContainer
150: .getControllers()) {
151: WebAppController webAppController;
152:
153: webAppController = earController.findWebAppController(name);
154:
155: if (webAppController != null)
156: return webAppController;
157: }
158:
159: return null;
160: }
161:
162: /**
163: * Destroy the deployment.
164: */
165: @Override
166: protected void stopImpl() {
167: _earContainer.stop();
168:
169: super .stopImpl();
170: }
171:
172: /**
173: * Destroy the deployment.
174: */
175: @Override
176: protected void destroyImpl() {
177: _earContainer.destroy();
178:
179: super .destroyImpl();
180: }
181:
182: public String toString() {
183: return "WebAppEarDeployGenerator[" + _earDeploy + "]";
184: }
185: }
|