1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class ComponentPOAServiceImpl 38 extends org.omg.CORBA.LocalObject 39 implements ComponentPOAService 40 { 41 static final private String _class_name = "ComponentPOAServiceImpl"; 43 static final private String _service_id = ComponentPOAService.SERVICE_ID; 44 45 private ORBService _orb_service; 46 private ServicesSet _services_set; 47 private org.omg.PortableServer.POA _home_poa; 48 private org.omg.PortableServer.POA _component_poa; 49 private ComponentServantActivatorImpl _servant_activator; 50 51 public 53 ComponentPOAServiceImpl() 54 { 55 _orb_service = null; 57 _services_set = null; 58 _home_poa = null; 59 _component_poa = null; 60 _servant_activator = null; 61 } 62 63 67 static public CallInterceptorFactory 68 repid2Factory(String repid) 69 { 70 final String opname = "repid2Factory"; 72 73 76 int idx1 = repid.indexOf(':'); 77 int idx2 = repid.lastIndexOf(':'); 78 String body = repid.substring(idx1+1, idx2); 81 String entrypt = null; 82 83 idx1 = body.indexOf('.'); 84 if (idx1==-1) { 85 entrypt = body.replace('/', '.'); 87 } else { 88 String res = ""; 89 idx2 = 0; 90 while (idx1!=-1) { 91 res = body.substring(idx2, idx1+1) + res; 92 idx2 = idx1+1; 93 idx1 = body.indexOf('.', idx2); 94 } 95 96 int idx3 = body.indexOf('/', idx2); 97 res = body.substring(idx2, idx3) + '.' + res; 98 entrypt = res+body.substring(idx3+1).replace('/', '.'); 99 } 100 101 entrypt = entrypt+"_IFact.create_factory"; 102 103 Object obj = TheClassLoader.newInstance(entrypt); 104 if (obj==null) { 105 final String msg = "IGNORE (interceptor factory can not be created with entrypoint: "+entrypt+")"; 107 TheLogger.debug(_class_name, opname, msg); 108 return null; 109 } 110 111 if (!(obj instanceof CallInterceptorFactory)) { 113 final String msg = "IGNORE (object is not an interceptor factory: "+obj.getClass()+")"; 115 TheLogger.debug(_class_name, opname, msg); 116 return null; 117 } 118 119 return (CallInterceptorFactory)obj; 120 } 121 122 126 final protected void 127 setHomePOA(org.omg.PortableServer.POA poa) 128 { 129 _home_poa = poa; 130 } 131 132 final protected void 133 setComponentPOA(org.omg.PortableServer.POA poa) 134 { 135 _component_poa = poa; 136 137 try { 139 _servant_activator = (ComponentServantActivatorImpl)poa.get_servant_manager(); 140 } catch (Exception ex) { 141 final String opname = "setComponentPOA"; 143 TheLogger.error(_class_name, opname, "FAILED", ex); 144 } 145 } 146 147 151 final public void 152 system_configuration_complete(SystemConfiguration cfg) 153 { 154 ComponentPOAConfiguration poacfg = (ComponentPOAConfiguration)cfg; 155 156 _orb_service = poacfg.orb_service(); 158 _services_set = poacfg.services_set(); 159 160 _servant_activator.setConfiguration(_orb_service, _services_set); 162 } 163 164 final public void 165 destroy() 166 { 167 _component_poa.destroy(true, true); 172 _home_poa.destroy(true, true); 173 } 174 175 179 final public String 180 service_id() 181 { 182 return _service_id; 183 } 184 185 189 final public org.omg.Components.CCMHome 190 activate_home(String uuid) 191 { 192 byte[] id = Double.toString(Math.random()).getBytes(); 194 195 return activate_home_with_id(id, uuid); 196 } 197 198 final public org.omg.Components.CCMHome 199 activate_home_with_id(byte[] id, String uuid) 200 { 201 final String opname = "activate_home_with_id"; 202 203 org.omg.CORBA.Object obj = null; 206 org.coach.ECM.ExtComponentInstallation extci = null; 207 org.coach.ECM.ComponentArchive carch = null; 208 209 obj = _orb_service.resolve_initial_references("ExtComponentInstallation"); 210 extci = org.coach.ECM.ExtComponentInstallationHelper.narrow(obj); 211 carch = extci.get_component_archive(uuid); 212 213 org.coach.ECM.ValuetypeFactoryDependency[] vfes = carch.get_valuetype_factories(); 216 org.coach.ECM.ValuetypeFactoryDependency vfe = null; 217 for (int i=0;i<vfes.length;i++) { 218 vfe = vfes[i]; 219 220 TheClassLoader.addResource(vfe.code_location); 222 223 Object ovf = TheClassLoader.newInstance(vfe.factory_entrypoint); 225 org.omg.CORBA.portable.ValueFactory vf = (org.omg.CORBA.portable.ValueFactory )obj; 226 227 ValueFactory fact = new ValueFactoryImpl(vfe.repid, vf); 229 _orb_service.register_valuefactory(fact); 230 } 231 232 233 TheClassLoader.addResource(carch.code_location()); 235 236 org.omg.Components.HomeExecutor hexe = null; 239 Object jobj = TheClassLoader.newInstance(carch.code_entrypoint()); 240 241 if (jobj==null) { 243 final String msg = "FAILED (invalid entrypoint)"; 245 TheLogger.error(_class_name, opname, msg); 246 } 247 248 if (jobj instanceof org.omg.Components.HomeExecutor) { 249 hexe = (org.omg.Components.HomeExecutor)jobj; 250 } else { 251 final String msg = "FAILED (not a Components::HomeExecutor)"; 253 TheLogger.error(_class_name, opname, msg); 254 } 255 256 if (hexe instanceof org.omg.Components.Servant) { 260 try { 261 org.omg.Components.Servant servant = (org.omg.Components.Servant)hexe; 262 _home_poa.activate_object_with_id(id, servant.as_native_servant()); 263 } catch (Exception ex) { 264 TheLogger.error(_class_name, opname, "FAILED", ex); 266 return null; 267 } 268 } else { 269 TheLogger.error(_class_name, opname, "FAILED (not a CCM servant)"); 270 return null; 271 } 272 273 String hrepid = carch.home_repid(); 275 org.omg.CORBA.Object ref = _home_poa.create_reference_with_id(id, hrepid); 276 org.omg.Components.CCMHome href = org.omg.Components.CCMHomeHelper.narrow(ref); 277 278 CallInterceptorFactory ifact = repid2Factory(hrepid); 282 if (ifact!=null) { 283 ifact.setContextInfo(_orb_service, _services_set, uuid); 284 } 285 286 HomeLocalEventsImpl levts = new HomeLocalEventsImpl(ifact); 287 HomeLocalReceptaclesImpl lrecs = new HomeLocalReceptaclesImpl(ifact); 288 org.omg.Components.CCM2Context ctx = new HomeSession2ContextImpl(href, _orb_service, this, _services_set, levts, lrecs); 290 291 hexe.set_ccm_context(ctx); 293 294 _servant_activator.registerHome(id, uuid, hexe, ifact, ctx); 296 297 return href; 298 } 299 300 final public void 301 passivate_home(org.omg.Components.CCMHome href) 302 { 303 try { 304 byte[] id = _home_poa.reference_to_id(href); 306 _home_poa.deactivate_object(id); 307 } catch (Exception ex) { 308 final String opname = "passivate_component"; 310 TheLogger.debug(_class_name, opname, "IGNORE", ex); 311 } 312 } 313 314 318 final public org.omg.CORBA.Object 319 create_ref_with_id(byte[] id, String repid) 320 { 321 _servant_activator.registerComponent(id); 323 324 return _component_poa.create_reference_with_id(id, repid); 326 } 327 328 final public byte[] 329 get_id_from_ref(org.omg.CORBA.Object ref) 330 throws InvalidReference 331 { 332 try { 333 return _component_poa.reference_to_id(ref); 334 } catch (Exception ex) { 335 final String opname = "get_id_from_ref"; 336 TheLogger.debug(_class_name, opname, "FAILED (rethrown)", ex); 337 throw new InvalidReference(); 338 } 339 } 340 341 final public void 342 passivate_component(byte[] id) 343 { 344 final String opname = "passivate_component"; 345 try { 346 _component_poa.deactivate_object(id); 348 } catch (Exception ex) { 349 TheLogger.debug(_class_name, opname, "IGNORE", ex); 351 } 352 } 353 354 final public void 355 remove_component(org.omg.Components.CCMObject comp) 356 { 357 final String opname = "remove_component"; 358 try { 359 byte[] id = _component_poa.reference_to_id(comp); 361 362 _servant_activator.unregisterComponent(id); 364 365 _component_poa.deactivate_object(id); 367 } catch (Exception ex) { 368 TheLogger.debug(_class_name, opname, "IGNORE", ex); 370 } 371 } 372 } 373 | Popular Tags |