1 28 29 30 package org.objectweb.corba.runtime; 31 32 35 public class ORBFactoryImpl 36 extends org.omg.CORBA.LocalObject 37 implements ORBFactory 38 { 39 static final private String _class_name = "ORBFactoryImpl"; 41 private java.util.ArrayList _default_factories; 42 private java.util.ArrayList _default_initializers; 43 44 protected 46 ORBFactoryImpl() 47 { 48 _default_factories = new java.util.ArrayList (); 50 _default_initializers = new java.util.ArrayList (); 51 } 52 53 57 static public SystemFactory 58 create_factory() 59 { 60 return new ORBFactoryImpl(); 61 } 62 63 67 70 static private org.omg.CORBA.ORB 71 initializeORB(String [] params, java.util.Properties props) 72 { 73 return org.omg.CORBA.ORB.init(params, props); 74 75 } 76 77 static protected String 79 extractIOR(String name) 80 { 81 final String opname = "extractIOR"; 82 83 if (name.startsWith("IOR:")) { 85 return name; 86 } 87 88 java.io.InputStream in = null; 90 try { 91 in = new java.io.FileInputStream (name); 92 } catch (java.io.FileNotFoundException ex) { 93 } 95 96 if (in==null) { 97 java.net.URL url = null; 99 try { 100 url = new java.net.URL (name); 101 in = url.openStream(); 102 } catch (Exception ex) { 103 } 105 } 106 107 if (in==null) { 108 final String msg = "FAILED (invalid format: "+name+")"; 109 TheLogger.error(_class_name, opname, msg); 110 return null; 111 } 112 113 java.io.BufferedReader reader = null; 115 StringBuffer res = new StringBuffer (); 116 117 try { 118 reader = new java.io.BufferedReader (new java.io.InputStreamReader (in)); 119 while(reader.ready()) { 120 res.append(reader.readLine()); 121 } 122 123 reader.close(); 124 } catch(Exception ex) { 125 final String msg = "IGNORE (resource: "+name+")"; 126 TheLogger.error(_class_name, opname, msg, ex); 127 return null; 128 } 129 130 return res.toString(); 131 } 132 133 static private org.omg.CORBA.ORB 139 createORB(ORBConfiguration cfg) 140 { 141 final String opname = "createORB"; 142 143 org.omg.CORBA.ORB orb = null; 145 146 String [] orb_inits = cfg.orb_initializers(); 148 java.util.Properties props = System.getProperties(); 149 for (int i=0;i<orb_inits.length;i++) { 150 TheLogger.debug(_class_name, "createORB", "ORBInitializer registered: "+orb_inits[i]); 151 props.put("org.omg.PortableInterceptor.ORBInitializerClass."+orb_inits[i], ""); 152 } 153 154 StringifiedInitialReference[] strirefs = cfg.stringified_initial_references(); 156 String [] args = new String [strirefs.length*2]; 157 int j=0; 158 for (int i=0;i<strirefs.length;i++) { 159 args[j] = "-ORBInitRef"; 161 args[j+1] = strirefs[i].name+"="+strirefs[i].ref; 162 163 171 j=j+2; 172 } 173 174 178 String cline = ""; 179 for (int i=0;i<args.length;i++) { 180 cline = cline+" "+args[i]; 181 } 182 183 orb = initializeORB(args, props); 185 186 try { 188 org.omg.PortableServer.POA rootPOA = null; 189 org.omg.CORBA.Object obj = orb.resolve_initial_references("RootPOA"); 190 rootPOA = org.omg.PortableServer.POAHelper.narrow(obj); 191 rootPOA.the_POAManager().activate(); 192 } catch (Exception ex) { 193 TheLogger.error(_class_name, opname, "FAILED", ex); 194 return null; 195 } 196 197 Runtime.getMainThread().runORB(orb); 199 200 ValueFactory[] vfacts = cfg.value_factories(); 203 org.omg.CORBA_2_3.ORB orb23 = (org.omg.CORBA_2_3.ORB )orb; 204 org.omg.CORBA.portable.ValueFactory vfact = null; 205 206 for (int i=0;i<vfacts.length;i++) { 207 vfact = vfacts[i].value_factory(); 209 orb23.register_value_factory(vfacts[i].type_id(), vfact); 210 } 211 212 return orb; 213 } 214 215 private ORBConfiguration 216 addDefaults(ORBConfiguration cfg) 217 { 218 ValueFactory[] ivfacts = cfg.value_factories(); 220 ValueFactory[] nfacts = null; 221 if (_default_factories.size()==0) { 223 nfacts = ivfacts; 224 } 225 else { 226 java.util.ArrayList dvfacts = _default_factories; 227 java.util.ArrayList nvfacts = new java.util.ArrayList (dvfacts); 228 nvfacts.addAll(java.util.Arrays.asList(ivfacts)); 229 nfacts = (ValueFactory[])nvfacts.toArray(new ValueFactory[0]); 230 } 231 232 String [] inits = cfg.orb_initializers(); 234 String [] ninits = null; 235 if (_default_initializers.size()==0) { 237 ninits = inits; 238 } 239 else { 240 java.util.ArrayList vinits = _default_initializers; 241 java.util.ArrayList nvinits = new java.util.ArrayList (vinits); 242 nvinits.addAll(java.util.Arrays.asList(inits)); 243 ninits = (String [])nvinits.toArray(new String [0]); 244 } 245 246 return new ORBConfigurationImpl(ninits, 248 nfacts, 249 cfg.initial_references(), 250 cfg.stringified_initial_references()); 251 } 252 253 257 final public SystemComponent 258 create_system_component(SystemConfiguration cfg) 259 { 260 ORBConfiguration orbcfg = (ORBConfiguration)cfg; 261 262 ORBConfiguration neworbcfg = addDefaults(orbcfg); 264 265 org.omg.CORBA.ORB orb = createORB(neworbcfg); 267 268 ORBServiceImpl orbs = new ORBServiceImpl(orb); 270 271 orbs.system_configuration_complete(neworbcfg); 273 274 InitialReference[] refs = neworbcfg.initial_references(); 276 for (int i=0;i<refs.length;i++) { 277 orbs.register_initial_references(refs[i].name, refs[i].ref); 278 } 279 280 return orbs; 281 } 282 283 287 final public void 288 add_default_valuefactory(ValueFactory vfact) 289 { 290 _default_factories.add(vfact); 291 } 292 293 final public void 294 add_default_initializer(String orbinit) 295 { 296 _default_initializers.add(orbinit); 297 } 298 } 299 | Popular Tags |