Jeff,
It would probably be helpful for the Mailet to explicitly know which mailing
list it is processing for.
It may also be helpful to know which command was matched, but that's getting
even more complicated.
This is the kind of thing I as trying to do.
With the minimum changes to the current API, which is why I came up with the
idea of allowing the Mailet to create the Matcher.
In the example you describe.
The list name could be moved into the Mailet configuration rather than the
Matcher configuration.
mailet class=AvalonListservManager
listName[EMAIL PROTECTED]/listName
repositoryNamejames-list/repositoryName
/mailet
The Mailet gets the list name by reading the configuration when it is
initialised.
The Mailet then creates the Matcher, passing it the same list name.
/**
* Our Matcher.
*
*/
private Matcher matcher ;
/**
* Initialise our Matcher, using the list name from our config.
*
*/
protected void initMatcher()
throws MessagingException
{
//
// Create our Matcher.
//
matcher = new CommandForListserv() ;
MatcherConfigImpl config = new MatcherConfigImpl();
//
// Set the Matcher list name.
//
config.setCondition(myListname);
config.setMailetContext(getMailetContext());
matcher.init(config);
}
/**
* Get our Matcher, creating a new one if required.
*
*/
public Matcher getMatcher()
{
if (null == matcher)
{
initMatcher() ;
}
return matcher ;
}
So, both the Mailet and the Matcher get the same list name, set once in the
Mailet configuration.
If you want to add additional communication between the Matcher and Mailet.
To be able to change the list name for example (not a very practical example,
but just suppose).
You could extend the Matcher class, to add setListName() and getListName()
methods.
class XCommandForListserv
extends CommandForListserv
{
public void setListName(String name) { } ;
public String getListName() { } ;
}
The Mailet could then create an XCommandForListserv, and have access to the new
methods.
Internally, the Mailet has a reference to the extended class, but externally it
is still a generic Matcher.
/**
* Our extended Matcher.
*
*/
private XCommandForListserv matcher ;
/**
* Initialise our Matcher, using the list name from our config.
*
*/
protected void initMatcher()
throws MessagingException
{
//
// Create our extended Matcher.
//
matcher = new XCommandForListserv() ;
MatcherConfigImpl config = new MatcherConfigImpl();
//
// Set the Matcher list name.
//
config.setCondition(myListname);
config.setMailetContext(getMailetContext());
matcher.init(config);
}
/**
* Get our Matcher, creating a new one if required.
*
*/
public Matcher getMatcher()
{
if (null == matcher)
{
initMatcher() ;
}
return matcher ;
}
/**
* Change the list name for no obvious reason.
*
*/
public void sillyExample(String name)
{
if (null != matcher)
{
matcher.setListName(name) ;
}
}
Would this enable you to do what you wanted ?
Hopefully, without too many side effects on the rest of the Mailet / Matcher
code already in place.
In theory, it would be possible to extend XCommandForListserv to enable the
Mailet to ask the Matcher what command was matched.
However, it would probably need to be thread safe and sync possible, but a
bit more complicated.
Hope this helps,
Dave
Jeff Keyser wrote:
I agree that the work of matching and doing something should be separate.
However, I'd like to suggest an alternative way of communicating, since it
may be helpful for a Mailet to know what parameters were user by the
Matcher.
I'm thinking specifically about the CommandForListserv Matcher and the
AvalonListservManager Mailet. It would probably be helpful for the Mailet
to explicitly know which mailing list it is processing for. It may also be
helpful to know which command was matched, but that's getting even more
complicated.
How to do this? I'm not sure, but if it can be done cleanly, I see it being
useful.
-Original Message-
From: Andrew Timberlake [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 22, 2002 12:00 PM
To: [EMAIL PROTECTED]
Subject: [Fwd: Re: Mailet API]
Thanks Dave for the response
I'm forwarding this thread back into the list as I would like to hear
the main developers, and others, feedback and insight into this.
Thanks
Andrew
-Forwarded Message-
From: Dave Morris [EMAIL PROTECTED]
To: Andrew Timberlake [EMAIL PROTECTED]
Subject: Re: Mailet API
Date: 22 Apr 2002 16:19:22