Author: mahrwald
Date: Mon Nov 30 10:49:27 2009
New Revision: 885371
URL: http://svn.apache.org/viewvc?rev=885371&view=rev
Log:
ARIES-56 Unwrap ServiceProxyWrapper for factory-ref bean creation
Modified:
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
Modified:
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
URL:
http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=885371&r1=885370&r2=885371&view=diff
==============================================================================
---
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
(original)
+++
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
Mon Nov 30 10:49:27 2009
@@ -206,6 +206,16 @@
if (factory != null) {
// look for instance method on factory object
Object factoryObj = factory.create();
+
+ // If the factory is a service reference, we need to get hold of
the actual proxy for the service
+ if (factoryObj instanceof ReferenceRecipe.ServiceProxyWrapper) {
+ try {
+ factoryObj = ((ReferenceRecipe.ServiceProxyWrapper)
factoryObj).convert(new ReifiedType(Object.class));
+ } catch (Exception e) {
+ throw new ComponentDefinitionException("Error when
instantiating bean " + getName() + " of class " + getType(), getRealCause(e));
+ }
+ }
+
// Map of matching methods
Map<Method, List<Object>> matches =
findMatchingMethods(factoryObj.getClass(), factoryMethod, true, args, argTypes);
if (matches.size() == 1) {
@@ -213,7 +223,7 @@
Map.Entry<Method, List<Object>> match =
matches.entrySet().iterator().next();
instance = invoke(match.getKey(), factoryObj,
match.getValue().toArray());
} catch (Throwable e) {
- throw new ComponentDefinitionException("Error when
instanciating bean " + getName() + " of class " + getType(), getRealCause(e));
+ throw new ComponentDefinitionException("Error when
instantiating bean " + getName() + " of class " + getType(), getRealCause(e));
}
} else if (matches.size() == 0) {
throw new ComponentDefinitionException("Unable to find a
matching factory method " + factoryMethod + " on class " +
factoryObj.getClass().getName() + " for arguments " + args + " when
instanciating bean " + getName());