felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r450113 - in /incubator/felix/trunk/framework/src/main/java/org/apache/felix: framework/ framework/searchpolicy/ moduleloader/
Date Tue, 26 Sep 2006 16:53:30 GMT
Author: rickhall
Date: Tue Sep 26 09:53:29 2006
New Revision: 450113

URL: http://svn.apache.org/viewvc?view=rev&rev=450113
Log:
Applied patch (FELIX-153) to implement Bundle.getResources().

Modified:
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IWire.java
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
Tue Sep 26 09:53:29 2006
@@ -160,6 +160,26 @@
         return m_felix.getBundleResource(this, name);
     }
 
+    public Enumeration getResources(String name) throws IOException
+    {
+        Object sm = System.getSecurityManager();
+
+        if (sm != null)
+        {
+            try
+            {
+                ((SecurityManager) sm).checkPermission(new AdminPermission(this,
+                    AdminPermission.RESOURCE));
+            }
+            catch (Exception e)
+            {
+                return null; // No permission
+            }
+        }
+
+        return m_felix.getBundleResources(this, name);
+    }
+
     /**
      * Returns an array of service references corresponding to
      * the bundle's registered services.
@@ -388,27 +408,6 @@
         {
             ((SecurityManager) sm).checkPermission(new AdminPermission(this,
                 AdminPermission.METADATA));
-        }
-
-        return null;
-    }
-
-    public Enumeration getResources(String name) throws IOException
-    {
-        // TODO: Implement Bundle.getResources()
-        Object sm = System.getSecurityManager();
-
-        if (sm != null)
-        {
-            try
-            {
-                ((SecurityManager) sm).checkPermission(new AdminPermission(this,
-                    AdminPermission.RESOURCE));
-            }
-            catch (Exception e)
-            {
-                return null; // No permission
-            }
         }
 
         return null;

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Tue
Sep 26 09:53:29 2006
@@ -995,6 +995,18 @@
     }
 
     /**
+     * Implementation for Bundle.getResources().
+    **/
+    protected Enumeration getBundleResources(BundleImpl bundle, String name)
+    {
+        if (bundle.getInfo().getState() == Bundle.UNINSTALLED)
+        {
+            throw new IllegalStateException("The bundle is uninstalled.");
+        }
+        return bundle.getInfo().getCurrentModule().getResources(name);
+    }
+
+    /**
      * Implementation for Bundle.getEntry().
     **/
     protected URL getBundleEntry(BundleImpl bundle, String name)

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java
Tue Sep 26 09:53:29 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Enumeration;
 
 import org.apache.felix.moduleloader.*;
 
@@ -89,6 +90,18 @@
     public URL getResource(String name)
     {
         return getClass().getClassLoader().getResource(name);
+    }
+
+    public Enumeration getResources(String name)
+    {
+       try
+       {
+           return getClass().getClassLoader().getResources(name);
+       }
+       catch (IOException ex)
+       {
+           return null;
+       }
     }
 
     public URL getResourceFromContent(String name)

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java
Tue Sep 26 09:53:29 2006
@@ -150,7 +150,7 @@
         return url;
     }
 
-    protected Enumeration getResources(String name)
+    public Enumeration getResources(String name)
     {
         Vector v = new Vector();
 

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
Tue Sep 26 09:53:29 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,6 +19,7 @@
 package org.apache.felix.framework.searchpolicy;
 
 import java.net.URL;
+import java.util.Enumeration;
 
 import org.apache.felix.moduleloader.*;
 
@@ -48,6 +49,12 @@
         throws ResourceNotFoundException
     {
         return m_policyCore.findResource(m_module, name);
+    }
+
+    public Enumeration findResources(String name)
+        throws ResourceNotFoundException
+    {
+        return m_policyCore.findResources(m_module, name);
     }
 
     public String findLibrary(String name)

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
Tue Sep 26 09:53:29 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.framework.searchpolicy;
 
+import java.io.IOException;
 import java.net.URL;
 import java.security.ProtectionDomain;
 import java.util.*;
@@ -88,7 +89,8 @@
         }
         else
         {
-            throw new IllegalStateException("Module manager is already initialized");
+            throw new IllegalStateException(
+                "Module manager is already initialized");
         }
     }
 
