bloritsch 2002/06/18 11:45:36
Modified: fortress/src/java/org/apache/excalibur/fortress
AbstractContainer.java Container.java
fortress/src/java/org/apache/excalibur/fortress/handler
AbstractComponentHandler.java ComponentFactory.java
ComponentHandler.java FactoryComponentHandler.java
PerThreadComponentHandler.java
PoolableComponentHandler.java
ThreadSafeComponentHandler.java
Added: fortress/src/java/org/apache/excalibur/fortress/lookup
ComponentServiceManager.java
FortressComponentManager.java
FortressComponentSelector.java
FortressServiceManager.java
FortressServiceSelector.java
Log:
enable Fortress to use ServiceManager--needs testing
Revision Changes Path
1.40 +21 -206
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- AbstractContainer.java 18 Jun 2002 14:25:49 -0000 1.39
+++ AbstractContainer.java 18 Jun 2002 18:45:36 -0000 1.40
@@ -30,9 +30,14 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
import org.apache.excalibur.event.Queue;
import org.apache.excalibur.event.command.Command;
import org.apache.excalibur.fortress.handler.ComponentHandler;
+import org.apache.excalibur.fortress.lookup.FortressComponentManager;
+import org.apache.excalibur.fortress.lookup.FortressComponentSelector;
+import org.apache.excalibur.fortress.lookup.FortressServiceManager;
import org.apache.excalibur.fortress.util.ExcaliburRoleManager;
import org.apache.excalibur.fortress.util.RoleManager;
import org.apache.excalibur.mpool.PoolManager;
@@ -245,7 +250,7 @@
{
if( !hintMap.containsKey( "selector" ) )
{
- hintMap.put( "selector", new ContainerComponentSelector(
this, role ) );
+ hintMap.put( "selector", new FortressComponentSelector(
this, role ) );
}
}
else
@@ -276,7 +281,8 @@
handler = (ComponentHandler)constructor.newInstance( new
Object[]{
klass,
configuration,
- new ContainerComponentManager( this, m_manager ),
+ new FortressComponentManager( this, m_manager ),
+ new FortressServiceManager( this, m_manager ),
m_context
} );
}
@@ -314,15 +320,15 @@
* @return Object a reference to the ComponentHandler or
ComponentSelector for the
* role/hint combo.
*/
- protected Object get( final String role, final Object hint )
- throws ComponentException
+ public Object get( final String role, final Object hint )
+ throws ServiceException
{
BucketMap hintMap = (BucketMap)m_mapper.get( role );
Object value;
if( null == hintMap )
{
- throw new ComponentException( role + "/" + hint.toString(),
"Component does not exist" );
+ throw new ServiceException( role + "/" + hint.toString(),
"Component does not exist" );
}
if( null == hint )
@@ -341,7 +347,7 @@
if( null == value )
{
- throw new ComponentException( role + "/" + hint.toString(),
"Component does not exist" );
+ throw new ServiceException( role + "/" + hint.toString(),
"Component does not exist" );
}
return value;
@@ -358,7 +364,7 @@
*
* @return true if a reference to the role exists.
*/
- protected boolean has( final String role, final Object hint )
+ public boolean has( final String role, final Object hint )
{
BucketMap hintMap = (BucketMap)m_mapper.get( role );
@@ -478,209 +484,18 @@
*/
protected final ComponentManager getComponentManager()
{
- return new ContainerComponentManager( this, m_manager );
- }
-
- /**
- * This is the Default ComponentLocator for the Container. It provides
- * a very simple abstraction, and makes it easy for the Container to
manage
- * the references.
- */
- protected static final class ContainerComponentManager
- implements ComponentManager
- {
- private final AbstractContainer m_components;
- private final BucketMap m_used;
- private final ComponentManager m_parent;
-
- /**
- * This constructor is for a ContainerComponentManager with no parent
- * ComponentLocator
- */
- public ContainerComponentManager( final AbstractContainer container )
- {
- this( container, null );
- }
-
- /**
- * This constructor is for a ContainerComponentManager with a parent
- * ComponentLocator
- */
- public ContainerComponentManager( final AbstractContainer container,
final ComponentManager parent )
- {
- m_parent = parent;
- m_components = container;
- m_used = new BucketMap();
- }
-
- public Component lookup( String role )
- throws ComponentException
- {
- Object temp = null;
-
- try
- {
- temp = m_components.get( role, null );
- }
- catch( ComponentException ce )
- {
- /* Logic is thus:
- * If we have the component and the get threw an exception,
we need to report that.
- * Otherwise, do the lookup on our parent
- * Otherwise, just throw the exception
- */
- if( m_components.has( role, null ) )
- {
- throw ce;
-
- }
- else if( null != m_parent )
- {
- return m_parent.lookup( role );
- }
- else
- {
- throw ce;
- }
- }
-
- if( temp instanceof ComponentSelector )
- {
- return (Component)temp;
- }
-
- if( !( temp instanceof ComponentHandler ) )
- {
- throw new ComponentException( role, "Invalid entry in
component manager" );
- }
-
- ComponentHandler handler = (ComponentHandler)temp;
-
- final Component component;
-
- try
- {
- if( !handler.isInitialized() )
- {
- handler.initialize();
- }
-
- component = handler.get();
- }
- catch( ComponentException ce )
- {
- throw ce; // rethrow
- }
- catch( Exception e )
- {
- throw new ComponentException( role, "Could not return a
reference to the Component", e );
- }
-
- m_used.put( component, handler );
-
- return component;
- }
-
- public boolean hasComponent( String role )
- {
- final boolean hasComponent = m_components.has( role, null );
-
- if( !hasComponent && null != m_parent )
- {
- return m_parent.hasComponent( role );
- }
-
- return hasComponent;
- }
-
- public void release( Component component )
- {
- final ComponentHandler handler;
-
- handler = (ComponentHandler)m_used.remove( component );
-
- if( null == handler && null != m_parent )
- {
- m_parent.release( component );
- return;
- }
-
- handler.put( component );
- }
+ return new FortressComponentManager( this, m_manager );
}
/**
- * This is the Default ComponentSelector for the Container. It provides
- * a very simple abstraction, and makes it easy for the Container to
manage
- * the references.
+ * Exposes to subclasses the service manager which this container
+ * uses to manage its child components.
+ *
+ * @return the child component manager
*/
- protected static final class ContainerComponentSelector
- implements ComponentSelector
+ protected final ServiceManager getServiceManager()
{
- private final String m_role;
- private final AbstractContainer m_components;
- private final BucketMap m_used;
-
- public ContainerComponentSelector( final AbstractContainer
container, final String role )
- {
- m_role = role;
- m_components = container;
- m_used = new BucketMap();
- }
-
- public Component select( final Object hint )
- throws ComponentException
- {
- if( null == hint )
- {
- throw new IllegalArgumentException( "hint cannot be null" );
- }
-
- ComponentHandler handler = (ComponentHandler)m_components.get(
m_role, hint );
-
- if( null == handler )
- {
- throw new ComponentException( m_role + "/" +
hint.toString(), "The hint does not exist in the ComponentSelector" );
- }
-
- final Component component;
-
- try
- {
- if( !handler.isInitialized() )
- {
- handler.initialize();
- }
-
- component = handler.get();
- }
- catch( ComponentException ce )
- {
- throw ce; // rethrow
- }
- catch( Exception e )
- {
- throw new ComponentException( m_role + "/" +
hint.toString(), "Could not return a reference to the Component", e );
- }
-
- m_used.put( component, handler );
-
- return component;
- }
-
- public boolean hasComponent( Object hint )
- {
- return m_components.has( m_role, hint );
- }
-
- public void release( Component component )
- {
- final ComponentHandler handler;
-
- handler = (ComponentHandler)m_used.remove( component );
-
- handler.put( component );
- }
+ return new FortressServiceManager( this, m_manager );
}
/**
1.12 +5 -1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/Container.java
Index: Container.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/Container.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Container.java 4 Apr 2002 16:04:28 -0000 1.11
+++ Container.java 18 Jun 2002 18:45:36 -0000 1.12
@@ -7,6 +7,8 @@
*/
package org.apache.excalibur.fortress;
+import org.apache.avalon.framework.service.ServiceException;
+
/**
* The Container is an interface used to assist Container developers to
obtain
* the desired object from the Context. All communication from the
@@ -17,5 +19,7 @@
*/
public interface Container extends ContainerConstants
{
+ Object get( String role, Object hint) throws ServiceException;
+ boolean has( String role, Object hint );
}
1.4 +6 -5
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java
Index: AbstractComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractComponentHandler.java 6 Jun 2002 04:47:10 -0000 1.3
+++ AbstractComponentHandler.java 18 Jun 2002 18:45:36 -0000 1.4
@@ -11,11 +11,11 @@
import org.apache.avalon.excalibur.instrument.Instrumentable;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.fortress.util.RoleManager;
@@ -56,11 +56,12 @@
public AbstractComponentHandler( final Class componentClass,
final Configuration config,
final ComponentManager manager,
+ final ServiceManager service,
final Context context )
throws Exception
{
m_logkit = (LoggerManager)context.get( Container.LOGGER_MANAGER );
- m_factory = new ComponentFactory( componentClass, config, manager,
context, m_logkit );
+ m_factory = new ComponentFactory( componentClass, config, manager,
service, context, m_logkit );
}
public boolean isInitialized()
@@ -77,7 +78,7 @@
/**
* Get a reference of the desired Component
*/
- public Component get()
+ public Object get()
throws Exception
{
if( !m_initialized )
@@ -100,7 +101,7 @@
/**
* Return a reference of the desired Component
*/
- public void put( final Component component )
+ public void put( final Object component )
{
if( !m_initialized )
{
1.13 +9 -1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java
Index: ComponentFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ComponentFactory.java 6 Jun 2002 04:47:10 -0000 1.12
+++ ComponentFactory.java 18 Jun 2002 18:45:36 -0000 1.13
@@ -19,6 +19,7 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.excalibur.mpool.ObjectFactory;
@@ -49,6 +50,10 @@
*/
private ComponentManager m_componentManager;
+ /** The component manager for this component.
+ */
+ private ServiceManager m_serviceManager;
+
/** The configuration for this component.
*/
private Configuration m_configuration;
@@ -72,12 +77,14 @@
public ComponentFactory( final Class componentClass,
final Configuration configuration,
final ComponentManager componentManager,
+ final ServiceManager serviceManager,
final Context context,
final LoggerManager logkit )
{
m_componentClass = componentClass;
m_configuration = configuration;
m_componentManager = componentManager;
+ m_serviceManager = serviceManager;
m_context = context;
m_logManager = logkit;
m_logger = m_logManager.getLoggerForCategory( "system.factory" );
@@ -114,6 +121,7 @@
ContainerUtil.contextualize( component, m_context );
ContainerUtil.compose( component, m_componentManager );
+ ContainerUtil.service( component, m_serviceManager );
ContainerUtil.configure( component, m_configuration );
if( component instanceof Parameterizable )
1.9 +5 -4
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentHandler.java
Index: ComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ComponentHandler.java 13 Jun 2002 17:24:51 -0000 1.8
+++ ComponentHandler.java 18 Jun 2002 18:45:36 -0000 1.9
@@ -9,10 +9,10 @@
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.service.ServiceManager;
/**
* The ComponentHandler interface marks the ComponentHandler implementations.
@@ -29,6 +29,7 @@
Class.class,
Configuration.class,
ComponentManager.class,
+ ServiceManager.class,
Context.class
};
@@ -43,11 +44,11 @@
* Gets the current reference to a Component according to the policy of
the
* implementation.
*/
- Component get() throws Exception;
+ Object get() throws Exception;
/**
* Puts the reference back in the ComponentHandler according to the
policy
* of the implementation.
*/
- void put( Component component );
+ void put( Object component );
}
1.17 +7 -6
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/FactoryComponentHandler.java
Index: FactoryComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/FactoryComponentHandler.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FactoryComponentHandler.java 6 Jun 2002 04:28:50 -0000 1.16
+++ FactoryComponentHandler.java 18 Jun 2002 18:45:36 -0000 1.17
@@ -8,10 +8,10 @@
package org.apache.excalibur.fortress.handler;
import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.service.ServiceManager;
/**
* The FactoryComponentHandler to make sure components are initialized
@@ -33,10 +33,11 @@
public FactoryComponentHandler( final Class componentClass,
final Configuration config,
final ComponentManager manager,
+ final ServiceManager service,
final Context context )
throws Exception
{
- super( componentClass, config, manager, context );
+ super( componentClass, config, manager, service, context );
m_logger = m_logkit.getLoggerForCategory( "system.handler.factory" );
m_name = "FactoryComponentHandler";
}
@@ -61,18 +62,18 @@
/**
* Get a reference of the desired Component
*/
- public Component get()
+ public Object get()
throws Exception
{
super.get();
- return (Component)m_factory.newInstance();
+ return m_factory.newInstance();
}
/**
* Return a reference of the desired Component
*/
- public void put( final Component component )
+ public void put( final Object component )
{
super.put( component );
1.18 +7 -11
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PerThreadComponentHandler.java
Index: PerThreadComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PerThreadComponentHandler.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- PerThreadComponentHandler.java 6 Jun 2002 04:27:57 -0000 1.17
+++ PerThreadComponentHandler.java 18 Jun 2002 18:45:36 -0000 1.18
@@ -8,10 +8,10 @@
package org.apache.excalibur.fortress.handler;
import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.service.ServiceManager;
/**
* The ThreadSafeComponentHandler to make sure components are initialized
@@ -35,10 +35,11 @@
public PerThreadComponentHandler( final Class componentClass,
final Configuration config,
final ComponentManager manager,
+ final ServiceManager service,
final Context context )
throws Exception
{
- super( componentClass, config, manager, context );
+ super( componentClass, config, manager, service, context );
m_instance = new ThreadLocalComponent( m_factory );
m_logger = m_logkit.getLoggerForCategory( "system.handler.perthread"
);
m_name = "PerThreadComponentHandler";
@@ -73,18 +74,18 @@
/**
* Get a reference of the desired Component
*/
- public final Component get()
+ public final Object get()
throws Exception
{
super.get();
- return m_instance.getComponent();
+ return m_instance.get();
}
/**
* Return a reference of the desired Component
*/
- public void put( final Component component )
+ public void put( final Object component )
{
super.put( component );
}
@@ -118,11 +119,6 @@
{
return null;
}
- }
-
- public Component getComponent()
- {
- return (Component)this.get();
}
}
}
1.21 +7 -6
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java
Index: PoolableComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- PoolableComponentHandler.java 6 Jun 2002 04:27:22 -0000 1.20
+++ PoolableComponentHandler.java 18 Jun 2002 18:45:36 -0000 1.21
@@ -8,10 +8,10 @@
package org.apache.excalibur.fortress.handler;
import org.apache.avalon.excalibur.logger.LoggerManager;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.service.ServiceManager;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.mpool.Pool;
import org.apache.excalibur.mpool.PoolManager;
@@ -45,10 +45,11 @@
public PoolableComponentHandler( final Class componentClass,
final Configuration config,
final ComponentManager manager,
+ final ServiceManager service,
final Context context )
throws Exception
{
- super( componentClass, config, manager, context );
+ super( componentClass, config, manager, service, context );
m_poolMin = config.getAttributeAsInteger( "pool-min", 10 );
m_logger = m_logkit.getLoggerForCategory( "system.handler.poolable"
);
m_poolManager = (PoolManager)context.get( Container.POOL_MANAGER );
@@ -79,18 +80,18 @@
/**
* Get a reference of the desired Component
*/
- public Component get()
+ public Object get()
throws Exception
{
super.get();
- return (Component)m_pool.acquire();
+ return m_pool.acquire();
}
/**
* Return a reference of the desired Component
*/
- public void put( final Component component )
+ public void put( final Object component )
{
super.put( component );
1.16 +8 -7
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java
Index: ThreadSafeComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ThreadSafeComponentHandler.java 17 Jun 2002 18:54:27 -0000 1.15
+++ ThreadSafeComponentHandler.java 18 Jun 2002 18:45:36 -0000 1.16
@@ -10,11 +10,11 @@
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
/**
* The ThreadSafeComponentHandler to make sure components are initialized
@@ -27,7 +27,7 @@
*/
public final class ThreadSafeComponentHandler extends
AbstractComponentHandler
{
- private Component m_instance;
+ private Object m_instance;
/**
* Create a ComponentHandler that takes care of hiding the details of
@@ -37,10 +37,11 @@
public ThreadSafeComponentHandler( final Class componentClass,
final Configuration config,
final ComponentManager manager,
+ final ServiceManager service,
final Context context )
throws Exception
{
- super( componentClass, config, manager, context );
+ super( componentClass, config, manager, service, context );
m_logger = m_logkit.getLoggerForCategory(
"system.handler.threadsafe" );
m_name = "ThreadSafeComponentHandler";
}
@@ -58,7 +59,7 @@
if( m_instance == null )
{
- m_instance = (Component)this.m_factory.newInstance();
+ m_instance = this.m_factory.newInstance();
}
if( m_logger.isDebugEnabled() )
@@ -79,7 +80,7 @@
/**
* Get a reference of the desired Component
*/
- public final Component get()
+ public final Object get()
throws Exception
{
super.get();
@@ -90,7 +91,7 @@
/**
* Return a reference of the desired Component
*/
- public void put( final Component component )
+ public void put( final Object component )
{
super.put( component );
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/ComponentServiceManager.java
Index: ComponentServiceManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.lookup;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
/**
* This is the Default ComponentManager for the Container. It provides
* a very simple abstraction, and makes it easy for the Container to manage
* the references.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/06/18 18:45:36 $
*/
public class ComponentServiceManager implements ServiceManager
{
private final ComponentManager m_manager;
/**
* This constructor is a constructor for a ComponentServiceManager
*/
public ComponentServiceManager( final ComponentManager wrapped )
{
m_manager = wrapped;
}
public Object lookup( String role )
throws ServiceException
{
Object temp = null;
try
{
temp = m_manager.lookup( role );
}
catch( ComponentException ce )
{
throw new ServiceException( role, "Could not return a reference
to the Component", ce );
}
return temp;
}
public boolean hasService( String role )
{
return m_manager.hasComponent( role );
}
public void release( Object component )
{
m_manager.release((Component) component);
}
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressComponentManager.java
Index: FortressComponentManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.lookup;
import org.apache.avalon.excalibur.collections.BucketMap;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.fortress.handler.ComponentHandler;
/**
* This is the Default ComponentManager for the Container. It provides
* a very simple abstraction, and makes it easy for the Container to manage
* the references.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/06/18 18:45:36 $
*/
public class FortressComponentManager implements ComponentManager
{
private final Container m_components;
private final BucketMap m_used;
private final ComponentManager m_parent;
/**
* This constructor is for a ContainerComponentManager with no parent
* ComponentLocator
*/
public FortressComponentManager( final Container container )
{
this( container, null );
}
/**
* This constructor is for a ContainerComponentManager with a parent
* ComponentLocator
*/
public FortressComponentManager( final Container container, final
ComponentManager parent )
{
m_parent = parent;
m_components = container;
m_used = new BucketMap();
}
public Component lookup( String role )
throws ComponentException
{
Object temp = null;
try
{
temp = m_components.get( role, null );
}
catch( ServiceException ce )
{
/* Logic is thus:
* If we have the component and the get threw an exception, we
need to report that.
* Otherwise, do the lookup on our parent
* Otherwise, just throw the exception
*/
if( m_components.has( role, null ) )
{
throw new ComponentException( role, ce.getMessage(), ce);
}
else if( null != m_parent )
{
return m_parent.lookup( role );
}
else
{
throw new ComponentException( role, ce.getMessage(), ce);
}
}
if( temp instanceof ComponentSelector )
{
return (Component)temp;
}
if( !( temp instanceof ComponentHandler ) )
{
throw new ComponentException( role, "Invalid entry in component
manager" );
}
ComponentHandler handler = (ComponentHandler)temp;
final Component component;
try
{
if( !handler.isInitialized() )
{
handler.initialize();
}
component = (Component)handler.get();
}
catch( ComponentException ce )
{
throw ce; // rethrow
}
catch( Exception e )
{
throw new ComponentException( role, "Could not return a reference
to the Component", e );
}
m_used.put( component, handler );
return component;
}
public boolean hasComponent( String role )
{
final boolean hasComponent = m_components.has( role, null );
if( !hasComponent && null != m_parent )
{
return m_parent.hasComponent( role );
}
return hasComponent;
}
public void release( Component component )
{
final ComponentHandler handler;
handler = (ComponentHandler)m_used.remove( component );
if( null == handler && null != m_parent )
{
m_parent.release( component );
return;
}
handler.put( component );
}
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressComponentSelector.java
Index: FortressComponentSelector.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.lookup;
import org.apache.avalon.excalibur.collections.BucketMap;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.fortress.handler.ComponentHandler;
/**
* This is the Default ComponentSelector for the Container. It provides
* a very simple abstraction, and makes it easy for the Container to manage
* the references.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/06/18 18:45:36 $
*/
public class FortressComponentSelector implements ComponentSelector
{
private final String m_role;
private final Container m_components;
private final BucketMap m_used;
public FortressComponentSelector( final Container container, final String
role )
{
m_role = role;
m_components = container;
m_used = new BucketMap();
}
public Component select( final Object hint )
throws ComponentException
{
if( null == hint )
{
throw new IllegalArgumentException( "hint cannot be null" );
}
ComponentHandler handler = null;
try
{
handler = (ComponentHandler)m_components.get( m_role, hint );
} catch (ServiceException se)
{
throw new ComponentException( hint.toString(), se.getMessage(),
se);
}
if( null == handler )
{
throw new ComponentException( m_role + "/" + hint.toString(),
"The hint does not exist in the ComponentSelector" );
}
final Component component;
try
{
if( !handler.isInitialized() )
{
handler.initialize();
}
component = (Component)handler.get();
}
catch( ComponentException ce )
{
throw ce; // rethrow
}
catch( Exception e )
{
throw new ComponentException( m_role + "/" + hint.toString(),
"Could not return a reference to the Component", e );
}
m_used.put( component, handler );
return component;
}
public boolean hasComponent( Object hint )
{
return m_components.has( m_role, hint );
}
public void release( Component component )
{
final ComponentHandler handler;
handler = (ComponentHandler)m_used.remove( component );
handler.put( component );
}
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceManager.java
Index: FortressServiceManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.lookup;
import org.apache.avalon.excalibur.collections.BucketMap;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.fortress.handler.ComponentHandler;
/**
* This is the Default ServiceManager for the Container. It provides
* a very simple abstraction, and makes it easy for the Container to manage
* the references.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/06/18 18:45:36 $
*/
public class FortressServiceManager implements ServiceManager
{
private final Container m_components;
private final BucketMap m_used;
private final ServiceManager m_parent;
/**
* This constructor is for a ContainerComponentManager with no parent
* ComponentLocator
*/
public FortressServiceManager( final Container container )
{
this( container, (ServiceManager)null );
}
/**
* This constructor is for a ContainerComponentManager with no parent
* ComponentLocator
*/
public FortressServiceManager( final Container container, final
ComponentManager parent )
{
this( container, (parent != null) ? new ComponentServiceManager(
parent ) : null );
}
/**
* This constructor is for a ContainerComponentManager with a parent
* ComponentLocator
*/
public FortressServiceManager( final Container container, final
ServiceManager parent )
{
m_parent = parent;
m_components = container;
m_used = new BucketMap();
}
public Object lookup( String role )
throws ServiceException
{
Object temp = null;
try
{
temp = m_components.get( role, null );
}
catch( ServiceException ce )
{
/* Logic is thus:
* If we have the component and the get threw an exception, we
need to report that.
* Otherwise, do the lookup on our parent
* Otherwise, just throw the exception
*/
if( m_components.has( role, null ) )
{
throw ce;
}
else if( null != m_parent )
{
return m_parent.lookup( role );
}
else
{
throw ce;
}
}
if( temp instanceof ServiceSelector )
{
return temp;
}
if( !( temp instanceof ComponentHandler ) )
{
throw new ServiceException( role, "Invalid entry in component
manager" );
}
ComponentHandler handler = (ComponentHandler)temp;
final Object component;
try
{
if( !handler.isInitialized() )
{
handler.initialize();
}
component = handler.get();
}
catch( ServiceException ce )
{
throw ce; // rethrow
}
catch( Exception e )
{
throw new ServiceException( role, "Could not return a reference
to the Component", e );
}
m_used.put( component, handler );
return component;
}
public boolean hasService( String role )
{
final boolean hasComponent = m_components.has( role, null );
if( !hasComponent && null != m_parent )
{
return m_parent.hasService( role );
}
return hasComponent;
}
public void release( Object component )
{
final ComponentHandler handler;
handler = (ComponentHandler)m_used.remove( component );
if( null == handler && null != m_parent )
{
m_parent.release( component );
return;
}
handler.put( component );
}
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java
Index: FortressServiceSelector.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.lookup;
import org.apache.avalon.excalibur.collections.BucketMap;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.excalibur.fortress.Container;
import org.apache.excalibur.fortress.handler.ComponentHandler;
/**
* This is the Default ServiceSelector for the Container. It provides
* a very simple abstraction, and makes it easy for the Container to manage
* the references.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/06/18 18:45:36 $
*/
public class FortressServiceSelector implements ServiceSelector
{
private final String m_role;
private final Container m_components;
private final BucketMap m_used;
public FortressServiceSelector( final Container container, final String
role )
{
m_role = role;
m_components = container;
m_used = new BucketMap();
}
public Object select( final Object hint )
throws ServiceException
{
if( null == hint )
{
throw new IllegalArgumentException( "hint cannot be null" );
}
ComponentHandler handler = (ComponentHandler)m_components.get(
m_role, hint );
if( null == handler )
{
throw new ServiceException( m_role + "/" + hint.toString(), "The
hint does not exist in the ComponentSelector" );
}
final Object component;
try
{
if( !handler.isInitialized() )
{
handler.initialize();
}
component = handler.get();
}
catch( ServiceException ce )
{
throw ce; // rethrow
}
catch( Exception e )
{
throw new ServiceException( m_role + "/" + hint.toString(),
"Could not return a reference to the Component", e );
}
m_used.put( component, handler );
return component;
}
public boolean isSelectable( Object hint )
{
return m_components.has( m_role, hint );
}
public void release( Object component )
{
final ComponentHandler handler;
handler = (ComponentHandler)m_used.remove( component );
handler.put( component );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>