1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class ContainerFactoryImpl 38 extends org.omg.CORBA.LocalObject 39 implements SystemFactory 40 { 41 static final private String _class_name = "ContainerFactoryImpl"; 43 44 protected 46 ContainerFactoryImpl() 47 { 48 } 49 50 54 static public SystemFactory 55 create_factory() 56 { 57 return new ContainerFactoryImpl(); 58 } 59 60 64 static private ServiceImpl[] 65 asServices(String [] uuids, ORBService orbs) 66 { 67 final String opname = "asServices"; 68 String msg = null; 69 70 if ((uuids==null) || (uuids.length==0)) { 72 return new ServiceImpl[0]; 73 } 74 75 java.util.ArrayList services = new java.util.ArrayList (); 78 79 org.omg.CORBA.Object obj = null; 82 org.coach.ECM.ExtComponentInstallation extci = null; 83 84 obj = orbs.resolve_initial_references("ExtComponentInstallation"); 85 extci = org.coach.ECM.ExtComponentInstallationHelper.narrow(obj); 86 87 ServiceImpl service = null; 88 org.coach.ECM.ServiceArchive sarchive = null; 89 for (int i=0;i<uuids.length;i++) { 90 sarchive = extci.get_service_archive(uuids[i]); 92 93 String serviceid = sarchive.service_id(); 98 service = new ServiceImpl(serviceid, uuids[i]); 99 100 org.coach.ECM.CORBAServiceRef rcsref = null; 102 103 try { 104 rcsref = sarchive.get_corbaservice_ref(); 105 106 CORBAServiceRef csref = new CORBAServiceRef(); 108 csref.stringified_initial_reference = orbs.object_to_string(rcsref.initial_reference); 109 csref.corba_type = rcsref.corba_type; 110 csref.orb_registration_name = rcsref.orb_registration_name; 111 112 service.setCorbaServiceRef(csref); 114 } catch (org.coach.ECM.NoCORBAServiceRefRequired ex) { 115 TheLogger.debug(_class_name, opname, "IGNORE", ex); 117 } 118 119 String codeloc = sarchive.code_location(); 121 TheClassLoader.addResource(codeloc); 122 123 msg = "Code location for service: "+uuids[i]+" is: "+codeloc; 124 TheLogger.debug(_class_name, opname, msg); 125 126 org.coach.ECA.ServiceInitializer serviceinit = null; 128 String entrypt = sarchive.code_entrypoint(); 129 130 msg = "Code entrypoint for service: "+uuids[i]+" is: "+entrypt; 131 TheLogger.debug(_class_name, opname, msg); 132 133 try { 134 serviceinit = (org.coach.ECA.ServiceInitializer)TheClassLoader.newInstance(entrypt); 135 } catch (ClassCastException ex) { 136 msg = "FAILED (not a service initializer)"; 139 TheLogger.debug(_class_name, opname, msg); 140 continue ; 142 } 143 144 service.setServiceInitializer(serviceinit); 146 147 services.add(service); 149 } 150 151 return (ServiceImpl[])services.toArray(new ServiceImpl[0]); 153 } 154 155 static private ServiceImpl[] 156 asServices(String [] uuids, String [] sids, String [] arch_locs, String [] entrypts, 157 String [] iref_regnames, String [] iref_iors) 158 { 159 final String opname = "asServices"; 160 String msg = null; 161 162 166 if ((uuids==null) || (uuids.length==0)) { 168 return new ServiceImpl[0]; 169 } 170 171 java.util.ArrayList services = new java.util.ArrayList (); 174 ServiceImpl service = null; 175 176 for (int i=0;i<uuids.length;i++) { 177 service = new ServiceImpl(sids[i], uuids[i]); 178 179 if ((iref_regnames[i]!=null) && (!iref_regnames.equals(""))) { 181 if ((iref_iors[i]==null) || (iref_iors[i].equals(""))) { 183 msg = "FAILED (no IOR for: "+iref_regnames[i]+")"; 184 TheLogger.debug(_class_name, opname, msg); 185 continue ; 187 } 188 189 CORBAServiceRef csref = new CORBAServiceRef(); 191 csref.corba_type = "unknown"; 192 csref.orb_registration_name = iref_regnames[i]; 193 csref.stringified_initial_reference = iref_iors[i]; 194 csref.initial_reference = null; 195 196 service.setCorbaServiceRef(csref); 198 } 199 200 String codeloc = arch_locs[i]; 202 TheClassLoader.addResource(codeloc); 203 204 org.coach.ECA.ServiceInitializer serviceinit = null; 206 String entrypt = entrypts[i]; 207 208 try { 209 serviceinit = (org.coach.ECA.ServiceInitializer)TheClassLoader.newInstance(entrypt); 210 } catch (ClassCastException ex) { 211 msg = "FAILED (not a service initializer)"; 214 TheLogger.debug(_class_name, opname, msg); 215 continue ; 217 } 218 219 service.setServiceInitializer(serviceinit); 221 222 services.add(service); 224 } 225 226 return (ServiceImpl[])services.toArray(new ServiceImpl[0]); 228 } 229 230 static private CORBAServiceRef[] 231 asDegenServices(org.coach.ECM.DegeneratedServiceRef[] dsrefs, 232 ORBService orbs) 233 { 234 if ((dsrefs==null) || (dsrefs.length==0)) { 236 return new CORBAServiceRef[0]; 237 } 238 239 CORBAServiceRef[] dservices = new CORBAServiceRef[dsrefs.length]; 240 241 for (int i=0;i<dsrefs.length;i++) { 242 dservices[i] = new CORBAServiceRef(); 244 dservices[i].corba_type = dsrefs[i].corba_type; 245 dservices[i].orb_registration_name = dsrefs[i].orb_registration_name; 246 dservices[i].stringified_initial_reference = dsrefs[i].initial_reference; 247 dservices[i].initial_reference = orbs.string_to_object(dsrefs[i].initial_reference); 248 } 249 250 return dservices; 251 } 252 253 static private CORBAServiceRef[] 254 asDegenServices(String [] iref_regnames, String [] iref_iors) 255 { 256 260 if ((iref_regnames==null) || (iref_regnames.length==0)) { 262 return new CORBAServiceRef[0]; 263 } 264 265 java.util.ArrayList dservices = new java.util.ArrayList (); 268 CORBAServiceRef dservice = null; 269 270 for (int i=0;i<iref_regnames.length;i++) { 271 if ((iref_iors[i]==null) || (iref_iors[i].equals(""))) { 273 final String opname = "asDegenServices"; 274 final String msg = "IGNORE (no IOR for: "+iref_regnames[i]+")"; 275 TheLogger.debug(_class_name, opname, msg); 276 continue ; 278 } 279 280 dservice = new CORBAServiceRef(); 282 dservice.corba_type = "unknown"; 283 dservice.orb_registration_name = iref_regnames[i]; 284 dservice.stringified_initial_reference = iref_iors[i]; 285 dservice.initial_reference = null; 286 dservices.add(dservice); 287 } 288 289 return (CORBAServiceRef[])dservices.toArray(new CORBAServiceRef[0]); 290 } 291 292 static private ORBService 293 createORBService(ServiceImpl[] services, 294 CORBAServiceRef[] dservices) 295 { 296 ServiceInitInfoImpl sii = new ServiceInitInfoImpl(services, dservices); 298 299 org.coach.ECA.ServiceInitializer sinit = null; 301 for (int i=0;i<services.length;i++) { 302 sinit = services[i].getServiceInitializer(); 303 sinit.pre_install(sii); 304 } 305 306 FactoryFinderService ffservice = ComponentRuntime.getFFService(); 308 309 SystemFactory orbfact = ffservice.find_service_factory(ORBService.SERVICE_ID); 311 312 ORBConfiguration orbcfg = sii.getORBConfiguration(); 314 315 ORBService orbservice = (ORBService)orbfact.create_system_component(orbcfg); 317 sii.setORBService(orbservice); 319 320 for (int i=0;i<services.length;i++) { 322 sinit = services[i].getServiceInitializer(); 323 sinit.post_install(sii); 324 } 325 326 return orbservice; 328 } 329 330 static private ComponentPOAService 332 createComponentPOAService(String poasid, 333 ORBService orbs, 334 ServicesSet sset) 335 { 336 FactoryFinderService ffservice = ComponentRuntime.getFFService(); 338 339 SystemFactory poafact = ffservice.find_service_factory(poasid); 341 342 ComponentPOAConfiguration poacfg = new ComponentPOAConfigurationImpl(null, null, orbs, sset); 344 345 ComponentPOAService poas = (ComponentPOAService)poafact.create_system_component(poacfg); 347 348 return poas; 350 } 351 352 356 static public ContainerService 362 asContainerService(String [] uuids, 363 org.coach.ECM.DegeneratedServiceRef[] dsrefs, 364 ORBService orbs, 365 String poasid) 366 { 367 ServiceImpl[] services = null; 368 CORBAServiceRef[] dservices = null; 369 ORBService orbservice = null; 370 ServicesSetImpl sset = null; 371 ComponentPOAService cpoaservice = null; 372 373 services = asServices(uuids, orbs); 375 376 dservices = asDegenServices(dsrefs, orbs); 378 379 orbservice = createORBService(services, dservices); 383 384 sset = new ServicesSetImpl(services, dservices, orbservice); 386 387 cpoaservice = createComponentPOAService(poasid, orbservice, sset); 389 390 ContainerService contservice = new ContainerServiceImpl(orbservice, cpoaservice, sset); 392 393 return contservice; 394 } 395 396 static public ContainerService 404 asContainerService(String [] uuids, 405 org.coach.ECM.DegeneratedServiceRef[] dsrefs, 406 StringifiedInitialReference[] sirefs, 407 String poasid) 408 { 409 ORBService orbservice = null; 411 412 FactoryFinderService ffservice = ComponentRuntime.getFFService(); 414 415 SystemFactory orbfact = ffservice.find_service_factory(ORBService.SERVICE_ID); 417 418 ORBConfiguration orbcfg = new ORBConfigurationImpl(null, null, null, sirefs); 421 422 orbservice = (ORBService)orbfact.create_system_component(orbcfg); 424 425 return asContainerService(uuids, dsrefs, orbservice, poasid); 427 } 428 429 437 441 final public SystemComponent 442 create_system_component(SystemConfiguration cfg) 443 { 444 final String opname = "create_system_component"; 445 final String msg = "operation not implemented"; 446 TheLogger.debug(_class_name, opname, msg); 447 throw new Error (msg); 448 } 449 } 450 | Popular Tags |