FELIX-1504 Move the "official" implementation of the ComponentInstance
interface to the ComponentContextImpl class. Instances of this class
are recreated whenever the component is activated. This ensures the
ComponentInstance contract which has the same lifecycle requirement.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@806106 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
index 6cdba29..1cc10e5 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -36,7 +36,6 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentConstants;
-import org.osgi.service.component.ComponentInstance;
import org.osgi.service.log.LogService;
/**
@@ -44,7 +43,7 @@
* implementation object's lifecycle.
*
*/
-public abstract class AbstractComponentManager implements Component, ComponentInstance
+public abstract class AbstractComponentManager implements Component
{
// the ID of this component
private long m_componentId;
@@ -522,8 +521,15 @@
});
}
- // implements the ComponentInstance.dispose() method
- public void dispose()
+ /**
+ * Get the object that is implementing this descriptor
+ *
+ * @return the object that implements the services
+ */
+ abstract Object getInstance();
+
+ // supports the ComponentInstance.dispose() method
+ void dispose()
{
dispose( ComponentConstants.DEACTIVATION_REASON_DISPOSED );
}
@@ -910,13 +916,6 @@
}
}
- /**
- * Get the object that is implementing this descriptor
- *
- * @return the object that implements the services
- */
- public abstract Object getInstance();
-
public abstract boolean hasConfiguration();
public abstract Dictionary getProperties();
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
index 06dd92c..537e61a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
@@ -33,7 +33,7 @@
* Implementation for the ComponentContext interface
*
*/
-public class ComponentContextImpl implements ComponentContext
+public class ComponentContextImpl implements ComponentContext, ComponentInstance
{
private AbstractComponentManager m_componentManager;
@@ -92,7 +92,7 @@
public ComponentInstance getComponentInstance()
{
- return m_componentManager;
+ return this;
}
@@ -112,4 +112,18 @@
{
return m_componentManager.getServiceReference();
}
+
+
+ //---------- ComponentInstance interface ------------------------------
+
+ public Object getInstance()
+ {
+ return getComponentManager().getInstance();
+ }
+
+
+ public void dispose()
+ {
+ getComponentManager().dispose();
+ }
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
index de5e7c8..016abda 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
@@ -100,10 +100,7 @@
*/
public ComponentInstance newInstance( Dictionary dictionary )
{
- ImmediateComponentManager cm = createComponentManager();
-
- // register with the internal set of created components
- m_componentInstances.put( cm, cm );
+ final ImmediateComponentManager cm = createComponentManager();
cm.setFactoryProperties( dictionary );
cm.reconfigure( m_configuration );
@@ -111,7 +108,10 @@
cm.enableInternal();
cm.activateInternal();
- return cm;
+ final ComponentInstance instance = cm.getComponentInstance();
+ m_componentInstances.put( cm, instance );
+
+ return instance;
}
@@ -200,12 +200,6 @@
}
- public String getName()
- {
- return "Component Factory " + getComponentMetadata().getName();
- }
-
-
//---------- ComponentHolder interface
public void configurationDeleted( String pid )
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
index 153e18a..94cc773 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
@@ -32,6 +32,7 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.ComponentInstance;
import org.osgi.service.log.LogService;
@@ -46,7 +47,7 @@
private Object m_implementationObject;
// The context that will be passed to the implementationObject
- private ComponentContext m_componentContext;
+ private ComponentContextImpl m_componentContext;
// the activate method
private ActivateMethod m_activateMethod;
@@ -99,7 +100,7 @@
// also be overwritten
protected boolean createComponent()
{
- ComponentContext tmpContext = new ComponentContextImpl( this );
+ ComponentContextImpl tmpContext = new ComponentContextImpl( this );
Object tmpComponent = createImplementationObject( tmpContext );
// if something failed creating the component instance, return false
@@ -124,6 +125,18 @@
}
+ ComponentContext getComponentContext()
+ {
+ return m_componentContext;
+ }
+
+
+ ComponentInstance getComponentInstance()
+ {
+ return m_componentContext;
+ }
+
+
//**********************************************************************************************************
/**
@@ -131,7 +144,7 @@
*
* @return the object that implements the services
*/
- public Object getInstance()
+ Object getInstance()
{
return m_implementationObject;
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
index 59552f5..c16ae26 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
@@ -28,7 +28,6 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentContext;
-import org.osgi.service.component.ComponentInstance;
import org.osgi.service.log.LogService;
@@ -81,7 +80,7 @@
/* (non-Javadoc)
* @see org.apache.felix.scr.AbstractComponentManager#getInstance()
*/
- public Object getInstance()
+ Object getInstance()
{
// this method is not expected to be called as the base call is
// overwritten in the BundleComponentContext class
@@ -154,7 +153,7 @@
}
}
- private static class BundleComponentContext extends ComponentContextImpl implements ComponentInstance
+ private static class BundleComponentContext extends ComponentContextImpl
{
private Bundle m_usingBundle;
@@ -181,23 +180,11 @@
}
- public ComponentInstance getComponentInstance()
- {
- return this;
- }
-
-
//---------- ComponentInstance interface ------------------------------
public Object getInstance()
{
return m_implementationObject;
}
-
-
- public void dispose()
- {
- getComponentManager().dispose();
- }
}
}