KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > WebModule


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.web;
23
24 import java.net.URL JavaDoc;
25
26 import org.jboss.deployment.DeploymentInfo;
27 import org.jboss.deployment.DeploymentException;
28 import org.jboss.system.ServiceMBeanSupport;
29
30 /** A container service used to introduce war dependencies. This service is
31  created by the AbstractWebContainer during the create(DeploymentInfo) call
32  and registered under the name "jboss.web.deployment:war="+di.shortName
33  This name is stored in the di.context under the key AbstractWebContainer.WEB_MODULE
34
35  When the jboss-web.xml dependencies are satisfied, this service is started
36  and this triggers the AbstractWebDeployer.start. Likewise, a stop on this
37  service triggers the AbstractWebDeployer.stop.
38  
39  @see AbstractWebContainer
40  
41  @author Scott.Stark@jboss.org
42  @version $Revison:$
43  */

44 public class WebModule extends ServiceMBeanSupport
45    implements WebModuleMBean
46 {
47    private DeploymentInfo di;
48    private AbstractWebContainer container;
49    private AbstractWebDeployer deployer;
50
51    public WebModule(DeploymentInfo di, AbstractWebContainer container,
52       AbstractWebDeployer deployer)
53    {
54       this.di = di;
55       this.container = container;
56       this.deployer = deployer;
57    }
58
59    protected void startService() throws Exception JavaDoc
60    {
61       startModule();
62    }
63
64    protected void stopService() throws Exception JavaDoc
65    {
66       stopModule();
67    }
68
69    protected void destroyService()
70    {
71       this.di = null;
72       this.container = null;
73       this.deployer = null;
74    }
75
76    /** Invokes the deployer start
77     */

78    public synchronized void startModule()
79       throws DeploymentException
80    {
81       // Get the war URL
82
URL JavaDoc warURL = di.localUrl != null ? di.localUrl : di.url;
83       WebApplication webApp = deployer.start(di);
84       di.context.put(AbstractWebContainer.WEB_APP, webApp);
85       container.addDeployedApp(warURL, webApp);
86    }
87
88    /** Invokes the deployer stop
89     */

90    public synchronized void stopModule()
91       throws DeploymentException
92    {
93       URL JavaDoc warURL = di.localUrl != null ? di.localUrl : di.url;
94       String JavaDoc warUrl = warURL.toString();
95       try
96       {
97          WebApplication webApp = container.removeDeployedApp(warURL);
98          if( deployer != null && webApp != null )
99          {
100             deployer.stop(di);
101          }
102          else
103          {
104             log.debug("Failed to find deployer/deployment for war: "+warUrl);
105          }
106       }
107       catch (DeploymentException e)
108       {
109          throw e;
110       }
111       catch (Exception JavaDoc e)
112       {
113          throw new DeploymentException("Error during stop", e);
114       }
115    }
116
117 }
118
Popular Tags