KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
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.deployers;
23
24 import org.jboss.deployers.spi.deployer.DeploymentUnit;
25 import org.jboss.deployment.DeploymentException;
26 import org.jboss.logging.Logger;
27 import org.jboss.metadata.WebMetaData;
28 import org.jboss.web.WebApplication;
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 AbstractWarDeployer
40  
41  @author Scott.Stark@jboss.org
42  @version $Revison:$
43  */

44 public class WebModule
45    implements WebModuleMBean
46 {
47    private static Logger log = Logger.getLogger(WebModule.class);
48    private DeploymentUnit di;
49    private AbstractWarDeployer container;
50    private AbstractWarDeployment deployment;
51
52    public WebModule(DeploymentUnit di, AbstractWarDeployer container,
53          AbstractWarDeployment deployment)
54    {
55       this.di = di;
56       this.container = container;
57       this.deployment = deployment;
58    }
59
60    public void create()
61    {
62       
63    }
64    public void start() throws Exception JavaDoc
65    {
66       startModule();
67    }
68
69    public void stop() throws Exception JavaDoc
70    {
71       stopModule();
72    }
73
74    public void destroy()
75    {
76       this.di = null;
77       this.container = null;
78       this.deployment = null;
79    }
80
81    /** Invokes the deployer start
82     */

83    public synchronized void startModule()
84       throws Exception JavaDoc
85    {
86       // Get the war URL
87
WebMetaData metaData = di.getAttachment(WebMetaData.class);
88       WebApplication webApp = deployment.start(di, metaData);
89       String JavaDoc warURL = di.getName();
90       container.addDeployedApp(warURL, webApp);
91    }
92
93    /** Invokes the deployer stop
94     */

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