## org.apache.catalina.core
Class ApplicationContext

    java.lang.Object
      org.apache.catalina.core.ApplicationContext

All Implemented Interfaces:
  javax.servlet.ServletContext

Direct Known Subclasses:
  ReplicatedContext.ReplApplContext

    public class ApplicationContext

extends java.lang.Object
implements javax.servlet.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:
  $Revision: 739532 $ $Date: 2009-01-31 10:52:13 +0100 (Sat, 31 Jan 2009) $
Author:
  Craig R. McClanahan, Remy Maucherat

Field Summary
`protected java.util.Map` `attributes` The context attributes for this context.

Constructor Summary
`ApplicationContext(java.lang.String basePath, StandardContext context)` Construct a new instance of this class, associated with the specified Context instance.

Method Summary
`protected void` `clearAttributes()` Clear all application-created attributes.
`java.lang.Object` `getAttribute(java.lang.String name)` Return the value of the specified context attribute, if any; otherwise return `null`.
`java.util.Enumeration` `getAttributeNames()` Return an enumeration of the names of the context attributes associated with this context.
`protected StandardContext` `getContext()`
`javax.servlet.ServletContext` `getContext(java.lang.String uri)` Return a `ServletContext` object that corresponds to a specified URI on the server.
`java.lang.String` `getContextPath()` Return the main path associated with this context.
`protected javax.servlet.ServletContext` `getFacade()` Return the facade associated with this ApplicationContext.
`java.lang.String` `getInitParameter(java.lang.String name)` Return the value of the specified initialization parameter, or `null` if this parameter does not exist.
`java.util.Enumeration` `getInitParameterNames()` Return the names of the context's initialization parameters, or an empty enumeration if the context has no initialization parameters.
`int` `getMajorVersion()` Return the major version of the Java Servlet API that we implement.
`java.lang.String` `getMimeType(java.lang.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.
`javax.servlet.RequestDispatcher` `getNamedDispatcher(java.lang.String name)` Return a `RequestDispatcher` object that acts as a wrapper for the named servlet.
`protected java.util.Map` `getReadonlyAttributes()`
`java.lang.String` `getRealPath(java.lang.String path)` Return the real path for a given virtual path, if possible; otherwise return `null`.
`javax.servlet.RequestDispatcher` `getRequestDispatcher(java.lang.String path)` Return a `RequestDispatcher` instance that acts as a wrapper for the resource at the given path.
`java.net.URL` `getResource(java.lang.String path)` Return the URL to the resource that is mapped to a specified path.
`java.io.InputStream` `getResourceAsStream(java.lang.String path)` Return the requested resource as an `InputStream`.
`java.util.Set` `getResourcePaths(java.lang.String path)` Return a Set containing the resource paths of resources member of the specified collection.
`javax.naming.directory.DirContext` `getResources()` Return the resources object that is mapped to a specified path.
`java.lang.String` `getServerInfo()` Return the name and version of the servlet container.
`javax.servlet.Servlet` `getServlet(java.lang.String name)` Deprecated. As of Java Servlet API 2.1, with no direct replacement.
`java.lang.String` `getServletContextName()` Return the display name of this web application.
`java.util.Enumeration` `getServletNames()` Deprecated. As of Java Servlet API 2.1, with no direct replacement.
`java.util.Enumeration` `getServlets()` Deprecated. As of Java Servlet API 2.1, with no direct replacement.
`void` `log(java.lang.Exception exception, java.lang.String message)` Deprecated. As of Java Servlet API 2.1, use `log(String, Throwable)` instead
`void` `log(java.lang.String message)` Writes the specified message to a servlet log file.
`void` `log(java.lang.String message, java.lang.Throwable throwable)` Writes the specified message and exception to a servlet log file.
`void` `removeAttribute(java.lang.String name)` Remove the context attribute with the specified name, if any.
`void` `setAttribute(java.lang.String name, java.lang.Object value)` Bind the specified value with the specified context attribute name, replacing any existing value for that name.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### attributes

    protected java.util.Map attributes

  The context attributes for this context.

Constructor Detail

### ApplicationContext

    public ApplicationContext(java.lang.String basePath,
                              StandardContext context)

  Construct a new instance of this class, associated with the specified Context instance.

  Parameters:
    `context` - The associated Context instance

Method Detail

### getResources

    public javax.naming.directory.DirContext getResources()

  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 java.lang.Object getAttribute(java.lang.String name)

  Return the value of the specified context attribute, if any; otherwise return `null`.

  Specified by:
    `getAttribute` in interface `javax.servlet.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 java.util.Enumeration getAttributeNames()

  Return an enumeration of the names of the context attributes associated with this context.

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

