org.mmbase.servlet
Class MMBaseServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byorg.mmbase.servlet.MMBaseServlet
All Implemented Interfaces:
org.mmbase.servlet.MMBaseStarter, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
BridgeServlet, DoveServlet, JamesServlet, RMIHandlerServlet

public class MMBaseServlet
extends javax.servlet.http.HttpServlet
implements org.mmbase.servlet.MMBaseStarter

MMBaseServlet is a base class for other MMBase servlets (like ImageServlet). Its main goal is to store a MMBase instance for all its descendants, but it can also be used as a serlvet itself, to show MMBase version information.

Since:
MMBase-1.6
Version:
$Id: MMBaseServlet.java,v 1.29 2004/03/16 14:38:38 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Field Summary
protected static MMBase mmbase
           
 
Constructor Summary
MMBaseServlet()
           
 
Method Summary
protected static void associateMapping(java.lang.String function, java.lang.String servletMapping, java.lang.Integer priority)
          Associate a given servletmapping with the given function.
protected  void decRefCount(javax.servlet.http.HttpServletRequest req)
          Decrease the reference count of the servlet
 void destroy()
           
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Serves MMBase version information.
protected  java.util.Map getAssociations()
          On default, servlets are not associated with any function.
 MMBase getMMBase()
          Returns the currently set MMBase object.
protected static java.lang.String getRequestURL(javax.servlet.http.HttpServletRequest req)
          Return URI with QueryString appended
static java.lang.String getServletByAssociation(java.lang.String function)
          Gets the name of the servlet that performs actions associated with the the given function.
static javax.servlet.http.HttpServlet getServletByMapping(java.lang.String mapping)
          Gets the servlet that belongs to the given mapping
 java.lang.String getServletInfo()
          Returns information about this servlet.
static java.util.List getServletMappings(java.lang.String servletName)
          Gets all the mappings for a given servlet.
static java.util.List getServletMappingsByAssociation(java.lang.String function)
          Gets all the mappings for a given association.
protected  void incRefCount(javax.servlet.http.HttpServletRequest req)
          Increase the reference count of the servlet (for debugging) and send running servlets to log once every 32 requests
 void init()
          The init of an MMBaseServlet checks if MMBase is running.
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          The service method is extended with calls for the refCount functionality (for performance related debugging).
 void setInitException(javax.servlet.ServletException e)
          If something went wrong (an exception occured), the caller may is informed by a call to this method.
 void setMMBase(MMBase mmb)
          Set MMBase object after initializion, in the caller.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mmbase

protected static MMBase mmbase
Constructor Detail

MMBaseServlet

public MMBaseServlet()
Method Detail

getAssociations

protected java.util.Map getAssociations()
On default, servlets are not associated with any function. This function is called in the init method.

Returns:
A map of Strings (function) -> Integer (priority). Never null.

getMMBase

public MMBase getMMBase()
Description copied from interface: org.mmbase.servlet.MMBaseStarter
Returns the currently set MMBase object.

Specified by:
getMMBase in interface org.mmbase.servlet.MMBaseStarter
Returns:
the MMBase instance or null.

setMMBase

public void setMMBase(MMBase mmb)
Description copied from interface: org.mmbase.servlet.MMBaseStarter
Set MMBase object after initializion, in the caller.

Specified by:
setMMBase in interface org.mmbase.servlet.MMBaseStarter

setInitException

public void setInitException(javax.servlet.ServletException e)
Description copied from interface: org.mmbase.servlet.MMBaseStarter
If something went wrong (an exception occured), the caller may is informed by a call to this method. (It may ignore it).

Specified by:
setInitException in interface org.mmbase.servlet.MMBaseStarter

init

public void init()
          throws javax.servlet.ServletException
The init of an MMBaseServlet checks if MMBase is running. It not then it is started.

Throws:
javax.servlet.ServletException

getServletByMapping

public static javax.servlet.http.HttpServlet getServletByMapping(java.lang.String mapping)
Gets the servlet that belongs to the given mapping

Parameters:
mapping - the mapping used to access the servlet
Returns:
the Servlet that handles the mapping

getServletMappings

public static java.util.List getServletMappings(java.lang.String servletName)
Gets all the mappings for a given servlet. So, this is a method to obtain info from web.xml.

Parameters:
servletName - the name of the servlet
Returns:
an unmodifiable list of servlet mappings for this servlet

getServletMappingsByAssociation

public static java.util.List getServletMappingsByAssociation(java.lang.String function)
Gets all the mappings for a given association. Use this to find out how to call a servlet to handle a certain type of operation or data (i.e 'images', 'attachments').

Parameters:
function - the function that identifies the type of association
Returns:
an unmodifiable list of servlet mappings associated with the function

getServletByAssociation

public static java.lang.String getServletByAssociation(java.lang.String function)
Gets the name of the servlet that performs actions associated with the the given function. Use this to find a servlet to handle a certain type of operation or data (i.e 'imageservlet', 'myimageservlet', 'images');

Parameters:
function - the function that identifies the type of association
Returns:
the name of the servlet associated with the function, or null if there is none

associateMapping

protected static void associateMapping(java.lang.String function,
                                       java.lang.String servletMapping,
                                       java.lang.Integer priority)
Associate a given servletmapping with the given function. Use this to set a servletmapping to call for a certain type of operation or data (i.e 'image-processing'); For now, only one servletmapping can be registered.

Parameters:
function - the function that identifies the type of association
servletMapping - mapping of the servlet to associate with the function
priority - priority of this association, the association only occurs if no servlet or servletmapping with higher priority for the same function is present already

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws javax.servlet.ServletException,
                  java.io.IOException
Serves MMBase version information. This doesn't do much usefull yet, but one could image lots of cool stuff here. Any other MMBase servlet will probably override this method.

Throws:
javax.servlet.ServletException
java.io.IOException

service

public void service(javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
             throws javax.servlet.ServletException,
                    java.io.IOException
The service method is extended with calls for the refCount functionality (for performance related debugging). So you can simply override doGet in extension classes, and this stays working, without having to think about it.

Throws:
javax.servlet.ServletException
java.io.IOException

getServletInfo

public java.lang.String getServletInfo()
Returns information about this servlet. Don't forget to override it.

Specified by:
getServletInfo in interface javax.servlet.Servlet

getRequestURL

protected static java.lang.String getRequestURL(javax.servlet.http.HttpServletRequest req)
Return URI with QueryString appended

Parameters:
req - The HttpServletRequest.

decRefCount

protected void decRefCount(javax.servlet.http.HttpServletRequest req)
Decrease the reference count of the servlet

Parameters:
req - The HttpServletRequest.

incRefCount

protected void incRefCount(javax.servlet.http.HttpServletRequest req)
Increase the reference count of the servlet (for debugging) and send running servlets to log once every 32 requests

Parameters:
req - The HttpServletRequest.
Warning: Scope will be changed to:
private

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Servlet


MMBase build 1.7.1.20041002