1 23 package com.sun.enterprise.naming; 24 25 import java.util.Hashtable ; 26 import java.util.Enumeration ; 27 import java.util.Properties ; 28 import javax.naming.*; 29 import javax.naming.spi.InitialContextFactory ; 30 import com.sun.enterprise.util.ORBManager; 31 import com.sun.appserv.naming.S1ASCtxFactory; 32 33 37 38 public class SerialInitContextFactory implements InitialContextFactory { 39 40 41 private Hashtable defaultEnv; 42 43 private S1ASCtxFactory s1asCtxFactory; 44 45 private String LBPOLICY = 46 System.getProperty(S1ASCtxFactory.LOAD_BALANCING_PROPERTY); 47 48 private String ENDPOINTS = 49 System.getProperty(S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY); 50 51 private static boolean _initializeOrbManager = true; 52 53 static { 54 com.sun.enterprise.util.ORBManager.setORBSystemProperties(); 57 } 58 59 65 public static void setInitializeOrbManager(boolean init) { 66 _initializeOrbManager = init; 67 } 68 69 72 public SerialInitContextFactory() { 73 74 if ((LBPOLICY != null && 75 !LBPOLICY.equals("")) || 76 (ENDPOINTS != null && 77 !ENDPOINTS.equals(""))) { 78 s1asCtxFactory = new S1ASCtxFactory(); 79 } else { 80 defaultEnv = new Hashtable (); 82 83 91 } 92 } 93 94 100 119 122 public Context getInitialContext(Hashtable env) throws NamingException { 123 124 if (_initializeOrbManager && 125 (env == null || 126 (env != null && env.get("java.naming.corba.orb") == null))) { 127 128 131 Properties props = new Properties (); 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 ) env.get("org.omg.CORBA.ORBInitialHost")); 137 props.put("org.omg.CORBA.ORBInitialPort", 138 (String ) env.get("org.omg.CORBA.ORBInitialPort")); 139 } 140 } 141 org.omg.CORBA.ORB 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 |