Schaible, J�rg wrote:
Hi Berin,
To make it a little more clear, consider following:
<providers id="p">
<provider id="a"/>
<provider id="b" />
</providers>
I know I could do a selector.select("a"), but I don't know how many
of these providers there are, nor what they're called..
Yep, a selector is the wrong tool for this. In Phoenix, you can
access the components as an array, or a map, or a list.
Unfortunately,
you can't expect that same behavior anywhere else.
I'll try to accomplish something similar with Fortress.
That said, you would have something along the lines of a
ProviderManager
which would allow you to gain all Providers via a simple
access method.
It might even let you specify which one exactly. An example interface
would be below:
interface ProviderManager
{
String ROLE = ProviderManager.class.getName();
Provider[] getAllProviders();
Provider findProvider(String hint);
release( Provider provider );
release( Provider[] provider );
}
** Note: If none of your providers are pooled, then they do not need
to be released. That makes the client code a bit easier to write.
The ProviderManager would create and manage all the individual
Providers that your system uses. WHen it is shut down, it in turn
destroys all the providers it has created.
Currently I would just create a Container implementation (by extending the AbstratcContainer or DefaultContainer) and use a DefaultContainerManager. Right point to start?
Yep. Now, you have direct access via protected members to the internal
setup of the container. When you look at the Map of components, the
first level connects you to a map for all components of the same role.
That Map allows you to access all the components that implement that
role by their id (or hint).
What you want to do to get the collection of providers exposed is
something like this:
public Provider[] getProviders()
{
final Map hintMap = (Map)m_mapper.get( role );
Provider[] providers = null;
if( null != hintMap )
{
Collection providerSet = hintMap.values();
providers = new Provider[providerSet.size()];
Iterator it = providerSet.iterator();
for ( int i = 0; it.hasNext(); i++ )
{
providers[i] = ((ComponentHandler)it.next()).get();
}
}
else
{
providers = new Provider[] {};
}
return providers;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]