Apache Tomcat 7.0.28

org.apache.catalina.core
Class ApplicationContext

java.lang.Object
  extended by org.apache.catalina.core.ApplicationContext
All Implemented Interfaces:
ServletContext
Direct Known Subclasses:
ReplicatedContext.ReplApplContext

public class ApplicationContext
extends Object
implements ServletContext

Standard implementation of ServletContext that represents a web application's execution environment. An instance of this class is associated with each instance of StandardContext.

Version:
$Id: ApplicationContext.java 1345359 2012-06-01 21:42:24Z kkolinko $
Author:
Craig R. McClanahan, Remy Maucherat

Field Summary
protected  Map<String,Object> attributes
          The context attributes for this context.
protected static boolean GET_RESOURCE_REQUIRE_SLASH
           
protected static boolean STRICT_SERVLET_COMPLIANCE
           
 
Fields inherited from interface javax.servlet.ServletContext
ORDERED_LIBS, TEMPDIR
 
Constructor Summary
ApplicationContext(StandardContext context)
          Construct a new instance of this class, associated with the specified Context instance.
 
Method Summary
 FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass)
          Add filter to context.
 FilterRegistration.Dynamic addFilter(String filterName, Filter filter)
          Add filter to context.
 FilterRegistration.Dynamic addFilter(String filterName, String filterClass)
          Add filter to context.
 void addListener(Class<? extends EventListener> listenerClass)
           
 void addListener(String className)
           
<T extends EventListener>
void
addListener(T t)
           
 ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass)
          Add servlet to context.
 ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet)
          Add servlet to context.
 ServletRegistration.Dynamic addServlet(String servletName, String servletClass)
          Add servlet to context.
protected  void clearAttributes()
          Clear all application-created attributes.
<T extends Filter>
T
createFilter(Class<T> c)
           
<T extends EventListener>
T
createListener(Class<T> c)
           
<T extends Servlet>
T
createServlet(Class<T> c)
           
 void declareRoles(String... roleNames)
           
 Object getAttribute(String name)
          Return the value of the specified context attribute, if any; otherwise return null.
 Enumeration<String> getAttributeNames()
          Return an enumeration of the names of the context attributes associated with this context.
 ClassLoader getClassLoader()
           
protected  StandardContext getContext()
           
 ServletContext getContext(String uri)
          Return a ServletContext object that corresponds to a specified URI on the server.
 String getContextPath()
          Return the main path associated with this context.
 Set<SessionTrackingMode> getDefaultSessionTrackingModes()
          By default SessionTrackingMode.URL is always supported, SessionTrackingMode.COOKIE is supported unless the cookies attribute has been set to false for the context and SessionTrackingMode.SSL is supported if at least one of the connectors used by this context has the attribute secure set to true.
 int getEffectiveMajorVersion()
           
 int getEffectiveMinorVersion()
           
 Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
          Return the supplied value if one was previously set, else return the defaults.
protected  ServletContext getFacade()
          Return the facade associated with this ApplicationContext.
 FilterRegistration getFilterRegistration(String filterName)
           
 Map<String,? extends FilterRegistration> getFilterRegistrations()
           
 String getInitParameter(String name)
          Return the value of the specified initialization parameter, or null if this parameter does not exist.
 Enumeration<String> getInitParameterNames()
          Return the names of the context's initialization parameters, or an empty enumeration if the context has no initialization parameters.
 JspConfigDescriptor getJspConfigDescriptor()
           
 int getMajorVersion()
          Return the major version of the Java Servlet API that we implement.
 String getMimeType(String file)
          Return the MIME type of the specified file, or null if the MIME type cannot be determined.
 int getMinorVersion()
          Return the minor version of the Java Servlet API that we implement.
 RequestDispatcher getNamedDispatcher(String name)
          Return a RequestDispatcher object that acts as a wrapper for the named servlet.
