001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.web;
023:
024: import java.net.URL;
025:
026: import org.jboss.deployment.DeploymentInfo;
027: import org.jboss.deployment.DeploymentException;
028: import org.jboss.system.ServiceMBeanSupport;
029:
030: /** A container service used to introduce war dependencies. This service is
031: created by the AbstractWebContainer during the create(DeploymentInfo) call
032: and registered under the name "jboss.web.deployment:war="+di.shortName
033: This name is stored in the di.context under the key AbstractWebContainer.WEB_MODULE
034:
035: When the jboss-web.xml dependencies are satisfied, this service is started
036: and this triggers the AbstractWebDeployer.start. Likewise, a stop on this
037: service triggers the AbstractWebDeployer.stop.
038:
039: @see AbstractWebContainer
040:
041: @author Scott.Stark@jboss.org
042: @version $Revison:$
043: */
044: public class WebModule extends ServiceMBeanSupport implements
045: WebModuleMBean {
046: private DeploymentInfo di;
047: private AbstractWebContainer container;
048: private AbstractWebDeployer deployer;
049:
050: public WebModule(DeploymentInfo di, AbstractWebContainer container,
051: AbstractWebDeployer deployer) {
052: this .di = di;
053: this .container = container;
054: this .deployer = deployer;
055: }
056:
057: protected void startService() throws Exception {
058: startModule();
059: }
060:
061: protected void stopService() throws Exception {
062: stopModule();
063: }
064:
065: protected void destroyService() {
066: this .di = null;
067: this .container = null;
068: this .deployer = null;
069: }
070:
071: /** Invokes the deployer start
072: */
073: public synchronized void startModule() throws DeploymentException {
074: // Get the war URL
075: URL warURL = di.localUrl != null ? di.localUrl : di.url;
076: WebApplication webApp = deployer.start(di);
077: di.context.put(AbstractWebContainer.WEB_APP, webApp);
078: container.addDeployedApp(warURL, webApp);
079: }
080:
081: /** Invokes the deployer stop
082: */
083: public synchronized void stopModule() throws DeploymentException {
084: URL warURL = di.localUrl != null ? di.localUrl : di.url;
085: String warUrl = warURL.toString();
086: try {
087: WebApplication webApp = container.removeDeployedApp(warURL);
088: if (deployer != null && webApp != null) {
089: deployer.stop(di);
090: } else {
091: log
092: .debug("Failed to find deployer/deployment for war: "
093: + warUrl);
094: }
095: } catch (DeploymentException e) {
096: throw e;
097: } catch (Exception e) {
098: throw new DeploymentException("Error during stop", e);
099: }
100: }
101:
102: }
|