KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > repository > impl > cache > AppServDELImpl


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 package com.sun.enterprise.admin.wsmgmt.repository.impl.cache;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import com.sun.enterprise.deployment.backend.DeploymentEventListener;
30 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
31 import com.sun.enterprise.deployment.backend.DeploymentEvent;
32 import com.sun.enterprise.deployment.backend.DeploymentRequest;
33 import com.sun.enterprise.deployment.Application;
34 import com.sun.enterprise.deployment.BundleDescriptor;
35 import com.sun.enterprise.deployment.WebServicesDescriptor;
36 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd;
37
38 import java.util.logging.Logger JavaDoc;
39 import java.util.logging.Level JavaDoc;
40 import com.sun.logging.LogDomains;
41
42 /**
43  * This class listens to the deploy/undeploy events. On deploy, it
44  * investigates the deployment descriptors for web services. If
45  * web services exist, the application or stand alone module is
46  * demarcated persistently. This cache is used to discover the
47  * deployed web services artifacts in the repository. This removes
48  * the need to read all the deployment descriptors in the repository.
49  * On un-deploy, the information, if any, in the cache is removed.
50  *
51  * @author Nazrul Islam
52  * @since J2SE 5.0
53  */

54 public class AppServDELImpl implements DeploymentEventListener {
55
56     /**
57      * Default constructor.
58      */

59     public AppServDELImpl() {
60     }
61
62     /**
63      * Listens to DEPLOY and UNDEPLOY events. On deploy, the
64      * cache is updated if the application or stand alone
65      * module has web services in it. For application, the ejb and web
66      * bundles with web services are identified. On un-deploy, the
67      * application or stand alone module is removed from cache.
68      */

69     public void notifyDeploymentEvent(DeploymentEvent event) {
70
71         try {
72             DeploymentEventInfo info = null;
73             if (event !=null) {
74                 info = event.getEventInfo();
75             }
76             Application rootDD = null;
77             DeploymentRequest dr = null;
78             if (info != null) {
79                 rootDD = info.getApplicationDescriptor();
80                 dr = info.getDeploymentRequest();
81             }
82             CacheMgr mgr = CacheMgr.getInstance();
83
84             // post deploy event
85
if ((event != null)
86                     && (event.getEventType()==DeploymentEvent.POST_DEPLOY)) {
87
88                 // if an ejb module
89
if (dr.isEjbModule()) {
90                     Set JavaDoc ws = rootDD.getWebServiceDescriptors();
91                     if ((ws != null) && !ws.isEmpty()) {
92                         mgr.addEjbModule(dr.getName());
93                         mgr.save();
94                     }
95
96                 // if a web module
97
} else if (dr.isWebModule()) {
98                     Set JavaDoc ws = rootDD.getWebServiceDescriptors();
99                     if ((ws != null) && !ws.isEmpty()) {
100                         mgr.addWebModule(dr.getName());
101                         mgr.save();
102                     }
103
104                 // if application
105
} else if (dr.isApplication()) {
106                     List JavaDoc ejb = new ArrayList JavaDoc();
107                     Set JavaDoc ejbBundles = rootDD.getEjbBundleDescriptors();
108
109                     for (Iterator JavaDoc iter=ejbBundles.iterator(); iter.hasNext();) {
110                         BundleDescriptor bd = (BundleDescriptor) iter.next();
111                         WebServicesDescriptor wsDD = bd.getWebServices();
112                         if (wsDD.hasWebServices()) {
113
114                             // ejb bundle has web services
115
ejb.add(bd.getModuleDescriptor().getArchiveUri());
116                         }
117                     }
118
119                     List JavaDoc web = new ArrayList JavaDoc();
120                     Set JavaDoc webBundles = rootDD.getWebBundleDescriptors();
121                     for (Iterator JavaDoc iter=webBundles.iterator(); iter.hasNext();) {
122                         BundleDescriptor bd = (BundleDescriptor) iter.next();
123                         WebServicesDescriptor wsDD = bd.getWebServices();
124                         if (wsDD.hasWebServices()) {
125
126                             // web bundle has web services
127
web.add(bd.getModuleDescriptor().getArchiveUri());
128                         }
129                     }
130
131                     if ( (!ejb.isEmpty()) || (!web.isEmpty()) ) {
132                         mgr.addJ2eeApplication(dr.getName(), ejb, web);
133                         mgr.save();
134                     }
135                 }
136                 WebServiceMgrBackEnd.getManager().removeFromCache(dr.getName());
137
138
139             // post undeploy event
140
} else if ((event != null)
141                     && (event.getEventType()==DeploymentEvent.POST_UNDEPLOY)) {
142
143                 // removes the app entry from cache
144
if (dr.isEjbModule()) {
145                     mgr.removeEjbModule(dr.getName());
146                     mgr.save();
147                 } else if (dr.isWebModule()) {
148                     mgr.removeWebModule(dr.getName());
149                     mgr.save();
150                 } else if (dr.isApplication()) {
151                     mgr.removeJ2eeApplication(dr.getName());
152                     mgr.save();
153                 }
154                 WebServiceMgrBackEnd.getManager().removeFromCache(dr.getName());
155             }
156
157
158
159         } catch (Exception JavaDoc e) {
160             _logger.log(Level.FINE, "Error in deployment event listener", e);
161         }
162     }
163
164     // ---- VARIABLES - PRIVATE --------------------------------------------
165
private static Logger JavaDoc _logger = Logger.getLogger(LogDomains.ADMIN_LOGGER);
166 }
167
Popular Tags