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 2007/06/05 17:19:53 UTC

svn commit: r544515 - in /felix/trunk/framework/src/main/java/org/apache/felix: framework/ framework/searchpolicy/ moduleloader/

Author: rickhall
Date: Tue Jun  5 08:19:52 2007
New Revision: 544515

URL: http://svn.apache.org/viewvc?view=rev&rev=544515
Log:
Modified bundle URL resource handling to remove the bundle class path index
from the resource path to the URL port number. This is a quick and dirty
hack that needs to be revisited, perhaps after spec clarification.

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
    felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java?view=diff&rev=544515&r1=544514&r2=544515
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundle.java Tue Jun  5 08:19:52 2007
@@ -492,12 +492,12 @@
             return null;
         }
 
-        public boolean hasInputStream(String urlPath) throws IOException
+        public boolean hasInputStream(int index, String urlPath) throws IOException
         {
             return (getClass().getClassLoader().getResource(urlPath) != null);
         }
 
-        public InputStream getInputStream(String urlPath) throws IOException
+        public InputStream getInputStream(int index, String urlPath) throws IOException
         {
             return getClass().getClassLoader().getResourceAsStream(urlPath);
         }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java?view=diff&rev=544515&r1=544514&r2=544515
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java Tue Jun  5 08:19:52 2007
@@ -55,7 +55,7 @@
         }
         // Verify that the resource pointed to be the URL exists.
         // The URL is constructed like this:
-        //     bundle://<module-id>/<resource-path>
+        //     bundle://<module-id>:<bundle-classpath-index>/<resource-path>
         // Where <module-id> = <bundle-id>.<revision>
         long bundleId = Util.getBundleIdFromModuleId(url.getHost());
         BundleImpl bundle = (BundleImpl) m_framework.getBundle(bundleId);
@@ -66,7 +66,7 @@
         int revision = Util.getModuleRevisionFromModuleId(url.getHost());
         IModule[] modules = bundle.getInfo().getModules();
         if ((modules == null) || (revision < 0) || (revision >= modules.length) ||
-            !modules[revision].getContentLoader().hasInputStream(url.getPath()))
+            !modules[revision].getContentLoader().hasInputStream(url.getPort(), url.getPath()))
         {
             throw new IOException("Resource does not exist: " + url);
         }
@@ -77,7 +77,7 @@
         if (!connected)
         {
             // The URL is constructed like this:
-            //     bundle://<module-id>/<resource-path>
+        //     bundle://<module-id>:<module-classpath-index>/<resource-path>
             // Where <module-id> = <bundle-id>.<revision>
             long bundleId = Util.getBundleIdFromModuleId(url.getHost());
             BundleImpl bundle = (BundleImpl) m_framework.getBundle(bundleId);
@@ -91,7 +91,8 @@
             {
                 throw new IOException("Resource does not exist: " + url);
             }
-            m_is = bundle.getInfo().getModules()[revision].getContentLoader().getInputStream(url.getPath());
+            m_is = bundle.getInfo().getModules()[revision]
+                .getContentLoader().getInputStream(url.getPort(), url.getPath());
             m_contentLength = (m_is == null) ? 0 : m_is.available();
             m_contentTime = 0L;
             m_contentType = URLConnection.guessContentTypeFromName(url.getFile());

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java?view=diff&rev=544515&r1=544514&r2=544515
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java Tue Jun  5 08:19:52 2007
@@ -143,7 +143,7 @@
         {
             if (getClassPath()[i].hasEntry(name))
             {
-                url = getURLPolicy().createURL((i + 1) + "/" + name);
+                url = getURLPolicy().createURL(i + 1, name);
             }
         }
 
@@ -169,7 +169,7 @@
                 // that we can differentiate between module content URLs
                 // (where the path will start with 0) and module class
                 // path URLs.
-                v.addElement(getURLPolicy().createURL((i + 1) + "/" + name));
+                v.addElement(getURLPolicy().createURL(i + 1, name));
             }
         }
 
@@ -186,7 +186,7 @@
         // the root of the bundle according to the spec.
         if (name.equals("/"))
         {
-            url = getURLPolicy().createURL("0/");
+            url = getURLPolicy().createURL(0, "/");
         }
 
         if (url == null)
@@ -203,54 +203,38 @@
                 // Module content URLs start with 0, whereas module
                 // class path URLs start with the index into the class
                 // path + 1.