@@ -162,11 +164,118 @@
         {
             throw ex;
         }
-
+    
         // We should never reach this point.
         return null;
     }
 
+    public Enumeration findResources(IModule module, String name)
+        throws ResourceNotFoundException
+    {
+        Enumeration urls;
+        // First, try to resolve the originating module.
+        // TODO: Consider opimizing this call to resolve, since it is called
+        // for each class load.
+        try
+        {
+            resolve(module);
+        }
+        catch (ResolveException ex)
+        {
+            // The spec states that if the bundle cannot be resolved, then
+            // only the local bundle's resources should be searched. So we
+            // will ask the module's own class path.
+            urls = module.getContentLoader().getResources(name);
+            if (urls != null)
+            {
+                return urls;
+            }
+            // We need to throw a resource not found exception.
+            throw new ResourceNotFoundException(name
+                + ": cannot resolve package " + ex.getPackage());
+        }
+
+        // Get the package of the target class/resource.
+        String pkgName = Util.getResourcePackage(name);
+
+        // Delegate any packages listed in the boot delegation
+        // property to the parent class loader.
+        // NOTE for the default package:
+        // Only consider delegation if we have a package name, since
+        // we don't want to promote the default package. The spec does
+        // not take a stand on this issue.
+        if (pkgName.length() > 0)
+        {
+            for (int i = 0; i < m_bootPkgs.length; i++)
+            {
+                // A wildcarded boot delegation package will be in the form of
+                // "foo.", so if the package is wildcarded do a startsWith() or a
+                // regionMatches() to ignore the trailing "." to determine if the
+                // request should be delegated to the parent class loader. If the
+                // package is not wildcarded, then simply do an equals() test to
+                // see if the request should be delegated to the parent class loader.
+                if ((m_bootPkgWildcards[i] &&
+                    (pkgName.startsWith(m_bootPkgs[i]) ||
+                    m_bootPkgs[i].regionMatches(0, pkgName, 0, pkgName.length())))
+                    || (!m_bootPkgWildcards[i] && m_bootPkgs[i].equals(pkgName)))
+                {
+                    try
+                    {
+                        urls = getClass().getClassLoader().getResources(name);
+                        return urls;
+                    }
+                    catch (IOException ex)
+                    {
+                        return null;
+                    }
+                }
+            }
+        }
+
+        // Look in the module's imports.
+        // We delegate to the module's wires to the resources.
+        // If any resources are found, this means that the package of these
+        // resources is imported, we must not keep looking since we do not
+        // support split-packages.
+
+        // Note that the search may be aborted if this method throws an
+        // exception, otherwise it continues if a null is returned.
+        IWire[] wires = module.getWires();
+        for (int i = 0; (wires != null) && (i < wires.length); i++)
+        {
+            // If we find the class or resource, then return it.
+            urls = wires[i].getResources(name);
+            if (urls != null)
+            {
+                return urls;
+            }
+        }
+
+        // If not found, try the module's own class path.
+        urls = module.getContentLoader().getResources(name);
+        if (urls != null)
+        {
+            return urls;
+        }
+
+        // If still not found, then try the module's dynamic imports.
+        // 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 = attemptDynamicImport(module, pkgName);
+        if (wire != null)
+        {
+            urls = wire.getResources(name);
+        }
+
+        if (urls == null)
+        {
+            throw new ResourceNotFoundException(name);
+        }
+
+        return urls;
+    }
+
     private Object findClassOrResource(IModule module, String name, boolean isClass)
         throws ClassNotFoundException, ResourceNotFoundException
     {
@@ -531,7 +640,7 @@
                 PackagePermission perm = new PackagePermission(pkg.getName(),
                     PackagePermission.EXPORT);
 
-                for (int i = 0;i < exporters.length;i++)
+                for (int i = 0; i < exporters.length; i++)
                 {
                     if (exporters[i] != null)
                     {
@@ -1784,4 +1893,4 @@
 
         return sb.toString();
     }
-}
+}
\ No newline at end of file

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
Tue Sep 26 09:53:29 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,6 +19,7 @@
 package org.apache.felix.framework.searchpolicy;
 
 import java.net.URL;
