com.caucho.server.http
Class Application

java.lang.Object
  |
  +--com.caucho.server.http.Application
All Implemented Interfaces:
CauchoApplication, ServletContext

public class Application
extends java.lang.Object
implements CauchoApplication

The state for a servlet application. Manages sessions, servlets, class loaders and configuration.


Method Summary
 void addDepend(Path path)
          Add a dependency
 void addListener(ExitListener listener)
          Adds a listener to be notified when the Application closes.
 void clearCache()
          Clears the cache.
static ServletException error(RegistryNode node, java.lang.String msg)
          Throws a configuration error for a given configuration line number.
static ServletException error(RegistryNode node, java.lang.Throwable e)
          Throws a configuration error for a given configuration line number.
 Path getAppDir()
          Returns the application's root directory.
 java.lang.String getAppDirName()
          Returns the user's string for the application root directory.
 Path getAppInf()
          Returns the APP-INF directory.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the servlet container attribute with the given name, or null if there is no attribute by that name.
 java.util.Enumeration getAttributeNames()
          Returns an Enumeration containing the attribute names available within this servlet context.
 ServletAuthenticator getAuthenticator()
          Returns the application's authenticator.
 java.lang.String getChain(java.lang.String mimeType)
          Returns the chained servlet name by the mime-type.
 DynamicClassLoader getClassLoader()
          Returns the class loader for the application.
 ServletContext getContext(java.lang.String name)
          Returns the named servlet context.
 java.lang.String getContextPath()
           
 java.util.ArrayList getDepends()
          Return all the dependencies
 java.lang.String getHost()
          Returns the application's virtual host name.
 java.lang.String getInitParameter(java.lang.String name)
          Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.
 java.util.Enumeration getInitParameterNames()
          Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.
 javax.naming.Context getJndiContext()
          Returns the JNDI context for this application.
 RequestDispatcher getLoginDispatcher(java.lang.String uriPath)
          Returns a request dispatcher for the given uripath.
 int getMajorVersion()
          Returns the Servlet API major version
 java.lang.String getMimeType(java.lang.String path)
          Returns the mime-type for a uri.
 int getMinorVersion()
          Returns the Servlet API minor version
 RequestDispatcher getNamedDispatcher(java.lang.String name)
          Returns a RequestDispatcher object that acts as a wrapper for the named servlet.
 RegistryNode getOriginalRegistry()
           
 java.util.HashMap getPathVariableMap()
           
 long getRandomSeed()
          Returns the server's random number generator.
 java.lang.String getRealPath(java.lang.String uri)
          Returns the physical path for the uri, in native path.
 RegistryNode getRegistry()
           
 RequestDispatcher getRequestDispatcher(java.lang.String uriPath)
          Returns a request dispatcher for the given uripath.
 java.net.URL getResource(java.lang.String name)
          Returns a resource for the given uri.
 java.io.InputStream getResourceAsStream(java.lang.String uripath)
          Returns the resource for a uripath as an input stream.
 java.util.Set getResourcePaths(java.lang.String prefix)
          Returns an enumeration of all the resources.
 ServletServer getServer()
          Returns the servlet server.
 java.lang.String getServerInfo()
          Returns the server identification string.
 Servlet getServlet(java.lang.String name)
          Deprecated.  
 java.lang.String getServletContextName()
          Returns the name of this web application correponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.
 java.util.Enumeration getServletNames()
          Deprecated.  
 java.util.Enumeration getServlets()
          Deprecated.  
 com.caucho.http.session.SessionManager getSessionManager()
          Returns the application's SessionManager.
 java.lang.String getURL()
           
 VirtualHost getVirtualHost()
          Returns the application's virtual host.
 Path getWar()
          Return the underlying war.
 Path getWorkDir()
          Returns the application's jsp work directory.
 void log(java.lang.Exception e, java.lang.String msg)
          Deprecated.  
 void log(java.lang.String message)
          Logs a message to the error file.
 void log(java.lang.String message, java.lang.Throwable e)
          Error logging
 void log(java.lang.String message, java.lang.Throwable e, HttpServletRequest request, HttpServletResponse response)
          Error logging
 void removeAttribute(java.lang.String name)
          Removes an attribute from the servlet context.
 void restart()
          Restarts the application.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets an application attribute.
 void setWar(Path war)
          Set the underlying war.
 java.lang.String toString()
           
static void verifyElements(RegistryNode node, IntMap validElements)
          Verify that all the child elements of the node are actually allowed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getPathVariableMap

