FELIX-4957 : [DS][RFC-212] Various issues with field references

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1691322 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java b/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
index 9d20620..38f24b9 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/helper/FieldHandler.java
@@ -645,26 +645,32 @@
                     }
                 }
             }
-            // updated needs only be done, if reference is dynamic
-            // and the value type is map or tuple
+            // updated needs only be done, if the value type is map or tuple
             else if ( mType == METHOD_TYPE.UPDATED)
             {
-                if ( !this.metadata.isStatic()
-                     && (this.valueType == ParamType.map || this.valueType == ParamType.tuple ) )
-                {
-                    final Object obj = getValue(key, refPair);
-                    final Object oldObj = this.boundValues.put(refPair, obj);
-
-                    if ( metadata.isReplace() )
+            	if ( this.valueType == ParamType.map || this.valueType == ParamType.tuple ) 
+            	{
+                    if ( !this.metadata.isStatic() )
                     {
-                        this.setFieldValue(componentInstance, getReplaceCollection());
+	                    final Object obj = getValue(key, refPair);
+	                    final Object oldObj = this.boundValues.put(refPair, obj);
+	
+	                    if ( metadata.isReplace() )
+	                    {
+	                        this.setFieldValue(componentInstance, getReplaceCollection());
+	                    }
+	                    else
+	                    {
+	                        @SuppressWarnings("unchecked")
+	                        final Collection<Object> col = (Collection<Object>)this.getFieldValue(componentInstance);
+	                        col.add(obj);
+	                        col.remove(oldObj);
+	                    }
                     }
                     else
                     {
-                        @SuppressWarnings("unchecked")
-                        final Collection<Object> col = (Collection<Object>)this.getFieldValue(componentInstance);
-                        col.add(obj);
-                        col.remove(oldObj);
+                    	// if it's static we need to reactivate
+                    	return MethodResult.REACTIVATE;
                     }
                 }
             }
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
index 4798302..8f40b64 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
@@ -462,12 +462,18 @@
         public void modifiedService( ServiceReference<T> serviceReference, RefPair<S, T> refPair, int trackingCount )
         {
             m_componentManager.log( LogService.LOG_DEBUG, "dm {0} tracking {1} MultipleStaticGreedy modified {2} (enter)", new Object[] {getName(), trackingCount, serviceReference}, null );
+            boolean reactivate = false;
             if (isActive())
             {
-                m_componentManager.invokeUpdatedMethod( DependencyManager.this, refPair, trackingCount );
+            	reactivate = m_componentManager.invokeUpdatedMethod( DependencyManager.this, refPair, trackingCount );
+            }
+            tracked( trackingCount );
+            if ( reactivate )
+            {
+                m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE, false, false );
+                m_componentManager.activateInternal( );
             }
             m_componentManager.log( LogService.LOG_DEBUG, "dm {0} tracking {1} MultipleStaticGreedy modified {2} (exit)", new Object[] {getName(), trackingCount, serviceReference}, null );
-            tracked( trackingCount );
         }
 
         public void removedService( ServiceReference<T> serviceReference, RefPair<S, T> refPair, int trackingCount )
@@ -563,13 +569,19 @@
         public void modifiedService( ServiceReference<T> serviceReference, RefPair<S, T> refPair, int trackingCount )
         {
             m_componentManager.log( LogService.LOG_DEBUG, "dm {0} tracking {1} MultipleStaticReluctant modified {2} (enter)", new Object[] {getName(), trackingCount, serviceReference}, null );
+            boolean reactivate = false;
             Collection<RefPair<S, T>> refs = this.refs.get();
             if (isActive() && refs.contains( refPair ))
             {
-                m_componentManager.invokeUpdatedMethod( DependencyManager.this, refPair, trackingCount );
+                reactivate = m_componentManager.invokeUpdatedMethod( DependencyManager.this, refPair, trackingCount );
+            }
+            tracked( trackingCount );
+            if ( reactivate )
+            {
+                m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE, false, false );
+                m_componentManager.activateInternal( );
             }
             m_componentManager.log( LogService.LOG_DEBUG, "dm {0} tracking {1} MultipleStaticReluctant modified {2} (exit)", new Object[] {getName(), trackingCount, serviceReference}, null );
-            tracked( trackingCount );
         }
 
         public void removedService( ServiceReference<T> serviceReference, RefPair<S, T> refPair, int trackingCount )