You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by go...@apache.org on 2012/07/04 18:57:16 UTC
svn commit: r1357336 -
/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
Author: gokturk
Date: Wed Jul 4 16:57:15 2012
New Revision: 1357336
URL: http://svn.apache.org/viewvc?rev=1357336&view=rev
Log:
Fix-2 for Felix-3576:
* Code is improved to detect correct BC injection among multiple constructors.
* Fix is moved to its own method.
Modified:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java?rev=1357336&r1=1357335&r2=1357336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java Wed Jul 4 16:57:15 2012
@@ -203,13 +203,30 @@ public class InstanceManager implements
m_handlers[i].init(this, metadata, configuration);
}
- /* Fix for Felix-3576
- * BundleContext injection is not registered with the InstanceManager.
- * We're iterating through factory's all constructors and register first
- * BundleContext parameter as constructor injection. So rest of the code
- * don't have to do anything to handle BundleContext mixed with other
- * injections.
- */
+ // Fix for Felix-3576
+ handleBCInjections();
+
+ // Check that the constructor parameter are continuous.
+ if (m_constructorRegistration != null) {
+ for (int i = 0; i < m_constructorRegistration.size(); i++) {
+ if (! m_constructorRegistration.containsKey(new Integer(i))) {
+ throw new ConfigurationException("The constructor parameter " + i + " is not managed");
+ }
+ }
+ }
+ }
+
+ /**
+ * BundleContext injection is not registered with the InstanceManager.
+ * We're iterating through factory's all constructors and register first
+ * BundleContext parameter as constructor injection. So rest of the code
+ * don't have to do anything to handle BundleContext mixed with other
+ * injections.
+ *
+ * @throws ConfigurationException
+ */
+ private void handleBCInjections() throws ConfigurationException
+ {
MethodMetadata[] constructors = getFactory().getPojoMetadata().getConstructors();
for(int i=0; i < constructors.length; i++ )
{
@@ -218,24 +235,49 @@ public class InstanceManager implements
{
if(ctorArguments[index].equals(BundleContext.class.getName()))
{
- Property contextInjection =
- new Property("__context", null, null, index, null,
- BundleContext.class.getName(), this, null);
+ //Check if its used with only other injections.
+ boolean injectionsConsistent = true;
+ for(int siblingIndex = 0; siblingIndex < ctorArguments.length; siblingIndex++)
+ {
+ if(siblingIndex == index){
+ continue;
+ }
+
+ String injectionType = ctorArguments[siblingIndex];
+ if(m_constructorRegistration.containsKey(new Integer(siblingIndex)))
+ {
+ ConstructorInjector siblingInjector =
+ (ConstructorInjector)m_constructorRegistration.get(new Integer(siblingIndex));
+ Class injectorClass = siblingInjector.getConstructorParameterType(siblingIndex);
+
+ if(injectorClass == null && ! injectorClass.getName().equals(injectionType))
+ {
+ injectionsConsistent = false;
+ break;
+ }
+ }
+ else
+ {
+ injectionsConsistent = false;
+ break;
+ }
+ }
- contextInjection.setValue(getContext());
- register(index, contextInjection);
+ if(injectionsConsistent)
+ {
+ Property contextInjection =
+ new Property("__context", null, null, index, null,
+ BundleContext.class.getName(), this, null);
+
+ contextInjection.setValue(getContext());
+ register(index, contextInjection);
+
+ // We register the first valid BC injection.
+ break;
+ }
}
}
}
-
- // Check that the constructor parameter are continuous.
- if (m_constructorRegistration != null) {
- for (int i = 0; i < m_constructorRegistration.size(); i++) {
- if (! m_constructorRegistration.containsKey(new Integer(i))) {
- throw new ConfigurationException("The constructor parameter " + i + " is not managed");
- }
- }
- }
}
/**