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/07/23 15:07:19 UTC

svn commit: r424730 - in /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix: framework/ framework/searchpolicy/ framework/util/ moduleloader/

Author: rickhall
Date: Sun Jul 23 06:07:18 2006
New Revision: 424730

URL: http://svn.apache.org/viewvc?rev=424730&view=rev
Log:
Performed some refactoring on the module loader layer to simplify the
structure to some degree by creating a IModuleDefinition that can be
used to store and access the module metadata.

Added:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java   (with props)
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java   (with props)
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java   (with props)
Removed:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/IR4SearchPolicy.java
Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.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/ServiceReferenceImpl.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java Sun Jul 23 06:07:18 2006
@@ -16,7 +16,6 @@
  */
 package org.apache.felix.framework;
 
-import org.apache.felix.framework.searchpolicy.IR4SearchPolicy;
 import org.apache.felix.framework.searchpolicy.R4Export;
 import org.apache.felix.moduleloader.IModule;
 import org.osgi.framework.Bundle;
@@ -86,8 +85,7 @@
 
     public boolean isRemovalPending()
     {
-        return ((IR4SearchPolicy)
-            m_exportingModule.getContentLoader().getSearchPolicy()).isRemovalPending();
+        return m_exportingModule.isRemovalPending();
     }
 
     public String toString()

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=424730&r1=424729&r2=424730&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 Jul 23 06:07:18 2006
@@ -343,15 +343,16 @@
             BundleInfo info = new BundleInfo(
                 m_logger, new SystemBundleArchive(), null);
             systembundle = new SystemBundle(this, info, activatorList);
-            systembundle.getInfo().addModule(m_factory.createModule("0"));
+            // Create a module for the system bundle.
+            IModuleDefinition md = new ModuleDefinition(
+                systembundle.getExports(), null, null, null);
+            systembundle.getInfo().addModule(m_factory.createModule("0", md));
             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);
@@ -1434,8 +1435,8 @@
                 
                 // Mark previous the bundle's old module for removal since
                 // it can no longer be used to resolve other modules per the spec.
-                IModule module = info.getModules()[info.getModules().length - 2];
-                m_policyCore.setRemovalPending(module, true);
+                ((ModuleImpl) info.getModules()[info.getModules().length - 2])
+                    .setRemovalPending(true);
         
                 fireBundleEvent(BundleEvent.UPDATED, bundle);
             }
@@ -1652,7 +1653,7 @@
 
             // Mark current module for removal since it can no longer
             // be used to resolve other modules per the spec.
-            m_policyCore.setRemovalPending(target.getInfo().getCurrentModule(), true);
+            ((ModuleImpl) target.getInfo().getCurrentModule()).setRemovalPending(true);
 
             // Put bundle in uninstalled bundle array.
             rememberUninstalledBundle(bundle);