public java.util.HashMap getPathVariableMap()

getVirtualHost

public VirtualHost getVirtualHost()
Returns the application's virtual host.

getServer

public ServletServer getServer()
Returns the servlet server.

getServerInfo

public java.lang.String getServerInfo()
Returns the server identification string.
Specified by:
getServerInfo in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
a String containing at least the servlet container name and version number

getMajorVersion

public int getMajorVersion()
Returns the Servlet API major version
Specified by:
getMajorVersion in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
2

getMinorVersion

public int getMinorVersion()
Returns the Servlet API minor version
Specified by:
getMinorVersion in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
3

getRandomSeed

public long getRandomSeed()
Returns the server's random number generator.

getContext

public ServletContext getContext(java.lang.String name)
Returns the named servlet context. The name is relative to the URL root, not the application root.
Specified by:
getContext in interface ServletContext
Parameters:
name - absolute url naming the context.
Returns:
the specified ServletContext or null.

getSessionManager

public com.caucho.http.session.SessionManager getSessionManager()
Returns the application's SessionManager.

getRealPath

public java.lang.String getRealPath(java.lang.String uri)
Returns the physical path for the uri, in native path. URI is relative to the contextPath.
Specified by:
getRealPath in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
path - a String specifying a virtual path
Returns:
a String specifying the real path, or null if the translation cannot be performed

getMimeType

public java.lang.String getMimeType(java.lang.String path)
Returns the mime-type for a uri. The uri is relative to the contextPath.
Specified by:
getMimeType in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
file - a String specifying the name of a file
Returns:
a String specifying the file's MIME type

getAuthenticator

public ServletAuthenticator getAuthenticator()
Returns the application's authenticator.
Specified by:
getAuthenticator in interface CauchoApplication

getResource

public java.net.URL getResource(java.lang.String name)
Returns a resource for the given uri.

Note: jdk 1.1.x doesn't appear to allow creation of private URL streams.

Specified by:
getResource in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
path - a String specifying the path to the 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 pathname is not given in the correct form

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String uripath)
Returns the resource for a uripath as an input stream.
Specified by:
getResourceAsStream in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
name - a String specifying the path to the 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 prefix)
Returns an enumeration of all the resources.
Specified by:
getResourcePaths in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
the - partial path used to match the resources, which must start with a /
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.

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(java.lang.String uriPath)
Returns a request dispatcher for the given uripath.
Specified by:
getRequestDispatcher in interface ServletContext
Parameters:
uriPath - absolute uri interpreted as relative to the app root.

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(java.lang.String name)
Description copied from interface: ServletContext
Returns a RequestDispatcher object that acts as a wrapper for the named servlet.

Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor. A servlet instance can determine its name using ServletConfig.getServletName().

This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.

Specified by:
getNamedDispatcher in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
name - a String specifying the name of a servlet to wrap
Returns:
a RequestDispatcher object that acts as a wrapper for the named servlet
See Also:
RequestDispatcher, ServletContext.getContext(java.lang.String), ServletConfig.getServletName()

getLoginDispatcher

public RequestDispatcher getLoginDispatcher(java.lang.String uriPath)
                                     throws ServletException
Returns a request dispatcher for the given uripath.
Parameters:
uriPath - absolute uri interpreted as relative to the app root.

restart

public void restart()
Restarts the application.

log

public void log(java.lang.String message)
Logs a message to the error file.
Specified by:
log in interface ServletContext
Parameters:
msg - the message to log

log

public void log(java.lang.Exception e,
                java.lang.String msg)
Deprecated.  

Specified by:
log in interface ServletContext

log

public void log(java.lang.String message,
                java.lang.Throwable e)
Error logging
Specified by:
log in interface CauchoApplication
Parameters:
message - message to log
e - stack trace of the error

log

public void log(java.lang.String message,
                java.lang.Throwable e,
                HttpServletRequest request,
                HttpServletResponse response)
Error logging
Parameters:
message - message to log
e - stack trace of the error

getJndiContext

public javax.naming.Context getJndiContext()
Returns the JNDI context for this application.

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: ServletContext
Returns the servlet container attribute with the given name, or null if there is no attribute by that name. An attribute allows a servlet container to give the servlet additional information not already provided by this interface. See your server documentation for information about its attributes. A list of supported attributes can be retrieved using getAttributeNames.

