1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 39 public class HomeSegmentedSession2ContextImpl 40 extends org.omg.CORBA.LocalObject 41 implements org.omg.Components.SegmentedSession2Context, org.coach.ECM.ECMContext 42 { 43 static private String _class_name = "SegmentedSession2ContextImpl"; 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 SegmentedIdCodec _idcodec; 52 53 protected 55 HomeSegmentedSession2ContextImpl() 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 HomeSegmentedSession2ContextImpl(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 SegmentedIdCodec(_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 org.omg.Components.ComponentId 218 get_component_id() 219 throws org.omg.Components.IllegalState 220 { 221 try { 222 return get_cid_from_ref(get_CCM_object()); 223 } catch (org.omg.Components.BadComponentReference ex) { 224 final String opname = "get_component_id"; 226 TheLogger.error(_class_name, opname, "FAILED", ex); 227 return null; 228 } 229 } 230 231 final public org.omg.Components.ComponentId 232 create_main_segment(org.omg.Components.SegmentDescr[] descrs) 233 { 234 return new ComponentIdImpl(org.omg.Components.COMPONENT_FACET.value, 235 org.omg.Components.COMPONENT_ID.value, 236 descrs); 237 } 238 239 final public org.omg.CORBA.Object 240 create_ref_from_cid(String repid, 241 org.omg.Components.ComponentId cid) 242 { 243 final String opname = "create_ref_from_cid"; 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 SegmentedId sid = new SegmentedId(); 257 sid.home_id = home_id; 258 sid.facet_id = cid.get_facet_id(); 259 sid.segment_id = cid.get_segment_id(); 260 sid.segment_descrs = cid.get_segment_descrs(); 261 byte[] rid = _idcodec.encode(sid); 262 263 return _poa_service.create_ref_with_id(rid, repid); 265 } 266 267 final public org.omg.Components.ComponentId 268 get_cid_from_ref(org.omg.CORBA.Object ref) 269 throws org.omg.Components.BadComponentReference 270 { 271 final String opname = "get_cid_from_ref"; 272 byte[] id = null; 273 try { 274 id = _poa_service.get_id_from_ref(ref); 275 } catch (org.objectweb.ccm.runtime.InvalidReference ex) { 276 TheLogger.debug(_class_name, opname, "FAILED (invalid ref, rethrown)", ex); 278 throw new org.omg.Components.BadComponentReference(); 279 } 280 281 SegmentedId sid = _idcodec.decode(id); 283 if (sid==null) { 284 TheLogger.debug(_class_name, opname, "FAILED (wrong format)"); 286 throw new org.omg.Components.BadComponentReference(); 287 } 288 289 return new ComponentIdImpl(sid.facet_id, sid.segment_id, sid.segment_descrs); 291 } 292 293 297 final public org.omg.CORBA.Object 298 get_service_internal(String sid, String siid) 299 throws org.coach.ECM.UnknownService, 300 org.coach.ECM.UnknownServiceInternal 301 { 302 Service service = _services_set.find_service(sid); 304 if (service==null) { 305 throw new org.coach.ECM.UnknownService(); 306 } 307 308 org.omg.CORBA.Object internal = service.get_service_internal(siid); 310 if (internal==null) { 311 throw new org.coach.ECM.UnknownServiceInternal(); 312 } 313 314 return internal; 315 } 316 } 317 | Popular Tags |