KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.rmi.PortableRemoteObject JavaDoc;
26 import java.rmi.*;
27 import java.util.*;
28 import java.io.*;
29 import javax.naming.*;
30 import com.sun.enterprise.util.ORBManager;
31 import org.omg.CosNaming.NamingContext JavaDoc;
32 import org.omg.CosNaming.NameComponent JavaDoc;
33 import org.omg.CosNaming.NamingContextHelper JavaDoc;
34 import org.omg.PortableServer.POA JavaDoc;
35 import org.omg.PortableServer.Servant JavaDoc;
36 import org.omg.PortableServer.LifespanPolicyValue JavaDoc;
37 import org.omg.CORBA.Policy JavaDoc;
38 import org.omg.PortableServer.ImplicitActivationPolicyValue JavaDoc;
39 import javax.rmi.CORBA.Tie JavaDoc;
40
41 import java.util.logging.*;
42 import com.sun.logging.*;
43
44 /**
45  * This class is the implementation of the Remote SerialContextProvider
46  *
47  * @author Sheetal Vartak
48  */

49
50 public class RemoteSerialContextProviderImpl
51     extends SerialContextProviderImpl {
52
53  static public final String JavaDoc SERIAL_CONTEXT_PROVIDER_NAME =
54         "SerialContextProvider";
55
56
57     private RemoteSerialContextProviderImpl(TransientContext rootContext)
58     throws RemoteException {
59     super(rootContext);
60     PortableRemoteObject.exportObject(this);
61     }
62
63    /**
64      * Create the remote object and publish it in the CosNaming name service.
65      */

66     static public void initSerialContextProvider(TransientContext rootContext)
67     throws RemoteException {
68         try {
69         SerialContextProviderImpl impl =
70         new RemoteSerialContextProviderImpl(rootContext);
71
72             Tie JavaDoc servantsTie = javax.rmi.CORBA.Util.getTie(impl);
73             
74             //servantsTie.orb(ORBManager.getORB());
75
//org.omg.CORBA.Object provider = servantsTie.thisObject());
76

77         // Create a CORBA objref for SerialContextProviderImpl using a POA
78
POA JavaDoc rootPOA = (POA JavaDoc)
79             ORBManager.getORB().resolve_initial_references("RootPOA");
80         
81         Policy JavaDoc[] policy = new Policy JavaDoc[2];
82         policy[0] = rootPOA.create_implicit_activation_policy(
83                 ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION);
84         policy[1] = rootPOA.create_lifespan_policy(
85         LifespanPolicyValue.PERSISTENT);
86
87         POA JavaDoc poa = rootPOA.create_POA("SerialContextProviderPOA", null,
88                      policy);
89         poa.the_POAManager().activate();
90         org.omg.CORBA.Object JavaDoc provider = poa.servant_to_reference(
91                             (Servant JavaDoc)servantsTie);
92             
93             // put object in NameService
94
org.omg.CORBA.Object JavaDoc objRef =
95                 ORBManager.getORB().resolve_initial_references("NameService");
96             NamingContext JavaDoc ncRef = NamingContextHelper.narrow(objRef);
97             NameComponent JavaDoc nc =
98                 new NameComponent JavaDoc(SERIAL_CONTEXT_PROVIDER_NAME, "");
99             NameComponent JavaDoc path[] = {nc};
100             ncRef.rebind(path, provider);
101
102         } catch (Exception JavaDoc ex) {
103
104             _logger.log(Level.SEVERE,
105                  "enterprise_naming.excep_in_insertserialcontextprovider",ex);
106             
107             RemoteException re =
108                 new RemoteException("initSerialCtxProvider error");
109             re.initCause(ex);
110             throw re;
111         }
112     }
113         
114    public Object JavaDoc lookup(String JavaDoc name)
115         throws NamingException, RemoteException {
116     Object JavaDoc obj = super.lookup(name);
117     // If CORBA object, resolve here in server to prevent a
118
// another round-trip to CosNaming.
119
try {
120         if( obj instanceof Reference ) {
121         Reference ref = (Reference) obj;
122         if( ref.getFactoryClassName().equals
123             (NamingManagerImpl.IIOPOBJECT_FACTORY) ) {
124             
125             Hashtable env = new Hashtable();
126             org.omg.CORBA.ORB JavaDoc orb = ORBManager.getORB();
127             env.put("java.naming.corba.orb", orb);
128             obj = javax.naming.spi.NamingManager.getObjectInstance
129             (obj, new CompositeName(name), null, env);
130         }
131         }
132         return obj;
133     } catch(RemoteException re) {
134         throw re;
135     } catch(Exception JavaDoc e) {
136         RemoteException re = new RemoteException("", e);
137             throw re;
138
139         }
140    }
141 }
142
Popular Tags