KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.logging.*;
27 import java.util.*;
28 import java.io.*;
29 import javax.naming.*;
30 import com.sun.logging.*;
31
32 import com.sun.enterprise.util.*;
33
34 /**
35  * This class is the implementation of the local SerialContextProvider
36  *
37  * @author Sheetal Vartak
38  */

39
40 public class LocalSerialContextProviderImpl
41     extends SerialContextProviderImpl {
42
43     private static LocalStringManagerImpl localStrings =
44     new LocalStringManagerImpl(LocalSerialContextProviderImpl.class);
45
46     static Logger _logger=LogDomains.getLogger(LogDomains.JNDI_LOGGER);
47
48     LocalSerialContextProviderImpl(TransientContext rootContext) throws RemoteException {
49     super(rootContext);
50     }
51
52     static LocalSerialContextProviderImpl getProvider(
53                        TransientContext rootContext) {
54     try {
55         return new LocalSerialContextProviderImpl(rootContext);
56     } catch (RemoteException re) {
57         _logger.log(Level.SEVERE,
58             localStrings.getLocalString("local.provider.null",
59                             "Exception occurred. Returning null provider : {0}" ,
60                             new Object JavaDoc[] {re.getMessage()}));
61         return null;
62     }
63     }
64
65     /**
66      * overriding the super.bind() since we need to make a copy of the object
67      * before it gets put into the rootContext
68      * Remote Provider already does that since when a method is called
69      * on a remote object (in our case the remote provider),
70      * the copies of the method arguments get passed and not the real objects.
71      */

72
73     public void bind(String JavaDoc name, Object JavaDoc obj)
74     throws NamingException, RemoteException {
75
76     Object JavaDoc copyOfObj = NamingUtils.makeCopyOfObject(obj);
77         super.bind(name, copyOfObj);
78     }
79     
80     
81     /**
82      * overriding the super.rebind() since we need to make a copy of the object
83      * before it gets put into the rootContext.
84      * Remote Provider already does that since when a method is called
85      * on a remote object (in our case the remote provider),
86      * the copies of the method arguments get passed and not the real objects.
87      */

88     
89     public void rebind(String JavaDoc name, Object JavaDoc obj)
90     throws NamingException, RemoteException {
91
92     Object JavaDoc copyOfObj = NamingUtils.makeCopyOfObject(obj);
93         super.rebind(name, copyOfObj);
94     }
95
96     public Object JavaDoc lookup(String JavaDoc name)
97         throws NamingException, RemoteException {
98     Object JavaDoc obj = super.lookup(name);
99     // If CORBA object, resolve here in server to prevent a
100
// another round-trip to CosNaming.
101
try {
102         if( obj instanceof Reference ) {
103         Reference ref = (Reference) obj;
104         if( ref.getFactoryClassName().equals
105             (NamingManagerImpl.IIOPOBJECT_FACTORY)) {
106             
107             Hashtable env = new Hashtable();
108             org.omg.CORBA.ORB JavaDoc orb = ORBManager.getORB();
109             env.put("java.naming.corba.orb", orb);
110             obj = javax.naming.spi.NamingManager.getObjectInstance
111             (obj, new CompositeName(name), null, env);
112             return obj;
113         }
114         }
115         return NamingUtils.makeCopyOfObject(obj);
116     } catch(RemoteException re) {
117         throw re;
118     } catch(Exception JavaDoc e) {
119         RemoteException re = new RemoteException("", e);
120             throw re;
121
122         }
123     }
124 }
125
Popular Tags