1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 39 public class HomeSession2ContextImpl 40 extends org.omg.CORBA.LocalObject 41 implements org.omg.Components.Session2Context, org.coach.ECM.ECMContext 42 { 43 static private String _class_name = "Session2ContextImpl"; 45 private org.omg.Components.CCMHome _home_ref; 46 private ORBService _orb_service; 47 private ComponentPOAService _poa_service; 48 private ServicesSet _services_set; 49 private HomeLocalEventsImpl _events; 50 private HomeLocalReceptaclesImpl _receptacles; 51 private MonolithicIdCodec _idcodec; 52 53 public 55 HomeSession2ContextImpl() 56 { 57 _home_ref = null; 59 _orb_service = null; 60 _poa_service = null; 61 _services_set = null; 62 _events = null; 63 _receptacles = null; 64 _idcodec = null; 65 } 66 67 protected 69 HomeSession2ContextImpl(org.omg.Components.CCMHome href, 70 ORBService orbs, 71 ComponentPOAService poas, 72 ServicesSet sset, 73 HomeLocalEventsImpl levts, 74 HomeLocalReceptaclesImpl lrecs) 75 { 76 _home_ref = href; 78 _orb_service = orbs; 79 _poa_service = poas; 80 _services_set = sset; 81 _events = levts; 82 _receptacles = lrecs; 83 84 _idcodec = new MonolithicIdCodec(_orb_service); 86 } 87 88 92 private org.omg.PortableServer.Current 93 getPOACurrent() 94 { 95 org.omg.CORBA.Object curr = _orb_service.resolve_initial_references("POACurrent"); 97 return org.omg.PortableServer.CurrentHelper.narrow(curr); 98 } 99 100 104 final public HomeLocalEventsImpl 105 getLocalEvents() 106 { 107 return _events; 108 } 109 110 final public HomeLocalReceptaclesImpl 111 getLocalReceptacles() 112 { 113 return _receptacles; 114 } 115 116 120 final public org.omg.Components.CCMHome 121 get_CCM_home() 122 { 123 return _home_ref; 124 } 125 126 130 final public org.omg.Components.HomeRegistrationLocal 131 get_home_registration() 132 { 133 return null; 135 } 136 137 final public void 138 req_passivate() 139 throws org.omg.Components.IllegalState, 140 org.omg.Components.PolicyMismatch 141 { 142 final String opname = "req_passivate"; 143 try { 144 org.omg.PortableServer.Current curr = getPOACurrent(); 145 byte[] id = curr.get_object_id(); 146 _poa_service.passivate_component(id); 147 } catch (org.omg.PortableServer.CurrentPackage.NoContext ex) { 148 TheLogger.debug(_class_name, opname, "FAILED (no context, rethrown)", ex); 149 throw new org.omg.Components.IllegalState(); 150 } catch (org.objectweb.ccm.runtime.WrongPolicy ex) { 151 TheLogger.debug(_class_name, opname, "FAILED (wrong policy, rethrown)", ex); 152 throw new org.omg.Components.PolicyMismatch(); 153 } 154 } 155 156 final public org.omg.Components.LocalEvents 157 get_events() 158 { 159 return null; 161 } 162 163 final public org.omg.Components.LocalReceptacles 164 get_receptacles() 165 { 166 return null; 168 } 169 170 final public void 171 remove_component(org.omg.Components.CCMObject comp) 172 { 173 _poa_service.remove_component(comp); 174 } 175 176 final public void 177 register_valuefactory(String repid, org.omg.CORBA.portable.ValueFactory vfact) 178 { 179 ValueFactory fact = new ValueFactoryImpl(repid, vfact); 180 _orb_service.register_valuefactory(fact); 181 } 182 183 final public org.omg.CORBA.Any 184 create_any() 185 { 186 return _orb_service.create_any(); 187 } 188 189 193 final public org.omg.CORBA.Object 194 get_CCM_object() 195 throws org.omg.Components.IllegalState 196 { 197 try { 198 org.omg.PortableServer.Current curr = getPOACurrent(); 199 byte[] id = curr.get_object_id(); 200 org.omg.PortableServer.POA poa = curr.get_POA(); 201 202 return poa.id_to_reference(id); 203 } catch (org.omg.PortableServer.CurrentPackage.NoContext exc) { 204 throw new org.omg.Components.IllegalState(); 205 } catch (Exception ex) { 206 final String opname = "get_CCM_object"; 208 TheLogger.error(_class_name, opname, "FAILED", ex); 209 return null; 210 } 211 } 212 213 217 final public byte[] 218 get_object_id() 219 throws org.omg.Components.IllegalState 220 { 221 try { 222 return get_id_from_ref(get_CCM_object()); 223 } catch (org.omg.Components.BadComponentReference ex) { 224 final String opname = "get_object_id"; 226 TheLogger.error(_class_name, opname, "FAILED", ex); 227 return null; 228 } 229 } 230 231 final public org.omg.CORBA.Object 232 create_ref(String repid) 233 { 234 byte[] id = Double.toString(Math.random()).getBytes(); 236 237 return create_ref_with_id(id, repid); 238 } 239 240 final public org.omg.CORBA.Object 241 create_ref_with_id(byte[] id, String repid) 242 { 243 final String opname = "create_ref_with_id"; 244 245 byte[] home_id = null; 248 try { 249 home_id = getPOACurrent().get_object_id(); 250 } catch (org.omg.PortableServer.CurrentPackage.NoContext exc) { 251 TheLogger.error(_class_name, opname, "FAILED (no context)", exc); 253 } 254 255 MonolithicId mid = new MonolithicId(); 257 mid.home_id = home_id; 258 mid.component_id = id; 259 byte[] rid = _idcodec.encode(mid); 260 261 return _poa_service.create_ref_with_id(rid, repid); 263 } 264 265 final public byte[] 266 get_id_from_ref(org.omg.CORBA.Object ref) 267 throws org.omg.Components.BadComponentReference 268 { 269 final String opname = "get_id_from_ref"; 270 byte[] id = null; 271 try { 272 id = _poa_service.get_id_from_ref(ref); 273 } catch (org.objectweb.ccm.runtime.InvalidReference ex) { 274 TheLogger.debug(_class_name, opname, "FAILED (invalid ref, rethrown)", ex); 276 throw new org.omg.Components.BadComponentReference(); 277 } 278 279 MonolithicId mid = _idcodec.decode(id); 281 if (mid==null) { 282 TheLogger.debug(_class_name, opname, "FAILED (wrong format)"); 284 throw new org.omg.Components.BadComponentReference(); 285 } 286 287 return mid.component_id; 288 } 289 290 final public org.omg.CORBA.Object 291 create_with_new_target(String repid) 292 throws org.omg.Components.IllegalState 293 { 294 byte[] id = null; 296 try { 297 id = getPOACurrent().get_object_id(); 298 } catch (org.omg.PortableServer.CurrentPackage.NoContext exc) { 299 throw new org.omg.Components.IllegalState(); 300 } 301 302 return _poa_service.create_ref_with_id(id, repid); 304 } 305 306 310 final public org.omg.CORBA.Object 311 get_service_internal(String sid, String siid) 312 throws org.coach.ECM.UnknownService, 313 org.coach.ECM.UnknownServiceInternal 314 { 315 Service service = _services_set.find_service(sid); 317 if (service==null) { 318 throw new org.coach.ECM.UnknownService(); 319 } 320 321 org.omg.CORBA.Object internal = service.get_service_internal(siid); 323 if (internal==null) { 324 throw new org.coach.ECM.UnknownServiceInternal(); 325 } 326 327 return internal; 328 } 329 } 330 | Popular Tags |