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 2006/02/02 11:34:13 UTC

svn commit: r374344 - in /incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework: ./ cache/ util/

Author: rickhall
Date: Thu Feb  2 02:34:05 2006
New Revision: 374344

URL: http://svn.apache.org/viewcvs?rev=374344&view=rev
Log:
Additional changes needed in the framework implementation as a result of
changes in the R4 search policy implementation and module loader layer.

Modified:
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/BundleInfo.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/Felix.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundle.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleArchive.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/util/Util.java

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/BundleInfo.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/BundleInfo.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/BundleInfo.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/BundleInfo.java Thu Feb  2 02:34:05 2006
@@ -342,42 +342,4 @@
         m_lockCount = info.m_lockCount;
         m_lockThread = info.m_lockThread;
     }
-
-    /**
-     * Converts a module identifier to a bundle identifier. Module IDs
-     * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
-     * method returns only the portion corresponding to the bundle ID.
-    **/
-    protected static long getBundleIdFromModuleId(String id)
-    {
-        try
-        {
-            String bundleId = (id.indexOf('.') >= 0)
-                ? id.substring(0, id.indexOf('.')) : id;
-            return Long.parseLong(bundleId);
-        }
-        catch (NumberFormatException ex)
-        {
-            return -1;
-        }
-    }
-
-    /**
-     * Converts a module identifier to a bundle identifier. Module IDs
-     * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
-     * method returns only the portion corresponding to the revision.
-    **/
-    protected static int getModuleRevisionFromModuleId(String id)
-    {
-        try
-        {
-            String rev = (id.indexOf('.') >= 0)
-                ? id.substring(id.indexOf('.') + 1) : id;
-            return Integer.parseInt(rev);
-        }
-        catch (NumberFormatException ex)
-        {
-            return -1;
-        }
-    }
 }

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/Felix.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/Felix.java Thu Feb  2 02:34:05 2006
@@ -41,6 +41,7 @@
 
     // MODULE FACTORY.
     private IModuleFactory m_factory = null;
+    private R4SearchPolicyCore m_policyCore = null;
 
     // Object used as a lock when calculating which bundles
     // when performing an operation on one or more bundles.
@@ -95,6 +96,9 @@
     // Service registry.
     private ServiceRegistry m_registry = null;
 
+    // Reusable bundle URL stream handler.
+    private URLStreamHandler m_bundleStreamHandler = null;
+
     // Reusable admin permission object for all instances
     // of the BundleImpl.
     private static AdminPermission m_adminPerm = new AdminPermission();
@@ -223,6 +227,7 @@
         m_cache = null;
         m_nextId = 1L;
         m_dispatchQueue = null;
+        m_bundleStreamHandler = new URLHandlersBundleStreamHandler(this);
         m_registry = new ServiceRegistry(m_logger);
 
         // Add a listener to the service registry; this is
@@ -270,18 +275,18 @@
         }
 
         // Create search policy for module loader.
-        R4SearchPolicy searchPolicy = new R4SearchPolicy(m_logger);
+        m_policyCore = new R4SearchPolicyCore(m_logger);
 
         // Add a resolver listener to the search policy
         // so that we will be notified when modules are resolved
         // in order to update the bundle state.
