CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

servlet::GenericServlet Class Reference

#include <GenericServlet.h>

Inheritance diagram for servlet::GenericServlet:
Collaboration diagram for servlet::GenericServlet:

List of all members.


Public Member Functions

 GenericServlet ()
virtual ~GenericServlet ()
virtual void destroy ()
virtual std::string getInitParameter (const std::string &name) const
virtual std::auto_ptr
< std::vector< std::string > > 
getInitParameterNames () const
virtual ServletConfiggetServletConfig () const
virtual ServletContextgetServletContext () const
virtual std::string getServletInfo () const
virtual void init (ServletConfig &config)
virtual void init ()
virtual void log (const std::string &msg)
virtual void log (const std::string &message, const std::exception &e)
virtual void service (ServletRequest &req, ServletResponse &res)=0
virtual std::string getServletName () const

Private Attributes

ServletConfigconfig

Detailed Description

Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, extend servlet::HttpServlet instead.

GenericServlet implements the Servlet and ServletConfig interfaces. GenericServlet may be directly extended by a servlet, although it's more common to extend a protocol-specific subclass such as HttpServlet.

GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface.

To write a generic servlet, you need only override the abstract service method.

Author:
Various
Version:
$Version$

Definition at line 98 of file GenericServlet.h.


Constructor & Destructor Documentation

servlet::GenericServlet::GenericServlet (  ) 

Does nothing. All of the servlet initialization is done by one of the init methods.

Definition at line 62 of file GenericServlet.cpp.

virtual servlet::GenericServlet::~GenericServlet (  )  [inline, virtual]

Definition at line 110 of file GenericServlet.h.


Member Function Documentation

void servlet::GenericServlet::destroy (  )  [virtual]

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. See servlet::Servlet#destroy.

Implements servlet::Servlet.

Definition at line 66 of file GenericServlet.cpp.

virtual std::string servlet::GenericServlet::getInitParameter ( const std::string &  name  )  const [virtual]

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. See servlet::ServletConfig#getInitParameter.

This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig object.

Parameters:
name a String specifying the name of the initialization parameter
Returns:
String a String containing the value of the initialization parameter

Implements servlet::ServletConfig.

auto_ptr< vector< string > > servlet::GenericServlet::getInitParameterNames (  )  const [virtual]

Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters. See servlet::ServletConfig#getInitParameterNames.

This method is supplied for convenience. It gets the parameter names from the servlet's ServletConfig object.

Returns:
Enumeration an enumeration of String objects containing the names of the servlet's initialization parameters

Implements servlet::ServletConfig.

Definition at line 75 of file GenericServlet.cpp.

References servlet::ServletConfig::getInitParameterNames(), and getServletConfig().

Here is the call graph for this function:

ServletConfig & servlet::GenericServlet::getServletConfig (  )  const [virtual]

Returns this servlet's servlet::ServletConfig object.

Returns:
ServletConfig the servlet::ServletConfig object that initialized this servlet

Definition at line 81 of file GenericServlet.cpp.

References config.

Referenced by getInitParameterNames(), and getServletContext().

ServletContext & servlet::GenericServlet::getServletContext (  )  const [virtual]

Returns a reference to the servlet::ServletContext in which this servlet is running. See servlet::ServletConfig#getServletContext.

This method is supplied for convenience. It gets the context from the servlet's ServletConfig object.

Returns:
ServletContext the ServletContext object passed to this servlet by the init method

Implements servlet::ServletConfig.

Definition at line 87 of file GenericServlet.cpp.

References getServletConfig(), and servlet::ServletConfig::getServletContext().

Here is the call graph for this function:

string servlet::GenericServlet::getServletInfo (  )  const [virtual]

Returns information about the servlet, such as author, version, and copyright. By default, this method returns an empty string. Override this method to have it return a meaningful value. See servlet::Servlet#getServletInfo.

Returns:
String information about this servlet, by default an empty string

Implements servlet::Servlet.

Definition at line 93 of file GenericServlet.cpp.

string servlet::GenericServlet::getServletName (  )  const [virtual]

Returns the name of this servlet instance. See servlet::ServletConfig#getServletName.

Returns:
the name of this servlet instance

Implements servlet::ServletConfig.

Definition at line 122 of file GenericServlet.cpp.

References config, and servlet::ServletConfig::getServletName().

Here is the call graph for this function:

void servlet::GenericServlet::init (  )  [virtual]

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(servlet::ServletConfig&), simply override this method and it will be called by GenericServlet.init(servlet::ServletConfig& config). The ServletConfig object can still be retrieved via getServletConfig.

Exceptions:
servlet::ServletException if an exception occurs that interrupts the servlet's normal operation

Definition at line 105 of file GenericServlet.cpp.

Referenced by init().

void servlet::GenericServlet::init ( ServletConfig config  )  [virtual]

Called by the servlet container to indicate to a servlet that the servlet is being placed into service. See servlet::Servlet#init.

This implementation stores the servlet::ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config).

Parameters:
config the ServletConfig object that contains configutation information for this servlet
Exceptions:
ServletException if an exception occurs that interrupts the servlet's normal operation
See also:
UnavailableException

Implements servlet::Servlet.

Definition at line 98 of file GenericServlet.cpp.

References init().

Here is the call graph for this function:

virtual void servlet::GenericServlet::log ( const std::string &  message,
const std::exception &  e 
) [virtual]

Writes an explanatory message and a stack trace for a given std::exception exception to the servlet log file, prepended by the servlet's name. See servlet::ServletContext#log(const std::string& msg, std::exception& e).

Parameters:
message a std::string that describes the error or exception
e the std::exception error or exception

virtual void servlet::GenericServlet::log ( const std::string &  msg  )  [virtual]

Writes the specified message to a servlet log file, prepended by the servlet's name. See servlet::ServletContext#log(const std::string& msg).

Parameters:
msg an std::string specifying the message to be written to the log file

virtual void servlet::GenericServlet::service ( ServletRequest req,
ServletResponse res 
) [pure virtual]

Called by the servlet container to allow the servlet to respond to a request. See servlet::Servlet#service.

This method is declared abstract so subclasses, such as HttpServlet, must override it.

Parameters:
req the ServletRequest object that contains the client's request
res the ServletResponse object that will contain the servlet's response
Exceptions:
ServletException if an exception occurs that interferes with the servlet's normal operation occurred
IOException if an input or output exception occurs

Implements servlet::Servlet.

Implemented in servlet::HttpServlet.


Member Data Documentation

Definition at line 99 of file GenericServlet.h.

Referenced by getServletConfig(), and getServletName().


The documentation for this class was generated from the following files:

SourceForge.net Logo