1 17 package org.apache.geronimo.jetty6; 18 19 import java.io.Serializable ; 20 import java.util.Set ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 import org.apache.geronimo.gbean.GBeanLifecycle; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 import org.mortbay.jetty.servlet.FilterMapping; 29 import org.mortbay.jetty.Handler; 30 31 34 public class JettyFilterMapping extends FilterMapping { 35 36 private final String [] urlPatterns; 37 private final boolean requestDispatch; 38 private final boolean forwardDispatch; 39 private final boolean includeDispatch; 40 private final boolean errorDispatch; 41 private final JettyFilterHolder jettyFilterHolder; 42 private final Collection jettyServletHolders; 43 private final JettyFilterMapping previous; 44 private final JettyServletRegistration jettyServletRegistration; 45 46 public JettyFilterMapping() { 48 this.urlPatterns = null; 49 this.requestDispatch = false; 50 this.forwardDispatch = false; 51 this.includeDispatch = false; 52 this.errorDispatch = false; 53 this.jettyFilterHolder = null; 54 this.jettyServletHolders = null; 55 this.previous = null; 56 this.jettyServletRegistration = null; 57 } 58 59 public JettyFilterMapping(String [] urlPatterns, 60 boolean requestDispatch, 61 boolean forwardDispatch, 62 boolean includeDispatch, 63 boolean errorDispatch, 64 JettyFilterHolder jettyFilterHolder, 65 Collection jettyServletHolders, 66 JettyFilterMapping previous, 67 JettyServletRegistration jettyServletRegistration) { 68 this.urlPatterns = urlPatterns; 69 this.requestDispatch = requestDispatch; 70 this.forwardDispatch = forwardDispatch; 71 this.includeDispatch = includeDispatch; 72 this.errorDispatch = errorDispatch; 73 this.jettyFilterHolder = jettyFilterHolder; 74 this.jettyServletHolders = jettyServletHolders; 75 this.previous = previous; 76 this.jettyServletRegistration = jettyServletRegistration; 77 78 if (jettyServletRegistration != null) { 79 assert jettyServletHolders != null ^ urlPatterns != null; 80 81 String filterName = jettyFilterHolder.getFilterName(); 82 int dispatches = 0; 83 if (requestDispatch) { 84 dispatches |= Handler.REQUEST; 85 } 86 if (forwardDispatch) { 87 dispatches |= Handler.FORWARD; 88 } 89 if (includeDispatch) { 90 dispatches |= Handler.INCLUDE; 91 } 92 if (errorDispatch) { 93 dispatches |= Handler.ERROR; 94 } 95 96 97 setFilterName(filterName); 98 setDispatches(dispatches); 99 setPathSpecs(urlPatterns); 100 if (jettyServletHolders != null) { 101 String [] servletNames = new String [jettyServletHolders.size()]; 102 int i = 0; 103 for (Iterator iterator = jettyServletHolders.iterator(); iterator.hasNext();) { 104 JettyServletHolder jettyServletHolder = (JettyServletHolder) iterator.next(); 105 servletNames[i++] = jettyServletHolder.getServletName(); 106 } 107 setServletNames(servletNames); 108 } 109 110 (jettyServletRegistration.getServletHandler()).addFilterMapping(this); 111 } 112 } 113 114 public String [] getUrlPatterns() { 115 return urlPatterns; 116 } 117 118 public boolean isRequestDispatch() { 119 return requestDispatch; 120 } 121 122 public boolean isForwardDispatch() { 123 return forwardDispatch; 124 } 125 126 public boolean isIncludeDispatch() { 127 return includeDispatch; 128 } 129 130 public boolean isErrorDispatch() { 131 return errorDispatch; 132 } 133 134 public JettyFilterHolder getFilter() { 135 return jettyFilterHolder; 136 } 137 138 public Collection getServlets() { 139 return jettyServletHolders; 140 } 141 142 public JettyFilterMapping getPrevious() { 143 return previous; 144 } 145 146 public JettyServletRegistration getJettyServletRegistration() { 147 return jettyServletRegistration; 148 } 149 150 public static final GBeanInfo GBEAN_INFO; 151 152 static { 153 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(JettyFilterMapping.class, NameFactory.URL_WEB_FILTER_MAPPING); 154 infoBuilder.addAttribute("urlPatterns", String [].class, true); 155 infoBuilder.addAttribute("requestDispatch", boolean.class, true); 156 infoBuilder.addAttribute("forwardDispatch", boolean.class, true); 157 infoBuilder.addAttribute("includeDispatch", boolean.class, true); 158 infoBuilder.addAttribute("errorDispatch", boolean.class, true); 159 160 infoBuilder.addReference("Filter", JettyFilterHolder.class, NameFactory.WEB_FILTER); 161 infoBuilder.addReference("Servlets", JettyServletHolder.class, NameFactory.SERVLET); 162 infoBuilder.addReference("Previous", JettyFilterMapping.class, NameFactory.URL_WEB_FILTER_MAPPING); 163 infoBuilder.addReference("JettyServletRegistration", JettyServletRegistration.class, NameFactory.WEB_MODULE); 164 165 infoBuilder.setConstructor(new String []{"urlPatterns", 166 "requestDispatch", 167 "forwardDispatch", 168 "includeDispatch", 169 "errorDispatch", 170 "Filter", 171 "Servlets", 172 "Previous", 173 "JettyServletRegistration"}); 174 175 GBEAN_INFO = infoBuilder.getBeanInfo(); 176 } 177 178 public static GBeanInfo getGBeanInfo() { 179 return GBEAN_INFO; 180 } 181 } 182 | Popular Tags |