You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/01/20 18:52:52 UTC

svn commit: r901306 - in /felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework: BundleImpl.java ModuleImpl.java RequiredBundleImpl.java URLHandlersBundleURLConnection.java

Author: rickhall
Date: Wed Jan 20 17:52:52 2010
New Revision: 901306

URL: http://svn.apache.org/viewvc?rev=901306&view=rev
Log:
More fixes.

Modified:
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/BundleImpl.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java
    felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=901306&r1=901305&r2=901306&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/BundleImpl.java (original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/BundleImpl.java Wed Jan 20 17:52:52 2010
@@ -25,9 +25,9 @@
 import java.util.*;
 
 import org.apache.felix.framework.cache.BundleArchive;
+import org.apache.felix.framework.candidateset.Module;
 import org.apache.felix.framework.ext.SecurityProvider;
 import org.apache.felix.framework.util.StringMap;
-import org.apache.felix.moduleloader.IModule;
 import org.osgi.framework.*;
 
 class BundleImpl implements Bundle
@@ -36,7 +36,7 @@
     private final Felix __m_felix;
 
     private final BundleArchive m_archive;
-    private IModule[] m_modules = new IModule[0];
+    private final List<Module> m_modules = new ArrayList<Module>(0);
     private volatile int m_state;
     private boolean m_useDeclaredActivationPolicy;
     private BundleActivator m_activator = null;
@@ -76,7 +76,7 @@
         m_activator = null;
         m_context = null;
 
-        IModule module = createModule();
+        Module module = createModule();
         addModule(module);
     }
 
@@ -127,10 +127,10 @@
     {
         // Remove the bundle's associated modules from the resolver state
         // and close them.
-        for (int i = 0; i < m_modules.length; i++)
+        for (int i = 0; i < m_modules.size(); i++)
         {
-            getFramework().getResolverState().removeModule(m_modules[i]);
-            ((ModuleImpl) m_modules[i]).close();
+            getFramework().getResolverState().removeModule(m_modules.get(i));
+            ((ModuleImpl) m_modules.get(i)).close();
         }
     }
 
@@ -151,8 +151,8 @@
 
             // Lastly, we want to reset our bundle be reinitializing our state
             // and recreating a module for the newest revision.
-            m_modules = new IModule[0];
-            final IModule module = createModule();
+            m_modules.clear();
+            final Module module = createModule();
             addModule(module);
             m_state = Bundle.INSTALLED;
             m_stale = false;
