KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > naming > ProviderManager


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.naming;
24
25 import java.rmi.*;
26
27 import java.util.logging.*;
28 import com.sun.logging.*;
29
30 /**
31  * This class is a facade for the remote and local SerialContextProvider
32  * The need for this class arose from the fact that we wanted to have a way
33  * of lazily initializing the Remote SerialContextProvider.
34  * The TransientContext member field has to be shared across both remote and
35  * local SerialContextProvider. It could have been a static variable but to avoid
36  * issues of static variables with multiple threads, etc, this class has been designed.
37  * The ORB needs to be initialized before the call to initRemoteProvider()
38  *
39  * @author Sheetal Vartak
40  */

41
42 public class ProviderManager {
43
44     // This is a singleton.
45
private static ProviderManager providerManager;
46     private TransientContext rootContext = new TransientContext();
47     private SerialContextProvider localProvider;
48     private boolean initRemoteProviderDone = false;
49     static Logger _logger = LogDomains.getLogger(LogDomains.JNDI_LOGGER);
50   
51     public synchronized static ProviderManager getProviderManager() {
52     if (providerManager == null ) {
53         providerManager = new ProviderManager();
54         }
55     return providerManager;
56     }
57
58     public TransientContext getTransientContext() {
59     return rootContext;
60     }
61     
62     public synchronized SerialContextProvider getLocalProvider() {
63       
64     if (localProvider == null) {
65         localProvider = LocalSerialContextProviderImpl.getProvider(rootContext);
66     }
67     return localProvider;
68     }
69
70     public synchronized void initRemoteProvider() throws RemoteException {
71     if (initRemoteProviderDone == false) {
72      
73         RemoteSerialContextProviderImpl.initSerialContextProvider(rootContext);
74         initRemoteProviderDone = true;
75     }
76     }
77
78
79 }
80
Popular Tags