1 7 8 package com.sun.corba.se.impl.oa.poa; 9 10 import java.util.HashMap ; 11 import java.util.BitSet ; 12 import java.util.Iterator ; 13 14 import com.sun.corba.se.impl.orbutil.ORBConstants ; 15 import com.sun.corba.se.spi.extension.ServantCachingPolicy ; 16 import com.sun.corba.se.spi.extension.ZeroPortPolicy ; 17 import com.sun.corba.se.spi.extension.CopyObjectPolicy ; 18 19 import org.omg.CORBA.*; 20 import org.omg.PortableServer.*; 21 import org.omg.PortableServer.POAPackage.*; 22 23 public final class Policies { 24 34 private static final int MIN_POA_POLICY_ID = THREAD_POLICY_ID.value ; 35 private static final int MAX_POA_POLICY_ID = REQUEST_PROCESSING_POLICY_ID.value ; 36 private static final int POLICY_TABLE_SIZE = MAX_POA_POLICY_ID - 37 MIN_POA_POLICY_ID + 1 ; 38 39 int defaultObjectCopierFactoryId ; 40 41 private HashMap policyMap = new HashMap () ; 43 public static final Policies defaultPolicies 44 = new Policies() ; 45 46 public static final Policies rootPOAPolicies 47 = new Policies( 48 ThreadPolicyValue._ORB_CTRL_MODEL, 49 LifespanPolicyValue._TRANSIENT, 50 IdUniquenessPolicyValue._UNIQUE_ID, 51 IdAssignmentPolicyValue._SYSTEM_ID, 52 ImplicitActivationPolicyValue._IMPLICIT_ACTIVATION, 53 ServantRetentionPolicyValue._RETAIN, 54 RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY ) ; 55 56 private int[] poaPolicyValues ; 57 58 private int getPolicyValue( int id ) 59 { 60 return poaPolicyValues[ id - MIN_POA_POLICY_ID ] ; 61 } 62 63 private void setPolicyValue( int id, int value ) 64 { 65 poaPolicyValues[ id - MIN_POA_POLICY_ID ] = value ; 66 } 67 68 private Policies( 69 int threadModel, 70 int lifespan, 71 int idUniqueness, 72 int idAssignment, 73 int implicitActivation, 74 int retention, 75 int requestProcessing ) 76 { 77 poaPolicyValues = new int[] { 78 threadModel, 79 lifespan, 80 idUniqueness, 81 idAssignment, 82 implicitActivation, 83 retention, 84 requestProcessing }; 85 } 86 87 private Policies() { 88 this( ThreadPolicyValue._ORB_CTRL_MODEL, 89 LifespanPolicyValue._TRANSIENT, 90 IdUniquenessPolicyValue._UNIQUE_ID, 91 IdAssignmentPolicyValue._SYSTEM_ID, 92 ImplicitActivationPolicyValue._NO_IMPLICIT_ACTIVATION, 93 ServantRetentionPolicyValue._RETAIN, 94 RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY ) ; 95 } 96 97 public String toString() { 98 StringBuffer buffer = new StringBuffer (); 99 buffer.append( "Policies[" ) ; 100 boolean first = true ; 101 Iterator iter = policyMap.values().iterator() ; 102 while (iter.hasNext()) { 103 if (first) 104 first = false ; 105 else 106 buffer.append( "," ) ; 107 108 buffer.append( iter.next().toString() ) ; 109 } 110 buffer.append( "]" ) ; 111 return buffer.toString() ; 112 } 113 114 117 private int getPOAPolicyValue( Policy policy) 118 { 119 if (policy instanceof ThreadPolicy) { 120 return ((ThreadPolicy) policy).value().value(); 121 } else if (policy instanceof LifespanPolicy) { 122 return ((LifespanPolicy) policy).value().value(); 123 } else if (policy instanceof IdUniquenessPolicy) { 124 return ((IdUniquenessPolicy) policy).value().value(); 125 } else if (policy instanceof IdAssignmentPolicy) { 126 return ((IdAssignmentPolicy) policy).value().value(); 127 } else if (policy instanceof ServantRetentionPolicy) { 128 return ((ServantRetentionPolicy) policy).value().value(); 129 } else if (policy instanceof RequestProcessingPolicy) { 130 return ((RequestProcessingPolicy) policy).value().value(); 131 } else if (policy instanceof ImplicitActivationPolicy) { 132 return ((ImplicitActivationPolicy) policy).value().value(); 133 } else 134 return -1 ; 135 } 136 137 140 private void checkForPolicyError( BitSet errorSet ) throws InvalidPolicy 141 { 142 for (short ctr=0; ctr<errorSet.length(); ctr++ ) 143 if (errorSet.get(ctr)) 144 throw new InvalidPolicy(ctr); 145 } 146 147 150 private void addToErrorSet( Policy[] policies, int policyId, 151 BitSet errorSet ) 152 { 153 for (int ctr=0; ctr<policies.length; ctr++ ) 154 if (policies[ctr].policy_type() == policyId) { 155 errorSet.set( ctr ) ; 156 return ; 157 } 158 } 159 160 163 Policies(Policy[] policies, int id ) throws InvalidPolicy 164 { 165 this(); 167 168 defaultObjectCopierFactoryId = id ; 169 170 if ( policies == null ) 171 return; 172 173 BitSet errorSet = new BitSet ( policies.length ) ; 176 177 for(short i = 0; i < policies.length; i++) { 178 Policy policy = policies[i]; 179 int POAPolicyValue = getPOAPolicyValue( policy ) ; 180 181 Integer key = new Integer ( policy.policy_type() ) ; 185 Policy prev = (Policy)(policyMap.get( key )) ; 186 if (prev == null) 187 policyMap.put( key, policy ) ; 188 189 if (POAPolicyValue >= 0) { 190 setPolicyValue( key.intValue(), POAPolicyValue ) ; 191 192 if ((prev != null) && 196 (getPOAPolicyValue( prev ) != POAPolicyValue)) 197 errorSet.set( i ) ; 198 } 199 } 200 201 203 if (!retainServants() && useActiveMapOnly() ) { 205 addToErrorSet( policies, SERVANT_RETENTION_POLICY_ID.value, 206 errorSet ) ; 207 addToErrorSet( policies, REQUEST_PROCESSING_POLICY_ID.value, 208 errorSet ) ; 209 } 210 211 if (isImplicitlyActivated()) { 213 if (!retainServants()) { 214 addToErrorSet( policies, IMPLICIT_ACTIVATION_POLICY_ID.value, 215 errorSet ) ; 216 addToErrorSet( policies, SERVANT_RETENTION_POLICY_ID.value, 217 errorSet ) ; 218 } 219 220 if (!isSystemAssignedIds()) { 221 addToErrorSet( policies, IMPLICIT_ACTIVATION_POLICY_ID.value, 222 errorSet ) ; 223 addToErrorSet( policies, ID_ASSIGNMENT_POLICY_ID.value, 224 errorSet ) ; 225 } 226 } 227 228 checkForPolicyError( errorSet ) ; 229 } 230 231 public Policy get_effective_policy( int type ) 232 { 233 Integer key = new Integer ( type ) ; 234 Policy result = (Policy)(policyMap.get(key)) ; 235 return result ; 236 } 237 238 239 public final boolean isOrbControlledThreads() { 240 return getPolicyValue( THREAD_POLICY_ID.value ) == 241 ThreadPolicyValue._ORB_CTRL_MODEL; 242 } 243 public final boolean isSingleThreaded() { 244 return getPolicyValue( THREAD_POLICY_ID.value ) == 245 ThreadPolicyValue._SINGLE_THREAD_MODEL; 246 } 247 248 249 public final boolean isTransient() { 250 return getPolicyValue( LIFESPAN_POLICY_ID.value ) == 251 LifespanPolicyValue._TRANSIENT; 252 } 253 public final boolean isPersistent() { 254 return getPolicyValue( LIFESPAN_POLICY_ID.value ) == 255 LifespanPolicyValue._PERSISTENT; 256 } 257 258 259 public final boolean isUniqueIds() { 260 return getPolicyValue( ID_UNIQUENESS_POLICY_ID.value ) == 261 IdUniquenessPolicyValue._UNIQUE_ID; 262 } 263 public final boolean isMultipleIds() { 264 return getPolicyValue( ID_UNIQUENESS_POLICY_ID.value ) == 265 IdUniquenessPolicyValue._MULTIPLE_ID; 266 } 267 268 269 public final boolean isUserAssignedIds() { 270 return getPolicyValue( ID_ASSIGNMENT_POLICY_ID.value ) == 271 IdAssignmentPolicyValue._USER_ID; 272 } 273 public final boolean isSystemAssignedIds() { 274 return getPolicyValue( ID_ASSIGNMENT_POLICY_ID.value ) == 275 IdAssignmentPolicyValue._SYSTEM_ID; 276 } 277 278 279 public final boolean retainServants() { 280 return getPolicyValue( SERVANT_RETENTION_POLICY_ID.value ) == 281 ServantRetentionPolicyValue._RETAIN; 282 } 283 284 285 public final boolean useActiveMapOnly() { 286 return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) == 287 RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY; 288 } 289 public final boolean useDefaultServant() { 290 return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) == 291 RequestProcessingPolicyValue._USE_DEFAULT_SERVANT; 292 } 293 public final boolean useServantManager() { 294 return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) == 295 RequestProcessingPolicyValue._USE_SERVANT_MANAGER; 296 } 297 298 299 public final boolean isImplicitlyActivated() { 300 return getPolicyValue( IMPLICIT_ACTIVATION_POLICY_ID.value ) == 301 ImplicitActivationPolicyValue._IMPLICIT_ACTIVATION; 302 } 303 304 305 public final int servantCachingLevel() 306 { 307 Integer key = new Integer ( ORBConstants.SERVANT_CACHING_POLICY ) ; 308 ServantCachingPolicy policy = (ServantCachingPolicy)policyMap.get( key ) ; 309 if (policy == null) 310 return ServantCachingPolicy.NO_SERVANT_CACHING ; 311 else 312 return policy.getType() ; 313 } 314 315 public final boolean forceZeroPort() 316 { 317 Integer key = new Integer ( ORBConstants.ZERO_PORT_POLICY ) ; 318 ZeroPortPolicy policy = (ZeroPortPolicy)policyMap.get( key ) ; 319 if (policy == null) 320 return false ; 321 else 322 return policy.forceZeroPort() ; 323 } 324 325 public final int getCopierId() 326 { 327 Integer key = new Integer ( ORBConstants.COPY_OBJECT_POLICY ) ; 328 CopyObjectPolicy policy = (CopyObjectPolicy)policyMap.get( key ) ; 329 if (policy != null) 330 return policy.getValue() ; 331 else 332 return defaultObjectCopierFactoryId ; 333 } 334 } 335 | Popular Tags |