1 package org.jacorb.orb.policies; 2 3 22 23 import org.omg.CORBA._PolicyManagerLocalBase; 24 25 import org.apache.avalon.framework.logger.*; 26 27 import java.util.*; 28 29 43 44 public class PolicyManager 45 extends _PolicyManagerLocalBase 46 { 47 private org.jacorb.orb.ORB orb; 48 private Map policy_overrides = null; 49 private Logger logger ; 50 51 54 55 public PolicyManager(org.jacorb.orb.ORB orb) 56 { 57 this.orb = orb; 58 policy_overrides = new HashMap(); 59 logger = orb.getConfiguration().getNamedLogger("jacorb.orb.policies"); 60 } 61 62 76 77 public synchronized org.omg.CORBA.Policy [] get_policy_overrides(int[] ts) 78 { 79 if (ts == null) 80 throw new IllegalArgumentException ("Argument may not be null"); 81 82 if (ts.length == 0) 83 { 84 return (org.omg.CORBA.Policy [])policy_overrides.values().toArray( new org.omg.CORBA.Policy []{}); 85 } 86 87 Vector policyList = new Vector(); 88 89 for (int i = 0; i < ts.length; i++ ) 90 { 91 org.omg.CORBA.Policy p = 92 (org.omg.CORBA.Policy )policy_overrides.get( new Integer ( ts[i] )); 93 if (p != null) 94 policyList.add(p); 95 } 96 97 org.omg.CORBA.Policy [] result = 98 (org.omg.CORBA.Policy [])policyList.toArray( new org.omg.CORBA.Policy []{}); 99 100 if (logger.isDebugEnabled()) 101 logger.debug("get_policy_overrides returns " + result.length + " policies"); 102 103 return result; 104 105 } 106 107 154 155 public synchronized void set_policy_overrides(org.omg.CORBA.Policy [] policies, 156 org.omg.CORBA.SetOverrideType set_add) 157 throws org.omg.CORBA.InvalidPolicies 158 { 159 if (policies == null) 160 throw new IllegalArgumentException ("Argument may not be null"); 161 162 HashMap newPolicies = new HashMap(); 163 StringBuffer sb = new StringBuffer (); 164 165 for (int i = 0; i < policies.length; i++ ) 169 { 170 171 if (!PolicyUtil.isInvocationPolicy( policies[i].policy_type() )) 172 { 173 throw new org.omg.CORBA.NO_PERMISSION ("Not an invocation policy, type " + 174 policies[i].policy_type() ); 175 } 176 Integer key = new Integer ( policies[i].policy_type()); 178 if ( newPolicies.put( key, policies[i] ) != null ) 179 { 180 throw new org.omg.CORBA.BAD_PARAM ( "Multiple policies of type " + 181 policies[i].policy_type(), 182 30, 183 org.omg.CORBA.CompletionStatus.COMPLETED_NO); 184 } 185 sb.append(" " + policies[i].policy_type() ); 186 } 187 188 189 if (set_add == org.omg.CORBA.SetOverrideType.SET_OVERRIDE ) 190 { 191 PolicyUtil.checkValidity(newPolicies); 192 if (logger.isDebugEnabled()) 193 logger.debug("SET_OVERRIDE, types: " + sb.toString()); 194 policy_overrides = newPolicies; 195 } 196 else if (set_add == org.omg.CORBA.SetOverrideType.ADD_OVERRIDE ) 197 { 198 HashMap test = new HashMap(); 200 test.putAll( newPolicies ); 201 PolicyUtil.checkValidity(test); 202 203 if (logger.isDebugEnabled()) 204 logger.debug("ADD_OVERRIDE, types: " + sb.toString()); 205 policy_overrides = test; 206 } 207 208 } 209 210 } 211 | Popular Tags |