KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > appclient > jws > AppclientJWSSupportManager


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.appclient.jws;
25
26 import com.sun.enterprise.deployment.Application;
27 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
28 import com.sun.enterprise.deployment.BundleDescriptor;
29 import com.sun.enterprise.deployment.runtime.JavaWebStartAccessDescriptor;
30 import com.sun.enterprise.deployment.util.ModuleDescriptor;
31 import com.sun.enterprise.server.event.ApplicationClientEvent;
32 import com.sun.enterprise.server.event.ApplicationClientLoaderEventListener;
33 import com.sun.enterprise.server.event.ApplicationEvent;
34 import com.sun.enterprise.server.event.ApplicationLoaderEventListener;
35 import com.sun.enterprise.server.event.ApplicationLoaderEventNotifier;
36 import com.sun.logging.LogDomains;
37 import java.io.IOException JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.Vector JavaDoc;
40 import java.util.logging.Level JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
43
44 /**
45  *Singleton that keeps the AppclientJWSSupportInfo up-to-date as applications and app clients
46  *are loaded and unloaded and as the administrator enables and disables
47  *Java Web Start access to them.
48  *
49  * @author tjquinn
50  */

51 public class AppclientJWSSupportManager implements ApplicationLoaderEventListener, ApplicationClientLoaderEventListener {
52     
53     private static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.SERVER_LOGGER);
54
55     /** the singleton instance */
56     private static AppclientJWSSupportManager instance;
57     
58     /** the data structure shared with the system web app */
59     private AppclientJWSSupportInfo jwsInfo;
60     
61     /** system property name used to turn off JWS feature */
62     private static final String JavaDoc JWS_FEATURE_ON_PROPERTY_NAME = "com.sun.aas.jws.featureon";
63     
64     /** indicates if JWS handling is turned on or off via property */
65     private final boolean isJWSFeatureOn = Boolean.valueOf(System.getProperty(JWS_FEATURE_ON_PROPERTY_NAME, "true"));
66     
67     /**
68      *Returns the singleton instance.
69      *@return the instance of the manager
70      */

71     public static AppclientJWSSupportManager getInstance() {
72         if (instance == null) {
73             instance = new AppclientJWSSupportManager();
74             if (instance.isJWSFeatureOn) {
75                 try {
76                     /*
77                      *Obtain the data structure object.
78                      */

79                     instance.jwsInfo = AppclientJWSSupportInfo.getInstance();
80                 } catch (IOException JavaDoc ioe) {
81                     _logger.log(Level.SEVERE, "Error initializing Java Web Start support information", ioe);
82                 } catch (Exception JavaDoc e) {
83                     throw new RuntimeException JavaDoc(e);
84                 }
85             }
86         }
87         return instance;
88     }
89
90      /**
91       *Register all deployed appclients with JWS service. This will be called by
92       *OnDemand initialization framework, when webcontainer starts.
93       */

94      public void startJWSServicesForDeployedAppclients() {
95          jwsInfo.startJWSServicesForDeployedAppclients();
96      }
97     
98     
99     /** Creates a new instance of AppclientJWSSupportManager */
100     private AppclientJWSSupportManager() {
101         /**
102          *If the JWS feature is turned on (the default), register this object
103          *as a listener for app loader and app client loader events.
104          */

105         if (isJWSFeatureOn) {
106             ApplicationLoaderEventNotifier.getInstance().addListener((ApplicationLoaderEventListener) this);
107             ApplicationLoaderEventNotifier.getInstance().addListener((ApplicationClientLoaderEventListener) this);
108         } else {
109             _logger.info("Java Web Start support turned off by " + JWS_FEATURE_ON_PROPERTY_NAME);
110         }
111     }
112
113     /**
114      *Responds to an application-related event broadcast by the instance.
115      *@param the ApplicationEvent describing what has happened
116      */

117     public void handleApplicationEvent(ApplicationEvent event) {
118         /*
119          *Respond to after-load or before-unload events.
120          */

121         int eventType = event.getEventType();
122         if ((eventType == event.BEFORE_APPLICATION_LOAD) ||
123             (eventType == event.AFTER_APPLICATION_UNLOAD) ) {
124             return;
125         }
126         
127         /*
128          *Get the module descriptors (if any) for eligible nested app clients.
129          *If there are any, start Java Web Start services for this app and
130          *those eligible app clients.
131          */

132         Application app = event.getApplication();
133         ModuleDescriptor [] mds = NamingConventions.getEligibleAppclientModuleDescriptors(app);
134         
135         if (mds.length > 0) {
136             try {
137                 if (eventType == event.AFTER_APPLICATION_LOAD) {
138                     jwsInfo.startJWSServicesForApplication(app, mds);
139                 } else if (eventType == event.BEFORE_APPLICATION_UNLOAD) {
140                     jwsInfo.endJWSServicesForApplication(app, mds);
141                 }
142             } catch (Throwable JavaDoc thr) {
143                 _logger.log(Level.SEVERE, "Error updating Java Web Start information for application " + app.getRegistrationName(), thr);
144             }
145         }
146
147     }
148
149     /**
150      *No-op implementation needed to conform to the interface.
151      */

152     public void handleEjbContainerEvent(com.sun.enterprise.server.event.EjbContainerEvent ejbContainerEvent) {
153     }
154     
155     /**
156      *Responds to app client events broadcast by the instance.
157      *@param the event describing what has happened
158      */

159     public void handleApplicationClientEvent(ApplicationClientEvent event) {
160         /*
161          *Respond to after-load or before-unload events.
162          */

163         int eventType = event.getEventType();
164         if ((eventType == event.BEFORE_APPLICATION_CLIENT_LOAD) ||
165             (eventType == event.AFTER_APPLICATION_CLIENT_UNLOAD) ) {
166             return;
167         }
168         
169         /*
170          *Find out if this app client is eligible for Java Web Start access.
171          */

172         Application app = event.getApplication();
173         
174         /*
175          *The Application object wraps the app client, so there should be only
176          *a single nested module (at most) representing the app client itself.
177          */

178         ModuleDescriptor [] mds = NamingConventions.getEligibleAppclientModuleDescriptors(app);
179         
180         if (mds.length > 1) {
181             _logger.warning("During app client loading, expected exactly one app client module in the wrapping application but found more; using the first one and ignoring the others");
182         } else if (mds.length == 0) {
183             _logger.warning("During app client loading, expected exactly one app client module in the wrapping application but found none; ignoring this app client and continuing");
184             return;
185         }
186         
187         try {
188             if (eventType == event.AFTER_APPLICATION_CLIENT_LOAD) {
189                 jwsInfo.startJWSServicesForAppclient(app, mds[0]);
190             } else if (eventType == event.BEFORE_APPLICATION_CLIENT_UNLOAD) {
191                 jwsInfo.endJWSServicesForAppclient(app, mds[0]);
192             }
193         } catch (Throwable JavaDoc thr) {
194             _logger.log(Level.SEVERE, "Error updating Java Web Start information for app client " + app.getRegistrationName(), thr);
195         }
196     }
197 }
198
Popular Tags