The attribute is returned as a java.lang.Object or some subclass. Attribute names should follow the same convention as package names. The Java Servlet API specification reserves names matching java.*, javax.*, and sun.*.

Specified by:
getAttribute in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
name - a String specifying the name of the attribute
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()
Description copied from interface: ServletContext
Returns an Enumeration containing the attribute names available within this servlet context. Use the ServletContext.getAttribute(java.lang.String) method with an attribute name to get the value of an attribute.
Specified by:
getAttributeNames in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
an Enumeration of attribute names
See Also:
ServletContext.getAttribute(java.lang.String)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Sets an application attribute.
Specified by:
setAttribute in interface ServletContext
Parameters:
name - the name of the attribute
value - the value of the attribute

removeAttribute

public void removeAttribute(java.lang.String name)
Removes an attribute from the servlet context.
Specified by:
removeAttribute in interface ServletContext
Parameters:
name - the name of the attribute to remove.

getServlet

public Servlet getServlet(java.lang.String name)
Deprecated.  

Specified by:
getServlet in interface ServletContext

getServlets

public java.util.Enumeration getServlets()
Deprecated.  

Specified by:
getServlets in interface ServletContext

getServletNames

public java.util.Enumeration getServletNames()
Deprecated.  

Specified by:
getServletNames in interface ServletContext

getServletContextName

public java.lang.String getServletContextName()
Description copied from interface: ServletContext
Returns the name of this web application correponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.
Specified by:
getServletContextName in interface CauchoApplication
Following copied from interface: javax.servlet.ServletContext
Returns:
The name of the web application or null if no name has been declared in the deployment descriptor.

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Description copied from interface: ServletContext
Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

This method can make available configuration information useful to an entire "web application". For example, it can provide a webmaster's email address or the name of a system that holds critical data.

Specified by:
getInitParameter in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
name - a String containing the name of the parameter whose value is requested
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()
Description copied from interface: ServletContext
Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.
Specified by:
getInitParameterNames in interface ServletContext
Following copied from 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)

getContextPath

public java.lang.String getContextPath()
Specified by:
getContextPath in interface CauchoApplication

getURL

public java.lang.String getURL()

getAppDir

public Path getAppDir()
Returns the application's root directory.
Specified by:
getAppDir in interface CauchoApplication

getAppDirName

public java.lang.String getAppDirName()
Returns the user's string for the application root directory.

getAppInf

public Path getAppInf()
Returns the APP-INF directory.

getWar

public Path getWar()
Return the underlying war.

setWar

public void setWar(Path war)
Set the underlying war.

addDepend

public void addDepend(Path path)
Add a dependency

getDepends

public java.util.ArrayList getDepends()
Return all the dependencies

getOriginalRegistry

public RegistryNode getOriginalRegistry()

getRegistry

public RegistryNode getRegistry()
Specified by:
getRegistry in interface CauchoApplication

getHost

public java.lang.String getHost()
Returns the application's virtual host name.
Specified by:
getHost in interface CauchoApplication

getChain

public java.lang.String getChain(java.lang.String mimeType)
Returns the chained servlet name by the mime-type. XXX: this will likely change with the Servlet 2.3 filters.
Specified by:
getChain in interface CauchoApplication

getClassLoader

public DynamicClassLoader getClassLoader()
Returns the class loader for the application. In general the class loader will have $APP_DIR/WEB-INF/classes and $APP_DIR/WEB-INF/lib.
Specified by:
getClassLoader in interface CauchoApplication
Returns:
the application's class loader.

addListener

public void addListener(ExitListener listener)
Adds a listener to be notified when the Application closes.
Specified by:
addListener in interface CauchoApplication
Parameters:
listener - the object to notify on close

clearCache

public void clearCache()
Clears the cache.
Specified by:
clearCache in interface CauchoApplication

getWorkDir

public Path getWorkDir()
Returns the application's jsp work directory.

verifyElements

public static void verifyElements(RegistryNode node,
                                  IntMap validElements)
                           throws ServletException
Verify that all the child elements of the node are actually allowed.
Parameters:
node - the configuration node
validElements - mapping of valid child elements.

error

public static ServletException error(RegistryNode node,
                                     java.lang.String msg)
Throws a configuration error for a given configuration line number.
Parameters:
node - the configuration node throwing the error.
msg - the error message.

error

public static ServletException error(RegistryNode node,
                                     java.lang.Throwable e)
Throws a configuration error for a given configuration line number.
Parameters:
node - the configuration node throwing the error.
e - exception thrown for that node.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object