public final class ServletContextRegistry extends Object
ServletContext
using
their contextPath as key and optionally a ServletContextRegistry.WebAppType
which gets set as ServletContext
attribute as follows:
ServletContext#setAttribute(org.onehippo.cms7.services.ServletContextRegistry.WebAppType, WebAppType)
.
ServletContexts can/should be registered/unregistered via init/destroy methods of a Servlet
or Filter
, or a ServletContextListener
its
contextInitialized/contextDestroyed event methods.
Registered ServletContexts can be looked up by their contextPath
or as an
unmodifiable map
by their context paths.
Modifier and Type | Class and Description |
---|---|
static class |
ServletContextRegistry.WebAppType |
Constructor and Description |
---|
ServletContextRegistry() |
Modifier and Type | Method and Description |
---|---|
static javax.servlet.ServletContext |
getContext(String contextPath) |
static Map<String,javax.servlet.ServletContext> |
getContexts() |
static Map<String,javax.servlet.ServletContext> |
getContexts(ServletContextRegistry.WebAppType type) |
static void |
register(javax.servlet.ServletContext ctx,
ServletContextRegistry.WebAppType type)
Register a
ServletContext |
static void |
unregister(javax.servlet.ServletContext ctx)
Unregister a
ServletContext |
public static void register(javax.servlet.ServletContext ctx, ServletContextRegistry.WebAppType type)
ServletContext
ctx
- the servletContext to registertype
- the WebAppType
to which the ctx
belongs. Not allowed to be null
IllegalStateException
- if the ServletContext already has been registered by its contextPathpublic static void unregister(javax.servlet.ServletContext ctx)
ServletContext
ctx
- the servletContext to unregisterIllegalStateException
- if the ServletContext has not been registered by its contextPathpublic static javax.servlet.ServletContext getContext(String contextPath)
contextPath
- The contextPath for which to lookup the ServletContextpublic static Map<String,javax.servlet.ServletContext> getContexts()
public static Map<String,javax.servlet.ServletContext> getContexts(ServletContextRegistry.WebAppType type)
type
mapped by their contextPathCopyright © 2012–2015 Hippo B.V. (http://www.onehippo.com). All rights reserved.