FileDocCategorySizeDatePackage
GenericMailet.javaAPI DocApache James 2.3.17938Fri Jan 12 12:56:34 GMT 2007org.apache.mailet

GenericMailet

public abstract class GenericMailet extends Object implements MailetConfig, Mailet
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

Fields Summary
private MailetConfig
config
Constructors Summary
Methods Summary
public voiddestroy()
Called by the mailer container to indicate to a mailet that the mailet is being taken out of service.


                            
       
        //Do nothing
    
public java.lang.StringgetInitParameter(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.

param
name - a String specifying the name of the initialization parameter
return
a String containing the value of the initalization parameter

        return config.getInitParameter(name);
    
public java.lang.StringgetInitParameter(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.

param
name - a String specifying the name of the initialization parameter
param
defValue - a String specifying the default value when the parameter is not present
return
a String containing the value of the initalization parameter

        String res = config.getInitParameter(name);
        if (res == null) {
            return defValue;
        } else {
            return res;
        }
    
public java.util.IteratorgetInitParameterNames()
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.

return
an Iterator of String objects containing the names of the mailet's initialization parameters

        return config.getInitParameterNames();
    
public MailetConfiggetMailetConfig()
Returns this Mailet's MailetConfig object.

return
the MailetConfig object that initialized this mailet

        return config;
    
public MailetContextgetMailetContext()
Returns a reference to the MailetContext in which this mailet is running.

return
the MailetContext object passed to this mailet by the init method

        return getMailetConfig().getMailetContext();
    
public java.lang.StringgetMailetInfo()
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.

return
information about this mailet, by default an empty string

        return "";
    
public java.lang.StringgetMailetName()
Returns the name of this mailet instance.

return
the name of this mailet instance

        return config.getMailetName();
    
public voidinit()

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

        //Do nothing... can be overriden
    
public voidinit(MailetConfig newConfig)

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).

param
MailetConfig newconfig - the MailetConfig object that contains configutation information for this mailet
throws
MessagingException if an exception occurs that interrupts the mailet's normal operation

        config = newConfig;
        init();
    
public voidlog(java.lang.String message)
Writes the specified message to a mailet log file, prepended by the mailet's name.

param
message - a String specifying the message to be written to the log file

        StringBuffer logBuffer =
            new StringBuffer(256)
                    .append(getMailetName())
                    .append(": ")
                    .append(message);
        getMailetContext().log(logBuffer.toString());
    
public voidlog(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.

param
message - a String that describes the error or exception
param
t - the java.lang.Throwable to be logged

        StringBuffer logBuffer =
            new StringBuffer(256)
                    .append(config.getMailetName())
                    .append(": ")
                    .append(message);
        getMailetContext().log(logBuffer.toString(), t);
    
public abstract voidservice(Mail mail)

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

This method is declared abstract so subclasses must override it.

param
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