org.apache.mailet
Class GenericMailet

java.lang.Object
  |
  +--org.apache.mailet.GenericMailet
All Implemented Interfaces:
Mailet, MailetConfig
Direct Known Subclasses:
AddFooter, AddHabeasWarrantMark, AddHeader, Counter, DumpSystemErr, ExceptionThrowingMailet, Forward, GenericListserv, GenericListservManager, Identity, JDBCAlias, JDBCVirtualUserTable, LocalDelivery, NotifyPostmaster, NotifySender, Null, PostmasterAlias, Redirect, RemoteDelivery, ServerTime, ToProcessor, ToRepository, UseHeaderRecipients

public abstract class GenericMailet
extends Object
implements Mailet, MailetConfig

GenericMailet makes writing mailets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the MailetConfig interface. GenericMailet also implements the log method, declared in the MailetContext interface.

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

Version:
1.0.0, 24/04/1999
Author:
Federico Barbieri , Stefano Mazzocchi , Pierpaolo Fumagalli , Serge Knystautas

Constructor Summary
GenericMailet()
           
 
Method Summary
 void destroy()
          Called by the mailer container to indicate to a mailet that the mailet is being taken out of service.
 String getInitParameter(String name)
          Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
 Iterator getInitParameterNames()
          Returns the names of the mailet's initialization parameters as an Iterator of String objects, or an empty Iterator if the mailet has no initialization parameters.
 MailetConfig getMailetConfig()
          Returns this matcher's MailetConfig object.
 MailetContext getMailetContext()
          Returns a reference to the MailetContext in which this mailet is running.
 String getMailetInfo()
          Returns information about the mailet, such as author, version, and copyright.
 String getMailetName()
          Returns the name of this mailet instance.
 void init()
          A convenience method which can be overridden so that there's no need to call super.init(config).
 void init(MailetConfig newConfig)
          Called by the mailet container to indicate to a mailet that the mailet is being placed into service.
 void log(String message)
          Writes the specified message to a mailet log file, prepended by the mailet's name.
 void log(String message, Throwable t)
          Writes an explanatory message and a stack trace for a given Throwable exception to the mailet log file, prepended by the mailet's name.
abstract  void service(Mail mail)
          Called by the mailet container to allow the mailet to process a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericMailet

public GenericMailet()
Method Detail

destroy

public void destroy()
Called by the mailer container to indicate to a mailet that the mailet is being taken out of service.

Specified by:
destroy in interface Mailet

getInitParameter

public String getInitParameter(String name)
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

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

Specified by:
getInitParameter in interface MailetConfig
Parameters:
name - - a String specifying the name of the initialization parameter
Returns:
String a String containing the value of the initalization parameter

getInitParameterNames

public Iterator getInitParameterNames()
Returns the names of the mailet's initialization parameters as an Iterator of String objects, or an empty Iterator if the mailet has no initialization parameters.

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

Specified by:
getInitParameterNames in interface MailetConfig
Returns:
Iterator an iterator of String objects containing the names of the mailet's initialization parameters

getMailetConfig

public MailetConfig getMailetConfig()
Returns this matcher's MailetConfig object.

Specified by:
getMailetConfig in interface Mailet
Returns:
MailetConfig the MailetConfig object that initialized this mailet

getMailetContext

public MailetContext getMailetContext()
Returns a reference to the MailetContext in which this mailet is running.

Specified by:
getMailetContext in interface MailetConfig
Returns:
MailetContext the MailetContext object passed to this mailet by the init method

getMailetInfo

public String getMailetInfo()
Returns information about the mailet, such as author, version, and copyright. By default, this method returns an empty string. Override this method to have it return a meaningful value.

Specified by:
getMailetInfo in interface Mailet
Returns:
String information about this mailet, by default an empty string

getMailetName

public String getMailetName()
Returns the name of this mailet instance.

Specified by:
getMailetName in interface MailetConfig
Returns:
the name of this mailet instance

init

public void init(MailetConfig newConfig)
          throws MessagingException

Called by the mailet container to indicate to a mailet that the mailet is being placed into service.

This implementation stores the MailetConfig object it receives from the mailet container for alter use. When overriding this form of the method, call super.init(config).

Specified by:
init in interface Mailet
Parameters:
newConfig - - a MailetConfig object containing the mailet's configuration and initialization parameters
Throws:
MessagingException - if an exception occurs that interrupts the mailet's normal operation

init

public void init()
          throws MessagingException

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

Instead of overriding init(MailetConfig), simply override this method and it will be called by GenericMailet.init(MailetConfig config). The MailetConfig object can still be retrieved via getMailetConfig().

Throws:
MessagingException - if an exception occurs that interrupts the mailet's normal operation

log

public void log(String message)
Writes the specified message to a mailet log file, prepended by the mailet's name.


log

public void log(String message,
                Throwable t)
Writes an explanatory message and a stack trace for a given Throwable exception to the mailet log file, prepended by the mailet's name.

Parameters:
message - - a String that describes the error or exception
t - - the java.lang.Throwable error or exception

service

public abstract void service(Mail mail)
                      throws MessagingException

Called by the mailet container to allow the mailet to process a message.

This method is declared abstract so subclasses must override it.

Specified by:
service in interface Mailet
Parameters:
mail - - the Mail object that contains the MimeMessage and routing information
Throws:
MessagingException - - if an exception occurs that interferes with the mailet's normal operation occurred


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."