You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by Glen Daniels <gd...@allaire.com> on 2001/01/23 06:48:12 UTC
Supplier pattern
The basic idea here is that what you keep in the registry isn't actual
Handler instances, it's HandlerSuppliers. A HandlerSupplier looks like
this:
public interface HandlerSupplier {
public Handler getHandler();
}
One common type of supplier is the Factory, which just generates you a new
Handler each time getHandler() is called:
public class HandlerFactory implements HandlerSupplier {
private ConfigInformation _cfg;
public HandlerFactory(ConfigInformation cfg)
{
_cfg = cfg;
}
public Handler getHandler()
{
return new AppropriateKindOfHandler(_cfg);
}
}
(you can either have one class of these per Handler class, or have a generic
one which can do a newInstance() on an appropriate Class object)
Other types of Suppliers include ones that only return a single static
instance of the Handler in question, and ones that return a member of a pool
of pre-existing Handlers.
The Supplier is initialized with the appropriate configuration information
from the WSDD for whatever particular class of Handler is involved (so it
can pass the correct constructor arguments or set the right properties
if/when it creates the Handler instances).
The beauty of this pattern is that it simply encapsulates some of the
lifecycle management issues in an extensible way, allowing us to defer some
of the more complex patterns until later implementations.
Thoughts?
--Glen