felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1787202 - in /felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl: inject/field/FieldHandler.java manager/ComponentContextImpl.java
Date Thu, 16 Mar 2017 15:04:43 GMT
Author: cziegeler
Date: Thu Mar 16 15:04:43 2017
New Revision: 1787202

URL: http://svn.apache.org/viewvc?rev=1787202&view=rev
Log:
FELIX-5572 : Reference target filter fails when using field strategy for multiple cardinality
reference with multiple component instances

Modified:
    felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/field/FieldHandler.java
    felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java

Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/field/FieldHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/field/FieldHandler.java?rev=1787202&r1=1787201&r2=1787202&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/field/FieldHandler.java
(original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/inject/field/FieldHandler.java
Thu Mar 16 15:04:43 2017
@@ -24,10 +24,7 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
@@ -65,18 +62,6 @@ public class FieldHandler
     /** State handling. */
     private volatile State state;
 
-    /** Mapping of ref pairs to value bound */
-    private final Map<RefPair<?, ?>, Object> boundValues = new TreeMap<RefPair<?,?>,
Object>(
-        new Comparator<RefPair<?, ?>>()
-        {
-
-            @Override
-            public int compare(final RefPair<?, ?> o1, final RefPair<?, ?> o2)
-            {
-                return o1.getRef().compareTo(o2.getRef());
-            }
-        });
-
     /**
      * Create a new field handler
      * @param fieldName name of the field
@@ -171,10 +156,10 @@ public class FieldHandler
         return true;
     }
 
-    private Collection<Object> getReplaceCollection()
+    private Collection<Object> getReplaceCollection(final BindParameters bp)
     {
         final List<Object> objects = new ArrayList<Object>();
-        for(final Object val : this.boundValues.values())
+        for(final Object val : bp.getComponentContext().getBoundValues(metadata.getName()).values())
         {
             objects.add(val);
         }
@@ -200,12 +185,12 @@ public class FieldHandler
                 if ( this.metadata.isOptional() && !this.metadata.isStatic() )
                 {
                     // we only reset if it was previously set with this value
-                    if ( this.boundValues.size() == 1 )
+                    if ( bp.getComponentContext().getBoundValues(metadata.getName()).size()
== 1 )
                     {
                         this.setFieldValue(componentInstance, null);
                     }
                 }
-                this.boundValues.remove(refPair);
+                bp.getComponentContext().getBoundValues(metadata.getName()).remove(refPair);
             }
             // updated needs only be done, if the value type is map or tuple
             // If it's a dynamic reference, the value can be updated
@@ -221,7 +206,7 @@ public class FieldHandler
                     final Object obj = ValueUtils.getValue(componentInstance.getClass().getName(),
                             valueType, field.getType(), key, refPair);
                     this.setFieldValue(componentInstance, obj);
-                    this.boundValues.put(refPair, obj);
+                    bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
             	}
             }
             // bind needs always be done
@@ -230,7 +215,7 @@ public class FieldHandler
                 final Object obj = ValueUtils.getValue(componentInstance.getClass().getName(),
                         valueType, field.getType(), key, refPair);
                 this.setFieldValue(componentInstance, obj);
-                this.boundValues.put(refPair, obj);
+                bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
             }
         }
         else
@@ -242,10 +227,10 @@ public class FieldHandler
             {
                 final Object obj = ValueUtils.getValue(componentInstance.getClass().getName(),
                         valueType, field.getType(), key, refPair);
-                this.boundValues.put(refPair, obj);
+                bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
                 if ( metadata.isReplace() )
                 {
-                    this.setFieldValue(componentInstance, getReplaceCollection());
+                    this.setFieldValue(componentInstance, getReplaceCollection(bp));
                 }
                 else
                 {
@@ -259,10 +244,10 @@ public class FieldHandler
             {
                 if ( !metadata.isStatic() )
                 {
-                    final Object obj = this.boundValues.remove(refPair);
+                    final Object obj = bp.getComponentContext().getBoundValues(metadata.getName()).remove(refPair);
                     if ( metadata.isReplace() )
                     {
-                        this.setFieldValue(componentInstance, getReplaceCollection());
+                        this.setFieldValue(componentInstance, getReplaceCollection(bp));
                     }
                     else
                     {
@@ -281,11 +266,11 @@ public class FieldHandler
                     {
 	                    final Object obj = ValueUtils.getValue(componentInstance.getClass().getName(),
 	                            valueType, field.getType(), key, refPair);
-	                    final Object oldObj = this.boundValues.put(refPair, obj);
+	                    final Object oldObj = bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
 
 	                    if ( metadata.isReplace() )
 	                    {
-	                        this.setFieldValue(componentInstance, getReplaceCollection());
+	                        this.setFieldValue(componentInstance, getReplaceCollection(bp));
 	                    }
 	                    else
 	                    {

Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java?rev=1787202&r1=1787201&r2=1787202&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
(original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
Thu Mar 16 15:04:43 2017
@@ -19,7 +19,11 @@
 package org.apache.felix.scr.impl.manager;
 
 
+import java.util.Comparator;
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -60,6 +64,11 @@ public class ComponentContextImpl<S> imp
 
     private final ComponentServiceObjectsHelper serviceObjectsHelper;
 
+    /** Mapping of ref pairs to value bound */
+    private final Map<String, Map<RefPair<?, ?>, Object>> boundValues =
new HashMap<String, Map<RefPair<?,?>,Object>>();
+
+
+
     public ComponentContextImpl( final SingleComponentManager<S> componentManager,
final Bundle usingBundle, ServiceRegistration<S> serviceRegistration )
     {
         m_componentManager = componentManager;
@@ -300,4 +309,28 @@ public class ComponentContextImpl<S> imp
 
     }
 
+    public Map<RefPair<?, ?>, Object> getBoundValues(final String key)
+    {
+        Map<RefPair<?, ?>, Object> map = this.boundValues.get(key);
+        if ( map == null )
+        {
+            map = createNewFieldHandlerMap();
+            this.boundValues.put(key, map);
+        }
+        return map;
+    }
+
+    private Map<RefPair<?, ?>, Object> createNewFieldHandlerMap()
+    {
+        return new TreeMap<RefPair<?,?>, Object>(
+                new Comparator<RefPair<?, ?>>()
+                {
+
+                    @Override
+                    public int compare(final RefPair<?, ?> o1, final RefPair<?,
?> o2)
+                    {
+                        return o1.getRef().compareTo(o2.getRef());
+                    }
+                });
+    }
 }



Mime
View raw message