Fix FELIX-4130
Allow retrieving the component instance from the instance description object
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1493183 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestArchitecture.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestArchitecture.java
index 149a53f..68a0a5d 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestArchitecture.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestArchitecture.java
@@ -31,6 +31,7 @@
import static junit.framework.Assert.*;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
public class TestArchitecture extends Common {
@@ -92,6 +93,9 @@
assertEquals(2, hd.getProperties().length);
assertEquals("FooProvider-3", hd.getManagedServicePid());
+ // Check the getInstance() method
+ assertSame(arch.getInstanceDescription().getInstance(), instance1);
+
}
@Test
@@ -110,6 +114,9 @@
assertEquals(2, hd.getProperties().length);
assertEquals("instance", hd.getManagedServicePid());
+ // Check the getInstance() method
+ assertSame(arch.getInstanceDescription().getInstance(), instance2);
+
}
/**
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
index 740689e..c1907e9 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/InstanceDescription.java
@@ -33,17 +33,17 @@
/**
* The list of handlers plugged on the component instance.
*/
- protected HandlerDescription[] m_handlers = new HandlerDescription[0];
+ protected HandlerDescription[] m_handlers;
/**
* The Underlying component instance.
*/
- protected ComponentInstance m_instance;
+ protected final ComponentInstance m_instance;
/**
* Component Type of the instance.
*/
- protected ComponentTypeDescription m_type;
+ protected final ComponentTypeDescription m_type;
/**
* Creates the instance description.
@@ -58,6 +58,14 @@
}
/**
+ * Gets the underlying component instance
+ * @return the component instance.
+ */
+ public ComponentInstance getInstance() {
+ return m_instance;
+ }
+
+ /**
* Gets the instance name.
* @return the name of the instance.
*/
@@ -87,10 +95,10 @@
*/
public void addHandler(HandlerDescription desc) {
// Verify that the dependency description is not already in the array.
- for (int i = 0; i < m_handlers.length; i++) {
- if (m_handlers[i] == desc) {
+ for (HandlerDescription handler : m_handlers) {
+ if (handler == desc) {
return; // NOTHING TO DO, the description is already in the
- // array
+ // array
}
}
// The component Description is not in the array, add it
@@ -107,9 +115,9 @@
* @return the handler description or <code>null</code> if not found
*/
public HandlerDescription getHandlerDescription(String handler) {
- for (int i = 0; i < m_handlers.length; i++) {
- if (m_handlers[i].getHandlerName().equalsIgnoreCase(handler)) {
- return m_handlers[i];
+ for (HandlerDescription description : m_handlers) {
+ if (description.getHandlerName().equalsIgnoreCase(handler)) {
+ return description;
}
}
return null;
@@ -160,8 +168,8 @@
instance.addAttribute(new Attribute("component.type", m_type.getName()));
// Handlers
- for (int i = 0; i < m_handlers.length; i++) {
- instance.addElement(m_handlers[i].getHandlerInfo());
+ for (HandlerDescription description : m_handlers) {
+ instance.addElement(description.getHandlerInfo());
}
return instance;