Fix the issue Felix-631
Set components as immediate when they don't provide services and do not specified that they are not immediate ("immediate="false"").
This detection is not applied for handlers. Handlers are never immediate, as their lifecycle is attached to the instance lifecycle.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@675866 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
index eda3e82..4e56b55 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
@@ -274,6 +274,22 @@
if (arch == null || arch.equalsIgnoreCase("true")) {
list.add(new RequiredHandler("architecture", null));
}
+
+
+ // Determine if the component must be immediate.
+ // A component becomes immediate if it doesn't provide a service,
+ // and does not specified that the component is not immediate.
+ if (m_componentMetadata.getElements("provides") == null) {
+ String imm = m_componentMetadata.getAttribute("immediate");
+ if (imm == null || !imm.equalsIgnoreCase("false")) {
+ getLogger().log(
+ Logger.WARNING,
+ "The component " + getFactoryName()
+ + " becomes immediate");
+ m_componentMetadata.addAttribute(new Attribute("immediate",
+ "true"));
+ }
+ }
// Add lifecycle callback if immediate = true
RequiredHandler reqCallback = new RequiredHandler("callback", null);
@@ -282,6 +298,7 @@
list.add(reqCallback);
}
+
return list;
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
index 2f3d5cb..a0ba2fa 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
@@ -18,7 +18,9 @@
*/
package org.apache.felix.ipojo;
+import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.List;
import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
import org.apache.felix.ipojo.metadata.Element;
@@ -135,6 +137,39 @@
instance.configure(m_componentMetadata, configuration);
return instance;
}
+
+
+ /**
+ * Computes required handlers. This method does not manipulate any
+ * non-immutable fields, so does not need to be synchronized.
+ * This method is overridden to avoid to use the same detection rules
+ * than atomic components. Indeed, architecture is disable by default,
+ * and an handler is never immediate.
+ * @return the required handler list.
+ */
+ public List getRequiredHandlerList() {
+ List list = new ArrayList();
+ Element[] elems = m_componentMetadata.getElements();
+ for (int i = 0; i < elems.length; i++) {
+ Element current = elems[i];
+ if (!"manipulation".equals(current.getName())) {
+ RequiredHandler req = new RequiredHandler(current.getName(),
+ current.getNameSpace());
+ if (!list.contains(req)) {
+ list.add(req);
+ }
+ }
+ }
+
+ // Unlike normal components, the architecture is enable only when
+ // specified.
+ String arch = m_componentMetadata.getAttribute("architecture");
+ if (arch != null && arch.equalsIgnoreCase("true")) {
+ list.add(new RequiredHandler("architecture", null));
+ }
+
+ return list;
+ }
private class HandlerTypeDescription extends ComponentTypeDescription {
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
index 8add263..2016dae 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
@@ -101,7 +101,7 @@
* @param value : the value passed to the field
*/
public void onSet(Object pojo, String fieldName, Object value) {
- // Nothing do do in the default implementation
+ // Nothing to do in the default implementation
}
/**
@@ -122,7 +122,7 @@
* @param args arguments array.
*/
public void onEntry(Object pojo, Method method, Object[] args) {
- // Nothing do do in the default implementation
+ // Nothing to do in the default implementation
}
/**
@@ -134,7 +134,7 @@
* @param returnedObj : the returned object (boxed for primitive type)
*/
public void onExit(Object pojo, Method method, Object returnedObj) {
- // Nothing do do in the default implementation
+ // Nothing to do in the default implementation
}
/**
@@ -144,7 +144,7 @@
* @param throwable : the thrown exception
*/
public void onError(Object pojo, Method method, Throwable throwable) {
- // Nothing do do in the default implementation
+ // Nothing to do in the default implementation
}
/**
@@ -155,7 +155,7 @@
* @param method : invoked method.
*/
public void onFinally(Object pojo, Method method) {
- // Nothing do do in the default implementation
+ // Nothing to do in the default implementation
}
/**
@@ -164,7 +164,7 @@
* @param instance : the created instance
*/
public void onCreation(Object instance) {
- // Nothing do do in the default implementation
+ // Nothing to do in the default implementation
}