1 17 18 19 package org.apache.catalina.util; 20 21 22 import javax.servlet.Filter ; 23 import javax.servlet.Servlet ; 24 import javax.servlet.ServletRequest ; 25 import javax.servlet.ServletResponse ; 26 import org.apache.catalina.InstanceEvent; 27 import org.apache.catalina.InstanceListener; 28 import org.apache.catalina.Wrapper; 29 30 31 38 39 public final class InstanceSupport { 40 41 42 44 45 52 public InstanceSupport(Wrapper wrapper) { 53 54 super(); 55 this.wrapper = wrapper; 56 57 } 58 59 60 62 63 66 private InstanceListener listeners[] = new InstanceListener[0]; 67 68 69 72 private Wrapper wrapper = null; 73 74 75 77 78 81 public Wrapper getWrapper() { 82 83 return (this.wrapper); 84 85 } 86 87 88 90 91 96 public void addInstanceListener(InstanceListener listener) { 97 98 synchronized (listeners) { 99 InstanceListener results[] = 100 new InstanceListener[listeners.length + 1]; 101 for (int i = 0; i < listeners.length; i++) 102 results[i] = listeners[i]; 103 results[listeners.length] = listener; 104 listeners = results; 105 } 106 107 } 108 109 110 118 public void fireInstanceEvent(String type, Filter filter) { 119 120 if (listeners.length == 0) 121 return; 122 123 InstanceEvent event = new InstanceEvent(wrapper, filter, type); 124 InstanceListener interested[] = null; 125 synchronized (listeners) { 126 interested = (InstanceListener[]) listeners.clone(); 127 } 128 for (int i = 0; i < interested.length; i++) 129 interested[i].instanceEvent(event); 130 131 } 132 133 134 143 public void fireInstanceEvent(String type, Filter filter, 144 Throwable exception) { 145 146 if (listeners.length == 0) 147 return; 148 149 InstanceEvent event = new InstanceEvent(wrapper, filter, type, 150 exception); 151 InstanceListener interested[] = null; 152 synchronized (listeners) { 153 interested = (InstanceListener[]) listeners.clone(); 154 } 155 for (int i = 0; i < interested.length; i++) 156 interested[i].instanceEvent(event); 157 158 } 159 160 161 171 public void fireInstanceEvent(String type, Filter filter, 172 ServletRequest request, 173 ServletResponse response) { 174 175 if (listeners.length == 0) 176 return; 177 178 InstanceEvent event = new InstanceEvent(wrapper, filter, type, 179 request, response); 180 InstanceListener interested[] = null; 181 synchronized (listeners) { 182 interested = (InstanceListener[]) listeners.clone(); 183 } 184 for (int i = 0; i < interested.length; i++) 185 interested[i].instanceEvent(event); 186 187 } 188 189 190 201 public void fireInstanceEvent(String type, Filter filter, 202 ServletRequest request, 203 ServletResponse response, 204 Throwable exception) { 205 206 if (listeners.length == 0) 207 return; 208 209 InstanceEvent event = new InstanceEvent(wrapper, filter, type, 210 request, response, exception); 211 InstanceListener interested[] = null; 212 synchronized (listeners) { 213 interested = (InstanceListener[]) listeners.clone(); 214 } 215 for (int i = 0; i < interested.length; i++) 216 interested[i].instanceEvent(event); 217 218 } 219 220 221 229 public void fireInstanceEvent(String type, Servlet servlet) { 230 231 if (listeners.length == 0) 232 return; 233 234 InstanceEvent event = new InstanceEvent(wrapper, servlet, type); 235 InstanceListener interested[] = null; 236 synchronized (listeners) { 237 interested = (InstanceListener[]) listeners.clone(); 238 } 239 for (int i = 0; i < interested.length; i++) 240 interested[i].instanceEvent(event); 241 242 } 243 244 245 254 public void fireInstanceEvent(String type, Servlet servlet, 255 Throwable exception) { 256 257 if (listeners.length == 0) 258 return; 259 260 InstanceEvent event = new InstanceEvent(wrapper, servlet, type, 261 exception); 262 InstanceListener interested[] = null; 263 synchronized (listeners) { 264 interested = (InstanceListener[]) listeners.clone(); 265 } 266 for (int i = 0; i < interested.length; i++) 267 interested[i].instanceEvent(event); 268 269 } 270 271 272 282 public void fireInstanceEvent(String type, Servlet servlet, 283 ServletRequest request, 284 ServletResponse response) { 285 286 if (listeners.length == 0) 287 return; 288 289 InstanceEvent event = new InstanceEvent(wrapper, servlet, type, 290 request, response); 291 InstanceListener interested[] = null; 292 synchronized (listeners) { 293 interested = (InstanceListener[]) listeners.clone(); 294 } 295 for (int i = 0; i < interested.length; i++) 296 interested[i].instanceEvent(event); 297 298 } 299 300 301 312 public void fireInstanceEvent(String type, Servlet servlet, 313 ServletRequest request, 314 ServletResponse response, 315 Throwable exception) { 316 317 if (listeners.length == 0) 318 return; 319 320 InstanceEvent event = new InstanceEvent(wrapper, servlet, type, 321 request, response, exception); 322 InstanceListener interested[] = null; 323 synchronized (listeners) { 324 interested = (InstanceListener[]) listeners.clone(); 325 } 326 for (int i = 0; i < interested.length; i++) 327 interested[i].instanceEvent(event); 328 329 } 330 331 332 337 public void removeInstanceListener(InstanceListener listener) { 338 339 synchronized (listeners) { 340 int n = -1; 341 for (int i = 0; i < listeners.length; i++) { 342 if (listeners[i] == listener) { 343 n = i; 344 break; 345 } 346 } 347 if (n < 0) 348 return; 349 InstanceListener results[] = 350 new InstanceListener[listeners.length - 1]; 351 int j = 0; 352 for (int i = 0; i < listeners.length; i++) { 353 if (i != n) 354 results[j++] = listeners[i]; 355 } 356 listeners = results; 357 } 358 359 } 360 361 362 } 363 | Popular Tags |