protected  Map<String,String> getReadonlyAttributes()
          Deprecated. 
 String getRealPath(String path)
          Return the real path for a given virtual path, if possible; otherwise return null.
 RequestDispatcher getRequestDispatcher(String path)
          Return a RequestDispatcher instance that acts as a wrapper for the resource at the given path.
 URL getResource(String path)
          Return the URL to the resource that is mapped to a specified path.
 InputStream getResourceAsStream(String path)
          Return the requested resource as an InputStream.
 Set<String> getResourcePaths(String path)
          Return a Set containing the resource paths of resources member of the specified collection.
 DirContext getResources()
          Deprecated. 
 String getServerInfo()
          Return the name and version of the servlet container.
 Servlet getServlet(String name)
          Deprecated. As of Java Servlet API 2.1, with no direct replacement.
 String getServletContextName()
          Return the display name of this web application.
 Enumeration<String> getServletNames()
          Deprecated. As of Java Servlet API 2.1, with no direct replacement.
 ServletRegistration getServletRegistration(String servletName)
           
 Map<String,? extends ServletRegistration> getServletRegistrations()
           
 Enumeration<Servlet> getServlets()
          Deprecated. As of Java Servlet API 2.1, with no direct replacement.
 SessionCookieConfig getSessionCookieConfig()
           
 void log(Exception exception, String message)
          Deprecated. As of Java Servlet API 2.1, use log(String, Throwable) instead
 void log(String message)
          Writes the specified message to a servlet log file.
 void log(String message, Throwable throwable)
          Writes the specified message and exception to a servlet log file.
 void removeAttribute(String name)
          Remove the context attribute with the specified name, if any.
 void setAttribute(String name, Object value)
          Bind the specified value with the specified context attribute name, replacing any existing value for that name.
 boolean setInitParameter(String name, String value)
           
protected  void setNewServletContextListenerAllowed(boolean allowed)
           
 void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRICT_SERVLET_COMPLIANCE

protected static final boolean STRICT_SERVLET_COMPLIANCE

GET_RESOURCE_REQUIRE_SLASH

protected static final boolean GET_RESOURCE_REQUIRE_SLASH

attributes

protected Map<String,Object> attributes
The context attributes for this context.

Constructor Detail

ApplicationContext

public ApplicationContext(StandardContext context)
Construct a new instance of this class, associated with the specified Context instance.

Parameters:
context - The associated Context instance
Method Detail

getResources

@Deprecated
public DirContext getResources()
Deprecated. 

Return the resources object that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.


getAttribute

public Object getAttribute(String name)
Return the value of the specified context attribute, if any; otherwise return null.

Specified by:
getAttribute in interface ServletContext
Parameters:
name - Name of the context attribute to return
Returns:
an Object containing the value of the attribute, or null if no attribute exists matching the given name
See Also:
ServletContext.getAttributeNames()

getAttributeNames

public Enumeration<String> getAttributeNames()
Return an enumeration of the names of the context attributes associated with this context.

Specified by:
getAttributeNames in interface ServletContext
Returns:
an Enumeration of attribute names
See Also:
ServletContext.getAttribute(java.lang.String)

getContext

public ServletContext getContext(String uri)
Return a ServletContext object that corresponds to a specified URI on the server. This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects or resources from the context. The given path must be absolute (beginning with a "/"), and is interpreted based on our virtual host's document root.

Specified by:
getContext in interface ServletContext
Parameters:
uri - Absolute URI of a resource on the server
Returns:
the ServletContext object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access.
See Also:
RequestDispatcher

getContextPath

public String getContextPath()
Return the main path associated with this context.

Specified by:
getContextPath in interface ServletContext

getInitParameter

public String getInitParameter(String name)
Return the value of the specified initialization parameter, or null if this parameter does not exist.

Specified by:
getInitParameter in interface ServletContext
Parameters:
name - Name of the initialization parameter to retrieve
Returns:
a String containing at least the servlet container name and version number
See Also:
ServletConfig.getInitParameter(java.lang.String)

getInitParameterNames

public Enumeration<String> getInitParameterNames()
Return the names of the context's initialization parameters, or an empty enumeration if the context has no initialization parameters.

Specified by:
getInitParameterNames in interface ServletContext
Returns:
an Enumeration of String objects containing the names of the context's initialization parameters
See Also:
ServletConfig.getInitParameter(java.lang.String)

getMajorVersion

