1 16 package org.mortbay.jetty.servlet; 17 18 import java.util.Enumeration ; 19 20 import javax.servlet.Filter ; 21 import javax.servlet.FilterConfig ; 22 import javax.servlet.ServletContext ; 23 24 import org.mortbay.http.HttpHandler; 25 26 27 31 public class FilterHolder 32 extends Holder 33 { 34 35 36 private transient Filter _filter; 37 private transient Config _config; 38 39 40 42 public FilterHolder() 43 {} 44 45 46 public FilterHolder(HttpHandler httpHandler, 47 String name, 48 String className) 49 { 50 super(httpHandler,name,className); 51 } 52 53 54 55 56 57 public void start() 58 throws Exception 59 { 60 super.start(); 61 62 if (!javax.servlet.Filter .class 63 .isAssignableFrom(_class)) 64 { 65 super.stop(); 66 throw new IllegalStateException (_class+" is not a javax.servlet.Filter"); 67 } 68 69 _filter=(Filter )newInstance(); 70 _config=new Config (); 71 _filter.init(_config); 72 } 73 74 75 public void stop() 76 { 77 if (_filter!=null) 78 _filter.destroy(); 79 _filter=null; 80 _config=null; 81 super.stop(); 82 } 83 84 85 public Filter getFilter() 86 { 87 return _filter; 88 } 89 90 91 public String toString() 92 { 93 return getName(); 94 } 95 96 97 98 99 class Config implements FilterConfig 100 { 101 102 public String getFilterName() 103 { 104 return FilterHolder.this.getName(); 105 } 106 107 108 public ServletContext getServletContext() 109 { 110 return ((WebApplicationHandler)_httpHandler).getServletContext(); 111 } 112 113 114 public String getInitParameter(String param) 115 { 116 return FilterHolder.this.getInitParameter(param); 117 } 118 119 120 public Enumeration getInitParameterNames() 121 { 122 return FilterHolder.this.getInitParameterNames(); 123 } 124 } 125 126 } 127 128 129 130 131 132 | Popular Tags |