1 21 package org.jacorb.orb.portableInterceptor; 22 23 import org.omg.PortableInterceptor.*; 24 import org.apache.avalon.framework.logger.Logger; 25 26 import java.util.*; 27 28 35 36 public class InterceptorManager 37 { 38 private Interceptor[] client_req_interceptors = null; 39 private Interceptor[] server_req_interceptors = null; 40 private Interceptor[] ior_interceptors = null; 41 private int[] profile_tags = null; 42 43 private org.omg.CORBA.ORB orb = null; 44 private int current_slots = 0; 45 private Logger logger; 46 47 private static ThreadLocal piCurrent = new ThreadLocal (); 48 49 public static final PICurrentImpl EMPTY_CURRENT = new PICurrentImpl(null, 0); 50 51 public InterceptorManager(Vector client_interceptors, 52 Vector server_interceptors, 53 Vector ior_intercept, 54 int slot_count, 55 org.omg.CORBA.ORB orb) 56 { 57 logger = 58 ((org.jacorb.orb.ORB)orb).getConfiguration().getNamedLogger("jacorb.orb.interceptors"); 59 60 if (logger.isInfoEnabled()) 61 { 62 logger.info("InterceptorManager started with " + 63 server_interceptors.size() +" SIs, " 64 + client_interceptors.size() + " CIs and " + 65 ior_intercept.size() + " IORIs"); 66 } 67 68 client_req_interceptors = 70 new ClientRequestInterceptor[client_interceptors.size()]; 71 72 for (int j = 0; j < client_req_interceptors.length; j++){ 74 String min = ((ClientRequestInterceptor) client_interceptors. 75 elementAt(0)).name(); 76 int min_index = 0; 77 78 for(int _i = 1; _i < client_interceptors.size(); _i++) 79 if (min.compareTo(((ClientRequestInterceptor) client_interceptors. 80 elementAt(_i)).name()) > 0){ 81 min = ((ClientRequestInterceptor) client_interceptors. 82 elementAt(_i)).name(); 83 min_index = _i; 84 } 85 86 client_req_interceptors[j] = (ClientRequestInterceptor) 87 client_interceptors.elementAt(min_index); 88 client_interceptors.removeElementAt(min_index); 89 } 90 91 server_req_interceptors = 92 new ServerRequestInterceptor[server_interceptors.size()]; 93 for (int j = 0; j < server_req_interceptors.length; j++){ 95 String min = ((ServerRequestInterceptor) server_interceptors. 96 elementAt(0)).name(); 97 int min_index = 0; 98 99 for(int _i = 1; _i < server_interceptors.size(); _i++) 100 if (min.compareTo(((ServerRequestInterceptor) server_interceptors. 101 elementAt(_i)).name()) > 0){ 102 min = ((ServerRequestInterceptor) server_interceptors. 103 elementAt(_i)).name(); 104 min_index = _i; 105 } 106 107 server_req_interceptors[j] = (ServerRequestInterceptor) 108 server_interceptors.elementAt(min_index); 109 110 server_interceptors.removeElementAt(min_index); 111 } 112 113 114 ior_interceptors = new IORInterceptor[ior_intercept.size()]; 115 for (int j = 0; j < ior_interceptors.length; j++){ 117 String min = ((IORInterceptor) ior_intercept.elementAt(0)).name(); 118 int min_index = 0; 119 120 for(int _i = 1; _i < ior_intercept.size(); _i++) 121 if (min.compareTo(((IORInterceptor) ior_intercept. 122 elementAt(_i)).name()) > 0){ 123 min = ((IORInterceptor) ior_intercept.elementAt(_i)).name(); 124 min_index = _i; 125 } 126 127 ior_interceptors[j] = (IORInterceptor) ior_intercept. 128 elementAt(min_index); 129 130 ior_intercept.removeElementAt(min_index); 131 } 132 133 this.orb = orb; 134 current_slots = slot_count; 135 } 136 137 140 public Current getCurrent() 141 { 142 Current value = (Current)piCurrent.get(); 143 if (value == null) 144 { 145 value = getEmptyCurrent(); 146 piCurrent.set(value); 147 } 148 return value; 149 } 150 151 155 public void setTSCurrent(Current current) 156 { 157 piCurrent.set(current); 158 } 159 160 164 public void removeTSCurrent() 165 { 166 piCurrent.set(null); 167 } 168 169 172 public Current getEmptyCurrent() 173 { 174 return new PICurrentImpl(orb, current_slots); 175 } 176 177 181 public ClientInterceptorIterator getClientIterator() 182 { 183 return new ClientInterceptorIterator(client_req_interceptors); 184 } 185 186 190 public ServerInterceptorIterator getServerIterator() 191 { 192 return new ServerInterceptorIterator(server_req_interceptors); 193 } 194 195 199 public IORInterceptorIterator getIORIterator() 200 { 201 return new IORInterceptorIterator(ior_interceptors, profile_tags); 202 } 203 204 205 208 public void setProfileTags (int [] ptags) 209 { 210 profile_tags = ptags; 211 } 212 213 216 public boolean hasClientRequestInterceptors() 217 { 218 return client_req_interceptors.length > 0; 219 } 220 221 224 public boolean hasServerRequestInterceptors() 225 { 226 return server_req_interceptors.length > 0; 227 } 228 229 232 public boolean hasIORInterceptors() 233 { 234 return ior_interceptors.length > 0; 235 } 236 237 public void destroy() 238 { 239 if( hasClientRequestInterceptors() ) 240 { 241 for( int i = 0; i < client_req_interceptors.length; i++ ) 242 { 243 client_req_interceptors[ i ].destroy(); 244 } 245 } 246 247 if( hasServerRequestInterceptors() ) 248 { 249 for( int i = 0; i < server_req_interceptors.length; i++ ) 250 { 251 server_req_interceptors[ i ].destroy(); 252 } 253 } 254 255 if( hasIORInterceptors() ) 256 { 257 for( int i = 0; i < ior_interceptors.length; i++ ) 258 { 259 ior_interceptors[ i ].destroy(); 260 } 261 } 262 263 } 264 } | Popular Tags |