felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r806106 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager: AbstractComponentManager.java ComponentContextImpl.java ComponentFactoryImpl.java ImmediateComponentManager.java ServiceFactoryComponentManager.java
Date Thu, 20 Aug 2009 10:16:32 GMT
Author: fmeschbe
Date: Thu Aug 20 10:16:31 2009
New Revision: 806106

URL: http://svn.apache.org/viewvc?rev=806106&view=rev
Log:
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.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=806106&r1=806105&r2=806106&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Thu Aug 20 10:16:31 2009
@@ -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();

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java?rev=806106&r1=806105&r2=806106&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
Thu Aug 20 10:16:31 2009
@@ -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();
+    }
 }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java?rev=806106&r1=806105&r2=806106&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
Thu Aug 20 10:16:31 2009
@@ -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 )

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=806106&r1=806105&r2=806106&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Thu Aug 20 10:16:31 2009
@@ -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;
     }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java?rev=806106&r1=806105&r2=806106&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
Thu Aug 20 10:16:31 2009
@@ -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();
-        }
     }
 }



Mime
View raw message