KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > client > naming > CoadunationInitialContextFactory


1 /*
2  * CoadunationClient: The client libraries for Coadunation. (RMI/CORBA)
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * CoadunationInitialContextFactory.java
20  *
21  * This Context Factory is responsible for initializing the context of for the
22  * client side. So that RMI connection can be made to Coadunation.
23  *
24  * Revision: $ID
25  */

26
27 package com.rift.coad.client.naming;
28
29 // java imports
30
import java.util.Hashtable JavaDoc;
31 import java.util.Properties JavaDoc;
32 import javax.naming.Context JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.naming.spi.InitialContextFactory JavaDoc;
35 import org.omg.CORBA.ORB JavaDoc;
36
37 // Coadunation imports
38
import com.rift.coad.client.interceptor.iiop.ClientInterceptorIntializer;
39 import com.rift.coad.lib.interceptor.credentials.Login;
40
41 /**
42  * This Context Factory is responsible for initializing the context of for the
43  * client side. So that RMI connection can be made to Coadunation.
44  *
45  * @author Brett Chaldecott
46  */

47 public class CoadunationInitialContextFactory implements InitialContextFactory JavaDoc {
48     
49     // class conconstants
50
public final static String JavaDoc USERNAME = "com.rift.coad.username";
51     public final static String JavaDoc PASSWORD = "com.rift.coad.password";
52     
53     // the static reference to the user login object.
54
public static ThreadLocal JavaDoc userLogin = new ThreadLocal JavaDoc();
55     
56     /**
57      *
58      * Creates a new instance of CoadunationInitialContextFactory
59      */

60     public CoadunationInitialContextFactory() {
61     }
62     
63     /**
64      * This method is responsible for instanciating the initial context using
65      * the supplied environment.
66      *
67      * @return The context to return.
68      * @param environment The environment to use to instanciate the url context.
69      * @exception NamingException
70      */

71     public Context JavaDoc getInitialContext(Hashtable JavaDoc environment) throws
72             NamingException JavaDoc {
73         if (environment.containsKey(USERNAME) &&
74                 environment.containsKey(PASSWORD)) {
75             userLogin.set(new Login((String JavaDoc)environment.get(USERNAME),
76                     (String JavaDoc)environment.get(PASSWORD)));
77         }
78         else {
79             userLogin.set(null);
80         }
81             
82         // setup the orb
83
System.setProperty("org.omg.PortableInterceptor.ORBInitializerClass." +
84                 ClientInterceptorIntializer.class.getName(),"");
85         Properties JavaDoc properties = new Properties JavaDoc();
86         properties.setProperty("org.omg.CORBA.ORBClass",
87                     "org.jacorb.orb.ORB");
88         properties.setProperty("org.omg.CORBA.ORBSingletonClass",
89                     "org.jacorb.orb.ORBSingleton");
90         ORB JavaDoc orb = ORB.init(new String JavaDoc[0],properties);
91         
92         // add the extra environmental variables
93
environment.put(Context.INITIAL_CONTEXT_FACTORY,
94                         "com.sun.jndi.cosnaming.CNCtxFactory");
95         environment.put("java.naming.corba.orb",orb);
96         
97         if (environment.containsKey(Context.PROVIDER_URL)) {
98             String JavaDoc url = "corbaloc:iiop:" +
99                     (String JavaDoc)environment.get(Context.PROVIDER_URL) +
100                     "/StandardNS/NameServer-POA/_root";
101             environment.put(Context.PROVIDER_URL,url);
102         }
103         
104         // instanciate the context
105
return new CoadunationContext(orb,environment);
106     }
107 }
108
Popular Tags