FileDocCategorySizeDatePackage
Policies.javaAPI DocJava SE 5 API10383Fri Aug 26 14:54:28 BST 2005com.sun.corba.se.impl.oa.poa

Policies

public final class Policies extends Object

Fields Summary
private static final int
MIN_POA_POLICY_ID
private static final int
MAX_POA_POLICY_ID
private static final int
POLICY_TABLE_SIZE
int
defaultObjectCopierFactoryId
private HashMap
policyMap
public static final Policies
defaultPolicies
public static final Policies
rootPOAPolicies
private int[]
poaPolicyValues
Constructors Summary
private Policies(int threadModel, int lifespan, int idUniqueness, int idAssignment, int implicitActivation, int retention, int requestProcessing)

 	poaPolicyValues = new int[] {
	    threadModel,
	    lifespan,
	    idUniqueness,
	    idAssignment,
	    implicitActivation,
	    retention,
	    requestProcessing };
    
private Policies()

        this( ThreadPolicyValue._ORB_CTRL_MODEL,
	    LifespanPolicyValue._TRANSIENT,
	    IdUniquenessPolicyValue._UNIQUE_ID,
	    IdAssignmentPolicyValue._SYSTEM_ID,
	    ImplicitActivationPolicyValue._NO_IMPLICIT_ACTIVATION,
	    ServantRetentionPolicyValue._RETAIN,
	    RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY ) ;
    
Policies(Policy[] policies, int id)
Main constructor used from POA::create_POA. This need only be visible within the POA package.

	// Make sure the defaults are set according to the POA spec
	this();			

	defaultObjectCopierFactoryId = id ;

	if ( policies == null )
	    return;

	// Set to record all indices in policies for which errors
	// were observed.
        BitSet errorSet = new BitSet( policies.length ) ;

	for(short i = 0; i < policies.length; i++) {
	    Policy policy = policies[i];
	    int POAPolicyValue = getPOAPolicyValue( policy ) ;

	    // Save the policy in policyMap to support 
	    // POA.get_effective_policy, if it was not already saved
	    // in policyMap.
	    Integer key = new Integer( policy.policy_type() ) ;
	    Policy prev = (Policy)(policyMap.get( key )) ;
	    if (prev == null) 
	        policyMap.put( key, policy ) ;

	    if (POAPolicyValue >= 0) {
	        setPolicyValue( key.intValue(), POAPolicyValue  ) ;

		// if the value of this POA policy was previously set to a 
		// different value than the current value given in 
		// POAPolicyValue, record an error.
		if ((prev != null) && 
		    (getPOAPolicyValue( prev ) != POAPolicyValue))
		    errorSet.set( i ) ;
	    }
	}

	// Check for bad policy combinations

	// NON_RETAIN requires USE_DEFAULT_SERVANT or USE_SERVANT_MANAGER
	if (!retainServants() && useActiveMapOnly() ) {
	    addToErrorSet( policies, SERVANT_RETENTION_POLICY_ID.value, 
		errorSet ) ;
	    addToErrorSet( policies, REQUEST_PROCESSING_POLICY_ID.value, 
		errorSet ) ;
	}

	// IMPLICIT_ACTIVATION requires SYSTEM_ID and RETAIN
	if (isImplicitlyActivated()) {
	    if (!retainServants()) {
		addToErrorSet( policies, IMPLICIT_ACTIVATION_POLICY_ID.value, 
		    errorSet ) ;
		addToErrorSet( policies, SERVANT_RETENTION_POLICY_ID.value, 
		    errorSet ) ;
	    }

	    if (!isSystemAssignedIds()) {
		addToErrorSet( policies, IMPLICIT_ACTIVATION_POLICY_ID.value, 
		    errorSet ) ;
		addToErrorSet( policies, ID_ASSIGNMENT_POLICY_ID.value, 
		    errorSet ) ;
	    } 
	}

	checkForPolicyError( errorSet ) ;
    
Methods Summary
private voidaddToErrorSet(Policy[] policies, int policyId, java.util.BitSet errorSet)
Add the first index in policies at which the policy is of type policyId to errorSet, if the polictId is in policies (it may not be).

        for (int ctr=0; ctr<policies.length; ctr++ )
	    if (policies[ctr].policy_type() == policyId) {
		errorSet.set( ctr ) ;
		return ;
	    }
    
private voidcheckForPolicyError(java.util.BitSet errorSet)
If any errors were found, throw INVALID_POLICY with the smallest index of any offending policy.

        for (short ctr=0; ctr<errorSet.length(); ctr++ )
	    if (errorSet.get(ctr)) 
		throw new InvalidPolicy(ctr);
    
public final booleanforceZeroPort()

	Integer key = new Integer( ORBConstants.ZERO_PORT_POLICY ) ;
	ZeroPortPolicy policy = (ZeroPortPolicy)policyMap.get( key ) ;
	if (policy == null)
	    return false ;
	else
	    return policy.forceZeroPort() ;
    
