cziegeler 2004/04/06 04:19:44
Modified: fortress/container-impl/src/java/org/apache/avalon/fortress/impl/handler
ComponentFactory.java
Log:
Test code for constructor injection
Revision Changes Path
1.30 +21 -4
avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
Index: ComponentFactory.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/fortress/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- ComponentFactory.java 2 Apr 2004 10:29:03 -0000 1.29
+++ ComponentFactory.java 6 Apr 2004 11:19:44 -0000 1.30
@@ -38,6 +38,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.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.commons.beanutils.BeanUtils;
@@ -51,7 +52,6 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision$ $Date$
- * @since 4.0
*/
public final class ComponentFactory
extends AbstractLogEnabledInstrumentable
@@ -402,7 +402,8 @@
/**
* This class collects all information about the components class:
* - the constructor to use
- *
+ * - the parameters to pass into the constructor
+ * - Additional infos about implemented methods
*/
protected class ClassInfo {
@@ -491,7 +492,20 @@
}
else
{
- throw new Exception("Unknown parameter type for constructor of
component: " + current);
+ // now test if this is a reference to a component!
+ // FIXME - This works only for thread safe components!
+ final String role = current.getName();
+ try
+ {
+ final Object component = m_serviceManager.lookup(role);
+ m_constructorArguments[i] = component;
+ m_serviceManager.release(component);
+ }
+ catch (Exception e)
+ {
+ throw new ServiceException("ComponentFactory",
+ "Unknown parameter type for constructor of
component: " + current, e);
+ }
}
}
@@ -525,6 +539,9 @@
}
}
+ /**
+ * Helper method for getting a named method that has one parameter of the
given type.
+ */
protected Method getMethod(String name, Class clazz) throws Exception
{
try
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]