org.apache.mailet.base
Class GenericMailet

java.lang.Object
  extended by org.apache.mailet.base.GenericMailet
All Implemented Interfaces:
Mailet, MailetConfig
Direct Known Subclasses:
AbstractAddFooter, AbstractSign, AddHabeasWarrantMark, AddSubjectPrefix, BayesianAnalysis, BayesianAnalysisFeeder, ClamAVScan, ClassifyBounce, Counter, DumpSystemErr, ExceptionThrowingMailet, HeadersToHTTP, Identity, LogMessage, MailAttributesToMimeHeaders, Null, OnlyText, PostmasterAlias, RecipientToLowerCase, RecoverAttachment, RemoveAllMailAttributes, RemoveMailAttribute, RemoveMimeHeader, ReplaceContent, SerialiseToHTTP, ServerTime, SetMailAttribute, SetMimeHeader, SMIMECheckSignature, SMIMEDecrypt, StripAttachment, ToProcessor, UnwrapText, UseHeaderRecipients, WrapText

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

Constructor Summary
GenericMailet()
           
 
Method Summary
protected  String arrayToString(Object[] array)
          Utility method for obtaining a string representation of an array of Objects.
protected  void checkInitParameters(String[] allowedArray)
          Utility method: Checks if there are unallowed init parameters specified in the configuration file against the String[] allowedInitParameters.
 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.
 boolean getInitParameter(String name, boolean defaultValue)
          Gets a boolean valued init parameter.
 String getInitParameter(String name, String defValue)
          Returns a String containing the value of the named initialization parameter, or defValue if the parameter does not exist.
 Iterator<String> 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.
 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.
 void log(String message, Throwable t)
          Writes an explanatory message and a stack trace for a given Throwable exception to the mailet log file.
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 boolean getInitParameter(String name,
                                boolean defaultValue)

Gets a boolean valued init parameter.

A convenience method. The result is parsed from the value of the named parameter in the MailetConfig.

Parameters:
name - name of the init parameter to be queried
defaultValue - this value will be substituted when the named value cannot be parse or when the init parameter is absent
Returns:
true when the init parameter is true (ignoring case); false when the init parameter is false (ignoring case); otherwise the default value
Throws:
NullPointerException - before init(MailetConfig)

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:
a String containing the value of the initalization parameter

getInitParameter

public String getInitParameter(String name,
                               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 Iterator<String> 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 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 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:
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(String message)
Writes the specified message to a mailet log file.

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

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.

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

checkInitParameters

protected final void checkInitParameters(String[] allowedArray)
                                  throws javax.mail.MessagingException
Utility method: Checks if there are unallowed init parameters specified in the configuration file against the String[] allowedInitParameters.

Parameters:
allowedArray - array of strings containing the allowed parameter names
Throws:
javax.mail.MessagingException - if an unknown parameter name is found

arrayToString

protected final String arrayToString(Object[] array)
Utility method for obtaining a string representation of an array of Objects.



Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.