felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r375026 - in /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework: BundleImpl.java Felix.java searchpolicy/ContentClassLoader.java searchpolicy/ContentLoaderImpl.java
Date Sun, 05 Feb 2006 13:28:27 GMT
Author: rickhall
Date: Sun Feb  5 05:28:26 2006
New Revision: 375026

URL: http://svn.apache.org/viewcvs?rev=375026&view=rev
Log:
Implemented Bundle.getEntry() for accessing the raw bundle JAR file; this
uses non-API methods from the Module Loader layer so it will need to be
tweaked in the future, but it appears to work for now.

Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentClassLoader.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=375026&r1=375025&r2=375026&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
Sun Feb  5 05:28:26 2006
@@ -55,6 +55,11 @@
         return m_info.getBundleId();
     }
 
+    public URL getEntry(String name)
+    {
+        return m_felix.getBundleEntry(this, name);
+    }
+
     public Dictionary getHeaders()
     {
         return m_felix.getBundleHeaders(this);
@@ -166,12 +171,6 @@
     public Enumeration getEntryPaths(String path)
     {
         // TODO: Implement Bundle.getEntryPaths()
-        return null;
-    }
-
-    public URL getEntry(String name)
-    {
-        // TODO: Implement Bundle.getEntry()
         return null;
     }
 

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=375026&r1=375025&r2=375026&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Sun Feb  5 05:28:26 2006
@@ -966,6 +966,24 @@
         return bundle.getInfo().getCurrentModule().getResource(name);
     }
 
+    /**
+     * Implementation for Bundle.getEntry().
+    **/
+    protected URL getBundleEntry(BundleImpl bundle, String name)
+    {
+        if (bundle.getInfo().getState() == Bundle.UNINSTALLED)
+        {
+            throw new IllegalStateException("The bundle is uninstalled.");
+        }
+// TODO: SECURITY - Implement correct check.
+        else if (System.getSecurityManager() != null)
+        {
+            AccessController.checkPermission(m_adminPerm);
+        }
+        return ((ContentLoaderImpl) bundle.getInfo().getCurrentModule()
+            .getContentLoader()).getResourceFromContent(name);
+    }
+
     protected ServiceReference[] getBundleRegisteredServices(BundleImpl bundle)
     {
         if (bundle.getInfo().getState() == Bundle.UNINSTALLED)

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentClassLoader.java?rev=375026&r1=375025&r2=375026&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentClassLoader.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentClassLoader.java
Sun Feb  5 05:28:26 2006
@@ -21,7 +21,6 @@
 import java.security.SecureClassLoader;
 import java.security.cert.Certificate;
 import java.util.Enumeration;
-import java.util.Vector;
 
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.util.Util;
@@ -198,48 +197,12 @@
 
     protected URL findResource(String name)
     {
-        URL url = null;
-
-        // Remove leading slash, if present.
-        if (name.startsWith("/"))
-        {
-            name = name.substring(1);
-        }
-
-        // Check the module class path.
-        for (int i = 0;
-            (url == null) &&
-            (i < m_contentLoader.getClassPath().length); i++)
-        {
-            if (m_contentLoader.getClassPath()[i].hasEntry(name))
-            {
-                url = m_contentLoader.getURLPolicy().createURL(i + "/" + name);
-            }
-        }
-
-        return url;
+        return m_contentLoader.getResource(name);
     }
 
     protected Enumeration findResources(String name)
     {
-        Vector v = new Vector();
-
-        // Remove leading slash, if present.
-        if (name.startsWith("/"))
-        {
-            name = name.substring(1);
-        }
-
-        // Check the module class path.
-        for (int i = 0; i < m_contentLoader.getClassPath().length; i++)
-        {
-            if (m_contentLoader.getClassPath()[i].hasEntry(name))
-            {
-                v.addElement(m_contentLoader.getURLPolicy().createURL(i + "/" + name));
-            }
-        }
-
-        return v.elements();
+        return m_contentLoader.getResources(name);
     }
 
     protected String findLibrary(String name)

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java?rev=375026&r1=375025&r2=375026&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
Sun Feb  5 05:28:26 2006
@@ -19,6 +19,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Enumeration;
+import java.util.Vector;
 
 import org.apache.felix.framework.Logger;
 import org.apache.felix.moduleloader.*;
@@ -111,12 +113,74 @@
 
     public URL getResource(String name)
     {
-        if (m_classLoader == null)
+        URL url = null;
+        // Remove leading slash, if present.
+        if (name.startsWith("/"))
         {
-            m_classLoader = new ContentClassLoader(this);
+            name = name.substring(1);
         }
 
-        return m_classLoader.getResourceFromModule(name);
+        // Check the module class path.
+        for (int i = 0;
+            (url == null) &&
+            (i < getClassPath().length); i++)
+        {
+            if (getClassPath()[i].hasEntry(name))
+            {
+                url = getURLPolicy().createURL((i + 1) + "/" + name);
+            }
+        }
+
+        return url;
+    }
+
+    protected Enumeration getResources(String name)
+    {
+        Vector v = new Vector();
+
+        // Remove leading slash, if present.
+        if (name.startsWith("/"))
+        {
+            name = name.substring(1);
+        }
+
+        // Check the module class path.
+        for (int i = 0; i < getClassPath().length; i++)
+        {
+            if (getClassPath()[i].hasEntry(name))
+            {
+                // Use the class path index + 1 for creating the path so
+                // 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));
+            }
+        }
+
+        return v.elements();
+    }
+
+    // TODO: API: Investigate making this an API call.
+    public URL getResourceFromContent(String name)
+    {
+        URL url = null;
+
+        // Remove leading slash, if present.
+        if (name.startsWith("/"))
+        {
+            name = name.substring(1);
+        }
+
+        // Check the module content.
+        if (getContent().hasEntry(name))
+        {
+            // 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);
+        }
+
+        return url;
     }
 
     public InputStream getResourceAsStream(String name)
@@ -127,10 +191,17 @@
             name = name.substring(1);
         }
         // The name is the path contructed like this:
-        // <class-path-index> / <relative-resource-path>
+        // <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(name.substring(0, name.indexOf('/')));
         name = name.substring(name.indexOf('/') + 1);
-        return m_contentPath[idx].getEntryAsStream(name);
+        if (idx == 0)
+        {
+            return m_content.getEntryAsStream(name);
+        }
+        return m_contentPath[idx - 1].getEntryAsStream(name);
     }
 
     public String toString()



Mime
View raw message