felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r902143 - in /felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework: capabilityset/CapabilitySet.java resolver/ResolverImpl.java
Date Fri, 22 Jan 2010 16:23:44 GMT
Author: rickhall
Date: Fri Jan 22 16:23:43 2010
New Revision: 902143

URL: http://svn.apache.org/viewvc?rev=902143&view=rev
Log:
Fixed some indexing bugs and added support for multi-valued attribute
indexing.

Modified:
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java?rev=902143&r1=902142&r2=902143&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
(original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
Fri Jan 22 16:23:43 2010
@@ -20,7 +20,6 @@
 
 import java.lang.reflect.Array;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -51,43 +50,75 @@
         // Index capability.
         for (Entry<String, Map<Object, Set<Capability>>> entry : m_indices.entrySet())
         {
-            if (cap.getAttribute(entry.getKey()) != null)
+            Attribute capAttr = cap.getAttribute(entry.getKey());
+            if (capAttr != null)
             {
+                Object capValue = capAttr.getValue();
+                if (capValue.getClass().isArray())
+                {
+                    capValue = convertArrayToList(capValue);
+                }
+
                 Map<Object, Set<Capability>> index = entry.getValue();
-                Set<Capability> caps = index.get(
-                    cap.getAttribute(entry.getKey()).getValue());
-if (cap.getAttribute(entry.getKey()).getValue().getClass().isArray())
-{
-    System.out.println("!!! ARRAY VALUE " + cap);
-}
-                if (caps == null)
+
+                if (capValue instanceof Collection)
+                {
+                    Collection c = (Collection) capValue;
+                    for (Object o : c)
+                    {
+                        indexCapability(index, cap, o);
+                    }
+                }
+                else
                 {
-                    caps = new HashSet<Capability>();
-                    index.put(cap.getAttribute(entry.getKey()).getValue(), caps);
+                    indexCapability(index, cap, capValue);
                 }
-                caps.add(cap);
             }
         }
 
 //        System.out.println("+++ INDICES " + m_indices);
     }
 
+    private void indexCapability(
+        Map<Object, Set<Capability>> index, Capability cap, Object capValue)
+    {
+        Set<Capability> caps = index.get(capValue);
+        if (caps == null)
+        {
+            caps = new HashSet<Capability>();
+            index.put(capValue, caps);
+        }
+        caps.add(cap);
+    }
+
     public void removeCapability(Capability cap)
     {
         if (m_capList.remove(cap))
         {
-            for (Iterator<Map.Entry<String, Map<Object, Set<Capability>>>>
-                it = m_indices.entrySet().iterator(); it.hasNext(); )
+            for (Entry<String, Map<Object, Set<Capability>>> entry : m_indices.entrySet())
             {
-                Map.Entry<String, Map<Object, Set<Capability>>> entry =
it.next();
-                if (cap.getAttribute(entry.getKey()) != null)
+                Attribute capAttr = cap.getAttribute(entry.getKey());
+                if (capAttr != null)
                 {
+                    Object capValue = capAttr.getValue();
+                    if (capValue.getClass().isArray())
+                    {
+                        capValue = convertArrayToList(capValue);
+                    }
+
                     Map<Object, Set<Capability>> index = entry.getValue();
-                    Set<Capability> caps = index.get(cap.getAttribute(entry.getKey()).getValue());
-                    caps.remove(cap);
-                    if (caps.size() == 0)
+
+                    if (capValue instanceof Collection)
                     {
-                        it.remove();
+                        Collection c = (Collection) capValue;
+                        for (Object o : c)
+                        {
+                            deindexCapability(index, cap, o);
+                        }
+                    }
+                    else
+                    {
+                        deindexCapability(index, cap, capValue);
                     }
                 }
             }
@@ -96,6 +127,17 @@
         }
     }
 
+    private void deindexCapability(
+        Map<Object, Set<Capability>> index, Capability cap, Object capValue)
+    {
+        Set<Capability> caps = index.get(capValue);
+        caps.remove(cap);
+        if (caps.size() == 0)
+        {
+            index.remove(capValue);
+        }
+    }
+
     public Set<Capability> match(SimpleFilter sf)
     {
         return matchMandatory(match(m_capList, sf), sf);
@@ -396,8 +438,8 @@
     **/
     private static List convertArrayToList(Object array)
     {
-        List list = new ArrayList(Array.getLength(array));
         int len = Array.getLength(array);
+        List list = new ArrayList(len);
         for (int i = 0; i < len; i++)
         {
             list.add(Array.get(array, i));

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java?rev=902143&r1=902142&r2=902143&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
(original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
Fri Jan 22 16:23:43 2010
@@ -830,7 +830,7 @@
             m_invokeCounts.put(methodName, count);
         }
 
-        if (!module.isResolved() && (wireMap.get(module) == null))
+        if (!module.isResolved() && !wireMap.containsKey(module))
         {
             wireMap.put(module, m_emptyWires);
 
@@ -866,6 +866,8 @@
             if (!rbReqs.isEmpty())
             {
                 Map<Requirement, Capability> rbMap = new HashMap<Requirement, Capability>();
+// TODO: FELIX3 - This approach isn't very efficient since it keeps recalculating the
+//       module wire for each package exported by the candidate module.
                 for (Entry<String, List<Blame>> entry : pkgs.m_requiredPkgs.entrySet())
                 {
                     for (Blame blame : entry.getValue())
@@ -884,19 +886,19 @@
                             }
                         }
                     }
+                }
 
-                    // Ignore modules that import themselves.
-                    for (Entry<Requirement, Capability> rbEntry : rbMap.entrySet())
+                // Ignore modules that import themselves.
+                for (Entry<Requirement, Capability> rbEntry : rbMap.entrySet())
+                {
+                    if (!module.equals(rbEntry.getValue().getModule()))
                     {
-                        if (!module.equals(rbEntry.getValue().getModule()))
-                        {
-                            moduleWires.add(
-                                new WireModuleImpl(module,
-                                    rbEntry.getKey(),
-                                    rbEntry.getValue().getModule(),
-                                    rbEntry.getValue(),
-                                    pkgs.getRequiredPackages(rbEntry.getValue())));
-                        }
+                        moduleWires.add(
+                            new WireModuleImpl(module,
+                                rbEntry.getKey(),
+                                rbEntry.getValue().getModule(),
+                                rbEntry.getValue(),
+                                pkgs.getRequiredPackages(rbEntry.getValue())));
                     }
                 }
             }



Mime
View raw message