Fix FELIX-3323:
Ipojo composite throw ClassCastException when configuration is updated thru ConfigAdmin
Several issues:
* A wrong cast
* The reconfiguration was not propagated to instances
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1242319 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java b/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java
index 9a03a5e..d739de5 100644
--- a/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java
+++ b/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeFactory.java
@@ -157,17 +157,20 @@
* @see org.apache.felix.ipojo.Factory#reconfigure(java.util.Dictionary)
*/
public synchronized void reconfigure(Dictionary properties) throws UnacceptableConfiguration, MissingHandlerException {
- if (properties == null || properties.get("name") == null) {
- throw new UnacceptableConfiguration("The configuration does not contains the \"name\" property");
+ if (properties == null || (properties.get("instance.name") == null && properties.get("name") == null)) { // Support both instance.name and name
+ throw new UnacceptableConfiguration("The configuration does not contains the \"instance.name\" property");
}
- String name = (String) properties.get("name");
-
- ComponentInstance instance = (CompositeManager) m_componentInstances.get(name);
-
- if (instance == null) {
- return; // The instance does not exist.
+
+ String name = (String) properties.get("instance.name");
+ if (name == null) {
+ name = (String) properties.get("name");
}
-
+
+ ComponentInstance instance = (ComponentInstance) m_componentInstances.get(name);
+ if (instance == null) { // The instance does not exists.
+ return;
+ }
+
instance.reconfigure(properties); // re-configure the component
}
diff --git a/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java b/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java
index 890855d..1fe3a10 100644
--- a/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java
+++ b/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/CompositeManager.java
@@ -33,6 +33,7 @@
import org.apache.felix.ipojo.ServiceContext;
import org.apache.felix.ipojo.architecture.InstanceDescription;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.BundleContext;
/**
@@ -85,6 +86,11 @@
private int m_state = STOPPED;
/**
+ * Logger.
+ */
+ private Logger m_logger;
+
+ /**
* Construct a new Component Manager.
* @param factory : the factory managing the instance manager
* @param context : the bundle context to give to the instance
@@ -97,6 +103,7 @@
m_internalContext = new CompositeServiceContext(m_context, this);
m_handlers = handlers;
m_description = new CompositeInstanceDescription(m_factory.getComponentDescription(), this);
+ m_logger = new Logger(m_context, this);
}
@@ -279,8 +286,10 @@
* @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
*/
public void reconfigure(Dictionary configuration) {
+ m_logger.log(Logger.INFO, "Reconfiguring composite with " + configuration);
for (int i = 0; i < m_handlers.length; i++) {
- m_handlers[i].reconfigure(configuration);
+ m_logger.log(Logger.INFO, "Delegating reconfiguration to " + m_handlers[i].getClassName());
+ m_handlers[i].getHandler().reconfigure(configuration);
}
}
diff --git a/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java b/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
index 357c262..bda4ac3 100644
--- a/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
+++ b/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/instance/InstanceHandler.java
@@ -230,7 +230,7 @@
* @param metadata : component type metadata.
* @param configuration : instance configuration.
* @throws ConfigurationException : occurs an instance cannot be parsed correctly.
- * @see org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
m_scope = getCompositeManager().getServiceContext();
@@ -323,7 +323,7 @@
/**
* Start method.
- * @see org.apache.felix.ipojo.CompositeHandler#start()
+ * @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
for (int j = 0; j < m_factories.length; j++) {
@@ -403,7 +403,7 @@
/**
* Return the handler description, i.e. the state of created instances.
* @return the handler description.
- * @see org.apache.felix.ipojo.CompositeHandler#getDescription()
+ * @see org.apache.felix.ipojo.Handler#getDescription()
*/
public HandlerDescription getDescription() {
return m_description;
@@ -421,4 +421,18 @@
return result;
}
+ /**
+ * The composite is reconfigured, we check if we have a property to change.
+ * We reconfigure all contained instances.
+ * @param configuration the new instance configuration
+ */
+ public void reconfigure(Dictionary configuration) {
+ for (int i = 0; i < m_configurations.length; i++) {
+ if (m_configurations[i].getInstance() != null) {
+ info("Reconfiguring " + m_configurations[i].getInstance().getInstanceName());
+ m_configurations[i].getInstance().reconfigure(configuration);
+ }
+ }
+
+ }
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
index 9fd8934..511ea30 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
@@ -631,9 +631,9 @@
* @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
*/
public void updated(String name, Dictionary properties) throws org.osgi.service.cm.ConfigurationException {
- InstanceManager instance;
+ ComponentInstance instance;
synchronized (this) {
- instance = (InstanceManager) m_componentInstances.get(name);
+ instance = (ComponentInstance) m_componentInstances.get(name);
}
if (instance == null) {