KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @(#) ApplicationRegistry.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.util.Hashtable JavaDoc;
40 import java.util.HashSet JavaDoc;
41 import java.util.Collection JavaDoc;
42
43 import com.sun.ejb.Container;
44 import com.sun.enterprise.deployment.Application;
45 import com.sun.enterprise.deployment.EjbDescriptor;
46
47 /**
48  * Registry for all j2ee application and stand alone ejb modules
49  * in a server instance.
50  *
51  * @author Mahesh Kannan
52  * @author Nazrul Islam
53  * @since JDK1.4
54  */

55 public final class ApplicationRegistry {
56
57     /** application id vs class loader */
58     protected Hashtable JavaDoc appID2ClassLoader;
59
60     /** stand alone module id vs class loader */
61     protected Hashtable JavaDoc moduleID2ClassLoader;
62
63     /** ClassLoader vs Application Objects */
64     protected Hashtable JavaDoc classLoader2Application;
65
66     /** EJBDescriptor vs Container */
67     protected Hashtable JavaDoc descriptor2Container;
68
69     /** holds unique ids of ejb containers for each deployed applications */
70     private HashSet JavaDoc uniqueIds;
71
72     /** the singleton instance */
73     private static ApplicationRegistry _instance;
74
75     static {
76         _instance = new ApplicationRegistry();
77     }
78
79     /**
80      * Returns the singleton instance.
81      *
82      * @return the singleton instance
83      */

84     public static ApplicationRegistry getInstance() {
85         return _instance;
86     }
87
88     /**
89      * Initializes the registry.
90      */

91     private ApplicationRegistry() {
92         this.appID2ClassLoader = new Hashtable JavaDoc();
93         this.moduleID2ClassLoader = new Hashtable JavaDoc();
94         this.descriptor2Container = new Hashtable JavaDoc();
95         this.classLoader2Application = new Hashtable JavaDoc();
96         this.uniqueIds = new HashSet JavaDoc();
97     }
98
99     /******** OLD RI METHODS ********/
100
101     /**
102      * Return the Container for the given EjbDescriptor.
103      * This is called at runtime from the Persistence Manager.
104      *
105      * @param desc ejb deployment descriptor
106      *
107      * @return the ejb container for the given descriptor obj
108      */

109     public Container getContainer(EjbDescriptor desc) {
110         return (Container) descriptor2Container.get(desc);
111     }
112
113     /**
114      * Return the Application for the given classloader.
115      * It is assumed that there is a 1-to-1 mapping
116      * from app to loader. This is called at runtime from the
117      * Persistence Manager.
118      *
119      * @param loader class loader
120      *
121      * @return deployment descriptor hierarchy for the given class loader
122      */

123     public Application getApplication(ClassLoader JavaDoc loader) {
124         return (Application) classLoader2Application.get(loader);
125     }
126
127     /**
128      * Get the class loader of a given application.
129      * Used in ServletDeployerImpl
130      *
131      * @param appID registration name of an application
132      *
133      * @return the class loader for the given registration name
134      */

135     public ClassLoader JavaDoc getClassLoaderForApplication(String JavaDoc appID) {
136         return (ClassLoader JavaDoc) appID2ClassLoader.get(appID);
137     }
138
139     /******** OLD RI METHODS ********/
140
141     /**
142      * Get the class loader of the given stand alone module.
143      *
144      * @param moduleID registration name of a stand alone module
145      *
146      * @return the class loader for the given stand alone
147      * module registration name
148      */

149     public ClassLoader JavaDoc getClassLoaderForModule(String JavaDoc moduleID) {
150         return (ClassLoader JavaDoc) moduleID2ClassLoader.get(moduleID);
151     }
152
153     /**
154      * Stores the given deployment descriptor and ejb container in a table.
155      *
156      * @param desc deployment descriptor of an ejb
157      * @param container ejb container
158      */

159     void addDescriptor2Container(EjbDescriptor desc,
160             Container container) {
161
162         descriptor2Container.put(desc, container);
163     }
164
165     /**
166      * Stores class loader against the given registration name for application.
167      *
168      * @param appID registration name of the application
169      * @param classLoader class loader associated with this application
170      */

171     void addAppId2ClassLoader(String JavaDoc appID, ClassLoader JavaDoc classLoader) {
172         appID2ClassLoader.put(appID, classLoader);
173     }
174
175     /**
176      * Stores class loader against the given registration name for stand alone
177      * module. We are keeping separate table because of possible name
178      * space collision.
179      *
180      * @param moduleID registration name of stand alone module
181      * @param classLoader class loader associated with this module
182      */

183     void addModuleId2ClassLoader(String JavaDoc moduleID, ClassLoader JavaDoc classLoader) {
184         moduleID2ClassLoader.put(moduleID, classLoader);
185     }
186
187     /**
188      * Stores the deployment descriptor hierarchy against the class loader.
189      *
190      * @param classLoader class loader used in an app
191      * @param app deployment descriptor hierarchy
192      */

193     void addClassLoader2Application(ClassLoader JavaDoc classLoader,
194             Application app) {
195
196         classLoader2Application.put(classLoader, app);
197     }
198
199     /**
200      * Removes the ejb container associated with the given deployment
201      * descriptor.
202      *
203      * @param desc ejb deployment descriptor
204      * @return the removed ejb container
205      */

206     Container removeDescriptor2Container(EjbDescriptor desc) {
207         return (Container) descriptor2Container.remove(desc);
208     }
209
210     /**
211      * Removes the class loader associated with the given registration name.
212      *
213      * @param appID registration name of an app
214      * @return the removed class loader
215      */

216     ClassLoader JavaDoc removeAppId2ClassLoader(String JavaDoc appID) {
217         return (ClassLoader JavaDoc) appID2ClassLoader.remove(appID);
218     }
219
220     /**
221      * Removes the class loader associated with the given stand alone module
222      * registration name. We are keeping separate table because of possible
223      * name space collision.
224      *
225      * @param moduleID registration name of stand alone module
226      * @return the removed class loader
227      */

228     ClassLoader JavaDoc removeModuleId2ClassLoader(String JavaDoc moduleID) {
229         return (ClassLoader JavaDoc) moduleID2ClassLoader.remove(moduleID);
230     }
231
232     /**
233      * Removes the deployment descriptor hierarchy associated with the given
234      * class loader.
235      *
236      * @param cl class loader used in an app
237      * @return the removed deployment descriptor hierarchy
238      */

239     Application removeClassLoader2Application(ClassLoader JavaDoc cl) {
240         return (Application) classLoader2Application.remove(cl);
241     }
242
243     /**
244      * Returns true if the given id is not already present in this registry.
245      * It adds the specified unique id to the registry if not already
246      * present. This is used to detect collision between two ejb bean
247      * containers.
248      *
249      * @param uniqueId unique id of an ejb bean container
250      *
251      * @return true if the given id is not already present in this registry
252      */

253     boolean isUnique(long uniqueId) {
254         return this.uniqueIds.add( new Long JavaDoc(uniqueId) );
255     }
256
257     /**
258      * Removes the given id from this registry.
259      *
260      * @param uniqueId unique if of an ejb bean container
261      *
262      * @return true if the registry contained the specified id
263      */

264     boolean removeUniqueId(long uniqueId) {
265         return this.uniqueIds.remove( new Long JavaDoc(uniqueId) );
266     }
267
268     /**
269      * Returns all the ejb containers available in this registry.
270      * This includes J2EE applications and stand alone ejb modules.
271      *
272      * @return a collection of ejb containers
273      */

274     Collection JavaDoc getAllEjbContainers() {
275
276         Collection JavaDoc containers = null;
277
278         if (this.descriptor2Container != null) {
279             containers = this.descriptor2Container.values();
280         }
281
282         return containers;
283     }
284 }
285
Popular Tags