public int getMajorVersion()
Return the major version of the Java Servlet API that we implement.

Specified by:
getMajorVersion in interface ServletContext
Returns:
3

getMinorVersion

public int getMinorVersion()
Return the minor version of the Java Servlet API that we implement.

Specified by:
getMinorVersion in interface ServletContext
Returns:
0

getMimeType

public String getMimeType(String file)
Return the MIME type of the specified file, or null if the MIME type cannot be determined.

Specified by:
getMimeType in interface ServletContext
Parameters:
file - Filename for which to identify a MIME type
Returns:
a String specifying the file's MIME type

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(String name)
Return a RequestDispatcher object that acts as a wrapper for the named servlet.

Specified by:
getNamedDispatcher in interface ServletContext
Parameters:
name - Name of the servlet for which a dispatcher is requested
Returns:
a RequestDispatcher object that acts as a wrapper for the named servlet, or null if the ServletContext cannot return a RequestDispatcher
See Also:
RequestDispatcher, ServletContext.getContext(java.lang.String), ServletConfig.getServletName()

getRealPath

public String getRealPath(String path)
Return the real path for a given virtual path, if possible; otherwise return null.

Specified by:
getRealPath in interface ServletContext
Parameters:
path - The path to the desired resource
Returns:
a String specifying the real path, or null if the translation cannot be performed

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String path)
Return a RequestDispatcher instance that acts as a wrapper for the resource at the given path. The path must begin with a "/" and is interpreted as relative to the current context root.

Specified by:
getRequestDispatcher in interface ServletContext
Parameters:
path - The path to the desired resource.
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the ServletContext cannot return a RequestDispatcher
See Also:
RequestDispatcher, ServletContext.getContext(java.lang.String)

getResource

public URL getResource(String path)
                throws MalformedURLException
Return the URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

Specified by:
getResource in interface ServletContext
Parameters:
path - The path to the desired resource
Returns:
the resource located at the named path, or null if there is no resource at that path
Throws:
MalformedURLException - if the path is not given in the correct form

getResourceAsStream

public InputStream getResourceAsStream(String path)
Return the requested resource as an InputStream. The path must be specified according to the rules described under getResource. If no such resource can be identified, return null.

Specified by:
getResourceAsStream in interface ServletContext
Parameters:
path - The path to the desired resource.
Returns:
the InputStream returned to the servlet, or null if no resource exists at the specified path

getResourcePaths

public Set<String> getResourcePaths(String path)
Return a Set containing the resource paths of resources member of the specified collection. Each path will be a String starting with a "/" character. The returned set is immutable.

Specified by:
getResourcePaths in interface ServletContext
Parameters:
path - Collection path
Returns:
a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.

getServerInfo

public String getServerInfo()
Return the name and version of the servlet container.

Specified by:
getServerInfo in interface ServletContext
Returns:
a String containing at least the servlet container name and version number

getServlet

@Deprecated
public Servlet getServlet(String name)
Deprecated. As of Java Servlet API 2.1, with no direct replacement.

Specified by:
getServlet in interface ServletContext

getServletContextName

public String getServletContextName()
Return the display name of this web application.

Specified by:
getServletContextName in interface ServletContext
Returns:
The name of the web application or null if no name has been declared in the deployment descriptor.

getServletNames

@Deprecated
public Enumeration<String> getServletNames()
Deprecated. As of Java Servlet API 2.1, with no direct replacement.

Specified by:
getServletNames in interface ServletContext

getServlets

@Deprecated
public Enumeration<Servlet> getServlets()
Deprecated. As of Java Servlet API 2.1, with no direct replacement.

Specified by:
getServlets in interface ServletContext

log

public void log(String message)
Writes the specified message to a servlet log file.

Specified by:
log in interface ServletContext
Parameters:
message - Message to be written

log

@Deprecated
public void log(Exception exception,
                           String message)
Deprecated. As of Java Servlet API 2.1, use log(String, Throwable) instead

Writes the specified exception and message to a servlet log file.

Specified by:
log in interface ServletContext
Parameters:
exception - Exception to be reported
message - Message to be written

log

public void log(String message,
                Throwable throwable)
