1 26 27 package org.objectweb.openccm.Containers; 28 29 36 37 public class ServantLocatorImpl 38 extends org.objectweb.openccm.corba.ServantLocatorBase 39 { 40 46 49 protected org.omg.PortableServer.POA poa_; 50 51 54 protected java.util.Random random_; 55 56 59 protected org.objectweb.ccm.util.WeakTable oid2cs_; 60 61 64 protected org.objectweb.ccm.util.WeakTable oid2uid_; 65 66 72 76 public 77 ServantLocatorImpl() 78 { 79 poa_ = null; 80 oid2cs_ = new org.objectweb.ccm.util.WeakTable(); 81 oid2uid_ = new org.objectweb.ccm.util.WeakTable(); 82 random_ = new java.util.Random (java.lang.System.currentTimeMillis()); 83 } 84 85 91 94 protected org.omg.CORBA.Object 95 createReference(HomeServant home_servant, 96 org.omg.Components.EnterpriseComponent instance, 97 org.omg.Components.PrimaryKeyBase key) 98 { 99 HomeExecutorBase home = home_servant.the_home_executor(); 100 java.lang.String comp_uid = home._the_component_uid(); 101 java.lang.String oid = null; 102 org.omg.CORBA.Object result = null; 103 104 java.math.BigInteger big = new java.math.BigInteger (128, random_); 108 109 oid = new java.lang.String (big.toByteArray()); 111 112 try 113 { 114 result = poa_.create_reference_with_id(big.toByteArray(), comp_uid); 115 } catch(Exception ex) { 117 ex.printStackTrace(System.err); 118 } 119 120 ComponentServantImpl comp_servant = new ComponentServantImpl(this, home_servant, instance, key); 121 122 oid2uid_.put(oid, comp_uid); 123 oid2cs_.put(oid, comp_servant); 124 125 comp_servant.setComponentRef(org.omg.Components.CCMObjectHelper.narrow(result)); 134 135 return result; 136 } 137 138 144 150 public org.omg.PortableServer.Servant 151 preinvoke(byte[] oid, 152 org.omg.PortableServer.POA adapter, 153 java.lang.String operation, 154 org.omg.PortableServer.ServantLocatorPackage.CookieHolder the_cookie) 155 throws org.omg.PortableServer.ForwardRequest 156 { 157 java.lang.String soid = new java.lang.String (oid); 158 java.lang.String uid = (java.lang.String )oid2uid_.get(soid); 159 ComponentServant servant = (ComponentServant)oid2cs_.get(soid); 160 161 if (servant == null) return null; 162 163 if (servant.activation_context().state()==ActivationContext.DEACTIVATED) 164 servant.activation_context().state(ActivationContext.ACTIVATED); 165 166 return (org.omg.PortableServer.Servant )servant.get_native_interface(uid); 167 } 168 169 175 public void 176 postinvoke(byte[] oid, 177 org.omg.PortableServer.POA adapter, 178 java.lang.String operation, 179 java.lang.Object the_cookie, 180 org.omg.PortableServer.Servant the_servant) 181 { 182 java.lang.String soid = new java.lang.String (oid); 183 java.lang.String uid = (java.lang.String )oid2uid_.get(soid); 184 ComponentServant servant = (ComponentServant)oid2cs_.get(soid); 185 186 if (servant != null) { 187 188 servant.release_native_interface((Interceptor)the_servant); 189 } 190 } 191 192 198 201 public void 202 setPOA(org.omg.PortableServer.POA poa) 203 { 204 poa_ = poa; 205 } 206 207 210 public org.omg.CORBA.Object 211 createPortReference(ComponentServant servant, 212 java.lang.String port_uid) 213 { 214 HomeExecutorBase home = servant.the_home_servant().the_home_executor(); 215 org.omg.CORBA.Object result = null; 216 217 java.math.BigInteger big = new java.math.BigInteger (128, random_); 221 java.lang.String oid = ""; 222 223 big = new java.math.BigInteger (128, random_); 225 oid = new java.lang.String (big.toByteArray()); 226 oid2uid_.put(oid, port_uid); 227 oid2cs_.put(oid, servant); 228 229 try 230 { 231 result = poa_.create_reference_with_id(big.toByteArray(), home._get_port_type_uid(port_uid)); 232 } catch(Exception ex) { 234 ex.printStackTrace(System.err); 235 } 236 237 return result; 238 } 239 240 243 public org.omg.CORBA.Object 244 createReference(HomeServant home_servant) 245 { 246 return createReference(home_servant, null, null); 247 } 248 249 252 public org.omg.CORBA.Object 253 createReference(HomeServant home_servant, 254 org.omg.Components.EnterpriseComponent instance) 255 { 256 return createReference(home_servant, instance, null); 257 } 258 259 262 public org.omg.CORBA.Object 263 findReference(HomeServant home_servant, 264 org.omg.Components.EnterpriseComponent instance) 265 { 266 ComponentServantImpl[] cs = null; 267 cs = (ComponentServantImpl[])oid2cs_.values().toArray(new ComponentServantImpl[0]); 268 org.omg.CORBA.Object result = null; 269 for (int i=0;i<cs.length;i++) 270 { 271 result = cs[i].getReferenceWithInstance(instance); 272 if (result!=null) 273 break; 274 } 275 276 if (result==null) 277 result = createReference(home_servant, instance); 278 279 return result; 280 } 281 282 285 public org.omg.CORBA.Object 286 createReference(HomeServant home_servant, 287 org.omg.Components.PrimaryKeyBase key) 288 { 289 return createReference(home_servant, null, key); 290 } 291 292 295 public void 296 removeReference(org.omg.CORBA.Object obj) 297 throws org.omg.Components.RemoveFailure 298 { 299 try { 300 String oid = new String (poa_.reference_to_id(obj)); 301 oid2uid_.remove(oid); 302 oid2cs_.remove(oid); 303 } catch (org.omg.PortableServer.POAPackage.WrongAdapter ex) { 304 throw new org.omg.Components.RemoveFailure(); 305 } catch (org.omg.PortableServer.POAPackage.WrongPolicy ex) { 306 throw new org.omg.Components.RemoveFailure(); 307 } 308 } 309 } 310 | Popular Tags |