KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * @(#) ApplicationClientModuleLoader.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Information and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.server;
38
39 import com.sun.enterprise.server.event.ApplicationClientEvent;
40 import com.sun.enterprise.server.event.ApplicationLoaderEventNotifier;
41 import java.net.URL JavaDoc;
42 import java.util.Set JavaDoc;
43 import com.sun.enterprise.loader.EJBClassPathUtils;
44 import com.sun.enterprise.config.ConfigException;
45 import com.sun.enterprise.instance.AppclientModulesManager;
46
47 import java.util.jar.Manifest JavaDoc;
48 import java.util.logging.Level JavaDoc;
49 import java.util.logging.Logger JavaDoc;
50 import com.sun.logging.LogDomains;
51 import com.sun.enterprise.loader.EJBClassLoader;
52
53 // for jsr77
54
import com.sun.enterprise.instance.InstanceEnvironment;
55 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
56 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder;
57 import com.sun.enterprise.deployment.Descriptor;
58 import com.sun.enterprise.deployment.EjbDescriptor;
59 import com.sun.enterprise.deployment.EjbBundleDescriptor;
60 import com.sun.enterprise.deployment.Application;
61 import java.util.Iterator JavaDoc;
62 import javax.management.MBeanException JavaDoc;
63 import com.sun.enterprise.Switch;
64
65 /**
66  * Application client loader loads and unloads stand alone Application client module.
67  *
68  * @author Sreenivas Munnangi
69  * @since JDK1.4
70  */

71 class ApplicationClientModuleLoader extends AbstractLoader {
72  
73     private ApplicationClientDescriptor acDescriptor = null;
74
75     static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.LOADER_LOGGER);
76
77     private ApplicationLoaderEventNotifier appLoaderEventNotifier;
78
79     /**
80      * ApplicationClientModuleLoader loads one module.
81      *
82      * @param modID the name of the Application client module
83      * @param parentClassLoader the parent class loader
84      * @param acModulesManager the application client module mgr
85      */

86     ApplicationClientModuleLoader(String JavaDoc modID, ClassLoader JavaDoc parentClassLoader,
87             AppclientModulesManager acModulesManager) {
88
89         super(modID, parentClassLoader, acModulesManager);
90
91     setDescriptor();
92
93          try {
94              this.application = acModulesManager.getDescriptor(modID, parentClassLoader, false);
95              appLoaderEventNotifier =
96                  ApplicationLoaderEventNotifier.getInstance();
97          } catch (ConfigException ce) {
98              _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc",
99                          ce);
100          }
101     }
102     
103     /**
104      *Loads the app client.
105      *Although the app client logic is not actually loaded into the app server,
106      *there may be some components interested in the load operation, so notify
107      *them.
108      *
109      * @param jsr77 create jsr77 mBeans if true
110      * @return true if load is successful
111      */

112     boolean load(boolean jsr77) {
113     notifyAppClientEvent(ApplicationClientEvent.BEFORE_APPLICATION_CLIENT_LOAD);
114  
115         notifyAppClientEvent(ApplicationClientEvent.AFTER_APPLICATION_CLIENT_LOAD);
116          
117     return true;
118     }
119         
120     /**
121      *Unloads the app client.
122      *Because no code is actually loaded into the server for app clients, there is
123      *none to unload. Still, notify any interested listeners.
124      *
125      * @param jsr77 delete jsr77 mBeans if true
126      * @return true if unload is successful
127      */

128     boolean unload(boolean jsr77) {
129     notifyAppClientEvent(ApplicationClientEvent.BEFORE_APPLICATION_CLIENT_UNLOAD);
130  
131         configManager.unregisterDescriptor(id);
132          
133         notifyAppClientEvent(ApplicationClientEvent.AFTER_APPLICATION_CLIENT_UNLOAD);
134         return true;
135     }
136
137
138     /**
139      * Create jsr77 root mBean
140      */

141     void createRootMBean() throws MBeanException JavaDoc {
142
143     try {
144             Switch.getSwitch().getManagementObjectManager().registerAppClient(
145         acDescriptor,
146         this.configManager.getInstanceEnvironment().getName(),
147         this.configManager.getLocation(this.id));
148     } catch (Exception JavaDoc e) {
149         throw new MBeanException JavaDoc(e);
150     }
151     }
152
153
154     /**
155      * Delete jsr77 root mBean
156      */

157     void deleteRootMBean() throws MBeanException JavaDoc {
158
159         Switch.getSwitch().getManagementObjectManager().unregisterAppClient(
160         acDescriptor,
161         this.configManager.getInstanceEnvironment().getName());
162     }
163
164
165     /**
166      * Create jsr77 mBeans for ejbs within this module
167      */

168     void createLeafMBeans() throws MBeanException JavaDoc {
169
170     return;
171     }
172
173
174     /**
175      * Create jsr77 mBeans for ejbs within this module
176      */

177     void createLeafMBean(Descriptor descriptor) throws MBeanException JavaDoc {
178
179     return;
180     }
181
182
183     /**
184      * Delete jsr77 mBeans for ejbs within this module
185      */

186     void deleteLeafMBeans() throws MBeanException JavaDoc {
187
188     return;
189     }
190
191     /**
192      * Delete jsr77 mBeans for ejbs within this module
193      */

194     void deleteLeafMBean(Descriptor descriptor) throws MBeanException JavaDoc {
195
196     return;
197     }
198
199
200     /**
201      * Delete jsr77 mBeans for the module and its' components
202      */

203     void deleteLeafAndRootMBeans() throws MBeanException JavaDoc {
204         deleteLeafMBeans();
205         deleteRootMBean();
206     }
207
208
209     /**
210      * Set state for the root mBean
211      */

212     void setState(int state) throws MBeanException JavaDoc {
213
214     return;
215     }
216
217     private void setDescriptor() {
218     acDescriptor = getApplicationClientDescriptor();
219     }
220
221     private ApplicationClientDescriptor getApplicationClientDescriptor() {
222     ApplicationClientDescriptor appCD = null;
223     try {
224             Application app = configManager.getDescriptor(this.id, null, false);
225             appCD = (ApplicationClientDescriptor) app.getStandaloneBundleDescriptor();
226         } catch(ConfigException ex) {
227             _logger.log(Level.WARNING,"Failed to get the ApplicationClientDescriptor");
228         }
229     return appCD;
230     }
231
232     /**
233      *Notifies interested listeners of the load or unload operation.
234      *@param the type of event to broadcast
235      */

236      protected void notifyAppClientEvent(int eventType) {
237     ApplicationClientEvent event = new ApplicationClientEvent(eventType,
238         getApplication(), getClassLoader());
239     appLoaderEventNotifier.notifyListeners(event);
240      }
241 }
242
Popular Tags