org.apache.mailet
Class GenericMatcher

java.lang.Object
  extended by org.apache.mailet.GenericMatcher
All Implemented Interfaces:
Matcher, MatcherConfig
Direct Known Subclasses:
AbstractNetworkMatcher, AbstractQuotaMatcher, All, AttachmentFileNameIs, CompareNumericHeaderValue, FetchedFrom, GenericRecipientMatcher, GenericRegexMatcher, HasAttachment, HasHabeasWarrantMark, HasHeader, HasMailAttribute, HasMailAttributeWithValue, HasMailAttributeWithValueRegex, InSpammerBlacklist, IsInWhiteList, IsSingleRecipient, IsSMIMEEncrypted, IsSMIMESigned, IsX509CertificateSubject, RelayLimit, SenderHostIs, SenderIs, SenderIsNull, SenderIsRegex, SizeGreaterThan, SMTPAuthSuccessful, SMTPAuthUserIs, SubjectIs, SubjectStartsWith

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

Constructor Summary
GenericMatcher()
           
 
Method Summary
 void destroy()
          Called by the mailet container to indicate to a matcher that the matcher is being taken out of service.
 java.lang.String getCondition()
          Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
 MailetContext getMailetContext()
          Returns a reference to the MailetContext in which this matcher is running.
 MatcherConfig getMatcherConfig()
          Returns this matcher's MatcherConfig object.
 java.lang.String getMatcherInfo()
          Returns information about the matcher, such as author, version, and copyright.
 java.lang.String getMatcherName()
          Returns the name of this matcher instance.
 void init()
          A convenience method which can be overridden so that there's no need to call super.init(config).
 void init(MatcherConfig newConfig)
          Called by the matcher container to indicate to a matcher that the matcher is being placed into service.
 void log(java.lang.String message)
          Writes the specified message to a matcher log file, prepended by the matcher'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 matcher log file, prepended by the matcher's name.
abstract  java.util.Collection match(Mail mail)
          Called by the matcher container to allow the matcher to process a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericMatcher

public GenericMatcher()
Method Detail

destroy

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

Specified by:
destroy in interface Matcher

getCondition

public java.lang.String getCondition()

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.

Specified by:
getCondition in interface MatcherConfig
Returns:
String a String containing the value of the initalization parameter

getMatcherConfig

public MatcherConfig getMatcherConfig()
Returns this matcher's MatcherConfig object.

Specified by:
getMatcherConfig in interface Matcher
Returns:
MatcherConfig the MatcherConfig object that initialized this matcher

getMailetContext

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

Specified by:
getMailetContext in interface MatcherConfig
Returns:
MailetContext the MailetContext object passed to this matcher by the init method

getMatcherInfo

public java.lang.String getMatcherInfo()
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.

Specified by:
getMatcherInfo in interface Matcher
Returns:
String information about this matcher, by default an empty string

getMatcherName

public java.lang.String getMatcherName()
Returns the name of this matcher instance.

Specified by:
getMatcherName in interface MatcherConfig
Returns:
the name of this matcher instance

init

public void init(MatcherConfig newConfig)
          throws javax.mail.MessagingException

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

Specified by:
init in interface Matcher
Parameters:
MatcherConfig - config - the MatcherConfig object that contains configutation information for this matcher
Throws:
javax.mail.MessagingException - if an exception occurs that interrupts the matcher'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(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
javax.mail.MessagingException

log

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

Parameters:
msg - - 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 matcher log file, prepended by the matcher's name.

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

match

public abstract java.util.Collection match(Mail mail)
                                    throws javax.mail.MessagingException

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

This method is declared abstract so subclasses must override it.

Specified by:
match in interface Matcher
Parameters:
mail - - the Mail object that contains the MimeMessage and routing information
Returns:
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
MessagingException - - if an message or address parsing exception occurs or an exception that interferes with the matcher's normal operation


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.