corba/src/share/classes/com/sun/corba/se/impl/oa/poa/Policies.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.oa.poa;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.util.HashMap ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.util.BitSet ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.util.Iterator ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import com.sun.corba.se.impl.orbutil.ORBConstants ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import com.sun.corba.se.spi.extension.ServantCachingPolicy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import com.sun.corba.se.spi.extension.ZeroPortPolicy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import com.sun.corba.se.spi.extension.CopyObjectPolicy ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CORBA.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.PortableServer.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.PortableServer.POAPackage.*;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
public final class Policies {
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
/* Order of *POLICY_ID :
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
   THREAD_
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
   LIFESPAN_
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
   ID_UNIQUENESS_
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
   ID_ASSIGNMENT_
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
   IMPLICIT_ACTIVATION_
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
   SERvANT_RETENTION_
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
   REQUEST_PROCESSING_
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
   The code in this class depends on this order!
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
*/
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    private static final int MIN_POA_POLICY_ID = THREAD_POLICY_ID.value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
    private static final int MAX_POA_POLICY_ID = REQUEST_PROCESSING_POLICY_ID.value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    private static final int POLICY_TABLE_SIZE = MAX_POA_POLICY_ID -
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
        MIN_POA_POLICY_ID + 1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
    int defaultObjectCopierFactoryId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    private HashMap policyMap = new HashMap() ; // Maps Integer(policy type) to Policy
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    public static final Policies defaultPolicies
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
        = new Policies() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    public static final Policies rootPOAPolicies
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        = new Policies(
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
            ThreadPolicyValue._ORB_CTRL_MODEL,
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
            LifespanPolicyValue._TRANSIENT,
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
            IdUniquenessPolicyValue._UNIQUE_ID,
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
            IdAssignmentPolicyValue._SYSTEM_ID,
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
            ImplicitActivationPolicyValue._IMPLICIT_ACTIVATION,
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
            ServantRetentionPolicyValue._RETAIN,
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
            RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    private int[] poaPolicyValues ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    private int getPolicyValue( int id )
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        return poaPolicyValues[ id - MIN_POA_POLICY_ID ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    private void setPolicyValue( int id, int value )
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        poaPolicyValues[ id - MIN_POA_POLICY_ID ] = value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    private Policies(
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        int threadModel,
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        int lifespan,
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        int idUniqueness,
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        int idAssignment,
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        int implicitActivation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        int retention,
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        int requestProcessing )
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        poaPolicyValues = new int[] {
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            threadModel,
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
            lifespan,
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            idUniqueness,
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            idAssignment,
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
            implicitActivation,
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
            retention,
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            requestProcessing };
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    private Policies() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        this( ThreadPolicyValue._ORB_CTRL_MODEL,
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
            LifespanPolicyValue._TRANSIENT,
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            IdUniquenessPolicyValue._UNIQUE_ID,
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
            IdAssignmentPolicyValue._SYSTEM_ID,
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
            ImplicitActivationPolicyValue._NO_IMPLICIT_ACTIVATION,
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            ServantRetentionPolicyValue._RETAIN,
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
            RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        StringBuffer buffer = new StringBuffer();
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        buffer.append( "Policies[" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        boolean first = true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        Iterator iter = policyMap.values().iterator() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        while (iter.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            if (first)
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                first = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                buffer.append( "," ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            buffer.append( iter.next().toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
        buffer.append( "]" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        return buffer.toString() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    /* Returns the integer value of the POA policy, if this is a
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
     * POA policy, otherwise returns -1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    private int getPOAPolicyValue( Policy policy)
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        if (policy instanceof ThreadPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
            return ((ThreadPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        } else if (policy instanceof LifespanPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            return ((LifespanPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        } else if (policy instanceof IdUniquenessPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            return ((IdUniquenessPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        } else if (policy instanceof IdAssignmentPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
            return ((IdAssignmentPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        } else if (policy instanceof ServantRetentionPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
            return ((ServantRetentionPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        } else if (policy instanceof RequestProcessingPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            return  ((RequestProcessingPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        } else if (policy instanceof ImplicitActivationPolicy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            return ((ImplicitActivationPolicy) policy).value().value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        }  else
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            return -1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    /** If any errors were found, throw INVALID_POLICY with the smallest
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
     * index of any offending policy.
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    private void checkForPolicyError( BitSet errorSet ) throws InvalidPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        for (short ctr=0; ctr<errorSet.length(); ctr++ )
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
            if (errorSet.get(ctr))
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
                throw new InvalidPolicy(ctr);
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    /** Add the first index in policies at which the policy is of type
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    * policyId to errorSet, if the polictId is in policies (it may not be).
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    private void addToErrorSet( Policy[] policies, int policyId,
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        BitSet errorSet )
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        for (int ctr=0; ctr<policies.length; ctr++ )
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
            if (policies[ctr].policy_type() == policyId) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                errorSet.set( ctr ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
                return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    /** Main constructor used from POA::create_POA.  This need only be visible
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    * within the POA package.
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    Policies(Policy[] policies, int id ) throws InvalidPolicy
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        // Make sure the defaults are set according to the POA spec
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        this();
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        defaultObjectCopierFactoryId = id ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
        if ( policies == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        // Set to record all indices in policies for which errors
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        // were observed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
        BitSet errorSet = new BitSet( policies.length ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
        for(short i = 0; i < policies.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
            Policy policy = policies[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            int POAPolicyValue = getPOAPolicyValue( policy ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            // Save the policy in policyMap to support
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            // POA.get_effective_policy, if it was not already saved
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            // in policyMap.
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
            Integer key = new Integer( policy.policy_type() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
            Policy prev = (Policy)(policyMap.get( key )) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            if (prev == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                policyMap.put( key, policy ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
            if (POAPolicyValue >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
                setPolicyValue( key.intValue(), POAPolicyValue  ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                // if the value of this POA policy was previously set to a
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
                // different value than the current value given in
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                // POAPolicyValue, record an error.
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                if ((prev != null) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
                    (getPOAPolicyValue( prev ) != POAPolicyValue))
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
                    errorSet.set( i ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        // Check for bad policy combinations
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        // NON_RETAIN requires USE_DEFAULT_SERVANT or USE_SERVANT_MANAGER
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        if (!retainServants() && useActiveMapOnly() ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
            addToErrorSet( policies, SERVANT_RETENTION_POLICY_ID.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
                errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
            addToErrorSet( policies, REQUEST_PROCESSING_POLICY_ID.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
                errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        // IMPLICIT_ACTIVATION requires SYSTEM_ID and RETAIN
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        if (isImplicitlyActivated()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
            if (!retainServants()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
                addToErrorSet( policies, IMPLICIT_ACTIVATION_POLICY_ID.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
                    errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
                addToErrorSet( policies, SERVANT_RETENTION_POLICY_ID.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
                    errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
            if (!isSystemAssignedIds()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
                addToErrorSet( policies, IMPLICIT_ACTIVATION_POLICY_ID.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
                    errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
                addToErrorSet( policies, ID_ASSIGNMENT_POLICY_ID.value,
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
                    errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
        checkForPolicyError( errorSet ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
    public Policy get_effective_policy( int type )
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        Integer key = new Integer( type ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
        Policy result = (Policy)(policyMap.get(key)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
    /* Thread Policies */
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    public final boolean isOrbControlledThreads() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        return getPolicyValue( THREAD_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            ThreadPolicyValue._ORB_CTRL_MODEL;
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    public final boolean isSingleThreaded() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
        return getPolicyValue( THREAD_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
            ThreadPolicyValue._SINGLE_THREAD_MODEL;
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
    /* Lifespan */
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
    public final boolean isTransient() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
        return getPolicyValue( LIFESPAN_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            LifespanPolicyValue._TRANSIENT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    public final boolean isPersistent() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        return getPolicyValue( LIFESPAN_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
            LifespanPolicyValue._PERSISTENT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    /* ID Uniqueness */
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    public final boolean isUniqueIds() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        return getPolicyValue( ID_UNIQUENESS_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
            IdUniquenessPolicyValue._UNIQUE_ID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    public final boolean isMultipleIds() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        return getPolicyValue( ID_UNIQUENESS_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            IdUniquenessPolicyValue._MULTIPLE_ID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    /* ID Assignment */
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    public final boolean isUserAssignedIds() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
        return getPolicyValue( ID_ASSIGNMENT_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
            IdAssignmentPolicyValue._USER_ID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    public final boolean isSystemAssignedIds() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        return getPolicyValue( ID_ASSIGNMENT_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
            IdAssignmentPolicyValue._SYSTEM_ID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
    /* Servant Rentention */
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    public final boolean retainServants() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
        return getPolicyValue( SERVANT_RETENTION_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            ServantRetentionPolicyValue._RETAIN;
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    /* Request Processing */
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    public final boolean useActiveMapOnly() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
            RequestProcessingPolicyValue._USE_ACTIVE_OBJECT_MAP_ONLY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    public final boolean useDefaultServant() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
        return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
            RequestProcessingPolicyValue._USE_DEFAULT_SERVANT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    public final boolean useServantManager() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        return getPolicyValue( REQUEST_PROCESSING_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
            RequestProcessingPolicyValue._USE_SERVANT_MANAGER;
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    /* Implicit Activation */
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    public final boolean isImplicitlyActivated() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        return getPolicyValue( IMPLICIT_ACTIVATION_POLICY_ID.value ) ==
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
        ImplicitActivationPolicyValue._IMPLICIT_ACTIVATION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    /* proprietary servant caching policy */
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    public final int servantCachingLevel()
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        Integer key = new Integer( ORBConstants.SERVANT_CACHING_POLICY ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        ServantCachingPolicy policy = (ServantCachingPolicy)policyMap.get( key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        if (policy == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
            return ServantCachingPolicy.NO_SERVANT_CACHING ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
            return policy.getType() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
    public final boolean forceZeroPort()
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
        Integer key = new Integer( ORBConstants.ZERO_PORT_POLICY ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        ZeroPortPolicy policy = (ZeroPortPolicy)policyMap.get( key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
        if (policy == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
            return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
            return policy.forceZeroPort() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    public final int getCopierId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        Integer key = new Integer( ORBConstants.COPY_OBJECT_POLICY ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        CopyObjectPolicy policy = (CopyObjectPolicy)policyMap.get( key ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        if (policy != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            return policy.getValue() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
            return defaultObjectCopierFactoryId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
}