1 7 8 package com.sun.corba.se.impl.interceptors; 9 10 import org.omg.PortableInterceptor.Interceptor ; 11 import org.omg.PortableInterceptor.ORBInitInfo ; 12 import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName ; 13 14 import org.omg.CORBA.INTERNAL ; 15 16 import java.util.ArrayList ; 17 import java.util.Collection ; 18 import java.util.Collections ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.lang.reflect.Array ; 22 23 import com.sun.corba.se.impl.logging.InterceptorsSystemException ; 24 25 32 public class InterceptorList { 33 34 static final int INTERCEPTOR_TYPE_CLIENT = 0; 40 static final int INTERCEPTOR_TYPE_SERVER = 1; 41 static final int INTERCEPTOR_TYPE_IOR = 2; 42 43 static final int NUM_INTERCEPTOR_TYPES = 3; 44 45 static final Class [] classTypes = { 49 org.omg.PortableInterceptor.ClientRequestInterceptor .class, 50 org.omg.PortableInterceptor.ServerRequestInterceptor .class, 51 org.omg.PortableInterceptor.IORInterceptor .class 52 }; 53 54 private boolean locked = false; 56 private InterceptorsSystemException wrapper ; 57 58 private Interceptor [][] interceptors = 63 new Interceptor [NUM_INTERCEPTOR_TYPES][]; 64 65 69 InterceptorList( InterceptorsSystemException wrapper ) { 70 this.wrapper = wrapper ; 71 initInterceptorArrays(); 73 } 74 75 87 void register_interceptor( Interceptor interceptor, int type ) 88 throws DuplicateName 89 { 90 if( locked ) { 92 throw wrapper.interceptorListLocked() ; 93 } 94 95 String interceptorName = interceptor.name(); 97 boolean anonymous = interceptorName.equals( "" ); 98 boolean foundDuplicate = false; 99 Interceptor [] interceptorList = interceptors[type]; 100 101 if( !anonymous ) { 104 int size = interceptorList.length; 105 106 for( int i = 0; i < size; i++ ) { 109 Interceptor in = (Interceptor )interceptorList[i]; 110 if( in.name().equals( interceptorName ) ) { 111 foundDuplicate = true; 112 break; 113 } 114 } 115 } 116 117 if( !foundDuplicate ) { 118 growInterceptorArray( type ); 119 interceptors[type][interceptors[type].length-1] = interceptor; 120 } 121 else { 122 throw new DuplicateName ( interceptorName ); 123 } 124 } 125 126 131 void lock() { 132 locked = true; 133 } 134 135 139 Interceptor [] getInterceptors( int type ) { 140 return interceptors[type]; 141 } 142 143 147 boolean hasInterceptorsOfType( int type ) { 148 return interceptors[type].length > 0; 149 } 150 151 155 private void initInterceptorArrays() { 156 for( int type = 0; type < NUM_INTERCEPTOR_TYPES; type++ ) { 157 Class classType = classTypes[type]; 158 159 interceptors[type] = 161 (Interceptor [])Array.newInstance( classType, 0 ); 162 } 163 } 164 165 168 private void growInterceptorArray( int type ) { 169 Class classType = classTypes[type]; 170 int currentLength = interceptors[type].length; 171 Interceptor [] replacementArray; 172 173 replacementArray = (Interceptor []) 176 Array.newInstance( classType, currentLength + 1 ); 177 System.arraycopy( interceptors[type], 0, 178 replacementArray, 0, currentLength ); 179 interceptors[type] = replacementArray; 180 } 181 182 186 void destroyAll() { 187 int numTypes = interceptors.length; 188 189 for( int i = 0; i < numTypes; i++ ) { 190 int numInterceptors = interceptors[i].length; 191 for( int j = 0; j < numInterceptors; j++ ) { 192 interceptors[i][j].destroy(); 193 } 194 } 195 } 196 197 200 void sortInterceptors() { 201 List sorted = null; 202 List unsorted = null; 203 204 int numTypes = interceptors.length; 205 206 for( int i = 0; i < numTypes; i++ ) { 207 int numInterceptors = interceptors[i].length; 208 if (numInterceptors > 0) { 209 sorted = new ArrayList (); unsorted = new ArrayList (); 212 } 213 for( int j = 0; j < numInterceptors; j++ ) { 214 Interceptor interceptor = interceptors[i][j]; 215 if (interceptor instanceof Comparable ) { 216 sorted.add(interceptor); 217 } else { 218 unsorted.add(interceptor); 219 } 220 } 221 if (numInterceptors > 0 && sorted.size() > 0) { 222 Collections.sort(sorted); 226 Iterator sortedIterator = sorted.iterator(); 227 Iterator unsortedIterator = unsorted.iterator(); 228 for( int j = 0; j < numInterceptors; j++ ) { 229 if (sortedIterator.hasNext()) { 230 interceptors[i][j] = 231 (Interceptor ) sortedIterator.next(); 232 } else if (unsortedIterator.hasNext()) { 233 interceptors[i][j] = 234 (Interceptor ) unsortedIterator.next(); 235 } else { 236 throw wrapper.sortSizeMismatch() ; 237 } 238 } 239 } 240 } 241 } 242 } 243 244 | Popular Tags |