-        searchPolicy.addResolverListener(new ResolveListener() {
+        m_policyCore.addResolverListener(new ResolveListener() {
             public void moduleResolved(ModuleEvent event)
             {
                 BundleImpl bundle = null;
                 try
                 {
-                    long id = BundleInfo.getBundleIdFromModuleId(
+                    long id = Util.getBundleIdFromModuleId(
                         event.getModule().getId());
                     if (id >= 0)
                     {
@@ -329,9 +334,8 @@
             }
         });
 
-        m_factory = new ModuleFactoryImpl(
-            m_logger, searchPolicy,
-            new URLPolicyImpl(m_logger, new URLHandlersBundleStreamHandler(this)));
+        m_factory = new ModuleFactoryImpl(m_logger);
+        m_policyCore.setModuleFactory(m_factory);
 
         // Initialize dispatch queue.
         m_dispatchQueue = new FelixDispatchQueue(m_logger);
@@ -349,10 +353,16 @@
             BundleInfo info = new BundleInfo(
                 m_logger, new SystemBundleArchive(), null);
             systembundle = new SystemBundle(this, info, activatorList);
-            systembundle.getInfo().addModule(
-                m_factory.createModule(
-                    "0", systembundle.getContentLoader(),
-                    systembundle.getAttributes()));
+            systembundle.getInfo().addModule(m_factory.createModule("0"));
+            systembundle.getContentLoader().setSearchPolicy(
+                new R4SearchPolicy(
+                    m_policyCore, systembundle.getInfo().getCurrentModule()));
+            m_factory.setContentLoader(
+                systembundle.getInfo().getCurrentModule(),
+                systembundle.getContentLoader());
+            m_policyCore.setExports(
+                systembundle.getInfo().getCurrentModule(), systembundle.getExports());
+
             m_installedBundleMap.put(
                 systembundle.getInfo().getLocation(), systembundle);
 
@@ -360,7 +370,7 @@
             // state to be set to RESOLVED.
             try
             {
-                searchPolicy.resolve(systembundle.getInfo().getCurrentModule());
+                m_policyCore.resolve(systembundle.getInfo().getCurrentModule());
             }
             catch (ResolveException ex)
             {
@@ -1361,13 +1371,10 @@
 //            }
         }
 
-        // Get the import search policy.
-        R4SearchPolicy search = (R4SearchPolicy) m_factory.getSearchPolicy();
-
         IModule module = bundle.getInfo().getCurrentModule();
         try
         {
-            search.resolve(module);
+            m_policyCore.resolve(module);
         }
         catch (ResolveException ex)
         {
@@ -1375,7 +1382,7 @@
             {
                 throw new BundleException(
                     "Unresolved package in bundle "
-                    + BundleInfo.getBundleIdFromModuleId(ex.getModule().getId())
+                    + Util.getBundleIdFromModuleId(ex.getModule().getId())
                     + ": " + ex.getPackage());
             }
             else
@@ -2512,14 +2519,13 @@
     {
         // First, find the bundle exporting the package.
         BundleImpl bundle = null;
-        R4SearchPolicy search = (R4SearchPolicy) m_factory.getSearchPolicy();
-        IModule[] exporters = search.getInUseExporters(new R4Import(pkgName, null, null));
+        IModule[] exporters = m_policyCore.getInUseExporters(new R4Import(pkgName, null, null));
         if (exporters != null)
         {
             // Since OSGi R4 there may be more than one exporting, so just
             // take the first one.
             bundle = (BundleImpl) getBundle(
-                BundleInfo.getBundleIdFromModuleId(exporters[0].getId()));
+                Util.getBundleIdFromModuleId(exporters[0].getId()));
         }
 
         // If we have found the exporting bundle, then return the
@@ -2539,7 +2545,7 @@
             IModule[] modules = bundle.getInfo().getModules();
             for (int modIdx = 0; modIdx < modules.length; modIdx++)
             {
-                R4Export export = R4SearchPolicy.getExportPackage(modules[modIdx], pkgName);
+                R4Export export = Util.getExportPackage(modules[modIdx], pkgName);
                 if (export != null)
                 {
                     return new ExportedPackageImpl(this, bundle, pkgName, export.getVersion());
@@ -2614,25 +2620,21 @@
     **/
     private void getExportedPackages(BundleImpl bundle, List list)
     {
-        R4SearchPolicy policy = (R4SearchPolicy) m_factory.getSearchPolicy();
-
         // Since a bundle may have many modules associated with it,
         // one for each revision in the cache, search each module
         // for each revision to get all exports.
         IModule[] modules = bundle.getInfo().getModules();
         for (int modIdx = 0; modIdx < modules.length; modIdx++)
         {
-            R4Export[] exports = (R4Export[])
-                modules[modIdx].getAttribute(
-                        R4SearchPolicy.EXPORTS_ATTR, new R4Export[0]);
-            if (exports.length > 0)
+            R4Export[] exports = m_policyCore.getExports(modules[modIdx]);
+            if ((exports != null) && (exports.length > 0))
             {
                 for (int expIdx = 0; expIdx < exports.length; expIdx++)
                 {
                     // See if the target bundle's module is one of the
                     // "in use" exporters of the package.
                     IModule[] inUseModules =
-                        policy.getInUseExporters(
+                        m_policyCore.getInUseExporters(
                             new R4Import(exports[expIdx].getName(), null, null));
                     // Search through the current providers to find the target
                     // module.
@@ -2675,7 +2677,7 @@
                 IModule[] modules = importer.getInfo().getModules();
                 for (int modIdx = 0; modIdx < modules.length; modIdx++)
                 {
-                    R4Wire wire = R4SearchPolicy.getWire(modules[modIdx], ep.getName());
+                    R4Wire wire = Util.getWire(modules[modIdx], ep.getName());
     
                     // If the resolving module is associated with the
                     // exporting bundle, then add current bundle to
@@ -2975,29 +2977,51 @@
                 m_logger,
                 Util.parseDelimitedString(
                     (String) headerMap.get(Constants.BUNDLE_NATIVECODE), ","));
-        ILibrary[] libs = {
-            new R4Library(
+        R4Library[] libraries = new R4Library[libraryHeaders.length];
+        for (int i = 0; i < libraries.length; i++)
+        {
+            libraries[i] = new R4Library(
                 m_logger, m_cache, id, revision,
                 getProperty(Constants.FRAMEWORK_OS_NAME),
                 getProperty(Constants.FRAMEWORK_PROCESSOR),
-                libraryHeaders)
-        };
+                libraryHeaders[i]);
+        }
+
+        // Now that we have all of the metadata associated with the
+        // module, we need to create the module itself. This is somewhat
+        // complicated because a module is constructed out of several
+        // interrelated pieces (e.g., content loader, search policy,
+        // url policy). We need to create all of these pieces and bind
+        // them together.
+
+        // First, create the module.
+        IModule module = m_factory.createModule(
+            Long.toString(id) + "." + Integer.toString(revision));
+        // Attach the R4 search policy metadata to the module.
+        m_policyCore.setExports(module, exports);
+        m_policyCore.setImports(module, imports);
+        m_policyCore.setDynamicImports(module, dynamics);
+        m_policyCore.setLibraries(module, libraries);
+
+        // Create the content loader associated with the module archive.
+        IContentLoader contentLoader = new ContentLoaderImpl(
+                m_logger,
+                m_cache.getArchive(id).getContent(revision),
+                m_cache.getArchive(id).getContentPath(revision));
+        // Set the content loader's search policy.
+        contentLoader.setSearchPolicy(
+                new R4SearchPolicy(m_policyCore, module));
+        // Set the content loader's URL policy.
+        contentLoader.setURLPolicy(
+// TODO: FIX - NEED URL POLICY PER MODULE.
+                new URLPolicyImpl(
+                    m_logger, m_bundleStreamHandler, module));
+
+        // Set the module's content loader to the created content loader.
+        m_factory.setContentLoader(module, contentLoader);
 
-        Object[][] attributes = {
-            new Object[] { R4SearchPolicy.EXPORTS_ATTR, exports },
-            new Object[] { R4SearchPolicy.IMPORTS_ATTR, imports },
-            new Object[] { R4SearchPolicy.DYNAMICIMPORTS_ATTR, dynamics },
-            new Object[] { R4SearchPolicy.LIBRARIES_ATTR, libs }
-        };
-
-        // Get the content loader associated with the module archive.
-        IContentLoader contentLoader =
-            m_cache.getArchive(id).getContentLoader(revision);
-
-        // Finally, create the module and return it.
-        return m_factory.createModule(
-            Long.toString(id) + "." + Integer.toString(revision),
-            contentLoader, attributes);
+        // Done, so return the module.
+        return module;
     }
 
     private BundleActivator createBundleActivator(BundleInfo info)

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java Thu Feb  2 02:34:05 2006
@@ -16,8 +16,8 @@
  */
 package org.apache.felix.framework;
 
-import org.apache.felix.framework.searchpolicy.R4SearchPolicy;
 import org.apache.felix.framework.searchpolicy.R4Wire;
+import org.apache.felix.framework.util.Util;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 
@@ -31,7 +31,7 @@
         m_registration = reg;
         m_bundle = bundle;
     }
-
+    
     protected ServiceRegistrationImpl getServiceRegistration()
     {
         return m_registration;
@@ -118,10 +118,11 @@
         // Get the package.
         String pkgName =
             org.apache.felix.moduleloader.Util.getClassPackage(className);
-        // Get package wiring from service provider and requester.
-        R4Wire requesterWire = R4SearchPolicy.getWire(
+        // Get package wiring from service requester.
+        R4Wire requesterWire = Util.getWire(
             ((BundleImpl) requester).getInfo().getCurrentModule(), pkgName);
-        R4Wire providerWire = R4SearchPolicy.getWire(
+        // Get package wiring from service provider.
+        R4Wire providerWire = Util.getWire(
             ((BundleImpl) m_bundle).getInfo().getCurrentModule(), pkgName);
 
         // There are three situations that may occur here:

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundle.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundle.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundle.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundle.java Thu Feb  2 02:34:05 2006
@@ -32,7 +32,7 @@
     private List m_activatorList = null;
     private BundleActivator m_activator = null;
     private Thread m_shutdownThread = null;
-    private Object[][] m_attributes = null;
+    private R4Export[] m_exports = null;
     private IContentLoader m_contentLoader = null;
 
     protected SystemBundle(Felix felix, BundleInfo info, List activatorList)
@@ -79,24 +79,24 @@
 
         // Now, create the list of standard framework exports for
         // the system bundle.
-        R4Export[] exports = new R4Export[classPathPkgs.length + 4];
+        m_exports = new R4Export[classPathPkgs.length + 4];
 
-        exports[0] = new R4Export(
+        m_exports[0] = new R4Export(
             "org.osgi.framework",
             new R4Directive[0],
             new R4Attribute[] { new R4Attribute("version", "1.3.0", false) });
 
-        exports[1] = new R4Export(
+        m_exports[1] = new R4Export(
             "org.osgi.service.packageadmin",
             new R4Directive[0],
             new R4Attribute[] { new R4Attribute("version", "1.2.0", false) });
 
-        exports[2] = new R4Export(
+        m_exports[2] = new R4Export(
                 "org.osgi.service.startlevel",
                 new R4Directive[0],
                 new R4Attribute[] { new R4Attribute("version", "1.0.0", false) });
 
-        exports[3] = new R4Export(
+        m_exports[3] = new R4Export(
                 "org.osgi.service.url",
                 new R4Directive[0],
                 new R4Attribute[] { new R4Attribute("version", "1.0.0", false) });
@@ -104,31 +104,26 @@
         // Copy the class path exported packages.
         for (int i = 0; i < classPathPkgs.length; i++)
         {
-            exports[i + 4] = new R4Export(classPathPkgs[i]);
+            m_exports[i + 4] = new R4Export(classPathPkgs[i]);
         }
 
-        m_attributes = new Object[][] {
-            new Object[] { R4SearchPolicy.EXPORTS_ATTR, exports },
-            new Object[] { R4SearchPolicy.IMPORTS_ATTR, new R4Import[0] }
-        };
-
         m_contentLoader = new SystemBundleContentLoader(getFelix().getLogger());
 
         String exportString = "";
-        for (int i = 0; i < exports.length; i++)
+        for (int i = 0; i < m_exports.length; i++)
         {
             exportString = exportString +
-            exports[i].getName()
+            m_exports[i].getName()
             + "; specification-version=\""
-            + exports[i].getVersion().toString() + "\"";
+            + m_exports[i].getVersion().toString() + "\"";
 
-            if (i < (exports.length - 1))
+            if (i < (m_exports.length - 1))
             {
                 exportString = exportString + ", ";
                 exportString = exportString +
-                    exports[i].getName()
+                    m_exports[i].getName()
                     + "; specification-version=\""
-                    + exports[i].getVersion().toString() + "\", ";
+                    + m_exports[i].getVersion().toString() + "\", ";
             }
         }
 
@@ -142,9 +137,9 @@
         ((SystemBundleArchive) getInfo().getArchive()).setManifestHeader(map);
     }
 
-    public Object[][] getAttributes()
+    public R4Export[] getExports()
     {
-        return m_attributes;
+        return m_exports;
     }
 
     public IContentLoader getContentLoader()

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleArchive.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleArchive.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleArchive.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleArchive.java Thu Feb  2 02:34:05 2006
@@ -21,6 +21,7 @@
 
 import org.apache.felix.framework.cache.BundleArchive;
 import org.apache.felix.framework.util.FelixConstants;
+import org.apache.felix.moduleloader.IContent;
 import org.apache.felix.moduleloader.IContentLoader;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
@@ -96,7 +97,13 @@
         m_headerMap = headerMap;
     }
 
-    public IContentLoader getContentLoader(int revision)
+    public IContent getContent(int revision)
+        throws Exception
+    {
+        return null;
+    }
+
+    public IContent[] getContentPath(int revision)
         throws Exception
     {
         return null;

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/SystemBundleContentLoader.java Thu Feb  2 02:34:05 2006
@@ -25,6 +25,8 @@
 public class SystemBundleContentLoader implements IContentLoader
 {
     private Logger m_logger = null;
+    private ISearchPolicy m_searchPolicy = null;
+    private IURLPolicy m_urlPolicy = null;
 
     public SystemBundleContentLoader(Logger logger)
     {
@@ -36,13 +38,24 @@
         return null;
     }
 
-    public void setModuleCallback(IModuleCallback callback)
+    public ISearchPolicy getSearchPolicy()
     {
+        return m_searchPolicy;
     }
 
-    public IModuleCallback getModuleCallback()
+    public void setSearchPolicy(ISearchPolicy searchPolicy)
     {
-        return null;
+        m_searchPolicy = searchPolicy;
+    }
+
+    public IURLPolicy getURLPolicy()
+    {
+        return m_urlPolicy;
+    }
+
+    public void setURLPolicy(IURLPolicy urlPolicy)
+    {
+        m_urlPolicy = urlPolicy;
     }
 
     public Class getClass(String name)

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java Thu Feb  2 02:34:05 2006
@@ -22,6 +22,8 @@
 import java.net.URLConnection;
 import java.security.Permission;
 
+import org.apache.felix.framework.util.Util;
+
 class URLHandlersBundleURLConnection extends URLConnection
 {
     private Felix m_framework;
@@ -57,13 +59,13 @@
             // The URL is constructed like this:
             //     bundle://<module-id>/<resource-path>
             // Where <module-id> = <bundle-id>.<revision>
-            long bundleId = BundleInfo.getBundleIdFromModuleId(url.getHost());
+            long bundleId = Util.getBundleIdFromModuleId(url.getHost());
             BundleImpl bundle = (BundleImpl) m_framework.getBundle(bundleId);
             if (bundle == null)
             {
                 throw new IOException("Unable to find bundle.");
             }
-            int revision = BundleInfo.getModuleRevisionFromModuleId(url.getHost());
+            int revision = Util.getModuleRevisionFromModuleId(url.getHost());
             m_is = bundle.getInfo().getModules()[revision].getContentLoader().getResourceAsStream(url.getPath());
             m_contentLength = (m_is == null) ? 0 : m_is.available();
             m_contentTime = 0L;

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/BundleArchive.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/BundleArchive.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/BundleArchive.java Thu Feb  2 02:34:05 2006
@@ -19,6 +19,7 @@
 import java.io.File;
 import java.util.Map;
 
+import org.apache.felix.moduleloader.IContent;
 import org.apache.felix.moduleloader.IContentLoader;
 import org.osgi.framework.BundleActivator;
 
@@ -163,15 +164,27 @@
 
     /**
      * <p>
-     * Returns the content loader that loads classes according to the class path
-     * of the specified revision of the bundle associated with this archive.
+     * Returns a content object that is associated with the specified bundle
+     * revision's JAR file.
      * </p>
      * @param revision the specified revision.
-     * @return A content loader that loads classes according to the class path
-     *         of the specified bundle revision.
+     * @return A content object for the specified bundle revision's JAR file.
      * @throws java.lang.Exception if any error occurs.
     **/
-    public IContentLoader getContentLoader(int revision)
+    public IContent getContent(int revision)
+        throws Exception;
+
+    /**
+     * <p>
+     * Returns an array of content objects that are associated with the
+     * specified bundle revision's class path.
+     * </p>
+     * @param revision the specified revision.
+     * @return An array of content objects for the specified bundle revision's
+     *         class path.
+     * @throws java.lang.Exception if any error occurs.
+    **/
+    public IContent[] getContentPath(int revision)
         throws Exception;
 
     /**

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/cache/DefaultBundleArchive.java Thu Feb  2 02:34:05 2006
@@ -24,7 +24,6 @@
 import java.util.zip.ZipEntry;
 
 import org.apache.felix.framework.Logger;
-import org.apache.felix.framework.searchpolicy.ContentLoaderImpl;
 import org.apache.felix.framework.util.*;
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.moduleloader.*;
@@ -67,7 +66,8 @@
     private long m_refreshCount = -1;
     private int m_revisionCount = -1;
 
-    public DefaultBundleArchive(Logger logger, File dir, long id, String location, InputStream is)    
+    public DefaultBundleArchive(
+        Logger logger, File dir, long id, String location, InputStream is)    
         throws Exception
     {
         this(logger, dir, id);
@@ -744,15 +744,49 @@
         return new JarFile(bundleJar);
     }
 
-    private IContentLoader getContentLoaderUnchecked(int revision)
+    private IContent getContentUnchecked(int revision)
         throws Exception
     {
-        // The general overiew of this method is to create a content loader
-        // for the specified module revision. This entails examining the
-        // module's class path to determine whether the module JAR file itself
-        // is on the module's class path and then creating IContent instances
-        // for everything on the class path and passing them into an
-        // IContentLoader instance.
+        // Get the revision directory.
+        File revisionDir = new File(
+            m_dir, REVISION_DIRECTORY + getRefreshCount() + "." + revision);
+        // Return a content object for the bundle itself.
+        return new JarContent(new File(revisionDir, BUNDLE_JAR_FILE));
+    }
+
+    public IContent getContent(int revision)
+        throws Exception
+    {
+        IContent content = null;
+    
+        if (System.getSecurityManager() != null)
+        {
+            try
+            {
+                content = (IContent) AccessController.doPrivileged(
+                    new PrivilegedAction(
+                        PrivilegedAction.GET_CONTENT_ACTION, this, revision));
+            }
+            catch (PrivilegedActionException ex)
+            {
+                throw ((PrivilegedActionException) ex).getException();
+            }
+        }
+        else
+        {
+            content = getContentUnchecked(revision);
+        }
+    
+        return content;
+    }
+
+    private IContent[] getContentPathUnchecked(int revision)
+        throws Exception
+    {
+        // Creating the content path entails examining the bundle's
+        // class path to determine whether the bundle JAR file itself
+        // is on the bundle's class path and then creating content
+        // objects for everything on the class path.
 
         // Get the revision directory.
         File revisionDir = new File(
@@ -813,21 +847,21 @@
             classPath = new IContent[] { self };
         }
 
-        return new ContentLoaderImpl(m_logger, self, classPath);
+        return classPath;
     }
 
-    public IContentLoader getContentLoader(int revision)
+    public IContent[] getContentPath(int revision)
         throws Exception
     {
-        IContentLoader contentLoader = null;
+        IContent[] contents = null;
 
         if (System.getSecurityManager() != null)
         {
             try
             {
-                contentLoader = (IContentLoader) AccessController.doPrivileged(
+                contents = (IContent[]) AccessController.doPrivileged(
                     new PrivilegedAction(
-                        PrivilegedAction.GET_CLASS_PATH_ACTION, this, revision));
+                        PrivilegedAction.GET_CONTENT_PATH_ACTION, this, revision));
             }
             catch (PrivilegedActionException ex)
             {
@@ -836,10 +870,10 @@
         }
         else
         {
-            contentLoader = getContentLoaderUnchecked(revision);
+            contents = getContentPathUnchecked(revision);
         }
 
-        return contentLoader;
+        return contents;
     }
 
 //  TODO: This will need to consider security.
@@ -1363,9 +1397,10 @@
         private static final int SET_START_LEVEL_ACTION = 9;
         private static final int OPEN_BUNDLE_JAR_ACTION = 10;
         private static final int CREATE_DATA_DIR_ACTION = 11;
-        private static final int GET_CLASS_PATH_ACTION = 12;
-        private static final int GET_ACTIVATOR_ACTION = 13;
-        private static final int SET_ACTIVATOR_ACTION = 14;
+        private static final int GET_CONTENT_ACTION = 12;
+        private static final int GET_CONTENT_PATH_ACTION = 13;
+        private static final int GET_ACTIVATOR_ACTION = 14;
+        private static final int SET_ACTIVATOR_ACTION = 15;
 
         private int m_action = 0;
         private DefaultBundleArchive m_archive = null;
@@ -1451,8 +1486,10 @@
                 case CREATE_DATA_DIR_ACTION:
                     m_archive.createDataDirectoryUnchecked(m_fileArg);
                     return null;
-                case GET_CLASS_PATH_ACTION:
-                    return m_archive.getContentLoaderUnchecked(m_intArg);
+                case GET_CONTENT_ACTION:
+                    return m_archive.getContentUnchecked(m_intArg);
+                case GET_CONTENT_PATH_ACTION:
+                    return m_archive.getContentPathUnchecked(m_intArg);
                 case GET_ACTIVATOR_ACTION:
                     return m_archive.getActivatorUnchecked(m_contentLoaderArg);
                 case SET_ACTIVATOR_ACTION:

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/util/Util.java?rev=374344&r1=374343&r2=374344&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/framework/util/Util.java Thu Feb  2 02:34:05 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   Copyright 2006 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -21,11 +21,92 @@
 import java.util.List;
 
 import org.apache.felix.framework.Logger;
-import org.apache.felix.framework.searchpolicy.R4LibraryHeader;
+import org.apache.felix.framework.searchpolicy.*;
+import org.apache.felix.moduleloader.IModule;
 
-public class Util
+public class Util extends org.apache.felix.moduleloader.Util
 {
     /**
+     * Converts a module identifier to a bundle identifier. Module IDs
+     * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
+     * method returns only the portion corresponding to the bundle ID.
+    **/
+    public static long getBundleIdFromModuleId(String id)
+    {
+        try
+        {
+            String bundleId = (id.indexOf('.') >= 0)
+                ? id.substring(0, id.indexOf('.')) : id;
+            return Long.parseLong(bundleId);
+        }
+        catch (NumberFormatException ex)
+        {
+            return -1;
+        }
+    }
+
+    /**
+     * Converts a module identifier to a bundle identifier. Module IDs
+     * are typically <tt>&lt;bundle-id&gt;.&lt;revision&gt;</tt>; this
+     * method returns only the portion corresponding to the revision.
+    **/
+    public static int getModuleRevisionFromModuleId(String id)
+    {
+        try
+        {
+            String rev = (id.indexOf('.') >= 0)
+                ? id.substring(id.indexOf('.') + 1) : id;
+            return Integer.parseInt(rev);
+        }
+        catch (NumberFormatException ex)
+        {
+            return -1;
+        }
+    }
+
+    public static R4Export getExportPackage(IModule m, String name)
+    {
+        R4Export[] pkgs =
+            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getExports();
+        for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
+        {
+            if (pkgs[i].getName().equals(name))
+            {
+                return pkgs[i];
+            }
+        }
+        return null;
+    }
+
+    public static R4Import getImportPackage(IModule m, String name)
+    {
+        R4Import[] pkgs =
+            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getImports();
+        for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
+        {
+            if (pkgs[i].getName().equals(name))
+            {
+                return pkgs[i];
+            }
+        }
+        return null;
+    }
+
+    public static R4Wire getWire(IModule m, String name)
+    {
+        R4Wire[] wires =
+            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getWires();
+        for (int i = 0; (wires != null) && (i < wires.length); i++)
+        {
+            if (wires[i].getExport().getName().equals(name))
+            {
+                return wires[i];
+            }
+        }
+        return null;
+    }
+
+    /**
      * Parses delimited string and returns an array containing the tokens. This
      * parser obeys quotes, so the delimiter character will be ignored if it is
      * inside of a quote. This method assumes that the quote character is not
@@ -105,7 +186,7 @@
     {
         if (libStrs == null)
         {
-            return null;
+            return new R4LibraryHeader[0];
         }
 
         List libList = new ArrayList();
@@ -119,11 +200,6 @@
             {
                 libList.add(libs[libIdx]);
             }
-        }
-
-        if (libList.size() == 0)
-        {
-            return null;
         }
 
         return (R4LibraryHeader[]) libList.toArray(new R4LibraryHeader[libList.size()]);