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

GenericMatcher

public abstract class GenericMatcher extends Object implements Matcher, MatcherConfig

GenericMatcher implements the Matcher and MatcherConfig interfaces.

GenericMatcher makes writing matchers easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the MatcherConfig interface. GenericMatcher also implements the log method, declared in the MatcherContext interface.

To write a generic matcher, you need only override the abstract match method.

version
1.0.0, 24/04/1999

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


                            
       
        //Do nothing
    
public java.lang.StringgetCondition()

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 matcher's MatcherConfig object.

return
String a String containing the value of the initalization parameter

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

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

        return getMatcherConfig().getMailetContext();
    
public MatcherConfiggetMatcherConfig()
Returns this matcher's MatcherConfig object.

return
MatcherConfig the MatcherConfig object that initialized this matcher

        return config;
    
public java.lang.StringgetMatcherInfo()
Returns information about the matcher, 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
String information about this matcher, by default an empty string

        return "";
    
public java.lang.StringgetMatcherName()
Returns the name of this matcher instance.

return
the name of this matcher instance

        return config.getMatcherName();
    
public voidinit(MatcherConfig newConfig)

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

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

param
MatcherConfig config - the MatcherConfig object that contains configutation information for this matcher
throws
MessagingException if an exception occurs that interrupts the matcher's normal operation

        config = newConfig;
        init();
    
public voidinit()

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

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

throws
MatcherException if an exception occurs that interrupts the matcher's normal operation

        //Do nothing... can be overridden
    
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 matcher log file, prepended by the matcher's name.

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

        StringBuffer logBuffer = 
            new StringBuffer(256)
                    .append(getMatcherName())
                    .append(": ")
                    .append(message);
        getMailetContext().log(logBuffer.toString(), t);
    
public voidlog(java.lang.String message)
Writes the specified message to a matcher log file, prepended by the matcher's name.

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

        StringBuffer logBuffer = 
            new StringBuffer(256)
                    .append(getMatcherName())
                    .append(": ")
                    .append(message);
        getMailetContext().log(logBuffer.toString());
    
public abstract java.util.Collectionmatch(Mail mail)

Called by the matcher container to allow the matcher 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
return
java.util.Collection - the recipients that the mailet container should have the mailet affect.
throws
javax.mail.MessagingException - if an exception occurs that interferes with the mailet's normal operation occurred