proyal 2002/07/30 09:49:53
Modified: fortress/src/java/org/apache/excalibur/fortress/lookup
ServiceComponentManager.java
Added: fortress/src/java/org/apache/excalibur/fortress/lookup
ServiceComponentSelector.java
Log:
Wrap a ServiceSelector in a ComponentSelector for
Composable users.
Revision Changes Path
1.3 +22 -12
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/ServiceComponentManager.java
Index: ServiceComponentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/ServiceComponentManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServiceComponentManager.java 8 Jul 2002 11:58:58 -0000 1.2
+++ ServiceComponentManager.java 30 Jul 2002 16:49:52 -0000 1.3
@@ -12,6 +12,7 @@
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;
/**
* This is the Default ServiceManager for the Container. It provides
@@ -36,22 +37,31 @@
public Component lookup( String role )
throws ComponentException
{
- Component temp = null;
-
try
{
- temp = (Component) m_manager.lookup( role );
+ final Object o = m_manager.lookup( role );
+
+ // Check for component since it should be the common case
+ if( o instanceof Component )
+ {
+ return ( Component ) o;
+ }
+ else if( o instanceof ServiceSelector )
+ {
+ return new ServiceComponentSelector( ( ServiceSelector ) o );
+ }
+ else
+ {
+ throw new ComponentException( role,
+ "The requested component does not
implement Component" );
+ }
}
catch( ServiceException ce )
{
- throw new ComponentException( role, "Could not return a reference to
the Component", ce );
+ throw new ComponentException( role,
+ "Could not return a reference to the
Component",
+ ce );
}
- catch( ClassCastException cce )
- {
- throw new ComponentException( role, "The requested component does not
implement Component", cce );
- }
-
- return temp;
}
public boolean hasComponent( String role )
@@ -61,6 +71,6 @@
public void release( Component component )
{
- m_manager.release(component);
+ m_manager.release( component );
}
}
1.1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/ServiceComponentSelector.java
Index: ServiceComponentSelector.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.ComponentSelector;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceSelector;
/**
* 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>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/30 16:49:52 $
*/
public class ServiceComponentSelector implements ComponentSelector
{
private final ServiceSelector m_selector;
/**
* This constructor is a constructor for a ComponentServiceSelector
*/
public ServiceComponentSelector( final ServiceSelector wrapped )
{
m_selector = wrapped;
}
public Component select( Object hint )
throws ComponentException
{
Component temp = null;
try
{
temp = ( Component ) m_selector.select( hint );
}
catch( ServiceException ce )
{
throw new ComponentException( ce.getRole(),
"Could not return a reference to the
Component",
ce );
}
catch( ClassCastException cce )
{
throw new ComponentException( "The requested component does not
implement Component",
cce );
}
return temp;
}
public boolean hasComponent( Object hint )
{
return m_selector.isSelectable( hint );
}
public void release( Component component )
{
m_selector.release( component );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>