### getContext

    public javax.servlet.ServletContext getContext(java.lang.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 `javax.servlet.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 java.lang.String getContextPath()

  Return the main path associated with this context.

  Specified by:
    `getContextPath` in interface `javax.servlet.ServletContext`

### getInitParameter

    public java.lang.String getInitParameter(java.lang.String name)

  Return the value of the specified initialization parameter, or `null` if this parameter does not exist.

  Specified by:
    `getInitParameter` in interface `javax.servlet.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 java.util.Enumeration 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 `javax.servlet.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 `javax.servlet.ServletContext`
  Returns:
    2

### getMinorVersion

    public int getMinorVersion()

  Return the minor version of the Java Servlet API that we implement.

  Specified by:
    `getMinorVersion` in interface `javax.servlet.ServletContext`
  Returns:
    5

### getMimeType

    public java.lang.String getMimeType(java.lang.String file)

  Return the MIME type of the specified file, or `null` if the MIME type cannot be determined.

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

### getNamedDispatcher

    public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)

  Return a `RequestDispatcher` object that acts as a wrapper for the named servlet.

  Specified by:
    `getNamedDispatcher` in interface `javax.servlet.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 java.lang.String getRealPath(java.lang.String path)

  Return the real path for a given virtual path, if possible; otherwise return `null`.

  Specified by:
    `getRealPath` in interface `javax.servlet.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 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.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 `javax.servlet.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 java.net.URL getResource(java.lang.String path)
                             throws java.net.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 `javax.servlet.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:
    `java.net.MalformedURLException` - if the path is not given in the correct form

### getResourceAsStream

    public java.io.InputStream getResourceAsStream(java.lang.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 `javax.servlet.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 java.util.Set getResourcePaths(java.lang.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 `javax.servlet.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 java.lang.String getServerInfo()

  Return the name and version of the servlet container.

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

### getServlet

    public javax.servlet.Servlet getServlet(java.lang.String name)

  Deprecated. As of Java Servlet API 2.1, with no direct replacement.

  Specified by:
    `getServlet` in interface `javax.servlet.ServletContext`

### getServletContextName

    public java.lang.String getServletContextName()

  Return the display name of this web application.

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

### getServletNames

    public java.util.Enumeration getServletNames()

  Deprecated. As of Java Servlet API 2.1, with no direct replacement.

  Specified by:
    `getServletNames` in interface `javax.servlet.ServletContext`

### getServlets

    public java.util.Enumeration getServlets()

  Deprecated. As of Java Servlet API 2.1, with no direct replacement.

  Specified by:
    `getServlets` in interface `javax.servlet.ServletContext`

### log

    public void log(java.lang.String message)

  Writes the specified message to a servlet log file.

  Specified by:
    `log` in interface `javax.servlet.ServletContext`
  Parameters:
    `message` - Message to be written

### log

    public void log(java.lang.Exception exception,
                    java.lang.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 `javax.servlet.ServletContext`
  Parameters:
    `exception` - Exception to be reported
    `message` - Message to be written

### log

    public void log(java.lang.String message,
                    java.lang.Throwable throwable)

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

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

### removeAttribute

    public void removeAttribute(java.lang.String name)

  Remove the context attribute with the specified name, if any.

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

### setAttribute

    public void setAttribute(java.lang.String name,
                             java.lang.Object value)

  Bind the specified value with the specified context attribute name, replacing any existing value for that name.

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

### getContext

    protected StandardContext getContext()

### getReadonlyAttributes

    protected java.util.Map getReadonlyAttributes()

### clearAttributes

    protected void clearAttributes()

  Clear all application-created attributes.

### getFacade

    protected javax.servlet.ServletContext getFacade()

  Return the facade associated with this ApplicationContext.

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