KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > jndi > spi > IIOPContextWrapperFactory


1 /**
2  * Copyright (C) 2002,2005 - INRIA (www.inria.fr)
3  *
4  * CAROL: Common Architecture for RMI ObjectWeb Layer
5  *
6  * This library is developed inside the ObjectWeb Consortium,
7  * http://www.objectweb.org
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  *
24  * --------------------------------------------------------------------------
25  * $Id: IIOPContextWrapperFactory.java,v 1.5 2005/03/14 10:48:17 benoitf Exp $
26  * --------------------------------------------------------------------------
27  */

28 package org.objectweb.carol.jndi.spi;
29
30 import java.util.Hashtable JavaDoc;
31
32 import javax.naming.NamingException JavaDoc;
33 import javax.naming.spi.InitialContextFactory JavaDoc;
34
35 import org.omg.CORBA.ORB JavaDoc;
36 import org.omg.PortableServer.POA JavaDoc;
37
38 import org.objectweb.carol.jndi.ns.IIOPCosNaming;
39 import org.objectweb.carol.rmi.exception.NamingExceptionHelper;
40 import org.objectweb.carol.util.configuration.CarolDefaultValues;
41
42 /**
43  * Class <code> IIOPRemoteReferenceContextWrapperFactory </code> is the CAROL
44  * JNDI Context factory. This context factory build the iiop context for
45  * reference wrapping to/from a remote object
46  * @author Guillaume Riviere
47  * @author Florent Benoit (refactoring)
48  * @see javax.naming.spi.InitialContextFactory
49  */

50 public class IIOPContextWrapperFactory extends AbsInitialContextFactory implements InitialContextFactory JavaDoc {
51
52     /**
53      * Referencing factory
54      */

55     public static final String JavaDoc REFERENCING_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory";
56
57     /**
58      * @return the real factory of this wrapper
59      */

60     protected String JavaDoc getReferencingFactory() {
61         return REFERENCING_FACTORY;
62     }
63
64     /**
65      * @return class of the wrapper (to be instantiated + pool).
66      */

67     protected Class JavaDoc getWrapperClass() {
68         return IIOPContext.class;
69     }
70
71     /**
72      * Unique instance of the ORB running in the JVM
73      */

74     private static ORB JavaDoc orb = null;
75
76     /**
77      * The orb was started or not ?
78      */

79     private static boolean orbStarted = false;
80
81     /**
82      * Root POA used by Carol
83      */

84     private static POA JavaDoc rootPOA = null;
85
86     /**
87      * For some protocols, there are some initialization stuff to do
88      * @throws NamingException if there is an exception
89      */

90     protected void init() throws NamingException JavaDoc {
91         // Initialize ORB if null
92
if (orb == null) {
93             orb = IIOPCosNaming.getOrb();
94         }
95
96         if (!orbStarted && System.getProperty(CarolDefaultValues.SERVER_MODE, "false").equalsIgnoreCase("true")) {
97             // Start ORB if it was not run and if we are in server mode
98
new Thread JavaDoc(new Runnable JavaDoc() {
99
100                 public void run() {
101                     orb.run();
102                 }
103             }).start();
104             orbStarted = true;
105         }
106
107         // activate root POA
108
if (rootPOA == null) {
109             try {
110                 rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
111                 rootPOA.the_POAManager().activate();
112             } catch (Exception JavaDoc e) {
113                 throw NamingExceptionHelper.create("Cannot get a single instance of rootPOA : " + e.getMessage(), e);
114             }
115         }
116
117     }
118
119     /**
120      * Store orb in the environment
121      * @param environment hashtable containing the environment
122      */

123     protected void addExtraConfInEnvironment(Hashtable JavaDoc environment) {
124         environment.put("java.naming.corba.orb", orb);
125     }
126 }
Popular Tags