KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > TomcatApplicationLoader


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 package com.sun.enterprise.server;
25
26 import com.sun.logging.LogDomains;
27 import com.sun.enterprise.config.ConfigException;
28 import com.sun.enterprise.config.serverbeans.J2eeApplication;
29 import com.sun.enterprise.deployment.Application;
30 import com.sun.enterprise.deployment.WebBundleDescriptor;
31 import com.sun.enterprise.instance.AppsManager;
32 import com.sun.enterprise.util.StringUtils;
33 import com.sun.enterprise.web.PEWebContainer;
34 import com.sun.enterprise.Switch;
35  
36 import java.util.Iterator JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Set JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40 import java.util.logging.Level JavaDoc;
41
42 import org.apache.catalina.Container;
43 import org.apache.catalina.Context;
44 import org.apache.catalina.Deployer;
45 import org.apache.catalina.Engine;
46 import org.apache.catalina.Host;
47 import org.apache.catalina.core.StandardHost;
48
49 /**
50  * This class extends ApplicationLoader to handle
51  * per application loading/unloading of web module.
52  *
53  * @author Amy Roh
54  */

55 public class TomcatApplicationLoader extends ApplicationLoader {
56  
57  
58     /** logger to log loader messages */
59     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.LOADER_LOGGER);
60     
61     
62     // ------------------------------------------------------------ Constructor
63

64     
65     /**
66      * TomcatApplicationLoader loads one application.
67      *
68      * @param appID the name of the application
69      * @param parentClassLoader parent class loader for this application
70      * @param appsManager the AppsManager for this VS
71      */

72     public TomcatApplicationLoader(String JavaDoc appID, ClassLoader JavaDoc parentClassLoader,
73             AppsManager appsManager) {
74
75         super(appID, parentClassLoader, appsManager);
76         _logger.log(Level.FINEST, "[TomcatApplicationLoader] " + appID);
77         this.appsManager = appsManager;
78         // get the instance of WebContainer
79
webContainer = PEWebContainer.getPEWebContainer();
80         _logger.log(Level.FINEST, "PEWebContainer " + webContainer);
81
82     }
83     
84     
85     // ----------------------------------------------------- Instance Variables
86

87
88     /**
89      * The AppsManager for this VS
90      * save for unload() since super.unload() calls done()
91      * and clears this.configManager
92      */

93     private AppsManager appsManager = null;
94
95
96     /**
97      * The WebContainer instance.
98      */

99     private PEWebContainer webContainer = null;
100     
101     
102     
103     /**
104      * Called from ApplicationManager. Called to load an application.
105      * This loads the web modules of this application on top of
106      * its super loader creating the EJB and MDB container.
107      *
108      * @return true if all modules were loaded successfully
109      */

110     boolean load(boolean jsr77) {
111
112         _logger.log(Level.FINEST, "[TomcatApplicationLoader] load " + jsr77);
113         boolean deployed = super.load(jsr77);
114         if (loadUnloadAction == Constants.LOAD_RAR) {
115             return deployed;
116         }
117         _logger.log(Level.FINEST, "deployed "+deployed);
118         if (webContainer == null) {
119             webContainer = PEWebContainer.getPEWebContainer();
120         }
121         if (deployed) {
122             J2eeApplication[] j2eeAppBeans = appsManager.getAllApps();
123             if (j2eeAppBeans != null) {
124                 for (int i = 0; i < j2eeAppBeans.length; i++) {
125                     if (j2eeAppBeans[i].getName().equals(id) && webContainer != null) {
126                         _logger.log(Level.FINEST,
127                                     "[TomcatApplicationLoader] loadJ2EEAppWebModule with "+j2eeAppBeans[i]);
128                         webContainer.loadJ2EEApplicationWebModules(j2eeAppBeans[i]);
129                        
130                     }
131                 }
132             }
133         }
134         return deployed;
135         
136     }
137
138         
139     /**
140      * Unloads this application.
141      *
142      * @return true if all modules were removed successfully
143      */

144     boolean unload(boolean jsr77) {
145
146         if (loadUnloadAction == Constants.UNLOAD_RAR) {
147             return super.unload(jsr77);
148         }
149
150         super.unloadWebserviceEndpoints(jsr77);
151
152         Set JavaDoc wbds = null;
153         J2eeApplication[] j2eeAppBeans = appsManager.getAllApps();
154         if (j2eeAppBeans != null) {
155             for (int i = 0; i < j2eeAppBeans.length; i++) {
156                 if (j2eeAppBeans[i].getName().equals(id)) {
157
158                     String JavaDoc virtualServers = null;
159                     try {
160                         virtualServers = appsManager.
161                             getVirtualServersByAppName(j2eeAppBeans[i].getName());
162                     } catch(ConfigException ce) {
163                         _logger.log(Level.FINEST, "[TomcatApplicationLoader] unload "
164                             + id + ". error getting virtualServers", ce);
165                     }
166                     
167                     _logger.log(Level.FINEST, "[TomcatApplicationLoader] unload "
168                                                +id);
169                     wbds = application.getWebBundleDescriptors();
170                     WebBundleDescriptor wbd = null;
171                     if ( wbds == null) continue;
172
173                     Iterator JavaDoc itr = wbds.iterator();
174                     
175                     while (itr.hasNext()){
176                         wbd = (WebBundleDescriptor) itr.next();
177                         String JavaDoc appName = wbd.getApplication().getRegistrationName();
178                         try {
179                 webContainer.unloadWebModule(wbd.getContextRoot(),
180                                                          appName,
181                                                          virtualServers,
182                                                          wbd);
183                         
184             } finally {
185                 try {
186                 Switch.getSwitch().
187                     getNamingManager().unbindObjects(wbd);
188                 } catch (javax.naming.NamingException JavaDoc nameEx) {
189                 _logger.log(Level.FINEST, "[TomcatApplicationLoader] "
190                     + " Exception during namingManager.unbindObject",
191                     nameEx);
192                 }
193             }
194                     }
195
196                 }
197             }
198         }
199
200         return super.unload(jsr77);
201     }
202 }
203
Popular Tags