com.bristle.javalib.log
Class LoggerFinder

java.lang.Object
  extended by com.bristle.javalib.log.LoggerFinder

public class LoggerFinder
extends Object

This class makes it possible for Java servlets to access an existing Logger that may be stored in the servlet's Session context, the servlet's ServletContext (application context), or as the Logger global singleton.

Usage:
       - The typical scenario for using this class is:
         - To find a Logger:
             LoggerFinder finder = new LoggerFinder(request);
             Logger logger = finder.find();
         - To save a Logger to be found by future calls to find(): 
             finder.saveInSession(logger);
             finder.saveInServletContext(logger)
             finder.saveAsGlobalSingleton(logger)  
Assumptions:
Effects:
       - Can update the servlet's Session context, ServletContext, and/or
         the Logger global singleton.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class LoggerFinder.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Field Summary
private  HttpServletRequest m_request
           
private  String strLOGGER_ATTRIBUTE_NAME
           
 
Constructor Summary
LoggerFinder(HttpServletRequest request)
          Constructor.
 
Method Summary
 Logger find()
          Find an existing Logger, searching first the Session context of the previously specified HttpServletRequest (if any), then the ServletContext (application context) of the servlet associated with that HttpServletRequest (if any), then the Logger global singleton (if any), returning null if no Logger is found in any of those places.
 Logger findSafely()
          Find an existing Logger, suppressing all possible errors.
 void saveAsGlobalSingleton(Logger logger)
          Save the specified Logger as the Logger global singleton, to be found by future calls to find().
 void saveInServletContext(Logger logger)
          Save the specified Logger in the ServletContext to be found by future calls to find().
 void saveInSession(Logger logger)
          Save the specified Logger in the Session to be found by future calls to find().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_request

private HttpServletRequest m_request

strLOGGER_ATTRIBUTE_NAME

private final String strLOGGER_ATTRIBUTE_NAME
Constructor Detail

LoggerFinder

public LoggerFinder(HttpServletRequest request)
Constructor.

Parameters:
request - The HttpServletRequest used to locate the contexts to be searched for the Logger.
Method Detail

find

public Logger find()
Find an existing Logger, searching first the Session context of the previously specified HttpServletRequest (if any), then the ServletContext (application context) of the servlet associated with that HttpServletRequest (if any), then the Logger global singleton (if any), returning null if no Logger is found in any of those places.

Returns:
The found Logger or null.

findSafely

public Logger findSafely()
Find an existing Logger, suppressing all possible errors. It is safe to call this method from an exception handler or finally clause without fear of throwing another exception. Find an existing Logger, searching first the Session context of the previously specified HttpServletRequest (if any), then the ServletContext (application context) of the servlet associated with that HttpServletRequest (if any), then the Logger global singleton (if any), returning null if no Logger is found in any of those places, and returning null if any error occurs.

Returns:
The found Logger or null.

saveInSession

public void saveInSession(Logger logger)
Save the specified Logger in the Session to be found by future calls to find().

Parameters:
logger - The Logger.

saveInServletContext

public void saveInServletContext(Logger logger)
Save the specified Logger in the ServletContext to be found by future calls to find().

Parameters:
logger - The Logger.

saveAsGlobalSingleton

public void saveAsGlobalSingleton(Logger logger)
Save the specified Logger as the Logger global singleton, to be found by future calls to find(). Note: Since the Logger singleton is global, this affects all users of all Logger instances, not only users of LoggerFinder.

Parameters:
logger - The Logger.