comparison src/org/eclipse/jetty/server/handler/ContextHandler.java @ 828:8579194add85

some ContextHandler cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 15 Sep 2016 16:47:49 -0600
parents 0048a843297a
children 7c737c376bc3
comparison
equal deleted inserted replaced
827:f89abbfb3a8f 828:8579194add85
1710 * A partial implementation of {@link javax.servlet.ServletContext}. A complete implementation is provided by the derived {@link ContextHandler}. 1710 * A partial implementation of {@link javax.servlet.ServletContext}. A complete implementation is provided by the derived {@link ContextHandler}.
1711 * </p> 1711 * </p>
1712 * 1712 *
1713 * 1713 *
1714 */ 1714 */
1715 public class Context implements ServletContext 1715 public final class Context implements ServletContext
1716 { 1716 {
1717 protected int _majorVersion = 3; 1717 protected int _majorVersion = 3;
1718 protected int _minorVersion = 0; 1718 protected int _minorVersion = 0;
1719 protected boolean _enabled = true; //whether or not the dynamic API is enabled for callers
1720 1719
1721 /* ------------------------------------------------------------ */ 1720 /* ------------------------------------------------------------ */
1722 protected Context() 1721 protected Context()
1723 { 1722 {
1724 } 1723 }
1857 * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String) 1856 * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
1858 */ 1857 */
1859 @Override 1858 @Override
1860 public RequestDispatcher getNamedDispatcher(String name) 1859 public RequestDispatcher getNamedDispatcher(String name)
1861 { 1860 {
1862 return null; 1861 throw new UnsupportedOperationException();
1863 } 1862 }
1864 1863
1865 /* ------------------------------------------------------------ */ 1864 /* ------------------------------------------------------------ */
1866 /* 1865 /*
1867 * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String) 1866 * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
1962 */ 1961 */
1963 @Override 1962 @Override
1964 @Deprecated 1963 @Deprecated
1965 public Servlet getServlet(String name) throws ServletException 1964 public Servlet getServlet(String name) throws ServletException
1966 { 1965 {
1967 return null; 1966 throw new UnsupportedOperationException();
1968 } 1967 }
1969 1968
1970 /* ------------------------------------------------------------ */ 1969 /* ------------------------------------------------------------ */
1971 /* 1970 /*
1972 * @see javax.servlet.ServletContext#getServletNames() 1971 * @see javax.servlet.ServletContext#getServletNames()
1974 @SuppressWarnings("unchecked") 1973 @SuppressWarnings("unchecked")
1975 @Override 1974 @Override
1976 @Deprecated 1975 @Deprecated
1977 public Enumeration getServletNames() 1976 public Enumeration getServletNames()
1978 { 1977 {
1979 return Collections.enumeration(Collections.EMPTY_LIST); 1978 throw new UnsupportedOperationException();
1980 } 1979 }
1981 1980
1982 /* ------------------------------------------------------------ */ 1981 /* ------------------------------------------------------------ */
1983 /* 1982 /*
1984 * @see javax.servlet.ServletContext#getServlets() 1983 * @see javax.servlet.ServletContext#getServlets()
1986 @SuppressWarnings("unchecked") 1985 @SuppressWarnings("unchecked")
1987 @Override 1986 @Override
1988 @Deprecated 1987 @Deprecated
1989 public Enumeration getServlets() 1988 public Enumeration getServlets()
1990 { 1989 {
1991 return Collections.enumeration(Collections.EMPTY_LIST); 1990 throw new UnsupportedOperationException();
1992 } 1991 }
1993 1992
1994 /* ------------------------------------------------------------ */ 1993 /* ------------------------------------------------------------ */
1995 /* 1994 /*
1996 * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String) 1995 * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String)
2184 final private static String __unimplmented="Unimplemented - use org.eclipse.jetty.servlet.ServletContextHandler"; 2183 final private static String __unimplmented="Unimplemented - use org.eclipse.jetty.servlet.ServletContextHandler";
2185 2184
2186 @Override 2185 @Override
2187 public Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) 2186 public Dynamic addFilter(String filterName, Class<? extends Filter> filterClass)
2188 { 2187 {
2189 LOG.warn(__unimplmented); 2188 throw new UnsupportedOperationException();
2190 return null;
2191 } 2189 }
2192 2190
2193 @Override 2191 @Override
2194 public Dynamic addFilter(String filterName, Filter filter) 2192 public Dynamic addFilter(String filterName, Filter filter)
2195 { 2193 {
2196 LOG.warn(__unimplmented); 2194 throw new UnsupportedOperationException();
2197 return null;
2198 } 2195 }
2199 2196
2200 @Override 2197 @Override
2201 public Dynamic addFilter(String filterName, String className) 2198 public Dynamic addFilter(String filterName, String className)
2202 { 2199 {
2203 LOG.warn(__unimplmented); 2200 throw new UnsupportedOperationException();
2204 return null;
2205 } 2201 }
2206 2202
2207 @Override 2203 @Override
2208 public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass) 2204 public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass)
2209 { 2205 {
2210 LOG.warn(__unimplmented); 2206 throw new UnsupportedOperationException();
2211 return null;
2212 } 2207 }
2213 2208
2214 @Override 2209 @Override
2215 public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) 2210 public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet)
2216 { 2211 {
2217 LOG.warn(__unimplmented); 2212 throw new UnsupportedOperationException();
2218 return null;
2219 } 2213 }
2220 2214
2221 @Override 2215 @Override
2222 public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className) 2216 public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
2223 { 2217 {
2224 LOG.warn(__unimplmented); 2218 throw new UnsupportedOperationException();
2225 return null;
2226 } 2219 }
2227 2220
2228 @Override 2221 @Override
2229 public <T extends Filter> T createFilter(Class<T> c) throws ServletException 2222 public <T extends Filter> T createFilter(Class<T> c) throws ServletException
2230 { 2223 {
2231 LOG.warn(__unimplmented); 2224 throw new UnsupportedOperationException();
2232 return null;
2233 } 2225 }
2234 2226
2235 @Override 2227 @Override
2236 public <T extends Servlet> T createServlet(Class<T> c) throws ServletException 2228 public <T extends Servlet> T createServlet(Class<T> c) throws ServletException
2237 { 2229 {
2238 LOG.warn(__unimplmented); 2230 throw new UnsupportedOperationException();
2239 return null;
2240 } 2231 }
2241 2232
2242 @Override 2233 @Override
2243 public Set<SessionTrackingMode> getDefaultSessionTrackingModes() 2234 public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
2244 { 2235 {
2245 LOG.warn(__unimplmented); 2236 throw new UnsupportedOperationException();
2246 return null;
2247 } 2237 }
2248 2238
2249 @Override 2239 @Override
2250 public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() 2240 public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
2251 { 2241 {
2252 LOG.warn(__unimplmented); 2242 throw new UnsupportedOperationException();
2253 return null;
2254 } 2243 }
2255 2244
2256 @Override 2245 @Override
2257 public FilterRegistration getFilterRegistration(String filterName) 2246 public FilterRegistration getFilterRegistration(String filterName)
2258 { 2247 {
2259 LOG.warn(__unimplmented); 2248 throw new UnsupportedOperationException();
2260 return null;
2261 } 2249 }
2262 2250
2263 @Override 2251 @Override
2264 public Map<String, ? extends FilterRegistration> getFilterRegistrations() 2252 public Map<String, ? extends FilterRegistration> getFilterRegistrations()
2265 { 2253 {
2266 LOG.warn(__unimplmented); 2254 throw new UnsupportedOperationException();
2267 return null;
2268 } 2255 }
2269 2256
2270 @Override 2257 @Override
2271 public ServletRegistration getServletRegistration(String servletName) 2258 public ServletRegistration getServletRegistration(String servletName)
2272 { 2259 {
2273 LOG.warn(__unimplmented); 2260 throw new UnsupportedOperationException();
2274 return null;
2275 } 2261 }
2276 2262
2277 @Override 2263 @Override
2278 public Map<String, ? extends ServletRegistration> getServletRegistrations() 2264 public Map<String, ? extends ServletRegistration> getServletRegistrations()
2279 { 2265 {
2280 LOG.warn(__unimplmented); 2266 throw new UnsupportedOperationException();
2281 return null;
2282 } 2267 }
2283 2268
2284 @Override 2269 @Override
2285 public SessionCookieConfig getSessionCookieConfig() 2270 public SessionCookieConfig getSessionCookieConfig()
2286 { 2271 {
2287 LOG.warn(__unimplmented); 2272 throw new UnsupportedOperationException();
2288 return null;
2289 } 2273 }
2290 2274
2291 @Override 2275 @Override
2292 public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) 2276 public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)
2293 { 2277 {
2294 LOG.warn(__unimplmented); 2278 throw new UnsupportedOperationException();
2295 } 2279 }
2296 2280
2297 @Override 2281 @Override
2298 public void addListener(String className) 2282 public void addListener(String className)
2299 { 2283 {
2300 if (!_enabled) 2284 throw new UnsupportedOperationException();
2301 throw new UnsupportedOperationException();
2302
2303 try
2304 {
2305 // Class<? extends EventListener> clazz = _classLoader==null?Loader.loadClass(ContextHandler.class,className):_classLoader.loadClass(className);
2306 Class clazz = _classLoader==null?Loader.loadClass(ContextHandler.class,className):_classLoader.loadClass(className);
2307 addListener(clazz);
2308 }
2309 catch (ClassNotFoundException e)
2310 {
2311 throw new IllegalArgumentException(e);
2312 }
2313 } 2285 }
2314 2286
2315 @Override 2287 @Override
2316 public <T extends EventListener> void addListener(T t) 2288 public <T extends EventListener> void addListener(T t)
2317 { 2289 {
2318 if (!_enabled) 2290 throw new UnsupportedOperationException();
2319 throw new UnsupportedOperationException();
2320 ContextHandler.this.addEventListener(t);
2321 ContextHandler.this.restrictEventListener(t);
2322 } 2291 }
2323 2292
2324 @Override 2293 @Override
2325 public void addListener(Class<? extends EventListener> listenerClass) 2294 public void addListener(Class<? extends EventListener> listenerClass)
2326 { 2295 {
2327 if (!_enabled) 2296 throw new UnsupportedOperationException();
2328 throw new UnsupportedOperationException();
2329
2330 try
2331 {
2332 EventListener e = createListener(listenerClass);
2333 ContextHandler.this.addEventListener(e);
2334 ContextHandler.this.restrictEventListener(e);
2335 }
2336 catch (ServletException e)
2337 {
2338 throw new IllegalArgumentException(e);
2339 }
2340 } 2297 }
2341 2298
2342 @Override 2299 @Override
2343 public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException 2300 public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException
2344 { 2301 {
2386 } 2343 }
2387 2344
2388 @Override 2345 @Override
2389 public JspConfigDescriptor getJspConfigDescriptor() 2346 public JspConfigDescriptor getJspConfigDescriptor()
2390 { 2347 {
2391 LOG.warn(__unimplmented); 2348 throw new UnsupportedOperationException();
2392 return null;
2393 } 2349 }
2394 2350
2395 public void setJspConfigDescriptor(JspConfigDescriptor d) 2351 public void setJspConfigDescriptor(JspConfigDescriptor d)
2396 { 2352 {
2397 2353 throw new UnsupportedOperationException();
2398 } 2354 }
2399 2355
2400 @Override 2356 @Override
2401 public void declareRoles(String... roleNames) 2357 public void declareRoles(String... roleNames)
2402 { 2358 {
2403 if (!isStarting()) 2359 throw new UnsupportedOperationException();
2404 throw new IllegalStateException ();
2405 if (!_enabled)
2406 throw new UnsupportedOperationException();
2407
2408 // TODO Auto-generated method stub
2409
2410 }
2411
2412 public void setEnabled(boolean enabled)
2413 {
2414 _enabled = enabled;
2415 }
2416
2417 public boolean isEnabled()
2418 {
2419 return _enabled;
2420 } 2360 }
2421 } 2361 }
2422 2362
2423 private static class CLDump implements Dumpable 2363 private static class CLDump implements Dumpable
2424 { 2364 {