@@ -383,7 +383,7 @@
                 {
                     for (Iterator it = resourceList.iterator(); it.hasNext(); )
                     {
-                        URL temp = ((IModule) moduleList.get(modIdx)).getEntry(
+                        URL temp = ((Module) moduleList.get(modIdx)).getEntry(
                             it.next() + ".properties");
                         if (temp != null)
                         {
@@ -454,15 +454,15 @@
         // version instead of the fragment itself. If there are
         // no hosts, but the module is a fragment, then just
         // search the module itself.
-        IModule[] hosts = module.getDependentHosts();
-        if ((hosts != null) && (hosts.length > 0))
+        List<Module> hosts = module.getDependentHosts();
+        if ((hosts != null) && (hosts.size() > 0))
         {
-            module = (ModuleImpl) hosts[0];
-            for (int hostIdx = 1; hostIdx < hosts.length; hostIdx++)
+            module = (ModuleImpl) hosts.get(0);
+            for (int hostIdx = 1; hostIdx < hosts.size(); hostIdx++)
             {
-                if (module.getVersion().compareTo(hosts[hostIdx].getVersion()) < 0)
+                if (module.getVersion().compareTo(hosts.get(hostIdx).getVersion()) < 0)
                 {
-                    module = (ModuleImpl) hosts[hostIdx];
+                    module = (ModuleImpl) hosts.get(hostIdx);
                 }
             }
         }
@@ -470,11 +470,7 @@
         // Create a list of the module and any attached fragments.
         List result = new ArrayList();
         result.add(module);
-        IModule[] fragments = module.getFragments();
-        for (int i = 0; (fragments != null) && (i < fragments.length); i++)
-        {
-            result.add(fragments[i]);
-        }
+        result.add(module.getFragments());
         return result;
     }
 
@@ -816,9 +812,9 @@
 
     synchronized boolean isExtension()
     {
-        for (int i = (m_modules.length - 1); i > -1; i--)
+        for (int i = (m_modules.size() - 1); i > -1; i--)
         {
-            if (m_modules[i].isExtension())
+            if (m_modules.get(i).isExtension())
             {
                 return true;
             }
@@ -962,7 +958,7 @@
 
     synchronized boolean isRemovalPending()
     {
-        return (m_state == Bundle.UNINSTALLED) || (m_modules.length > 1)  || m_stale;
+        return (m_state == Bundle.UNINSTALLED) || (m_modules.size() > 1)  || m_stale;
     }
 
     //
@@ -981,7 +977,7 @@
      * no limit on the potential number of bundle JAR file revisions.
      * @return array of modules corresponding to the bundle JAR file revisions.
     **/
-    synchronized IModule[] getModules()
+    synchronized List<Module> getModules()
     {
         return m_modules;
     }
@@ -992,11 +988,11 @@
      * @return <tt>true</tt> if the specified module is in the array of modules
      *         associated with this bundle, <tt>false</tt> otherwise.
     **/
-    synchronized boolean hasModule(IModule module)
+    synchronized boolean hasModule(Module module)
     {
-        for (int i = 0; i < m_modules.length; i++)
+        for (int i = 0; i < m_modules.size(); i++)
         {
-            if (m_modules[i] == module)
+            if (m_modules.get(i) == module)
             {
                 return true;
             }
@@ -1009,20 +1005,20 @@
      * in the module array.
      * @return the newest module.
     **/
-    synchronized IModule getCurrentModule()
+    synchronized Module getCurrentModule()
     {
-        return m_modules[m_modules.length - 1];
+        return m_modules.get(m_modules.size() - 1);
     }
 
     synchronized boolean isUsed()
     {
         boolean used = false;
-        for (int i = 0; !used && (i < m_modules.length); i++)
+        for (int i = 0; !used && (i < m_modules.size()); i++)
         {
-            IModule[] dependents = ((ModuleImpl) m_modules[i]).getDependents();
-            for (int j = 0; (dependents != null) && (j < dependents.length) && !used; j++)
+            List<Module> dependents = ((ModuleImpl) m_modules.get(i)).getDependents();
+            for (int j = 0; (dependents != null) && (j < dependents.size()) && !used; j++)
             {
-                if (dependents[j] != m_modules[i])
+                if (dependents.get(j) != m_modules.get(i))
                 {
                     used = true;
                 }
@@ -1038,7 +1034,7 @@
         m_archive.revise(location, is);
         try
         {
-            IModule module = createModule();
+            Module module = createModule();
             addModule(module);
         }
         catch (Exception ex)
@@ -1057,13 +1053,9 @@
     // system bundle needs to add its module directly to the bundle,
     // since it doesn't have an archive from which the module will
     // be created, which is the normal case.
-    synchronized void addModule(IModule module) throws Exception
+    synchronized void addModule(Module module) throws Exception
     {
-        IModule[] backup = m_modules;
-        IModule[] dest = new IModule[m_modules.length + 1];
-        System.arraycopy(m_modules, 0, dest, 0, m_modules.length);
-        dest[m_modules.length] = module;
-        m_modules = dest;
+        m_modules.add(module);
 
         // Set protection domain after adding the module to the bundle,
         // since this requires that the bundle has a module.
@@ -1078,7 +1070,7 @@
             }
             catch (Exception ex) 
             {
-                m_modules = backup;
+                m_modules.remove(m_modules.size() - 1);
                 throw ex;
             }
         }
@@ -1094,7 +1086,7 @@
         }
     }
 
-    private IModule createModule() throws Exception
+    private Module createModule() throws Exception
     {
         // Get and parse the manifest from the most recent revision to
         // create an associated module for it.
@@ -1146,9 +1138,9 @@
     {
         ProtectionDomain pd = null;
 
-        for (int i = m_modules.length - 1; (i >= 0) && (pd == null); i--)
+        for (int i = m_modules.size() - 1; (i >= 0) && (pd == null); i--)
         {
-            pd = (ProtectionDomain) m_modules[i].getSecurityContext();
+            pd = (ProtectionDomain) m_modules.get(i).getSecurityContext();
         }
 
         return pd;

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java?rev=901306&r1=901305&r2=901306&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java (original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/ModuleImpl.java Wed Jan 20 17:52:52 2010
@@ -1340,7 +1340,7 @@
         // At this point, the module's imports were searched and so was the
         // the module's content. Now we make an attempt to load the
         // class/resource via a dynamic import, if possible.
-        IWire wire = null;
+        Wire wire = null;
         try
         {
             wire = m_resolver.resolveDynamicImport(this, pkgName);
@@ -1904,14 +1904,14 @@
                 // native library.
                 if (result == null)
                 {
-                    R4Library[] libs = getNativeLibraries();
-                    for (int libIdx = 0; (libs != null) && (libIdx < libs.length); libIdx++)
+                    List<R4Library> libs = getNativeLibraries();
+                    for (int libIdx = 0; (libs != null) && (libIdx < libs.size()); libIdx++)
                     {
-                        if (libs[libIdx].match(m_configMap, name))
+                        if (libs.get(libIdx).match(m_configMap, name))
                         {
                             // Search bundle content first for native library.
                             result = getContent().getEntryAsNativeLibrary(
-                                libs[libIdx].getEntryName());
+                                libs.get(libIdx).getEntryName());
                             // If not found, then search fragments in order.
                             for (int i = 0;
                                 (result == null) && (m_fragmentContents != null)
@@ -1919,7 +1919,7 @@
                                 i++)
                             {
                                 result = m_fragmentContents[i].getEntryAsNativeLibrary(
-                                    libs[libIdx].getEntryName());
+                                    libs.get(libIdx).getEntryName());
                             }
                         }
                     }

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java?rev=901306&r1=901305&r2=901306&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java (original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java Wed Jan 20 17:52:52 2010
@@ -62,12 +62,12 @@
         // of the dependent modules.
         Set bundleSet = new HashSet();
         // Loop through all of this bundle's modules.
-        Module[] modules = m_bundle.getModules();
-        for (int modIdx = 0; (modules != null) && (modIdx < modules.length); modIdx++)
+        List<Module> modules = m_bundle.getModules();
+        for (int modIdx = 0; (modules != null) && (modIdx < modules.size()); modIdx++)
         {
             // For each of this bundle's modules, loop through all of the
             // modules that require it and add them to the module list.
-            List<Module> dependents = ((ModuleImpl) modules[modIdx]).getDependentRequirers();
+            List<Module> dependents = ((ModuleImpl) modules.get(modIdx)).getDependentRequirers();
             for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
             {
                 if (dependents.get(depIdx).getBundle() != null)

Modified: felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java?rev=901306&r1=901305&r2=901306&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java (original)
+++ felix/sandbox/rickhall/framework-proto/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java Wed Jan 20 17:52:52 2010
@@ -23,6 +23,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.Permission;
+import java.util.List;
 import org.apache.felix.framework.candidateset.Module;
 
 import org.apache.felix.framework.util.Util;
@@ -77,8 +78,8 @@
         m_contentTime = bundle.getLastModified();
 
         int revision = Util.getModuleRevisionFromModuleId(url.getHost());
-        Module[] modules = bundle.getModules();
-        if ((modules == null) || (revision >= modules.length))
+        List<Module> modules = bundle.getModules();
+        if ((modules == null) || (revision >= modules.size()))
         {
             throw new IOException("Resource does not exist: " + url);
         }
@@ -86,7 +87,7 @@
         // If the revision is not specified, check the latest
         if (revision < 0)
         {
-            revision = modules.length - 1;
+            revision = modules.size() - 1;
         }
 
         // If the resource cannot be found at the current class path index,
@@ -96,15 +97,15 @@
         // Of course, this approach won't work in cases where there are multiple
         // resources with the same path, since it will always find the first
         // one on the class path.
-        m_targetModule = modules[revision];
+        m_targetModule = modules.get(revision);
         m_classPathIdx = url.getPort();
         if (m_classPathIdx < 0)
         {
             m_classPathIdx = 0;
         }
-        if (!modules[revision].hasInputStream(m_classPathIdx, url.getPath()))
+        if (!modules.get(revision).hasInputStream(m_classPathIdx, url.getPath()))
         {
-            URL newurl = modules[revision].getResourceByDelegation(url.getPath());
+            URL newurl = modules.get(revision).getResourceByDelegation(url.getPath());
             if (newurl == null)
             {
                 throw new IOException("Resource does not exist: " + url);