1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 import org.omg.PortableServer.THREAD_POLICY_ID ; 36 import org.omg.PortableServer.ThreadPolicy ; 37 import org.omg.PortableServer.ThreadPolicyValue ; 38 import org.omg.PortableServer.ThreadPolicyValueHelper; 39 import org.omg.PortableServer.LIFESPAN_POLICY_ID ; 40 import org.omg.PortableServer.LifespanPolicy ; 41 import org.omg.PortableServer.LifespanPolicyValue ; 42 import org.omg.PortableServer.LifespanPolicyValueHelper; 43 import org.omg.PortableServer.ID_UNIQUENESS_POLICY_ID ; 44 import org.omg.PortableServer.IdUniquenessPolicy ; 45 import org.omg.PortableServer.IdUniquenessPolicyValue ; 46 import org.omg.PortableServer.IdUniquenessPolicyValueHelper; 47 import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID ; 48 import org.omg.PortableServer.IdAssignmentPolicy ; 49 import org.omg.PortableServer.IdAssignmentPolicyValue ; 50 import org.omg.PortableServer.IdAssignmentPolicyValueHelper; 51 import org.omg.PortableServer.IMPLICIT_ACTIVATION_POLICY_ID ; 52 import org.omg.PortableServer.ImplicitActivationPolicy ; 53 import org.omg.PortableServer.ImplicitActivationPolicyValue ; 54 import org.omg.PortableServer.ImplicitActivationPolicyValueHelper; 55 import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID ; 56 import org.omg.PortableServer.ServantRetentionPolicy ; 57 import org.omg.PortableServer.ServantRetentionPolicyValue ; 58 import org.omg.PortableServer.ServantRetentionPolicyValueHelper; 59 import org.omg.PortableServer.REQUEST_PROCESSING_POLICY_ID ; 60 import org.omg.PortableServer.RequestProcessingPolicy ; 61 import org.omg.PortableServer.RequestProcessingPolicyValue ; 62 import org.omg.PortableServer.RequestProcessingPolicyValueHelper; 63 64 67 public class ComponentPOAFactoryImpl 68 extends org.omg.CORBA.LocalObject 69 implements SystemFactory 70 { 71 static final private String _class_name = "ComponentPOAFactoryImpl"; 73 74 protected 76 ComponentPOAFactoryImpl() 77 { 78 } 79 80 84 static public SystemFactory 85 create_factory() 86 { 87 return new ComponentPOAFactoryImpl(); 88 } 89 90 94 static private org.omg.CORBA.Policy [] 95 checkPolicies(org.omg.CORBA.Policy [] pols, 96 ORBService orbs) 97 { 98 String opname = "checkPolicies"; 99 100 java.util.Vector rpols = new java.util.Vector (); 111 112 boolean threadingpol_set = false; 113 boolean lifespanpol_set = false; 114 boolean iduniqpol_set = false; 115 boolean idassignpol_set = false; 116 boolean servantretpol_set = false; 117 boolean reqprocpol_set = false; 118 boolean implactpol_set = false; 119 for (int i=0;i<pols.length;i++) { 120 if (pols[i].policy_type()==THREAD_POLICY_ID.value) { 121 rpols.add(pols[i]); 123 threadingpol_set = true; 124 } 125 else if (pols[i].policy_type()==LIFESPAN_POLICY_ID.value) { 126 rpols.add(pols[i]); 128 lifespanpol_set = true; 129 } 130 else if (pols[i].policy_type()==ID_UNIQUENESS_POLICY_ID.value) { 131 rpols.add(pols[i]); 133 iduniqpol_set = true; 134 } 135 else if (pols[i].policy_type()==ID_ASSIGNMENT_POLICY_ID.value) { 136 IdAssignmentPolicy idassignpol = (IdAssignmentPolicy )pols[i]; 138 if (idassignpol.value()!=IdAssignmentPolicyValue.USER_ID) { 139 String msg = "IGNORE (was expecting USER_ID)"; 141 TheLogger.debug(_class_name, opname, msg); 142 } else { 143 rpols.add(pols[i]); 144 idassignpol_set = true; 145 } 146 } 147 else if (pols[i].policy_type()==IMPLICIT_ACTIVATION_POLICY_ID.value) { 148 ImplicitActivationPolicy implactpol = (ImplicitActivationPolicy )pols[i]; 150 if (implactpol.value()!=ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION) { 151 String msg = "IGNORE (was expecting NO_IMPLICIT_ACTIVATION)"; 153 TheLogger.debug(_class_name, opname, msg); 154 } else { 155 rpols.add(pols[i]); 156 implactpol_set = true; 157 } 158 } 159 else if (pols[i].policy_type()==SERVANT_RETENTION_POLICY_ID.value) { 160 ServantRetentionPolicy servantretpol = (ServantRetentionPolicy )pols[i]; 162 if (servantretpol.value()!=ServantRetentionPolicyValue.RETAIN) { 163 String msg = "IGNORE (was expecting RETAIN)"; 165 TheLogger.debug(_class_name, opname, msg); 166 } else { 167 rpols.add(pols[i]); 168 servantretpol_set = true; 169 } 170 } 171 else if (pols[i].policy_type()==REQUEST_PROCESSING_POLICY_ID.value) { 172 RequestProcessingPolicy reqprocpol = (RequestProcessingPolicy )pols[i]; 174 if (reqprocpol.value()!=RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY) { 175 String msg = "IGNORE (was expecting USE_ACTIVE_OBJECT_MAP_ONLY)"; 177 TheLogger.debug(_class_name, opname, msg); 178 } else { 179 rpols.add(pols[i]); 180 reqprocpol_set = true; 181 } 182 } 183 else { 184 rpols.add(pols[i]); 185 } 186 } 187 188 org.omg.CORBA.Policy pol = null; 190 org.omg.CORBA.Any value = null; 191 if (!threadingpol_set) { 192 value = orbs.create_any(); 193 ThreadPolicyValueHelper.insert(value, ThreadPolicyValue.ORB_CTRL_MODEL); 194 pol = orbs.create_policy(THREAD_POLICY_ID.value, value); 195 rpols.add(pol); 196 } 197 198 if (!lifespanpol_set) { 199 value = orbs.create_any(); 200 LifespanPolicyValueHelper.insert(value, LifespanPolicyValue.TRANSIENT); 201 pol = orbs.create_policy(LIFESPAN_POLICY_ID.value, value); 202 rpols.add(pol); 203 } 204 205 if (!iduniqpol_set) { 206 value = orbs.create_any(); 207 IdUniquenessPolicyValueHelper.insert(value, IdUniquenessPolicyValue.UNIQUE_ID); 208 pol = orbs.create_policy(ID_UNIQUENESS_POLICY_ID.value, value); 209 rpols.add(pol); 210 } 211 212 if (!idassignpol_set) { 213 value = orbs.create_any(); 214 IdAssignmentPolicyValueHelper.insert(value, IdAssignmentPolicyValue.USER_ID); 215 pol = orbs.create_policy(ID_ASSIGNMENT_POLICY_ID.value, value); 216 rpols.add(pol); 217 } 218 219 if (!servantretpol_set) { 220 value = orbs.create_any(); 221 ServantRetentionPolicyValueHelper.insert(value, ServantRetentionPolicyValue.RETAIN); 222 pol = orbs.create_policy(SERVANT_RETENTION_POLICY_ID.value, value); 223 rpols.add(pol); 224 } 225 226 if (!reqprocpol_set) { 227 value = orbs.create_any(); 228 RequestProcessingPolicyValueHelper.insert(value, RequestProcessingPolicyValue.USE_SERVANT_MANAGER); 229 pol = orbs.create_policy(REQUEST_PROCESSING_POLICY_ID.value, value); 230 rpols.add(pol); 231 } 232 233 if (!implactpol_set) { 234 value = orbs.create_any(); 235 ImplicitActivationPolicyValueHelper.insert(value, ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); 236 pol = orbs.create_policy(IMPLICIT_ACTIVATION_POLICY_ID.value, value); 237 rpols.add(pol); 238 } 239 240 return (org.omg.CORBA.Policy [])rpols.toArray(new org.omg.CORBA.Policy [0]); 241 } 242 243 static private org.omg.PortableServer.POA 244 createPOA(POAConfiguration cfg) 245 { 246 ORBService orbs = cfg.orb_service(); 248 249 org.omg.PortableServer.POA root_poa = null; 251 root_poa = org.omg.PortableServer.POAHelper.narrow(orbs.resolve_initial_references("RootPOA")); 252 253 org.omg.PortableServer.POA poa = null; 255 org.omg.CORBA.Policy [] rpols = checkPolicies(cfg.policies(), orbs); 256 String name = ""; 257 try { 258 if ((cfg.name()==null) || (cfg.name().equals(""))) { 260 name = Double.toString(Math.random()); 261 } 262 else { 263 name = cfg.name(); 264 } 265 266 poa = root_poa.create_POA(name, null, rpols); 267 poa.the_POAManager().activate(); 268 269 ComponentServantActivatorImpl csa = new ComponentServantActivatorImpl(); 271 poa.set_servant_manager(csa); 272 } catch (Exception ex) { 273 String opname = "createPOA"; 274 TheLogger.error(_class_name, opname, "FAILED", ex); 275 return null; 276 } 277 278 return poa; 279 } 280 281 285 final public SystemComponent 286 create_system_component(SystemConfiguration cfg) 287 { 288 ComponentPOAConfiguration poacfg = (ComponentPOAConfiguration)cfg; 289 ORBService orbs = poacfg.orb_service(); 290 291 ComponentPOAServiceImpl poas = new ComponentPOAServiceImpl(); 293 294 POAConfiguration hpoacfg = new POAConfigurationImpl(null, null, orbs); 296 297 org.omg.PortableServer.POA hpoa = createPOA(hpoacfg); 298 poas.setHomePOA(hpoa); 299 300 org.omg.PortableServer.POA cpoa = createPOA(poacfg); 302 poas.setComponentPOA(cpoa); 303 304 poas.system_configuration_complete(poacfg); 306 307 return poas; 308 } 309 } 310 | Popular Tags |