felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r949048 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
Date Fri, 28 May 2010 00:20:18 GMT
Author: gnodet
Date: Fri May 28 00:20:18 2010
New Revision: 949048

URL: http://svn.apache.org/viewvc?rev=949048&view=rev
Log:
Refactor duplicated code (FELIX-2035)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java?rev=949048&r1=949047&r2=949048&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FelixResolverState.java
Fri May 28 00:20:18 2010
@@ -282,17 +282,7 @@ public class FelixResolverState implemen
 
                 // Remove host's existing exported packages from index.
                 List<Capability> caps = host.getCapabilities();
-                for (int i = 0; (caps != null) && (i < caps.size()); i++)
-                {
-                    if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-                    {
-                        m_modCapSet.removeCapability(caps.get(i));
-                    }
-                    else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-                    {
-                        m_pkgCapSet.removeCapability(caps.get(i));
-                    }
-                }
+                removeCapabilities(caps);
 
                 // Attach the new fragments to the host.
                 fragments = (newFragments.isEmpty()) ? null : newFragments;
@@ -316,17 +306,7 @@ public class FelixResolverState implemen
 
                 // Reindex the host's exported packages.
                 caps = host.getCapabilities();
-                for (int i = 0; (caps != null) && (i < caps.size()); i++)
-                {
-                    if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-                    {
-                        m_modCapSet.addCapability(caps.get(i));
-                    }
-                    else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-                    {
-                        m_pkgCapSet.addCapability(caps.get(i));
-                    }
-                }
+                addCapabilities(caps);
             }
         }
     }
@@ -361,17 +341,7 @@ public class FelixResolverState implemen
 
                     // Remove host's existing exported packages from index.
                     List<Capability> caps = host.getCapabilities();
-                    for (int i = 0; (caps != null) && (i < caps.size()); i++)
-                    {
-                        if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-                        {
-                            m_modCapSet.removeCapability(caps.get(i));
-                        }
-                        else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-                        {
-                            m_pkgCapSet.removeCapability(caps.get(i));
-                        }
-                    }
+                    removeCapabilities(caps);
 
                     // Attach the fragments to the host.
                     try
@@ -394,17 +364,43 @@ public class FelixResolverState implemen
 
                     // Reindex the host's exported packages.
                     caps = host.getCapabilities();
-                    for (int i = 0; (caps != null) && (i < caps.size()); i++)
-                    {
-                        if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-                        {
-                            m_modCapSet.addCapability(caps.get(i));
-                        }
-                        else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-                        {
-                            m_pkgCapSet.addCapability(caps.get(i));
-                        }
-                    }
+                    addCapabilities(caps);
+                }
+            }
+        }
+    }
+
+    private void addCapabilities(List<Capability> caps)
+    {
+        if (caps != null)
+        {
+            for (Capability cap : caps)
+            {
+                if (cap.getNamespace().equals(Capability.MODULE_NAMESPACE))
+                {
+                    m_modCapSet.addCapability(cap);
+                }
+                else if (cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
+                {
+                    m_pkgCapSet.addCapability(cap);
+                }
+            }
+        }
+    }
+
+    private void removeCapabilities(List<Capability> caps)
+    {
+        if (caps != null)
+        {
+            for (Capability cap : caps)
+            {
+                if (cap.getNamespace().equals(Capability.MODULE_NAMESPACE))
+                {
+                    m_modCapSet.removeCapability(cap);
+                }
+                else if (cap.getNamespace().equals(Capability.PACKAGE_NAMESPACE))
+                {
+                    m_pkgCapSet.removeCapability(cap);
                 }
             }
         }
@@ -515,17 +511,7 @@ public class FelixResolverState implemen
         caps = host.getCapabilities();
 
         // Add exports to unresolved package map.
-        for (int i = 0; (caps != null) && (i < caps.size()); i++)
-        {
-            if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-            {
-                m_modCapSet.addCapability(caps.get(i));
-            }
-            else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-            {
-                m_pkgCapSet.addCapability(caps.get(i));
-            }
-        }
+        addCapabilities(caps);
     }
 
     private void removeHost(Module host)
@@ -542,17 +528,7 @@ public class FelixResolverState implemen
 
         // Remove exports from package maps.
         caps = host.getCapabilities();
-        for (int i = 0; (caps != null) && (i < caps.size()); i++)
-        {
-            if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-            {
-                m_modCapSet.removeCapability(caps.get(i));
-            }
-            else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-            {
-                m_pkgCapSet.removeCapability(caps.get(i));
-            }
-        }
+        removeCapabilities(caps);
 
         // Set fragments to null, which will remove the module from all
         // of its dependent fragment modules.
@@ -699,17 +675,7 @@ public class FelixResolverState implemen
         // The system bundle module should always be resolved, so we only need
         // to update the resolved capability map.
         List<Capability> caps = module.getCapabilities();
-        for (int i = 0; (caps != null) && (i < caps.size()); i++)
-        {
-            if (caps.get(i).getNamespace().equals(Capability.MODULE_NAMESPACE))
-            {
-                m_modCapSet.addCapability(caps.get(i));
-            }
-            else if (caps.get(i).getNamespace().equals(Capability.PACKAGE_NAMESPACE))
-            {
-                m_pkgCapSet.addCapability(caps.get(i));
-            }
-        }
+        addCapabilities(caps);
     }
 
     public synchronized void moduleResolved(Module module)



Mime
View raw message