+import java.util.Enumeration;
 
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.moduleloader.*;
@@ -123,6 +124,31 @@
         }
 
         return url;
+    }
+
+    public Enumeration getResources(String name) throws ResourceNotFoundException
+    {
+        Enumeration urls = null;
+
+        // Get the package of the target class.
+        String pkgName = Util.getResourcePackage(name);
+
+        // Only check when the package of the target resource is
+        // the same as the package for the wire.
+        if (m_export.getName().equals(pkgName))
+        {
+            urls = m_exporter.getContentLoader().getResources(name);
+
+            // If no resource was found, then we must throw an exception
+            // since the exporter for this package did not contain the
+            // requested class.
+            if (urls == null)
+            {
+                throw new ResourceNotFoundException(name);
+            }
+        }
+
+        return urls;
     }
 
     public String toString()

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
Tue Sep 26 09:53:29 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Enumeration;
 
 public interface IContentLoader
 {
@@ -37,6 +38,7 @@
 
     public Class getClass(String name);
     public URL getResource(String name);
+    public Enumeration getResources(String name);
     public URL getResourceFromContent(String name);
 
     public boolean hasInputStream(String urlPath)

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IModule.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
Tue Sep 26 09:53:29 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,6 +19,7 @@
 package org.apache.felix.moduleloader;
 
 import java.net.URL;
+import java.util.Enumeration;
 
 public interface IModule
 {
@@ -31,6 +32,7 @@
 
     public Class getClass(String name);
     public URL getResource(String name);
+    public Enumeration getResources(String name);
 
     public Object getSecurityContext();
 }

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java
Tue Sep 26 09:53:29 2006
@@ -19,13 +19,13 @@
 package org.apache.felix.moduleloader;
 
 import java.net.URL;
-
-import org.apache.felix.moduleloader.ResourceNotFoundException;
+import java.util.Enumeration;
 
 public interface ISearchPolicy
 {
     public Object[] definePackage(String name);
     public Class findClass(String name) throws ClassNotFoundException;
     public URL findResource(String name) throws ResourceNotFoundException;
+    public Enumeration findResources(String name) throws ResourceNotFoundException;
     public String findLibrary(String name);
 }

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IWire.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IWire.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IWire.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/IWire.java
Tue Sep 26 09:53:29 2006
@@ -19,6 +19,7 @@
 package org.apache.felix.moduleloader;
 
 import java.net.URL;
+import java.util.Enumeration;
 
 import org.apache.felix.framework.searchpolicy.R4Export;
 
@@ -29,4 +30,5 @@
     public R4Export getExport();
     public Class getClass(String name) throws ClassNotFoundException;
     public URL getResource(String name) throws ResourceNotFoundException;
+    public Enumeration getResources(String name) throws ResourceNotFoundException;
 }

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java?view=diff&rev=450113&r1=450112&r2=450113
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
Tue Sep 26 09:53:29 2006
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,6 +19,7 @@
 package org.apache.felix.moduleloader;
 
 import java.net.URL;
+import java.util.Enumeration;
 
 import org.apache.felix.framework.Logger;
 
@@ -105,6 +106,22 @@
         try
         {
             return m_contentLoader.getSearchPolicy().findResource(name);
+        }
+        catch (ResourceNotFoundException ex)
+        {
+            m_logger.log(
+                Logger.LOG_WARNING,
+                ex.getMessage(),
+                ex);
+        }
+        return null;
+    }
+
+    public Enumeration getResources(String name)
+    {
+        try
+        {
+           return m_contentLoader.getSearchPolicy().findResources(name);
         }
         catch (ResourceNotFoundException ex)
         {



Mime
View raw message