@@ -2432,7 +2433,7 @@
         IModule[] modules = bundle.getInfo().getModules();
         for (int modIdx = 0; modIdx < modules.length; modIdx++)
         {
-            R4Export[] exports = m_policyCore.getExports(modules[modIdx]);
+            R4Export[] exports = modules[modIdx].getDefinition().getExports();
             if ((exports != null) && (exports.length > 0))
             {
                 for (int expIdx = 0; expIdx < exports.length; expIdx++)
@@ -2477,12 +2478,12 @@
             IModule[] modules = importer.getInfo().getModules();
             for (int modIdx = 0; modIdx < modules.length; modIdx++)
             {
-                R4Wire wire = Util.getWire(modules[modIdx], ep.getName());
+                IWire wire = Util.getWire(modules[modIdx], ep.getName());
 
                 // If the resolving module is associated with the
                 // exporting bundle, then add current bundle to
                 // import list.
-                if ((wire != null) && exporterInfo.hasModule(wire.getExportingModule()))
+                if ((wire != null) && exporterInfo.hasModule(wire.getExporter()))
                 {
                     // Add the bundle to the list of importers.
                     list.add(bundles[bundleIdx]);
@@ -2694,27 +2695,27 @@
         // 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(targetId) + "." + Integer.toString(revision));
-
-        // Attach the R4 search policy metadata to the module.
-        m_policyCore.setExports(module, mp.getExports());
-        m_policyCore.setImports(module, mp.getImports());
-        m_policyCore.setDynamicImports(module, mp.getDynamicImports());
-        m_policyCore.setLibraries(module,
+        // interrelated pieces (e.g., module definition, content loader,
+        // search policy, url policy). We need to create all of these
+        // pieces and bind them together.
+
+        // Create the module definition for the new module.
+        IModuleDefinition md = new ModuleDefinition(
+            mp.getExports(),
+            mp.getImports(),
+            mp.getDynamicImports(),
             mp.getLibraries(
                 m_cache,
                 targetId,
                 revision,
                 m_config.get(Constants.FRAMEWORK_OS_NAME),
                 m_config.get(Constants.FRAMEWORK_PROCESSOR)));
+                
+        // Create the module using the module definition.
+        IModule module = m_factory.createModule(
+            Long.toString(targetId) + "." + Integer.toString(revision), md);
 
-        // Create the content loader associated with the module archive.
+        // Create the content loader from the module archive.
         IContentLoader contentLoader = new ContentLoaderImpl(
                 m_logger,
                 m_cache.getArchive(targetId).getRevision(revision).getContent(),
@@ -3740,8 +3741,8 @@
             java.security.PermissionCollection pc = 
                 java.security.Policy.getPolicy().getPermissions(cs);
 
-            R4Import[] imports = m_policyCore.getImports(
-                m_bundle.getInfo().getCurrentModule());
+            R4Import[] imports =
+                m_bundle.getInfo().getCurrentModule().getDefinition().getImports();
             
             for (int i = 0;i < imports.length; i++)
             {
@@ -3755,8 +3756,8 @@
                 }
             }
             // Check export permission for all exports of the current module.
-            R4Export[] implicitImports = m_policyCore.getExports(
-                m_bundle.getInfo().getCurrentModule());
+            R4Export[] implicitImports =
+                m_bundle.getInfo().getCurrentModule().getDefinition().getExports();
             
             for (int i = 0;i < implicitImports.length; i++)
             {

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceReferenceImpl.java Sun Jul 23 06:07:18 2006
@@ -16,8 +16,8 @@
  */
 package org.apache.felix.framework;
 
-import org.apache.felix.framework.searchpolicy.R4Wire;
 import org.apache.felix.framework.util.Util;
+import org.apache.felix.moduleloader.IWire;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 
@@ -119,10 +119,10 @@
         String pkgName =
             Util.getClassPackage(className);
         // Get package wiring from service requester.
-        R4Wire requesterWire = Util.getWire(
+        IWire requesterWire = Util.getWire(
             ((BundleImpl) requester).getInfo().getCurrentModule(), pkgName);
         // Get package wiring from service provider.
-        R4Wire providerWire = Util.getWire(
+        IWire providerWire = Util.getWire(
             ((BundleImpl) m_bundle).getInfo().getCurrentModule(), pkgName);
 
         // There are three situations that may occur here:
@@ -168,7 +168,7 @@
         // same source module.
         else
         {
-            allow = providerWire.getExportingModule().equals(requesterWire.getExportingModule());
+            allow = providerWire.getExporter().equals(requesterWire.getExporter());
         }
 
         return allow;

Added: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java?rev=424730&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java (added)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java Sun Jul 23 06:07:18 2006
@@ -0,0 +1,58 @@
+/*
+ *   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.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.framework.searchpolicy;
+
+import org.apache.felix.moduleloader.IModuleDefinition;
+
+public class ModuleDefinition implements IModuleDefinition
+{
+    public R4Export[] m_exports = null;
+    public R4Import[] m_imports = null;
+    public R4Import[] m_dynamicImports = null;
+    public R4Library[] m_libraries = null;
+
+    public ModuleDefinition(
+        R4Export[] exports, R4Import[] imports,
+        R4Import[] dynamicImports, R4Library[] libraries)
+    {
+        m_exports = exports;
+        m_imports = imports;
+        m_dynamicImports = dynamicImports;
+        m_libraries = libraries;
+    }
+
+    public R4Export[] getExports()
+    {
+// TODO: ML - These should probably all return copies of the array.
+        return m_exports;
+    }
+
+    public R4Import[] getImports()
+    {
+        return m_imports;
+    }
+
+    public R4Import[] getDynamicImports()
+    {
+        return m_dynamicImports;
+    }
+
+    public R4Library[] getLibraries()
+    {
+        return m_libraries;
+    }
+}
\ No newline at end of file

Propchange: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleDefinition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicy.java Sun Jul 23 06:07:18 2006
@@ -20,7 +20,7 @@
 
 import org.apache.felix.moduleloader.*;
 
-public class R4SearchPolicy implements IR4SearchPolicy
+public class R4SearchPolicy implements ISearchPolicy
 {
     private R4SearchPolicyCore m_policyCore = null;
     private IModule m_module = null;
@@ -51,91 +51,6 @@
     public String findLibrary(String name)
     {
         return m_policyCore.findLibrary(m_module, name);
-    }
-
-    public R4Export[] getExports()
-    {
-        return m_policyCore.getExports(m_module);
-    }
-
-    public void setExports(R4Export[] exports)
-    {
-        m_policyCore.setExports(m_module, exports);
-    }
-
-    public R4Import[] getImports()
-    {
-        return m_policyCore.getImports(m_module);
-    }
-
-    public void setImports(R4Import[] imports)
-    {
-        m_policyCore.setImports(m_module, imports);
-    }
-
-    public R4Import[] getDynamicImports()
-    {
-        return m_policyCore.getDynamicImports(m_module);
-    }
-
-    public void setDynamicImports(R4Import[] imports)
-    {
-        m_policyCore.setDynamicImports(m_module, imports);
-    }
-
-    public R4Library[] getLibraries()
-    {
-        return m_policyCore.getLibraries(m_module);
-    }
-
-    public void setLibraries(R4Library[] libraries)
-    {
-        m_policyCore.setLibraries(m_module, libraries);
-    }
-
-    public R4Wire[] getWires()
-    {
-        return m_policyCore.getWires(m_module);
-    }
-
-    public void setWires(R4Wire[] wires)
-    {
-        m_policyCore.setWires(m_module, wires);
-    }
-
-    public boolean isResolved()
-    {
-        return m_policyCore.isResolved(m_module);
-    }
-
-    public void setResolved(boolean resolved)
-    {
-        m_policyCore.setResolved(m_module, resolved);
-    }
-
-    public void resolve() throws ResolveException
-    {
-        m_policyCore.resolve(m_module);
-    }
-
-    public boolean isRemovalPending()
-    {
-        return m_policyCore.isRemovalPending(m_module);
-    }
-
-    public void setRemovalPending(boolean removalPending)
-    {
-        m_policyCore.setRemovalPending(m_module, removalPending);
-    }
-
-    public void addResolverListener(ResolveListener l)
-    {
-        m_policyCore.addResolverListener(l);
-    }
-
-    public void removeResolverListener(ResolveListener l)
-    {
-        m_policyCore.removeResolverListener(l);
     }
 
     public String toString()

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java Sun Jul 23 06:07:18 2006
@@ -90,160 +90,13 @@
         }
     }
 
-    public synchronized R4Export[] getExports(IModule module)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        return (data == null) ? null : data.m_exports;
-    }
-
-    public synchronized void setExports(IModule module, R4Export[] exports)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        if (data == null)
-        {
-            data = new ModuleData(module);
-            m_moduleDataMap.put(module, data);
-        }
-        data.m_exports = exports;
-
-        // When a module is added and its exports are set, create an
-        // aggregated list of available exports to simplify later
-        // processing when resolving bundles.
-
-        // Add exports to available package map.
-        for (int i = 0; (exports != null) && (i < exports.length); i++)
-        {
-            IModule[] modules = (IModule[]) m_availPkgMap.get(exports[i].getName());
-
-            // We want to add the module into the list of available
-            // exporters in sorted order (descending version and
-            // ascending bundle identifier). Insert using a simple
-            // binary search algorithm.
-            if (modules == null)
-            {
-                modules = new IModule[] { module };
-            }
-            else
-            {
-                int top = 0, bottom = modules.length - 1, middle = 0;
-                Version middleVersion = null;
-                while (top <= bottom)
-                {
-                    middle = (bottom - top) / 2 + top;
-                    middleVersion = Util.getExportPackage(
-                        modules[middle], exports[i].getName()).getVersion();
-                    // Sort in reverse version order.
-                    int cmp = middleVersion.compareTo(exports[i].getVersion());
-                    if (cmp < 0)
-                    {
-                        bottom = middle - 1;
-                    }
-                    else if (cmp == 0)
-                    {
-                        // Sort further by ascending bundle ID.
-                        long middleId = Util.getBundleIdFromModuleId(modules[middle].getId());
-                        long exportId = Util.getBundleIdFromModuleId(module.getId());
-                        if (middleId < exportId)
-                        {
-                            top = middle + 1;
-                        }
-                        else
-                        {
-                            bottom = middle - 1;
-                        }
-                    }
-                    else
-                    {
-                        top = middle + 1;
-                    }
-                }
-
-                IModule[] newMods = new IModule[modules.length + 1];
-                System.arraycopy(modules, 0, newMods, 0, top);
-                System.arraycopy(modules, top, newMods, top + 1, modules.length - top);
-                newMods[top] = module;
-                modules = newMods;
-            }
-
-            m_availPkgMap.put(exports[i].getName(), modules);
-        }
-    }
-
-    public synchronized R4Import[] getImports(IModule module)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        return (data == null) ? null : data.m_imports;
-    }
-
-    public synchronized void setImports(IModule module, R4Import[] imports)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        if (data == null)
-        {
-            data = new ModuleData(module);
-            m_moduleDataMap.put(module, data);
-        }
-        data.m_imports = imports;
-    }
-
-    public synchronized R4Import[] getDynamicImports(IModule module)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        return (data == null) ? null : data.m_dynamicImports;
-    }
-
-    public synchronized void setDynamicImports(IModule module, R4Import[] imports)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        if (data == null)
-        {
-            data = new ModuleData(module);
-            m_moduleDataMap.put(module, data);
-        }
-        data.m_dynamicImports = imports;
-    }
-
-    public synchronized R4Library[] getLibraries(IModule module)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        return (data == null) ? null : data.m_libraries;
-    }
-
-    public synchronized void setLibraries(IModule module, R4Library[] libraries)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        if (data == null)
-        {
-            data = new ModuleData(module);
-            m_moduleDataMap.put(module, data);
-        }
-        data.m_libraries = libraries;
-    }
-
-    public synchronized R4Wire[] getWires(IModule module)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        return (data == null) ? null : data.m_wires;
-    }
-
-    public synchronized void setWires(IModule module, R4Wire[] wires)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        if (data == null)
-        {
-            data = new ModuleData(module);
-            m_moduleDataMap.put(module, data);
-        }
-        data.m_wires = wires;
-    }
-
-    public synchronized boolean isResolved(IModule module)
+    protected synchronized boolean isResolved(IModule module)
     {
         ModuleData data = (ModuleData) m_moduleDataMap.get(module);
         return (data == null) ? false : data.m_resolved;
     }
 
-    public synchronized void setResolved(IModule module, boolean resolved)
+    protected synchronized void setResolved(IModule module, boolean resolved)
     {
         ModuleData data = (ModuleData) m_moduleDataMap.get(module);
         if (data == null)
@@ -254,23 +107,6 @@
         data.m_resolved = resolved;
     }
 
-    public synchronized boolean isRemovalPending(IModule module)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        return (data == null) ? false : data.m_removalPending;
-    }
-
-    public synchronized void setRemovalPending(IModule module, boolean removalPending)
-    {
-        ModuleData data = (ModuleData) m_moduleDataMap.get(module);
-        if (data == null)
-        {
-            data = new ModuleData(module);
-            m_moduleDataMap.put(module, data);
-        }
-        data.m_removalPending = removalPending;
-    }
-
     public Object[] definePackage(IModule module, String pkgName)
     {
         R4Package pkg = Util.getExportPackage(module, pkgName);
@@ -438,7 +274,7 @@
         throws ClassNotFoundException, ResourceNotFoundException
     {
         // We delegate to the module's wires to find the class or resource.
-        R4Wire[] wires = getWires(module);
+        IWire[] wires = module.getWires();
         for (int i = 0; (wires != null) && (i < wires.length); i++)
         {
             // If we find the class or resource, then return it.
@@ -461,7 +297,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.
-        R4Wire wire = attemptDynamicImport(module, pkgName);
+        IWire wire = attemptDynamicImport(module, pkgName);
 
         // If the dynamic import was successful, then this initial
         // time we must directly return the result from dynamically
@@ -522,7 +358,7 @@
         return null;
     }
 
-    private R4Wire attemptDynamicImport(IModule module, String pkgName)
+    private IWire attemptDynamicImport(IModule module, String pkgName)
     {
         R4Wire wire = null;
         IModule candidate = null;
@@ -588,7 +424,7 @@
                 // wiring attribute.
                 if (candidate != null)
                 {
-                    R4Wire[] wires = getWires(module);
+                    IWire[] wires = module.getWires();
                     R4Wire[] newWires = null;
                     if (wires == null)
                     {
@@ -606,7 +442,7 @@
                         module, candidate,
                         Util.getExportPackage(candidate, impMatch.getName()));
                     newWires[newWires.length - 1] = wire;
-                    setWires(module, newWires);
+                    ((ModuleImpl) module).setWires(newWires);
 m_logger.log(Logger.LOG_DEBUG, "WIRE: " + newWires[newWires.length - 1]);
                 }
             }
@@ -623,7 +459,7 @@
     {
         // Check the dynamic import specs for a match of
         // the target package.
-        R4Import[] dynamics = getDynamicImports(module);
+        R4Import[] dynamics = module.getDefinition().getDynamicImports();
         R4Import impMatch = null;
         for (int i = 0; (impMatch == null) && (dynamics != null)
             && (i < dynamics.length); i++)
@@ -669,7 +505,7 @@
 
         // TODO: This "matching" algorithm does not fully
         // match the spec and should be improved.
-        R4Library[] libs = getLibraries(module);
+        R4Library[] libs = module.getDefinition().getLibraries();
         for (int i = 0; (libs != null) && (i < libs.length); i++)
         {
             String path = libs[i].getPath(name);
@@ -802,7 +638,7 @@
 
         // Loop through each import and calculate its resolving
         // set of candidates.
-        R4Import[] imports = getImports(module);
+        R4Import[] imports = module.getDefinition().getImports();
         for (int impIdx = 0; (imports != null) && (impIdx < imports.length); impIdx++)
         {
             // Get the candidates from the "in use" and "available"
@@ -927,7 +763,7 @@
         {
             // The spec says that we cannot consider modules that
             // are pending removal, so ignore them.
-            if (includeRemovalPending || !isRemovalPending(modules[modIdx]))
+            if (includeRemovalPending || !modules[modIdx].isRemovalPending())
             {
                 // Get the modules export package for the target package.
                 R4Export export = Util.getExportPackage(
@@ -1001,7 +837,7 @@
         // of the root module that is not also imported; uses constraints
         // for exported packages that are also imported will be taken
         // care of as part of normal import package processing.
-        R4Export[] exports = getExports(rootModule);
+        R4Export[] exports = rootModule.getDefinition().getExports();
         Map usesMap = new HashMap();
         for (int i = 0; (exports != null) && (i < exports.length); i++)
         {
@@ -1124,11 +960,11 @@
                 // Get the actual exporter from the wire or if there
                 // is no wire, then get the export is from the module
                 // itself.
-                R4Wire wire = Util.getWire(module, uses[usesIdx]);
+                IWire wire = Util.getWire(module, uses[usesIdx]);
                 if (wire != null)
                 {
                     usesMap = calculateUsesDependencies(
-                        resolverMap, wire.getExportingModule(), wire.getExport(), usesMap);
+                        resolverMap, wire.getExporter(), wire.getExport(), usesMap);
                 }
                 else
                 {
@@ -1224,7 +1060,7 @@
         {
             Map.Entry entry = (Map.Entry) iter.next();
             IModule module = (IModule) entry.getKey();
-            R4Wire[] wires = (R4Wire[]) entry.getValue();
+            IWire[] wires = (IWire[]) entry.getValue();
 
             // Set the module's resolved and wiring attribute.
             setResolved(module, true);
@@ -1232,7 +1068,7 @@
             // only modules may not have wires.
             if (wires.length > 0)
             {
-                setWires(module, wires);
+                ((ModuleImpl) module).setWires(wires);
             }
 
             // Remove the wire's exporting module from the "available"
@@ -1245,7 +1081,7 @@
 m_logger.log(Logger.LOG_DEBUG, "WIRE: " + wires[wireIdx]);
                 // First remove the wire module from "available" package map.
                 IModule[] modules = (IModule[]) m_availPkgMap.get(wires[wireIdx].getExport().getName());
-                modules = removeModuleFromArray(modules, wires[wireIdx].getExportingModule());
+                modules = removeModuleFromArray(modules, wires[wireIdx].getExporter());
                 m_availPkgMap.put(wires[wireIdx].getExport().getName(), modules);
 
                 // Also remove any exported packages from the "available"
@@ -1256,7 +1092,7 @@
                 // to a different module. If the exported package is not
                 // actually exported, then we just want to remove it
                 // completely, since it cannot be used.
-                if (wires[wireIdx].getExportingModule() != module)
+                if (wires[wireIdx].getExporter() != module)
                 {
                     modules = (IModule[]) m_availPkgMap.get(wires[wireIdx].getExport().getName());
                     modules = removeModuleFromArray(modules, module);
@@ -1265,7 +1101,7 @@
 
                 // Add the module of the wire to the "in use" package map.
                 modules = (IModule[]) m_inUsePkgMap.get(wires[wireIdx].getExport().getName());
-                modules = addModuleToArray(modules, wires[wireIdx].getExportingModule());
+                modules = addModuleToArray(modules, wires[wireIdx].getExporter());
                 m_inUsePkgMap.put(wires[wireIdx].getExport().getName(), modules);
             }
         }
@@ -1282,7 +1118,7 @@
         }
 
         List nodeList = (List) resolverMap.get(module);
-        R4Wire[] wires = new R4Wire[nodeList.size()];
+        IWire[] wires = new IWire[nodeList.size()];
 
         // Put the module in the wireMap with an empty wire array;
         // we do this early so we can use it to detect cycles.
@@ -1459,6 +1295,71 @@
 
     public void moduleAdded(ModuleEvent event)
     {
+        synchronized (m_factory)
+        {
+            // When a module is added, create an aggregated list of available
+            // exports to simplify later processing when resolving bundles.
+            IModule module = event.getModule();
+            R4Export[] exports = module.getDefinition().getExports();
+
+            // Add exports to available package map.
+            for (int i = 0; (exports != null) && (i < exports.length); i++)
+            {
+                IModule[] modules = (IModule[]) m_availPkgMap.get(exports[i].getName());
+
+                // We want to add the module into the list of available
+                // exporters in sorted order (descending version and
+                // ascending bundle identifier). Insert using a simple
+                // binary search algorithm.
+                if (modules == null)
+                {
+                    modules = new IModule[] { module };
+                }
+                else
+                {
+                    int top = 0, bottom = modules.length - 1, middle = 0;
+                    Version middleVersion = null;
+                    while (top <= bottom)
+                    {
+                        middle = (bottom - top) / 2 + top;
+                        middleVersion = Util.getExportPackage(
+                            modules[middle], exports[i].getName()).getVersion();
+                        // Sort in reverse version order.
+                        int cmp = middleVersion.compareTo(exports[i].getVersion());
+                        if (cmp < 0)
+                        {
+                            bottom = middle - 1;
+                        }
+                        else if (cmp == 0)
+                        {
+                            // Sort further by ascending bundle ID.
+                            long middleId = Util.getBundleIdFromModuleId(modules[middle].getId());
+                            long exportId = Util.getBundleIdFromModuleId(module.getId());
+                            if (middleId < exportId)
+                            {
+                                top = middle + 1;
+                            }
+                            else
+                            {
+                                bottom = middle - 1;
+                            }
+                        }
+                        else
+                        {
+                            top = middle + 1;
+                        }
+                    }
+
+                    IModule[] newMods = new IModule[modules.length + 1];
+                    System.arraycopy(modules, 0, newMods, 0, top);
+                    System.arraycopy(modules, top, newMods, top + 1, modules.length - top);
+                    newMods[top] = module;
+                    modules = newMods;
+                }
+
+                m_availPkgMap.put(exports[i].getName(), modules);
+            }
+        }
     }
 
     public void moduleRemoved(ModuleEvent event)
@@ -1472,7 +1373,7 @@
         synchronized (m_factory)
         {
             // Remove exports from package maps.
-            R4Export[] exports = getExports(event.getModule());
+            R4Export[] exports = event.getModule().getDefinition().getExports();
             for (int i = 0; (exports != null) && (i < exports.length); i++)
             {
                 // Remove from "available" package map.
@@ -1601,13 +1502,7 @@
     private static class ModuleData
     {
         public IModule m_module = null;
-        public R4Export[] m_exports = null;
-        public R4Import[] m_imports = null;
-        public R4Import[] m_dynamicImports = null;
-        public R4Library[] m_libraries = null;
-        public R4Wire[] m_wires = null;
         public boolean m_resolved = false;
-        public boolean m_removalPending = false;
         public ModuleData(IModule module)
         {
             m_module = module;
@@ -1648,7 +1543,7 @@
         long impId = Util.getBundleIdFromModuleId(module.getId());
         
         // Next, check to see if the module imports the package.
-        R4Wire[] wires = getWires(module);
+        IWire[] wires = module.getWires();
         for (int i = 0; (wires != null) && (i < wires.length); i++)
         {
             if (wires[i].getExport().getName().equals(pkgName))
@@ -1656,7 +1551,7 @@
                 imported = true;
 
                 long expId = Util.getBundleIdFromModuleId(
-                    wires[i].getExportingModule().getId());
+                    wires[i].getExporter().getId());
 
                 StringBuffer sb = new StringBuffer("****\n****\n");
                 sb.append("Package '");
@@ -1684,7 +1579,7 @@
         // whether or not there is an exporter available.
         if (!imported)
         {
-            R4Import[] imports = getImports(module);
+            R4Import[] imports = module.getDefinition().getImports();
             for (int i = 0; (imports != null) && (i < imports.length); i++)
             {
                 if (imports[i].getName().equals(pkgName) && imports[i].isOptional())

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java Sun Jul 23 06:07:18 2006
@@ -21,7 +21,7 @@
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.moduleloader.*;
 
-public class R4Wire
+public class R4Wire implements IWire
 {
     private IModule m_importer = null;
     private IModule m_exporter = null;
@@ -34,21 +34,33 @@
         m_export = export;
     }
 
-    public IModule getImportingModule()
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getImportingModule()
+     */
+    public IModule getImporter()
     {
         return m_importer;
     }
 
-    public IModule getExportingModule()
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getExportingModule()
+     */
+    public IModule getExporter()
     {
         return m_exporter;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getExport()
+     */
     public R4Export getExport()
     {
         return m_export;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+     */
     public Class getClass(String name) throws ClassNotFoundException
     {
         Class clazz = null;
@@ -83,6 +95,9 @@
         return clazz;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
+     */
     public URL getResource(String name) throws ResourceNotFoundException
     {
         URL url = null;

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/Util.java Sun Jul 23 06:07:18 2006
@@ -23,6 +23,7 @@
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.searchpolicy.*;
 import org.apache.felix.moduleloader.IModule;
+import org.apache.felix.moduleloader.IWire;
 
 public class Util
 {
@@ -190,8 +191,7 @@
 
     public static R4Export getExportPackage(IModule m, String name)
     {
-        R4Export[] pkgs =
-            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getExports();
+        R4Export[] pkgs = m.getDefinition().getExports();
         for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
         {
             if (pkgs[i].getName().equals(name))
@@ -204,8 +204,7 @@
 
     public static R4Import getImportPackage(IModule m, String name)
     {
-        R4Import[] pkgs =
-            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getImports();
+        R4Import[] pkgs = m.getDefinition().getImports();
         for (int i = 0; (pkgs != null) && (i < pkgs.length); i++)
         {
             if (pkgs[i].getName().equals(name))
@@ -216,10 +215,9 @@
         return null;
     }
 
-    public static R4Wire getWire(IModule m, String name)
+    public static IWire getWire(IModule m, String name)
     {
-        R4Wire[] wires =
-            ((IR4SearchPolicy) m.getContentLoader().getSearchPolicy()).getWires();
+        IWire[] wires = m.getWires();
         for (int i = 0; (wires != null) && (i < wires.length); i++)
         {
             if (wires[i].getExport().getName().equals(name))

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModule.java Sun Jul 23 06:07:18 2006
@@ -21,7 +21,11 @@
 public interface IModule
 {
     public String getId();
+    public IModuleDefinition getDefinition();
     public IContentLoader getContentLoader();
+    public IWire[] getWires();
+
+    public boolean isRemovalPending();
 
     public Class getClass(String name);
     public URL getResource(String name);

Added: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java?rev=424730&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java (added)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java Sun Jul 23 06:07:18 2006
@@ -0,0 +1,27 @@
+/*
+ *   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.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+import org.apache.felix.framework.searchpolicy.*;
+
+public interface IModuleDefinition
+{
+    public R4Export[] getExports();
+    public R4Import[] getImports();
+    public R4Import[] getDynamicImports();
+    public R4Library[] getLibraries();
+}
\ No newline at end of file

Propchange: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleDefinition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java Sun Jul 23 06:07:18 2006
@@ -21,7 +21,7 @@
     public IModule[] getModules();
     public IModule getModule(String id);
 
-    public IModule createModule(String id);    
+    public IModule createModule(String id, IModuleDefinition md);    
     public void removeModule(IModule module);
 
     public void setContentLoader(IModule module, IContentLoader contentLoader);

Added: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java?rev=424730&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java (added)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java Sun Jul 23 06:07:18 2006
@@ -0,0 +1,30 @@
+/*
+ *   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.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+import java.net.URL;
+
+import org.apache.felix.framework.searchpolicy.R4Export;
+
+public interface IWire
+{
+    public IModule getImporter();
+    public IModule getExporter();
+    public R4Export getExport();
+    public Class getClass(String name) throws ClassNotFoundException;
+    public URL getResource(String name) throws ResourceNotFoundException;
+}
\ No newline at end of file

Propchange: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IWire.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java Sun Jul 23 06:07:18 2006
@@ -45,7 +45,7 @@
         return (IModule) m_moduleMap.get(id);
     }
 
-    public IModule createModule(String id)
+    public IModule createModule(String id, IModuleDefinition md)
     {
         IModule module = null;
 
@@ -55,7 +55,7 @@
         {
             if (m_moduleMap.get(id) == null)
             {
-                module = new ModuleImpl(m_logger, id);
+                module = new ModuleImpl(m_logger, id, md);
                 m_moduleMap.put(id, module);
             }
             else

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java?rev=424730&r1=424729&r2=424730&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java Sun Jul 23 06:07:18 2006
@@ -24,12 +24,16 @@
 {
     private Logger m_logger = null;
     private String m_id = null;
+    private boolean m_removalPending = false;
+    private IModuleDefinition m_md = null;
     private IContentLoader m_contentLoader = null;
+    private IWire[] m_wires = null;
 
-    ModuleImpl(Logger logger, String id)
+    ModuleImpl(Logger logger, String id, IModuleDefinition md)
     {
         m_logger = logger;
         m_id = id;
+        m_md = md;
     }
 
     public String getId()
@@ -37,6 +41,11 @@
         return m_id;
     }
 
+    public IModuleDefinition getDefinition()
+    {
+        return m_md;
+    }
+
     public IContentLoader getContentLoader()
     {
         return m_contentLoader;
@@ -45,6 +54,26 @@
     protected void setContentLoader(IContentLoader contentLoader)
     {
         m_contentLoader = contentLoader;
+    }
+
+    public IWire[] getWires()
+    {
+        return m_wires;
+    }
+
+    public void setWires(IWire[] wires)
+    {
+        m_wires = wires;
+    }
+
+    public boolean isRemovalPending()
+    {
+        return m_removalPending;
+    }
+
+    public void setRemovalPending(boolean removalPending)
+    {
+        m_removalPending = removalPending;
     }
 
     public Class getClass(String name)