KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @(#) AbstractLoader.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 java.io.File JavaDoc;
40 import java.util.Vector JavaDoc;
41 import java.util.Set JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.Enumeration JavaDoc;
44 import java.util.HashSet JavaDoc;
45 import java.util.logging.Logger JavaDoc;
46 import java.util.logging.Level JavaDoc;
47 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
48 import javax.naming.NameAlreadyBoundException JavaDoc;
49
50 import com.sun.ejb.Container;
51 import com.sun.ejb.ContainerFactory;
52
53 import com.sun.enterprise.Switch;
54 import com.sun.enterprise.deployment.Application;
55 import com.sun.enterprise.deployment.ConnectorDescriptor;
56 import com.sun.enterprise.deployment.BundleDescriptor;
57 import com.sun.enterprise.deployment.EjbDescriptor;
58 import com.sun.enterprise.SecurityManager;
59 import com.sun.enterprise.loader.EJBClassLoader;
60 import com.sun.enterprise.loader.EJBClassPathUtils;
61 import com.sun.enterprise.loader.InstrumentableClassLoader;
62 import com.sun.logging.LogDomains;
63 import com.sun.enterprise.security.factory.FactoryForSecurityManagerFactoryImpl;
64 import com.sun.enterprise.security.factory.SecurityManagerFactory;
65 import com.sun.enterprise.security.factory.FactoryForSecurityManagerFactory;
66
67 import com.sun.enterprise.security.SecurityUtil;
68
69 import com.sun.enterprise.config.ConfigContext;
70 import com.sun.enterprise.config.ConfigException;
71 import com.sun.enterprise.config.serverbeans.Applications;
72 import com.sun.enterprise.config.serverbeans.Domain;
73 import com.sun.enterprise.config.serverbeans.J2eeApplication;
74
75 import com.sun.enterprise.instance.BaseManager;
76
77 import com.sun.enterprise.util.io.FileUtils;
78 import com.sun.enterprise.util.Utility;
79
80 import com.sun.enterprise.connectors.*;
81 import com.sun.enterprise.server.ondemand.entry.*;
82
83 //for jsr77
84
import com.sun.enterprise.deployment.Descriptor;
85 import javax.management.MBeanException JavaDoc;
86
87 import com.sun.enterprise.security.application.EJBSecurityManager;
88 import com.sun.enterprise.server.event.ApplicationEvent;
89 import com.sun.enterprise.server.event.EjbContainerEvent;
90 import com.sun.enterprise.server.event.ApplicationLoaderEventNotifier;
91
92 import com.sun.enterprise.admin.monitor.WSMonitorLifeCycleFactory;
93
94 /**
95  * Base loader to load and unload applicaton and stand alone module.
96  *
97  * @author Mahesh Kannan
98  * @author Nazrul Islam
99  * @since JDK1.4
100  */

101 abstract class AbstractLoader implements EntryPoint {
102  
103     /** the registration name for this application */
104     protected String JavaDoc id = null;
105
106     /** parent class loader of ejb class loader */
107     ClassLoader JavaDoc parentClassLoader = null;
108
109     /** ejb class loader used by this application */
110     ClassLoader JavaDoc ejbClassLoader = null;
111
112     /** deployment descriptor object for this application */
113     Application application = null;
114
115     protected boolean robFlag = false;
116
117     /** application registry */
118     protected ApplicationRegistry registry = null;
119
120     /** encapsulates application related information */
121     protected BaseManager configManager = null;
122
123     /** logger to log loader messages */
124     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.LOADER_LOGGER);
125
126     /** factory for SecurityManagerFactory */
127     private FactoryForSecurityManagerFactory ffsmf = null;
128
129     /*** This variable tells whether to load/unload pools and resources recursively. **/
130
131     protected boolean cascade=false;
132
133     /** Possible values for this:
134      * 0. LOAD_UNSET is before initialization
135      *
136      * For loading:
137      * 1. LOAD_ALL is for loading regular application
138      * 2. LOAD_RAR is for loading the rar part of the embedded rar
139      * 3. LOAD_REST is for loading the rest part of the embedded rar
140      * Embedded rar is loaded in two steps so we can create connector
141      * resources in between.
142      *
143      * For unloading:
144      * 4. UNLOAD_ALL is for unloading regular application
145      * 5. UNLOAD_RAR is for unloading the rar part of the embedded rar
146      * 6. UNLOAD_REST is for unloading the rest part of the embedded rar
147      * Embedded rar is unloaded in two steps so we can delete connector
148      * resources in between.
149      */

150     protected int loadUnloadAction;
151
152     private ApplicationLoaderEventNotifier loaderEventNotifier;
153
154     private ConfigContext dynamicConfigContext;
155
156     /**
157      * Constructor. ApplicationLoader loads an application or
158      * stand alone ejb module.
159      *
160      * @param id the registration name of this application
161      * @param parentClassLoader the parent class loader
162      * @param configMgr the config manager for this VS
163      */

164     AbstractLoader(String JavaDoc id, ClassLoader JavaDoc parentClassLoader,
165             BaseManager configMgr) {
166
167         this.id = id;
168         this.parentClassLoader = parentClassLoader;
169         this.registry = ApplicationRegistry.getInstance();
170         this.configManager = configMgr;
171
172     this.loaderEventNotifier =
173         ApplicationLoaderEventNotifier.getInstance();
174     }
175
176     /**
177      * Initializes this loader by creating the ejb class loader.
178      *
179      * @param classPaths class paths for the ejb class loader
180      */

181     protected void initializeLoader(String JavaDoc[] classPaths, String JavaDoc moduleRoot, ModuleType JavaDoc moduleType) {
182         this.ejbClassLoader = EJBClassPathUtils.createEJBClassLoader(
183                         classPaths, moduleRoot, this.id, this.parentClassLoader, moduleType);
184     }
185
186     /**
187      * Initializes this loader to the given classloader
188      */

189     protected void initializeLoader(ClassLoader JavaDoc clazzloader) {
190         this.ejbClassLoader = clazzloader;
191     }
192
193     void setConfigContext(ConfigContext dynamicConfigContext) {
194     this.dynamicConfigContext = dynamicConfigContext;
195     }
196
197     /**
198      * Loads a deployed application or stand alone module.
199      * If jsr77 is true then corresponding jsr77 mBeans will be created
200      * during load time.
201      *
202      * @param jsr77 create jsr77 mbeans if true
203      */

204     abstract boolean load(boolean jsr77);
205
206     /**
207      * Unloads a deployed application or stand alone module.
208      * If jsr77 is true then corresponding jsr77 mBeans will be deleted
209      * during unload time.
210      *
211      * @param jsr77 delete jsr77 mbeans if true
212      */

213     abstract boolean unload(boolean jsr77);
214
215     /**
216      * Create jsr77 root mBean
217      * The root mBean corresponds to either an application
218      * or stand-alone module depending on j2ee type
219      */

220     abstract void createRootMBean () throws MBeanException JavaDoc;
221
222     /**
223      * Delete jsr77 root mBean
224      * The root mBean corresponds to either an application
225      * or stand-alone module depending on j2ee type
226      */

227     abstract void deleteRootMBean () throws MBeanException JavaDoc;
228
229     /**
230      * Create jsr77 mBeans for components within root mBean
231      * The leaf mBeans correspond to the child objects of rootMBean.
232      * For an ejb stand-alone module it will be ejbs
233      * and for a web stand-alone module it will be servlets
234      * and for a connector stand-alone module it will be resource adapters
235      */

236     abstract void createLeafMBeans () throws MBeanException JavaDoc;
237
238     /**
239      * Delete jsr77 mBeans for components within root mBean
240      * The leaf mBeans correspond to the child objects of rootMBean.
241      * For an ejb stand-alone module it will be ejbs
242      * and for a web stand-alone module it will be servlets
243      * and for a connector stand-alone module it will be resource adapters
244      */

245     abstract void deleteLeafMBeans () throws MBeanException JavaDoc;
246
247     /**
248      * Create jsr77 mBean for the leaf object
249      * The leaf mBean correspond to the child object of rootMBean.
250      * For an ejb stand-alone module it will be ejb
251      * and for a web stand-alone module it will be servlet
252      * and for a connector stand-alone module it will be resource adapter
253      *
254      * @param descriptor descriptor object for the leaf element
255      */

256     abstract void createLeafMBean (Descriptor descriptor) throws MBeanException JavaDoc;
257
258     /**
259      * Delete jsr77 mBean for the leaf object
260      * The leaf mBean correspond to the child object of rootMBean.
261      * For an ejb stand-alone module it will be ejb
262      * and for a web stand-alone module it will be servlet
263      * and for a connector stand-alone module it will be resource adapter
264      */

265     abstract void deleteLeafMBean (Descriptor descriptor) throws MBeanException JavaDoc;
266
267     /**
268      * Delete jsr77 mBeans for the root and its' components
269      */

270     abstract void deleteLeafAndRootMBeans () throws MBeanException JavaDoc;
271
272     /**
273      * Set state for jsr77 root mBean
274      * The state can be set for a root mBean and it could be
275      * one of STARTING, RUNNING, STOPPING, STOPPED, or FAILED
276      *
277      * @param state state of the module or application
278      */

279     abstract void setState(int state) throws MBeanException JavaDoc;
280
281     /**
282      * Returns the ejb class loader used by this loader.
283      *
284      * @return the ejb class loader
285      */

286     ClassLoader JavaDoc getClassLoader() {
287         return this.ejbClassLoader;
288     }
289
290     /**
291      * Returns the deployment descriptor object used by this loader.
292      *
293      * @return the deployment descriptor object
294      */

295     Application getApplication() {
296         return this.application;
297     }
298     
299     /**
300      * Helps garbage collector by assigning member variables to null.
301      * This is called from unload.
302      *
303      * @see #unload
304      */

305     protected void done() {
306
307         // releases resources (file handles, etc) in the class loader
308
if (this.ejbClassLoader instanceof EJBClassLoader) {
309             ((EJBClassLoader) ejbClassLoader).done();
310         }
311         
312         // set connector descriptor classloaders to null
313
Set JavaDoc rars = this.application.getRarDescriptors();
314         for (Iterator JavaDoc itr = rars.iterator(); itr.hasNext();) {
315             ConnectorDescriptor cd = (ConnectorDescriptor) itr.next();
316             cd.setClassLoader(null);
317         }
318         
319         this.id = null;
320         this.parentClassLoader = null;
321         this.application = null;
322         this.ejbClassLoader = null;
323         this.registry = null;
324         this.configManager = null;
325     }
326
327     /**
328      * Unloads all the ejb bean containers.
329      * If jsr77 is true then corresponding jsr77 mBeans will be deleted
330      * during unload time.
331      *
332      * @param jsr77 delete jsr77 mBeans if true
333      * @return true if unloaded successfully
334      */

335     protected boolean unloadEjbs(boolean jsr77) {
336
337         boolean result = true;
338
339         if (this.application == null) {
340             result = false;
341         } else {
342
343             // undeploy ejb module
344
Vector JavaDoc beanDescriptors = this.application.getEjbDescriptors();
345             Enumeration JavaDoc e = beanDescriptors.elements();
346
347             while ( e.hasMoreElements() ) {
348                 EjbDescriptor nextDescriptor = (EjbDescriptor) e.nextElement();
349
350         notifyEjbEvent(EjbContainerEvent.BEFORE_EJB_CONTAINER_UNLOAD,
351             nextDescriptor);
352
353                 // removes the unique id from the registry
354
this.registry.removeUniqueId( nextDescriptor.getUniqueId() );
355
356                 try {
357                     // removes the bean container from the application registry
358
Container container = (Container) this.registry.
359                             removeDescriptor2Container(nextDescriptor);
360                     if (container != null) {
361                         container.undeploy();
362                     }
363
364                 } catch (Exception JavaDoc beanEx) {
365                     result = false;
366                     _logger.log(Level.WARNING,
367                         "loader.unexpected_error_while_unloading_ejb_container",
368                         beanEx);
369                 }
370
371         notifyEjbEvent(EjbContainerEvent.AFTER_EJB_CONTAINER_UNLOAD,
372             nextDescriptor);
373
374                 if (jsr77) {
375                           try {
376                             deleteLeafMBean(nextDescriptor);
377                           } catch (MBeanException JavaDoc mbe) {
378                               _logger.log(Level.WARNING,
379                               "loader.delete_ejb_mbean_exception", mbe);
380                           }
381                 }
382             }
383
384             if (!application.isVirtual()) {
385                 // removes the class loader from the application registry
386
this.registry.removeAppId2ClassLoader(this.id);
387             } else {
388                 this.registry.removeModuleId2ClassLoader(this.id);
389             }
390
391             // removes the descriptor object from the application registry
392
this.registry.removeClassLoader2Application(this.ejbClassLoader);
393
394         }
395
396         _logger.log(Level.FINE,"[AbstractLoader] Unload EJB(s) Status: "
397                     + result);
398
399         return result;
400     }
401
402     void initializeRegistry() {
403         if (!application.isVirtual()) {
404             // adds the ejb class loader to the repository
405
this.registry.addAppId2ClassLoader(this.id, this.ejbClassLoader);
406         } else {
407             this.registry.addModuleId2ClassLoader(this.id, this.ejbClassLoader);
408         }
409
410         // adds the deployment descriptor obj to the repository
411
this.registry.addClassLoader2Application(this.ejbClassLoader,
412                                                  this.application);
413     }
414
415     /**
416      * Creates the bean containers for all ejbs.
417      * If jsr77 is true then corresponding jsr77 mBeans will be created
418      * during load time.
419      *
420      * @return true if all modules deployed successfully
421      */

422     protected boolean loadEjbs(boolean jsr77) {
423
424         // application.getApplicationArchivist().getClassLoader();
425
final ClassLoader JavaDoc loader = this.ejbClassLoader;
426
427         if (this.application == null) {
428             return false;
429         }
430         
431         if (_logger.isLoggable(Level.FINEST)) {
432             _logger.log(Level.FINEST,
433                         "[AbstractLoader] Id: " + this.id +
434                         " Setting thread context class loader to: " + loader);
435         }
436
437         /*
438          *5003242 - Save current context class loader as it is changed. Restored in finally block of next try.
439         */

440         ClassLoader JavaDoc savedContextClassLoader = Utility.setContextClassLoader(loader);
441
442       try {
443
444         initializeRegistry();
445         HashSet JavaDoc myContainers = new HashSet JavaDoc();
446
447         if (_logger.isLoggable(Level.FINEST)) {
448             _logger.log(Level.FINEST,
449                         "[AbstractLoader] Id: " + this.id
450                         + " Unique Id: " + this.application.getUniqueId());
451         }
452        
453         Vector JavaDoc beanDescriptors = application.getEjbDescriptors();
454
455         // create EJB containers for each EJB
456
Enumeration JavaDoc e = beanDescriptors.elements();
457         ContainerFactory cf = Switch.getSwitch().getContainerFactory();
458
459         while (e.hasMoreElements()) {
460             EjbDescriptor nextDescriptor = (EjbDescriptor) e.nextElement();
461
462             // detects any unique id collisions
463
if ( !this.registry.isUnique( nextDescriptor.getUniqueId() ) ) {
464
465                 _logger.log(Level.SEVERE, "loader.duplicate_unique_id",
466                             new Object JavaDoc[] {
467                               String.valueOf(nextDescriptor.getUniqueId()),
468                               nextDescriptor.getName()
469                             });
470
471                 // unload all the ejbs
472
unloadEjbs(jsr77);
473
474                 // abort loading
475
return false;
476             }
477
478             try {
479         if(ffsmf == null){
480             ffsmf = FactoryForSecurityManagerFactoryImpl.getInstance();
481         }
482         SecurityManagerFactory smf = ffsmf.getSecurityManagerFactory("ejb");
483         SecurityManager JavaDoc sm = smf.createSecurityManager(nextDescriptor);
484                 // create the bean container
485
Container container = null;
486                 try {
487             notifyEjbEvent(EjbContainerEvent.BEFORE_EJB_CONTAINER_LOAD,
488             nextDescriptor);
489
490                     container = cf.createContainer(nextDescriptor, loader,
491                     sm, dynamicConfigContext);
492
493             notifyEjbEvent(EjbContainerEvent.AFTER_EJB_CONTAINER_LOAD,
494             nextDescriptor);
495                 } catch (NameAlreadyBoundException JavaDoc jndiEx) {
496
497                     // logs a message
498
_logger.log(Level.SEVERE, "loader.jndi_name_conflict",
499                                 new Object JavaDoc[] {
500                                     this.id,
501                                     nextDescriptor.getJndiName(),
502                                     nextDescriptor.getName()
503                                 });
504
505                     // logs the actual exception
506
_logger.log(Level.SEVERE,
507                         "loader.naming_exception_in_createcontainer", jndiEx);
508
509                     // remove all loaded ejbs
510
unloadEjbs(jsr77);
511
512                     // abort loading
513
return false;
514                 }
515
516                 if (_logger.isLoggable(Level.FINE)) {
517                     _logger.log(Level.FINE,
518                                 "Created container with uinque id: "
519                                 + nextDescriptor.getUniqueId());
520                 }
521
522                 // adds the container to the repository
523
this.registry.addDescriptor2Container(nextDescriptor,container);
524
525                 // adds the container to the temp local table
526
myContainers.add(container);
527
528             } catch (Exception JavaDoc beanEx) {
529                 _logger.log(Level.SEVERE,
530                     "loader.unexpected_error_while_creating_ejb_container",
531                     beanEx);
532
533                 // remove all loaded ejbs
534
unloadEjbs(jsr77);
535
536                 return false;
537             }
538
539             if (jsr77) {
540               try {
541                 createLeafMBean(nextDescriptor);
542               } catch (MBeanException JavaDoc mbe) {
543                 _logger.log(Level.WARNING, "loader.create_ejb_mbean_exception", mbe);
544               }
545             }
546         }
547
548     try {
549             Enumeration JavaDoc en = beanDescriptors.elements();
550             // generate policy files for applications with ejbs not otherwise
551
while (en.hasMoreElements()) {
552                 EjbDescriptor nextDescriptor = (EjbDescriptor)en.nextElement();
553                 SecurityUtil.generatePolicyFile(
554                     EJBSecurityManager.getContextID(nextDescriptor));
555             }
556     } catch (Exception JavaDoc ge) {
557             _logger.log(Level.SEVERE,
558             "code.could_not_generate/load_the_policy_files_for_system_app",
559             ge);
560
561         // remove all loaded ejbs
562
unloadEjbs(jsr77);
563
564         return false;
565     }
566  
567         // notify ejb containers that application deployment succeeded.
568
Iterator JavaDoc iter = myContainers.iterator();
569         while ( iter.hasNext() ) {
570             Container c = (Container) iter.next();
571             c.doAfterApplicationDeploy();
572             //IASRI 4717059 BEGIN
573
/*
574             if (robFlag) {
575                 if ( c instanceof EntityContainer) {
576                     ( (EntityContainer) c).setROBNotifier(robNotifier);
577                 }
578             }
579             */

580             //IASRI 4717059 END
581
}
582
583         // diagnostics of all the roles and acls
584
com.sun.enterprise.security.Audit.showACL(this.application);
585
586         // log that ejbs were loaded
587
if (this.application.getEjbComponentCount() > 0) {
588             _logger.log(Level.INFO, "loader.ejbs_loaded", this.id);
589         }
590
591         _logger.log(Level.FINE,"[AbstractLoader] loadEjbs completed");
592
593         return true;
594       } finally {
595             /*
596              *5003242 - Restore saved context class loader.
597              */

598             Utility.setContextClassLoader(savedContextClassLoader);
599       }
600             
601     }
602
603     // ---- START OF IASRI 4666595 ---------------------------------------
604

605     /**
606      * Unloads all the rar.
607      * If jsr77 is true then corresponding jsr77 mBeans will be deleted
608      * during unload time.
609      *
610      * @param jsr77 delete jsr77 mBeans if true
611      * @return true if unloaded successfully
612      */

613     protected boolean unloadRars(boolean jsr77) {
614         boolean result = true;
615         // undeploy rar module
616
try {
617             Set JavaDoc rarsDescriptors = this.application.getRarDescriptors();
618             ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
619         
620             for (Iterator JavaDoc itr = rarsDescriptors.iterator(); itr.hasNext();) {
621                 ConnectorDescriptor cd = (ConnectorDescriptor) itr.next();
622                 String JavaDoc rarName = cd.getDeployName();
623                 String JavaDoc jndiName = this.id+
624                          ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER+
625                          FileUtils.makeFriendlyFilenameNoExtension(rarName);
626                 connectorRuntime.destroyActiveResourceAdapter(jndiName,cascade);
627                 if (jsr77) {
628                      deleteLeafMBean(cd);
629                 }
630             }
631         } catch (Exception JavaDoc rarEx) {
632             result = false;
633             _logger.log(Level.WARNING,
634                         "loader.application_loader_exception", rarEx);
635         }
636
637         _logger.log(Level.FINE,"[AbstractLoader] Unload RAR(s) Status: "
638                     + result);
639
640         return result;
641     }
642
643     
644     /**
645      * Load the rars of that application
646      * If jsr77 is true then corresponding jsr77 mBeans will be created
647      * during load time.
648      *
649      * @param jsr77 delete jsr77 mBeans if true
650      * @return true if all modules deployed successfully
651      */

652     protected boolean loadRars(boolean jsr77) {
653         
654         try {
655
656             String JavaDoc appLocation = this.configManager.getLocation(this.id);
657             Set JavaDoc rars = application.getRarDescriptors();
658             ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
659
660             for (Iterator JavaDoc itr = rars.iterator(); itr.hasNext();) {
661                 ConnectorDescriptor cd = (ConnectorDescriptor) itr.next();
662                 String JavaDoc rarName = cd.getDeployName();
663                 String JavaDoc location = appLocation
664                                 + File.separator
665                                 + FileUtils.makeFriendlyFilename(rarName);
666                 String JavaDoc jndiName = this.id+
667                        ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER+
668                        FileUtils.makeFriendlyFilenameNoExtension(rarName);
669                 connectorRuntime.createActiveResourceAdapter(
670                               cd,jndiName,location,this.cascade);
671                 if (jsr77) {
672                     createLeafMBean(cd);
673                 }
674             }
675             // now load resources associated with these embedded RARs
676
try {
677                 ConnectorResourcesLoader crl = new ConnectorResourcesLoader(ApplicationServer.getServerContext());
678                 crl.loadEmbeddedRarResources(id,getApplication());
679             } catch (ConfigException cex) {
680                 _logger.log(Level.SEVERE, "loader.connector_resource_initialization_error", cex);
681             }
682         } catch (Exception JavaDoc rarEx) {
683             _logger.log(Level.WARNING,
684                         "loader.application_loader_exception", rarEx);
685         }
686         _logger.log(Level.FINE,"[AbstractLoader] loadRars completed");
687         return true;
688     }
689  
690     protected void setCascade(boolean cascade) {
691         this.cascade=cascade;
692     }
693
694     protected boolean getCascade() {
695         return this.cascade;
696     }
697
698     protected int getLoadUnloadAction(){
699         return this.loadUnloadAction;
700     }
701
702     protected void setLoadUnloadAction(int loadUnloadAction) {
703         this.loadUnloadAction = loadUnloadAction;
704     }
705
706     // ---- END OF IASRI 4666595 ----------------------------------------
707

708     /**
709      * Loads all the Web Service Management MBeans.
710      * If jsr77 is true then corresponding jsr77 mBeans will be created
711      * during load time.
712      *
713      * @param jsr77 create jsr77 mBeans if true
714      * @return true if unloaded successfully
715      */

716     protected boolean loadWebserviceEndpoints(boolean jsr77) {
717
718         boolean result = true;
719
720         if (this.application == null) {
721             result = false;
722         } else {
723
724             Set JavaDoc bundleSet = new HashSet JavaDoc();
725             bundleSet.addAll(this.application.getEjbBundleDescriptors());
726             bundleSet.addAll(this.application.getWebBundleDescriptors());
727
728             // unload web service endpoint
729
Iterator JavaDoc itr = bundleSet.iterator();
730
731             while ( itr.hasNext() ) {
732                 BundleDescriptor nextDescriptor = (BundleDescriptor)
733                         itr.next();
734
735                 try {
736                     WSMonitorLifeCycleFactory.getInstance().
737                     getWSMonitorLifeCycleProvider().
738                     registerWebServiceEndpoints(
739                     this.application.getRegistrationName(), nextDescriptor);
740                 } catch (Exception JavaDoc e) {
741                   _logger.log(Level.WARNING,
742                   "loader.register_ws_endpoint_error",
743                   this.application.getRegistrationName());
744                   _logger.log(Level.WARNING,
745                   "loader.register_ws_endpoint_exception", e);
746                    result = false;
747                 }
748
749                 /*
750                 if (jsr77) {
751                       try {
752                             createLeafMBeans(nextDescriptor);
753                           } catch (MBeanException mbe) {
754                                 mbe.printStackTrace();
755                               _logger.log(Level.WARNING,
756                               "loader.create_ejb_mbean_exception", mbe);
757                           }
758                 }
759                 */

760
761                 _logger.log(Level.FINE,
762                  "[AbstractLoader] Unload Web Service Endpoint(s) Status: " +
763                  result);
764             }
765         }
766
767         return result;
768     }
769
770     /**
771      * Unloads all the Web Service Management MBeans.
772      * If jsr77 is true then corresponding jsr77 mBeans will be deleted
773      * during unload time.
774      *
775      * @param jsr77 delete jsr77 mBeans if true
776      * @return true if unloaded successfully
777      */

778     protected boolean unloadWebserviceEndpoints(boolean jsr77) {
779
780         boolean result = true;
781
782         if (this.application == null) {
783             result = false;
784         } else {
785
786             // unload web service endpoint
787
Set JavaDoc bundleSet = new HashSet JavaDoc();
788             bundleSet.addAll(this.application.getEjbBundleDescriptors());
789             bundleSet.addAll(this.application.getWebBundleDescriptors());
790             Iterator JavaDoc itr = bundleSet.iterator();
791
792             while ( itr.hasNext() ) {
793                 BundleDescriptor nextDescriptor = (BundleDescriptor) itr.next();
794
795                 try {
796                     WSMonitorLifeCycleFactory.getInstance().
797                     getWSMonitorLifeCycleProvider().
798                     unregisterWebServiceEndpoints(
799                     this.application.getRegistrationName(), nextDescriptor);
800                 } catch (Exception JavaDoc e) {
801                   _logger.log(Level.WARNING,
802                   "loader.unregister_ws_endpoint_error",
803                   this.application.getRegistrationName());
804                   _logger.log(Level.WARNING,
805                   "loader.register_ws_endpoint_exception", e);
806                    result = false;
807                 }
808
809                 /*
810                 if (jsr77) {
811                     try {
812                         deleteLeafMBeans(nextDescriptor);
813                     } catch (MBeanException mbe) {
814                                 mbe.printStackTrace();
815                         _logger.log(Level.WARNING,
816                         "loader.delete_ejb_mbean_exception", mbe);
817                     }
818                 }
819                 */

820
821                 _logger.log(Level.FINE,
822                 "[AbstractLoader] Unload Web Service Endpoint(s) Status: " +
823                 result);
824             }
825         }
826
827         return result;
828     }
829
830     public void generateEntryContext(Object JavaDoc context) {
831          ServerEntryHelper.generateAppLoaderEntryContext((Descriptor) context);
832     }
833
834     protected void notifyAppEvent(int eventType) {
835     ApplicationEvent event = new ApplicationEvent(eventType,
836         getApplication(), getClassLoader());
837         generateEntryContext(getApplication());
838     loaderEventNotifier.notifyListeners(event);
839     }
840
841     protected void notifyEjbEvent(int eventType, EjbDescriptor desc) {
842     EjbContainerEvent event = new EjbContainerEvent(eventType,
843         desc, getClassLoader());
844         generateEntryContext(desc);
845     loaderEventNotifier.notifyListeners(event);
846     }
847
848     /**
849      * Loads all the EJB 3.0 persistence entities bundled in this application.
850      */

851     protected boolean loadPersistenceUnits() {
852         try{
853             new PersistenceUnitLoaderImpl().load(new ApplicationInfoImpl());
854             return true;
855         }catch(Exception JavaDoc ge){
856             _logger.log(Level.WARNING, ge.getMessage(), ge);
857             return false;
858         }
859     }
860
861     /**
862      * Unloads all the EJB 3.0 persistence entities bundled in this application.
863      */

864     protected boolean unloadPersistenceUnits() {
865         try{
866             new PersistenceUnitLoaderImpl().unload(new ApplicationInfoImpl());
867             return true;
868         }catch(Exception JavaDoc ge){
869             _logger.log(Level.WARNING, ge.getMessage(), ge);
870             return false;
871         }
872     }
873
874     private class ApplicationInfoImpl
875             implements PersistenceUnitLoader.ApplicationInfo {
876         public Application getApplication() {
877             return application;
878         }
879
880         public InstrumentableClassLoader getClassLoader() {
881             return InstrumentableClassLoader.class.cast(ejbClassLoader);
882         }
883
884         public String JavaDoc getApplicationLocation() {
885             try {
886                 return configManager.getLocation(id);
887             } catch (ConfigException e) {
888                 throw new RuntimeException JavaDoc(e);
889             }
890         }
891     }
892 }
893
Popular Tags