Class ServletManager

java.lang.Object
  |
  +--ServletManager

public class ServletManager
extends java.lang.Object
implements javax.servlet.ServletContext

Load and manage servlets for a virtual server.


Field Summary
 java.text.SimpleDateFormat dateFormatter
          Date format string for HTTP headers, kept here so we only have to make it once.
protected  FileClassLoader loader
          The class loader used for loading new servlets.
protected  java.lang.String name
          The name of this ServletManager.
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of the named attribute of the network service, or null if the attribute does not exist.
 java.util.Enumeration getAttributeNames()
          Returns an enumeration of named attribute of the network service.
 javax.servlet.ServletContext getContext(java.lang.String name)
          Get a context by name: NOT SUPPORTED.
 int getMajorVersion()
          Returns the major version of the supported version of the Java Servlet API (2.2).
 java.lang.String getMimeType(java.lang.String file)
          Returns the mime type of the specified file, or null if not known.
 int getMinorVersion()
          Returns the minor version of the supported version of the Java Servlet API (2.2).
 java.lang.String getName()
          Get the name of this ServletManager.
 java.lang.String getRealPath(java.lang.String path)
          Applies alias rules to the specified virtual path and returns the corresponding real path.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String name)
          Get a request dispatcher for a named servlet: NOT SUPPORTED.
 java.net.URL getResource(java.lang.String name)
          Get a resource by name: NOT SUPPORTED.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Get a resource by name: NOT SUPPORTED.
 java.lang.String getServerInfo()
          Returns the name and version of the network service under which the servlet is running.
 javax.servlet.Servlet getServlet(java.lang.String name)
          Deprecated.  
 java.util.Enumeration getServletNames()
          Deprecated.  
 java.util.Enumeration getServlets()
          Deprecated.  
protected  java.util.Properties loadProperties(java.lang.String filename)
           
protected  javax.servlet.Servlet loadServlet(java.lang.String name)
          Load and initialize a servlet.
 boolean loadServlet(java.lang.String name, java.lang.Class servlet_class)
          return true if servlet is new, false otherwise
 void log(java.lang.Exception ex, java.lang.String msg)
          Write the stacktrace and the given message string to standard output.
 void log(java.lang.String msg)
          Writes the given message string to standard out.
 void log(java.lang.String msg, java.lang.Throwable thrown)
          Write the stacktrace and the given message string to standard output.
protected  java.util.Properties parseInitArgs(java.lang.String initArgs)
           
 void removeAttribute(java.lang.String name)
          Remove an attribute.
 void setAttribute(java.lang.String name, java.lang.Object object)
          Set an attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loader

protected FileClassLoader loader
The class loader used for loading new servlets.

name

protected java.lang.String name
The name of this ServletManager.

dateFormatter

public java.text.SimpleDateFormat dateFormatter
Date format string for HTTP headers, kept here so we only have to make it once.
Method Detail

loadServlet

public boolean loadServlet(java.lang.String name,
                           java.lang.Class servlet_class)
                    throws java.lang.IllegalAccessException,
                           java.lang.InstantiationException
return true if servlet is new, false otherwise

loadServlet

protected javax.servlet.Servlet loadServlet(java.lang.String name)
                                     throws javax.servlet.ServletException
Load and initialize a servlet. If the servlet is already loaded and initialized, a reference to the existing Servlet is returned.
Parameters:
name - The name of the servlet class to load/instantiate.
Returns:
the loaded and instantiated servlet
Throws:
java.lang.Exception - If there is an error while initializing the servlet.

getName

public java.lang.String getName()
Get the name of this ServletManager.

loadProperties

protected java.util.Properties loadProperties(java.lang.String filename)

parseInitArgs

protected java.util.Properties parseInitArgs(java.lang.String initArgs)

getMajorVersion

public int getMajorVersion()
Returns the major version of the supported version of the Java Servlet API (2.2).
Specified by:
getMajorVersion in interface javax.servlet.ServletContext

getMinorVersion

public int getMinorVersion()
Returns the minor version of the supported version of the Java Servlet API (2.2).
Specified by:
getMinorVersion in interface javax.servlet.ServletContext

getServlet

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

Returns the servlet of the specified name, or null if not loaded. When the servlet is returned it is initialized and ready to accept service requests.

Note: This is a dangerous method to call for the following reasons.

Specified by:
getServlet in interface javax.servlet.ServletContext
Parameters:
name - the name of the desired servlet.
Throws:
if - the servlet could not be initialized

getServlets

public java.util.Enumeration getServlets()
Deprecated.  