-                url = getURLPolicy().createURL("0/" + name);
+                url = getURLPolicy().createURL(0, name);
             }
         }
 
         return url;
     }
 
-    public boolean hasInputStream(String urlPath)
+    public boolean hasInputStream(int index, String urlPath)
     {
         if (urlPath.startsWith("/"))
         {
             urlPath = urlPath.substring(1);
         }
-        // The urlPath is the path portion of a resource URL
-        // that is contructed above in getResouce() like this:
-        // <index> / <relative-resource-path>
-        // where <index> == 0 is the module content
-        // and <index> > 0 is the index into the class
-        // path - 1.
-        int idx = Integer.parseInt(urlPath.substring(0, urlPath.indexOf('/')));
-        urlPath = urlPath.substring(urlPath.indexOf('/') + 1);
-        if (idx == 0)
+        if (index == 0)
         {
             return m_content.hasEntry(urlPath);
         }
-        return m_contentPath[idx - 1].hasEntry(urlPath);
+        return m_contentPath[index - 1].hasEntry(urlPath);
     }
 
-    public InputStream getInputStream(String urlPath)
+    public InputStream getInputStream(int index, String urlPath)
         throws IOException
     {
         if (urlPath.startsWith("/"))
         {
             urlPath = urlPath.substring(1);
         }
-        // The urlPath is the path portion of a resource URL
-        // that is contructed above in getResouce() like this:
-        // <index> / <relative-resource-path>
-        // where <index> == 0 is the module content
-        // and <index> > 0 is the index into the class
-        // path - 1.
-        int idx = Integer.parseInt(urlPath.substring(0, urlPath.indexOf('/')));
-        urlPath = urlPath.substring(urlPath.indexOf('/') + 1);
-        if (idx == 0)
+        if (index == 0)
         {
             return m_content.getEntryAsStream(urlPath);
         }
-        return m_contentPath[idx - 1].getEntryAsStream(urlPath);
+        return m_contentPath[index - 1].getEntryAsStream(urlPath);
     }
 
     public String toString()

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java?view=diff&rev=544515&r1=544514&r2=544515
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java Tue Jun  5 08:19:52 2007
@@ -41,7 +41,7 @@
         m_module = module;
     }
 
-    public URL createURL(String path)
+    public URL createURL(int port, String path)
     {
          // Add a slash if there is one already, otherwise
          // the is no slash separating the host from the file
@@ -55,7 +55,7 @@
          {
              return m_secureAction.createURL(
                  FelixConstants.BUNDLE_URL_PROTOCOL,
-                 m_module.getId(), -1, path, m_streamHandler);
+                 m_module.getId(), port, path, m_streamHandler);
          }
          catch (MalformedURLException ex)
          {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java?view=diff&rev=544515&r1=544514&r2=544515
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java Tue Jun  5 08:19:52 2007
@@ -41,8 +41,16 @@
     public Enumeration getResources(String name);
     public URL getResourceFromContent(String name);
 
-    public boolean hasInputStream(String urlPath)
+    // TODO: ML - For expediency, the index argument was added to these methods
+    // but it is not clear that this makes sense in the long run. This needs to
+    // be readdressed in the future, perhaps by the spec to clearly indicate
+    // how resources on the bundle class path are searched, which is why we
+    // need the index number in the first place -- to differentiate among
+    // resources with the same name on the bundle class path. This was previously
+    // handled as part of the resource path, but that approach is not spec
+    // compliant.
+    public boolean hasInputStream(int index, String urlPath)
         throws IOException;
-    public InputStream getInputStream(String urlPath)
+    public InputStream getInputStream(int index, String urlPath)
         throws IOException;
 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java?view=diff&rev=544515&r1=544514&r2=544515
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java Tue Jun  5 08:19:52 2007
@@ -22,5 +22,13 @@
 
 public interface IURLPolicy
 {
-    public URL createURL(String path);
+    // TODO: ML - For expediency, the port argument was added to this method
+    // but it is not clear that it makes sense in the long run. This needs to
+    // be readdressed in the future, perhaps by the spec to clearly indicate
+    // how resources on the bundle class path are searched, which is why we
+    // need the port number in the first place -- to differentiate among
+    // resources with the same name on the bundle class path. This was previously
+    // handled as part of the resource path, but that approach is not spec
+    // compliant.
+    public URL createURL(int port, String path);
 }