KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Hashtable JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.Properties JavaDoc;
28 import javax.naming.*;
29 import javax.naming.spi.InitialContextFactory JavaDoc;
30 import com.sun.enterprise.util.ORBManager;
31 import com.sun.appserv.naming.S1ASCtxFactory;
32
33 /**
34  * Implements the JNDI SPI InitialContextFactory interface used to create
35  * the InitialContext objects. It creates an instance of the serial context.
36  */

37
38 public class SerialInitContextFactory implements InitialContextFactory JavaDoc {
39
40
41     private Hashtable JavaDoc defaultEnv;
42
43     private S1ASCtxFactory s1asCtxFactory;
44
45     private String JavaDoc LBPOLICY =
46                  System.getProperty(S1ASCtxFactory.LOAD_BALANCING_PROPERTY);
47
48     private String JavaDoc ENDPOINTS =
49                  System.getProperty(S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY);
50     
51     private static boolean _initializeOrbManager = true;
52
53     static {
54         // setting ORB class and ORB singleton to SE values
55
//setting RMI-IIOP delegates to EE values
56
com.sun.enterprise.util.ORBManager.setORBSystemProperties();
57     }
58
59     /**
60      * Set to false if you do not want the OrbManager to be initialized.
61      * This is necessary in the NodeAgent since OrbManager initialization causes
62      * the NSS certificate database to be opended (and loaded) in which case
63      * it cannot be synchronized on Windows platforms (file in use).
64      */

65     public static void setInitializeOrbManager(boolean init) {
66         _initializeOrbManager = init;
67     }
68     
69     /**
70      * Default constructor. Creates an ORB if one is not already created.
71      */

72     public SerialInitContextFactory() {
73      
74         if ((LBPOLICY != null &&
75          !LBPOLICY.equals("")) ||
76         (ENDPOINTS != null &&
77          !ENDPOINTS.equals(""))) {
78         s1asCtxFactory = new S1ASCtxFactory();
79     } else {
80         // create a default env
81
defaultEnv = new Hashtable JavaDoc();
82
83         // Client side : removing the initialization of the ORB
84
// from the constructor since
85
// we need to propagate the host:port values that are
86
// set in the App client to ORB.init()
87
/* if (_initializeOrbManager) {
88             ORBManager.init(null, null);
89         defaultEnv.put("java.naming.corba.orb", ORBManager.getORB());
90         }*/

91     }
92     }
93
94     // Removing this constructor since it never gets called in the
95
// in the JNDI code path
96
// a call to new InitialContext(env) creates an instance of
97
// this class via the SerialInitContextFactory.class.newInstance()
98
// which will call the nullary constructor
99

100     /* public SerialInitContextFactory(Hashtable env) {
101
102     if ((LBPOLICY != null &&
103          !LBPOLICY.equals("")) ||
104         (ENDPOINTS != null &&
105          !ENDPOINTS.equals("")) ||
106         env.get(S1ASCtxFactory.LOAD_BALANCING_PROPERTY) != null ||
107         env.get(S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY) != null) {
108         s1asCtxFactory = new S1ASCtxFactory(env);
109     } else {
110         defaultEnv = env;
111         if (_initializeOrbManager) {
112             ORBManager.init(null, (Properties)env);
113         defaultEnv.put("java.naming.corba.orb", ORBManager.getORB());
114         System.out.println("SHEETAL : port# " + ORBManager.getORBInitialPort());
115         }
116     }
117     }
118 */

119     /**
120      * Create the InitialContext object.
121      */

122     public Context getInitialContext(Hashtable JavaDoc env) throws NamingException {
123         
124     if (_initializeOrbManager &&
125         (env == null ||
126          (env != null && env.get("java.naming.corba.orb") == null))) {
127
128         //javax.naming.InitialContext passes its own local Hashtable
129
//variable, so can't cast it to Properties.
130

131         Properties JavaDoc props = new Properties JavaDoc();
132         if (env != null) {
133             if (env.get("org.omg.CORBA.ORBInitialHost") != null &&
134             env.get("org.omg.CORBA.ORBInitialPort") != null) {
135             props.put("org.omg.CORBA.ORBInitialHost",
136                   (String JavaDoc) env.get("org.omg.CORBA.ORBInitialHost"));
137             props.put("org.omg.CORBA.ORBInitialPort",
138                   (String JavaDoc) env.get("org.omg.CORBA.ORBInitialPort"));
139         }
140         }
141         org.omg.CORBA.ORB JavaDoc orb = ORBManager.getORB(props) ;
142         if (defaultEnv != null)
143         defaultEnv.put("java.naming.corba.orb", orb ) ;
144         if (env != null)
145         env.put("java.naming.corba.orb", orb );
146     }
147     
148     if (SerialContext.getSticky() != null) {
149         Context ctx = SerialContext.getStickyContext();
150         return ctx;
151     }
152
153     if (s1asCtxFactory != null) {
154         return (s1asCtxFactory.getInitialContext(env));
155     }
156         
157     if (env != null) {
158             return new SerialContext(env);
159         } else {
160             return new SerialContext(defaultEnv);
161         }
162     }
163 }
164
Popular Tags