Enhydra 5.1 API

org.enhydra.servlet.servletManager
Class EnhydraServletContext

java.lang.Object
  |
  +--org.enhydra.servlet.servletManager.EnhydraServletContext
All Implemented Interfaces:
javax.servlet.ServletContext

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


Constructor Summary
protected EnhydraServletContext(java.lang.String name, org.apache.log4j.Logger logger, ServletManager servletManager, java.util.Properties initArgs, java.lang.String docRoot, MultiClassLoader classLoader)
           
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
          Returns an Enumeration containing the attribute names available within this servlet context.
 MultiClassLoader getClassLoader()
          Return the class loader used to load the servlet.
 javax.servlet.ServletContext getContext(java.lang.String uripath)
          Returns a ServletContext object that corresponds to a specified URL on the server.
 java.lang.String getInitParameter(java.lang.String name)
          Return the value for the given context parameter name.
 java.util.Enumeration getInitParameterNames()
          Return an Enumeration of all of the context parameter names.
 org.apache.log4j.Logger getLogger()
          Return the LogChannel for the servlet.
 int getMajorVersion()
          Returns the major version of the Java Servlet API that this Web server supports.
 java.lang.String getMimeType(java.lang.String file)
           
 int getMinorVersion()
          Returns the minor version of the Servlet API that this Web server supports.
 java.lang.String getName()
          Returns the name of this servlet.
 javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
          Returns a dispatcher for the given resource name.
 java.lang.String getRealPath(java.lang.String path)
          Transate a partial path to the real location on disk.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String urlpath)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the named path.
 java.net.URL getResource(java.lang.String path)
          Returns the resource that is mapped to a specified path.
 java.io.InputStream getResourceAsStream(java.lang.String path)
          Returns the resource located at the named path as an InputStream object.
 java.lang.String getServerInfo()
           
 javax.servlet.Servlet getServlet(java.lang.String name)
           
 java.util.Enumeration getServletNames()
          Returns an enumeration of the Servlet object names in this server.
 java.util.Enumeration getServlets()
           
 void log(java.lang.Exception except, java.lang.String msg)
           
 void log(java.lang.String msg)
           
 void log(java.lang.String message, java.lang.Throwable throwable)
          Writes the stack trace and an explanatory message for a given Throwable exception to the servlet log file.
 void removeAttribute(java.lang.String name)
          Removes the attribute with the given name from the servlet context.
 void setAttribute(java.lang.String name, java.lang.Object object)
          Gives an attribute a name in this servlet context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnhydraServletContext

protected EnhydraServletContext(java.lang.String name,
                                org.apache.log4j.Logger logger,
                                ServletManager servletManager,
                                java.util.Properties initArgs,
                                java.lang.String docRoot,
                                MultiClassLoader classLoader)
Method Detail

getServlet

public javax.servlet.Servlet getServlet(java.lang.String name)
                                 throws javax.servlet.ServletException
Specified by:
getServlet in interface javax.servlet.ServletContext
javax.servlet.ServletException

getServlets

public java.util.Enumeration getServlets()
Specified by:
getServlets in interface javax.servlet.ServletContext

log

public void log(java.lang.String msg)
Specified by:
log in interface javax.servlet.ServletContext

log

public void log(java.lang.Exception except,
                java.lang.String msg)
Specified by:
log in interface javax.servlet.ServletContext

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Transate a partial path to the real location on disk. This depends on what the servlet's docRoot was set to. For example, suppose a servlet is configured with the docRoot "/tmp/images/". Then "/tmp/images" will be passed into this object's constructor. If the servlet then asks for the path "/foo/bar.gif" to be translated, it will recieve "/tmp/images/foo/bar.gif".

Specified by:
getRealPath in interface javax.servlet.ServletContext
Parameters:
path - The filname (probably the tail end of a URL) to translate.
Returns:
A filename on the hard disk.

getMimeType

public java.lang.String getMimeType(java.lang.String file)
Specified by:
getMimeType in interface javax.servlet.ServletContext

getServerInfo

public java.lang.String getServerInfo()
Specified by:
getServerInfo in interface javax.servlet.ServletContext

getMajorVersion

public int getMajorVersion()
Returns the major version of the Java Servlet API that this Web server supports.

Specified by:
getMajorVersion in interface javax.servlet.ServletContext
Returns:
2

getMinorVersion

public int getMinorVersion()
Returns the minor version of the Servlet API that this Web server supports.

Specified by:
getMinorVersion in interface javax.servlet.ServletContext
Returns:
2

getContext

public javax.servlet.ServletContext getContext(java.lang.String uripath)
Returns a ServletContext object that corresponds to a specified URL on the server.

This method allows servlets to gain access to the resources located at a specified URL and obtain RequestDispatcher objects from it.

In security conscious environments, the servlet engine can return null for a given URL.