Writes the specified message and exception to a servlet log file.

Specified by:
log in interface ServletContext
Parameters:
message - Message to be written
throwable - Exception to be reported

removeAttribute

public void removeAttribute(String name)
Remove the context attribute with the specified name, if any.

Specified by:
removeAttribute in interface ServletContext
Parameters:
name - Name of the context attribute to be removed

setAttribute

public void setAttribute(String name,
                         Object value)
Bind the specified value with the specified context attribute name, replacing any existing value for that name.

Specified by:
setAttribute in interface ServletContext
Parameters:
name - Attribute name to be bound
value - New attribute value to be bound

addFilter

public FilterRegistration.Dynamic addFilter(String filterName,
                                            String filterClass)
                                     throws IllegalStateException
Add filter to context.

Specified by:
addFilter in interface ServletContext
Parameters:
filterName - Name of filter to add
filterClass - Name of filter class
Returns:
null if the filter has already been fully defined, else a FilterRegistration.Dynamic object that can be used to further configure the filter
Throws:
IllegalStateException - if the context has already been initialised
UnsupportedOperationException - - if this context was passed to the ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent) method of a ServletContextListener that was not declared in web.xml, a web-fragment or annotated with WebListener.

addFilter

public FilterRegistration.Dynamic addFilter(String filterName,
                                            Filter filter)
                                     throws IllegalStateException
Add filter to context.

Specified by:
addFilter in interface ServletContext
Parameters:
filterName - Name of filter to add
filter - Filter to add
Returns:
null if the filter has already been fully defined, else a FilterRegistration.Dynamic object that can be used to further configure the filter
Throws:
IllegalStateException - if the context has already been initialised
UnsupportedOperationException - - if this context was passed to the ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent) method of a ServletContextListener that was not declared in web.xml, a web-fragment or annotated with WebListener.

addFilter

public FilterRegistration.Dynamic addFilter(String filterName,
                                            Class<? extends Filter> filterClass)
                                     throws IllegalStateException
Add filter to context.

Specified by:
addFilter in interface ServletContext
Parameters:
filterName - Name of filter to add
filterClass - Class of filter to add
Returns:
null if the filter has already been fully defined, else a FilterRegistration.Dynamic object that can be used to further configure the filter
Throws:
IllegalStateException - if the context has already been initialised
UnsupportedOperationException - - if this context was passed to the ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent) method of a ServletContextListener that was not declared in web.xml, a web-fragment or annotated with WebListener.

createFilter

public <T extends Filter> T createFilter(Class<T> c)
                              throws ServletException
Specified by:
createFilter in interface ServletContext
Returns:
TODO
Throws:
ServletException

getFilterRegistration

public FilterRegistration getFilterRegistration(String filterName)
Specified by:
getFilterRegistration in interface ServletContext
Returns:
TODO

addServlet

public ServletRegistration.Dynamic addServlet(String servletName,
                                              String servletClass)
                                       throws IllegalStateException
Add servlet to context.

Specified by:
addServlet in interface ServletContext
Parameters:
servletName - Name of servlet to add
servletClass - Name of servlet class
Returns:
null if the servlet has already been fully defined, else a ServletRegistration.Dynamic object that can be used to further configure the servlet
Throws:
IllegalStateException - if the context has already been initialised
UnsupportedOperationException - - if this context was passed to the ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent) method of a ServletContextListener that was not declared in web.xml, a web-fragment or annotated with WebListener.

addServlet

public ServletRegistration.Dynamic addServlet(String servletName,
                                              Servlet servlet)
                                       throws IllegalStateException
Add servlet to context.

Specified by:
addServlet in interface ServletContext
Parameters:
servletName - Name of servlet to add
servlet - Servlet instance to add
Returns:
null if the servlet has already been fully defined, else a ServletRegistration.Dynamic object that can be used to further configure the servlet
Throws:
IllegalStateException - if the context has already been initialised
UnsupportedOperationException - - if this context was passed to the ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent) method of a ServletContextListener that was not declared in web.xml, a web-fragment or annotated with WebListener.

addServlet