public final intgetCopierId()

	Integer key = new Integer( ORBConstants.COPY_OBJECT_POLICY ) ;
	CopyObjectPolicy policy = (CopyObjectPolicy)policyMap.get( key ) ;
	if (policy != null)
	    return policy.getValue() ;
	else
	    return defaultObjectCopierFactoryId ;
    
private intgetPOAPolicyValue(Policy policy)

        if (policy instanceof ThreadPolicy) {
	    return ((ThreadPolicy) policy).value().value();
        } else if (policy instanceof LifespanPolicy) {
	    return ((LifespanPolicy) policy).value().value();
        } else if (policy instanceof IdUniquenessPolicy) {
	    return ((IdUniquenessPolicy) policy).value().value();
        } else if (policy instanceof IdAssignmentPolicy) {
	    return ((IdAssignmentPolicy) policy).value().value();
        } else if (policy instanceof ServantRetentionPolicy) {
	    return ((ServantRetentionPolicy) policy).value().value();
        } else if (policy instanceof RequestProcessingPolicy) {
	    return  ((RequestProcessingPolicy) policy).value().value();
        } else if (policy instanceof ImplicitActivationPolicy) {
	    return ((ImplicitActivationPolicy) policy).value().value();
        }  else
	    return -1 ;
    
private intgetPolicyValue(int id)


         
    
        return poaPolicyValues[ id - MIN_POA_POLICY_ID ] ;
    
public Policyget_effective_policy(int type)

	Integer key = new Integer( type ) ;
	Policy result = (Policy)(policyMap.get(key)) ;
	return result ;
    
public final booleanisImplicitlyActivated()

	return getPolicyValue( IMPLICIT_ACTIVATION_POLICY_ID.value ) == 
	ImplicitActivationPolicyValue._IMPLICIT_ACTIVATION;
    
public final booleanisMultipleIds()

	return getPolicyValue( ID_UNIQUENESS_POLICY_ID.value ) == 
	    IdUniquenessPolicyValue._MULTIPLE_ID;
    
public final booleanisOrbControlledThreads()

	return getPolicyValue( THREAD_POLICY_ID.value ) == 
	    ThreadPolicyValue._ORB_CTRL_MODEL;
    
public final booleanisPersistent()

	return getPolicyValue( LIFESPAN_POLICY_ID.value ) == 
	    LifespanPolicyValue._PERSISTENT;
    
public final booleanisSingleThreaded()

	return getPolicyValue( THREAD_POLICY_ID.value ) == 
	    ThreadPolicyValue._SINGLE_THREAD_MODEL;
    
public final booleanisSystemAssignedIds()

	return getPolicyValue( ID_ASSIGNMENT_POLICY_ID.value ) == 
	    IdAssignmentPolicyValue._SYSTEM_ID;
    
public final booleanisTransient()

	return getPolicyValue( LIFESPAN_POLICY_ID.value ) == 
	    LifespanPolicyValue._TRANSIENT;
    
public final booleanisUniqueIds()

	return getPolicyValue( ID_UNIQUENESS_POLICY_ID.value ) == 
	    IdUniquenessPolicyValue._UNIQUE_ID;
    
public final booleanisUserAssignedIds()

	return getPolicyValue( ID_ASSIGNMENT_POLICY_ID.value ) == 
	    IdAssignmentPolicyValue._USER_ID;
    
public final booleanretainServants()

	return getPolicyValue( SERVANT_RETENTION_POLICY_ID.value ) == 
	    ServantRetentionPolicyValue._RETAIN;
    
public final intservantCachingLevel()

	Integer key = new Integer( ORBConstants.SERVANT_CACHING_POLICY ) ;
	ServantCachingPolicy policy = (ServantCachingPolicy)policyMap.get( key ) ;
	if (policy == null)
	    return ServantCachingPolicy.NO_SERVANT_CACHING ;
	else
	    return policy.getType() ;
    
private voidsetPolicyValue(int id, int value)

        poaPolicyValues[ id - MIN_POA_POLICY_ID ] = value ;
    
public java.lang.StringtoString()

	StringBuffer buffer = new StringBuffer();
	buffer.append( "Policies[" ) ;
	boolean first = true ;
	Iterator iter = policyMap.values().iterator() ;
	while (iter.hasNext()) {
	    if (first)
		first = false ;
	    else
		buffer.append( "," ) ;

	    buffer.append( iter.next().toString() ) ;
	} 
	buffer.append( "]" ) ;
	return buffer.toString() ;
    
public final booleanuseActiveMapOnly()

	return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) == 
	    RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY;
    
public final booleanuseDefaultServant()

	return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) == 
	    RequestProcessingPolicyValue._USE_DEFAULT_SERVANT;
    
public final booleanuseServantManager()

	return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) == 
	    RequestProcessingPolicyValue._USE_SERVANT_MANAGER;