Specified by:
getContext in interface javax.servlet.ServletContext
Parameters:
uripath - a String specifying the URL for which you are requesting a ServletContext object
Returns:
the ServletContext object that corresponds to the named URL
See Also:
RequestDispatcher

getResource

public java.net.URL getResource(java.lang.String path)
                         throws java.net.MalformedURLException
Returns the resource that is mapped to a specified path. The path must be in the form /dir/dir/file.ext.

This method allows the Web server to make a resource available to a servlet from any source. Resources can be located on a local or remote file system, in a database, or on a remote network site.

This method can return null if no resource is mapped to the pathname.

The servlet engine must implement the URL handlers and URLConnection objects that are necessary to access the resource.

This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This method does not use class loaders.

Specified by:
getResource in interface javax.servlet.ServletContext
Parameters:
path - a String specifying the path to the resource, in the form /dir/dir/file.ext
Returns:
the resource located at the named path, or null if there is no resource at that path
Throws:
java.net.MalformedURLException - if the pathname is not given in the correct form

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
Returns the resource located at the named path as an InputStream object.

The data in the InputStream can be of any type or length. The path must be of the form /dir/dir/file.ext. This method returns null if no resource exists at the specified path.

Metainformation such as content length and content type that is available when you use the getResource method is lost when you use this method.

The servlet engine must implement the URL handlers and URLConnection objects necessary to access the resource.

This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet engines to make a resource available to a servlet from any location, without using a class loader.

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

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String urlpath)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the named path. You can use a RequestDispatcher object to forward a request to the resource or include a resource in a response.

The pathname must be in the form /dir/dir/file.ext. This method returns null if the ServletContext cannot return a RequestDispatcher.

The servlet engine is responsible for wrapping the resource with a RequestDispatcher object.

Specified by:
getRequestDispatcher in interface javax.servlet.ServletContext
Parameters:
urlpath - a String specifying the pathname to the resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the path you specify
See Also:
RequestDispatcher

log

public void log(java.lang.String message,
                java.lang.Throwable throwable)
Writes the stack trace and an explanatory message for a given Throwable exception to the servlet log file. The stack trace is part of the Throwable object, and the message is the one you specify in the message parameter. The name and type of the servlet log file is specific to the servlet engine, but it is usually an event log.

Specified by:
log in interface javax.servlet.ServletContext
Parameters:
message - a String that describes the error or exception
throwable - the Throwable error or exception

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in interface javax.servlet.ServletContext

getAttributeNames

public java.util.Enumeration getAttributeNames()
Returns an Enumeration containing the attribute names available within this servlet context. You can use the getAttribute(java.lang.String) method with an attribute name to get the value of an attribute.

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

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object object)
Gives an attribute a name in this servlet context. If the name specified is already used for an attribute, this method will overwrite the old attribute and bind the name to the new attribute.

Attribute names should follow the same convention as package names. The Java Servlet API specification reserves names matching java.*, javax.*, and sun.*.

Specified by:
setAttribute in interface javax.servlet.ServletContext
Parameters:
name - a String specifying the name of the attribute
object - an Object representing the attribute to be given the name

removeAttribute

public void removeAttribute(java.lang.String name)
Removes the attribute with the given name from the servlet context. If you remove an attribute, and then use getAttribute(java.lang.String) to retrieve the attribute's value, getAttribute returns null.

Specified by:
removeAttribute in interface javax.servlet.ServletContext
Parameters:
name - a String specifying the name of the attribute to be removed

getNamedDispatcher

public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
Returns a dispatcher for the given resource name.

Specified by:
getNamedDispatcher in interface javax.servlet.ServletContext
Parameters:
name - A String resource name to use to find a RequestDispatcher.
Returns:
a RequestDispatcher for the given resource name.

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Return the value for the given context parameter name.

Specified by:
getInitParameter in interface javax.servlet.ServletContext
Parameters:
name - A String context parameter name.
Returns:
a String context parameter value.

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Return an Enumeration of all of the context parameter names.

Specified by:
getInitParameterNames in interface javax.servlet.ServletContext
Returns:
an Enumeration of String parameter names.

getName

public java.lang.String getName()
Returns the name of this servlet. This is the id string used to identify the servlet to the ServletManager.

Returns:
The servlet's name.

getLogger

public org.apache.log4j.Logger getLogger()
Return the LogChannel for the servlet. The servlet my write directly to this channel, or use the log() method, which will write to the log channel at the INFO level.

Returns:
The servlet's LogChannel.

getClassLoader

public MultiClassLoader getClassLoader()
Return the class loader used to load the servlet. Enhydra applications will use this to load the presentation objects, avoiding a second redundant class loader.

Returns:
The class loaded used to load the servlet.

getServletNames

public java.util.Enumeration getServletNames()
Returns an enumeration of the Servlet object names in this server.

Specified by:
getServletNames in interface javax.servlet.ServletContext

Enhydra 5.1 API