donaldp 2002/11/09 15:38:29
Modified: fortress/src/java/org/apache/excalibur/fortress/lookup
FortressServiceSelector.java
Log:
role --> key
Revision Changes Path
1.17 +46 -27
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java
Index: FortressServiceSelector.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FortressServiceSelector.java 9 Nov 2002 09:16:31 -0000 1.16
+++ FortressServiceSelector.java 9 Nov 2002 23:38:29 -0000 1.17
@@ -67,14 +67,23 @@
public class FortressServiceSelector
implements ServiceSelector
{
- private final String m_role;
+ private final String m_key;
private final Container m_container;
private final Map m_used;
public FortressServiceSelector( final Container container,
- final String role )
+ final String key )
{
- m_role = role;
+ if( null == container )
+ {
+ throw new NullPointerException( "container" );
+ }
+ if( null == key )
+ {
+ throw new NullPointerException( "key" );
+ }
+
+ m_key = key;
m_container = container;
m_used = new StaticBucketMap();
}
@@ -82,48 +91,58 @@
public Object select( final Object hint )
throws ServiceException
{
- if( null == hint )
- {
- final String message = "hint cannot be null";
- throw new IllegalArgumentException( message );
- }
-
- final ComponentHandler handler =
- (ComponentHandler)m_container.get( m_role, hint );
- if( null == handler )
- {
- final String message =
- "The hint does not exist in the ComponentSelector";
- throw new ServiceException( m_role + "/" + hint.toString(),
- message );
- }
-
try
{
+ final ComponentHandler handler = getHandler( hint );
final Object component = handler.get();
m_used.put( component, handler );
return component;
}
- catch( ServiceException ce )
+ catch( final ServiceException ce )
{
throw ce; // rethrow
}
- catch( Exception e )
+ catch( final Exception e )
{
- throw new ServiceException( m_role + "/" + hint.toString(),
- "Could not return a reference to the
Component", e );
+ final String name = m_key + "/" + hint.toString();
+ final String message = "Could not return a reference to the Component";
+ throw new ServiceException( name, message, e );
}
}
- public boolean isSelectable( Object hint )
+ public boolean isSelectable( final Object hint )
{
- return m_container.has( m_role, hint );
+ return m_container.has( m_key, hint );
}
public void release( Object component )
{
final ComponentHandler handler =
(ComponentHandler)m_used.remove( component );
- handler.put( component );
+ if( null != handler )
+ {
+ handler.put( component );
+ }
+ }
+
+ private ComponentHandler getHandler( final Object hint )
+ throws ServiceException
+ {
+ if( null == hint )
+ {
+ final String message = "hint cannot be null";
+ throw new IllegalArgumentException( message );
+ }
+
+ final ComponentHandler handler =
+ (ComponentHandler)m_container.get( m_key, hint );
+ if( null == handler )
+ {
+ final String message =
+ "The hint does not exist in the ComponentSelector";
+ throw new ServiceException( m_key + "/" + hint.toString(),
+ message );
+ }
+ return handler;
}
}
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>