org.apache.mailet
Class GenericMailet

java.lang.Object
  extended by org.apache.mailet.GenericMailet
All Implemented Interfaces:
Mailet, MailetConfig
Direct Known Subclasses:
AbstractAddFooter, AbstractRedirect, AbstractVirtualUserTable, AddHabeasWarrantMark, BayesianAnalysis, BayesianAnalysisFeeder, ClamAVScan, CommandListservManager, CommandListservProcessor, Counter, DumpSystemErr, ExceptionThrowingMailet, FromRepository, GenericListserv, GenericListservManager, Identity, JDBCAlias, LocalDelivery, LogMessage, Null, PostmasterAlias, RemoteDelivery, RemoveAllMailAttributes, RemoveMailAttribute, ServerTime, SetMailAttribute, SetMimeHeader, SMIMEAbstractSign, SMIMECheckSignature, SMIMEDecrypt, ToMultiRepository, ToProcessor, ToRepository, UseHeaderRecipients, UsersRepositoryAliasingForwarding, WhiteListManager

public abstract class GenericMailet
extends java.lang.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

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.
 java.lang.String getInitParameter(java.lang.String name)
          Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
 java.lang.String getInitParameter(java.lang.String name, java.lang.String defValue)
          Returns a String containing the value of the named initialization parameter, or defValue if the parameter does not exist.
 java.util.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 Mailet's MailetConfig object.
 MailetContext getMailetContext()
          Returns a reference to the MailetContext in which this mailet is running.
 java.lang.String getMailetInfo()
          Returns information about the mailet, such as author, version, and copyright.
 java.lang.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(java.lang.String message)
          Writes the specified message to a mailet log file, prepended by the mailet's name.
 void log(java.lang.String message, java.lang.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 java.lang.String getInitParameter(java.lang.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:
a String containing the value of the initalization parameter

getInitParameter

public java.lang.String getInitParameter(java.lang.String name,
                                         java.lang.String defValue)
Returns a String containing the value of the named initialization parameter, or defValue 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.

Parameters:
name - - a String specifying the name of the initialization parameter
defValue - - a String specifying the default value when the parameter is not present
Returns:
a String containing the value of the initalization parameter

getInitParameterNames

public java.util.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:
an Iterator of String objects containing the names of the mailet's initialization parameters

getMailetConfig

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

Specified by:
getMailetConfig in interface Mailet
Returns:
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:
the MailetContext object passed to this mailet by the init method

getMailetInfo

public java.lang.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:
information about this mailet, by default an empty string

getMailetName

public java.lang.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 javax.mail.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 later use. When overriding this form of the method, call super.init(config).

Specified by:
init in interface Mailet
Parameters:
MailetConfig - newconfig - the MailetConfig object that contains configutation information for this mailet
Throws:
javax.mail.MessagingException - if an exception occurs that interrupts the mailet's normal operation

init

public void init()
          throws javax.mail.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:
javax.mail.MessagingException - if an exception occurs that interrupts the mailet's normal operation

log

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

Parameters:
message - - a String specifying the message to be written to the log file

log

public void log(java.lang.String message,
                java.lang.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 to be logged

service

public abstract void service(Mail mail)
                      throws javax.mail.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:
javax.mail.MessagingException - - if an exception occurs that interferes with the mailet's normal operation


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.