Aaron Knauf wrote: ...
When a mailet wishes to obtain a resource, it would use code similar to the following:
------------------------------------------------------------------
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.util.List;
public void init() {
// The context returned here *is* our configuration.
Context myContext = new InitialContext();
How can this be done? Do you need to have a Classloader for each Mailet?
// What is the name of our widget server?This is not true IOC. The Mailet asks for something, it is not given it.
String widgetServerName = (String)myContext.lookup("widgetServerName");
// Obtain a datasource for the widget sales database
DataSource salesDb = (DataSource)myContext.lookup("salesDb");
// Get a list of all of the addresses to send sales new sale notifications to
List addressList = (List)myContext.lookup("notifyees");
// Obtain a reference to a custom mail repository used by this mailet
MailRepository repository = (MailRepository)myContext.lookup("myRepository");
}
-------------------------------------------------------------------
The Context returned by new InitialContext() is specific to this Mailet.
IOC in practice means that the container calls a method on the child. This is not the case here...
...
One thing I like about this is the huge scope that container implementers have for providing access to value-add features. The ability to pull an actual DataSource out of the context, rather than just a JDBC url is a good example. On the surface, this may seem like an invitation to sabotage mailet portability. I think that quite the opposite is true.Then this is not a configuration, but a ComponentManager. Avalon has separated the concepts, here they are intermixed.
There is a place when this still happens which is the Context, but it's also the most controversial part of the Framework and the most unportable one. This is basically a Context as I see it.
--
Nicola Ken Barozzi [EMAIL PROTECTED]
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