public ServletRegistration.Dynamic addServlet(String servletName,
                                              Class<? extends Servlet> servletClass)
                                       throws IllegalStateException
Add servlet to context.

Specified by:
addServlet in interface ServletContext
Parameters:
servletName - Name of servlet to add
servletClass - Class of servlet to add
Returns:
null if the servlet has already been fully defined, else a ServletRegistration.Dynamic object that can be used to further configure the servlet
Throws:
IllegalStateException - if the context has already been initialised
UnsupportedOperationException - - if this context was passed to the ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent) method of a ServletContextListener that was not declared in web.xml, a web-fragment or annotated with WebListener.

createServlet

public <T extends Servlet> T createServlet(Class<T> c)
                                throws ServletException
Specified by:
createServlet in interface ServletContext
Returns:
TODO
Throws:
ServletException

getServletRegistration

public ServletRegistration getServletRegistration(String servletName)
Specified by:
getServletRegistration in interface ServletContext
Returns:
TODO

getDefaultSessionTrackingModes

public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
By default SessionTrackingMode.URL is always supported, SessionTrackingMode.COOKIE is supported unless the cookies attribute has been set to false for the context and SessionTrackingMode.SSL is supported if at least one of the connectors used by this context has the attribute secure set to true.

Specified by:
getDefaultSessionTrackingModes in interface ServletContext
Returns:
TODO

getEffectiveSessionTrackingModes

public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
Return the supplied value if one was previously set, else return the defaults.

Specified by:
getEffectiveSessionTrackingModes in interface ServletContext
Returns:
TODO

getSessionCookieConfig

public SessionCookieConfig getSessionCookieConfig()
Specified by:
getSessionCookieConfig in interface ServletContext
Returns:
TODO

setSessionTrackingModes

public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)
Specified by:
setSessionTrackingModes in interface ServletContext
Throws:
IllegalStateException - if the context has already been initialised
IllegalArgumentException - If SSL is requested in combination with anything else or if an unsupported tracking mode is requested

setInitParameter

public boolean setInitParameter(String name,
                                String value)
Specified by:
setInitParameter in interface ServletContext
Returns:
TODO

addListener

public void addListener(Class<? extends EventListener> listenerClass)
Specified by:
addListener in interface ServletContext

addListener

public void addListener(String className)
Specified by:
addListener in interface ServletContext

addListener

public <T extends EventListener> void addListener(T t)
Specified by:
addListener in interface ServletContext

createListener

public <T extends EventListener> T createListener(Class<T> c)
                                       throws ServletException
Specified by:
createListener in interface ServletContext
Returns:
TODO
Throws:
ServletException

declareRoles

public void declareRoles(String... roleNames)
Specified by:
declareRoles in interface ServletContext

getClassLoader

public ClassLoader getClassLoader()
Specified by:
getClassLoader in interface ServletContext
Returns:
TODO

getEffectiveMajorVersion

public int getEffectiveMajorVersion()
Specified by:
getEffectiveMajorVersion in interface ServletContext
Returns:
TODO

getEffectiveMinorVersion

public int getEffectiveMinorVersion()
Specified by:
getEffectiveMinorVersion in interface ServletContext
Returns:
TODO

getFilterRegistrations

public Map<String,? extends FilterRegistration> getFilterRegistrations()
Specified by:
getFilterRegistrations in interface ServletContext
Returns:
TODO

getJspConfigDescriptor

public JspConfigDescriptor getJspConfigDescriptor()
Specified by:
getJspConfigDescriptor in interface ServletContext
Returns:
TODO

getServletRegistrations

public Map<String,? extends ServletRegistration> getServletRegistrations()
Specified by:
getServletRegistrations in interface ServletContext
Returns:
TODO

getContext

protected StandardContext getContext()

getReadonlyAttributes

@Deprecated
protected Map<String,String> getReadonlyAttributes()
Deprecated. 


clearAttributes

protected void clearAttributes()
Clear all application-created attributes.


getFacade

protected ServletContext getFacade()
Return the facade associated with this ApplicationContext.


setNewServletContextListenerAllowed

protected void setNewServletContextListenerAllowed(boolean allowed)

Apache Tomcat 7.0.28

Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.