Returns an enumeration of the Servlet objects in this server. Only servlets that are accessible (i.e., from the same namespace) will be returned. The enumeration always includes the servlet itself.

Note: This is a dangerous method to call for the following reasons.

Specified by:
getServlets in interface javax.servlet.ServletContext
See Also:
getServletNames, getServlet

getServletNames

public java.util.Enumeration getServletNames()
Deprecated.  

Returns an enumeration of the Servlet object names in this server. Only servlets that are accessible (i.e., from the same namespace) will be returned. The enumeration always includes the servlet itself.

Note: This is a dangerous method to call for the following reasons.

Specified by:
getServletNames in interface javax.servlet.ServletContext

log

public void log(java.lang.Exception ex,
                java.lang.String msg)
Write the stacktrace and the given message string to standard output.
Specified by:
log in interface javax.servlet.ServletContext
Parameters:
exception - the exception to be written.
msg - the message to be written

log

public void log(java.lang.String msg)
Writes the given message string to standard out.
Specified by:
log in interface javax.servlet.ServletContext
Parameters:
msg - the message to be written

log

public void log(java.lang.String msg,
                java.lang.Throwable thrown)
Write the stacktrace and the given message string to standard output.
Specified by:
log in interface javax.servlet.ServletContext
Parameters:
msg - the message to be written
thrown - the exception to be written.

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Applies alias rules to the specified virtual path and returns the corresponding real path. For example, in an HTTP servlet, this method would resolve the path against the HTTP service's docroot. Returns null if virtual paths are not supported, or if the translation could not be performed for any reason.
Specified by:
getRealPath in interface javax.servlet.ServletContext
Parameters:
path - the virtual path to be translated into a real path

getServerInfo

public java.lang.String getServerInfo()
Returns the name and version of the network service under which the servlet is running. For example, if the network service was an HTTP service
Specified by:
getServerInfo in interface javax.servlet.ServletContext

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the value of the named attribute of the network service, or null if the attribute does not exist. This method allows access to additional information about the service, not already provided by the other methods in this interface. Attribute names should follow the same convention as package names. The package names java.* and javax.* are reserved for use by Javasoft, and com.sun.* is reserved for use by Sun Microsystems.
Specified by:
getAttribute in interface javax.servlet.ServletContext
Parameters:
name - the name of the attribute whose value is required
Returns:
the value of the attribute, or null if the attribute does not exist.

getAttributeNames

public java.util.Enumeration getAttributeNames()
Returns an enumeration of named attribute of the network service.
Specified by:
getAttributeNames in interface javax.servlet.ServletContext

getMimeType

public java.lang.String getMimeType(java.lang.String file)
Returns the mime type of the specified file, or null if not known.
Specified by:
getMimeType in interface javax.servlet.ServletContext
Parameters:
file - name of the file whose mime type is required

removeAttribute

public void removeAttribute(java.lang.String name)
Remove an attribute.
Specified by:
removeAttribute in interface javax.servlet.ServletContext

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object object)
Set an attribute.
Specified by:
setAttribute in interface javax.servlet.ServletContext

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String name)
Get a request dispatcher for a named servlet: NOT SUPPORTED. A RequestDispatcher is supposed to allow a servlet to generate some or all of its response content using "forward" or "include" to invoke another servlet or fetch some static content resource. The servlet 2.2 spec has many complexities here that we avoid by not handling request dispatchers at all. For example, the resource name may include parameters; these are to supplement and supersede existing parameters for the scope of the call, but no longer. The resource name must be absolute, i.e., relative to the context root. And the servlet container is to ignore response headers or cookies written by a servlet invoked in this way.
Specified by:
getRequestDispatcher in interface javax.servlet.ServletContext

getResource

public java.net.URL getResource(java.lang.String name)
Get a resource by name: NOT SUPPORTED. This is new in 2.2; it allows a servlet to obtain a handle for some other local or remote resource in a local name space defined by the servlet container.
Specified by:
getResource in interface javax.servlet.ServletContext

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Get a resource by name: NOT SUPPORTED. This is new in 2.2; it is supposed to allow a servlet to obtain a content stream from some other local or remote resource in the local name space.
Specified by:
getResourceAsStream in interface javax.servlet.ServletContext

getContext

public javax.servlet.ServletContext getContext(java.lang.String name)
Get a context by name: NOT SUPPORTED. This is new in 2.2; it is supposed to allow a servlet to obtain a handle to a context for a related Web application or external server, for use in getting RequestDispatchers for resources held by that context.
Specified by:
getContext in interface javax.servlet.ServletContext