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 2011/04/27 22:51:11 UTC

svn commit: r1097233 [4/4] - in /felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework: ./ resolver/ util/

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java Wed Apr 27 20:51:10 2011
@@ -43,7 +43,7 @@ class EntryFilterEnumeration implements 
     {
         m_bundle = bundle;
         BundleRevision br = m_bundle.getCurrentRevision();
-        List<BundleRevision> fragments = ((BundleRevisionImpl) br).getFragments();
+        List<BundleRevision> fragments = ((BundleWiringImpl) br.getWiring()).getFragments();
         if (includeFragments && (fragments != null))
         {
             m_revisions = new ArrayList(fragments.size() + 1);

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ExtensionManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ExtensionManager.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ExtensionManager.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ExtensionManager.java Wed Apr 27 20:51:10 2011
@@ -27,6 +27,7 @@ import java.net.URLStreamHandler;
 import java.security.AccessControlException;
 import java.security.AllPermission;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -36,13 +37,15 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 import java.util.Set;
-
 import org.apache.felix.framework.Felix.StatefulResolver;
+
+import org.apache.felix.framework.resolver.ResolverWire;
 import org.apache.felix.framework.util.FelixConstants;
 import org.apache.felix.framework.util.StringMap;
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.framework.util.manifestparser.ManifestParser;
 import org.apache.felix.framework.resolver.Content;
+import org.apache.felix.framework.util.manifestparser.R4Library;
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
@@ -53,6 +56,7 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWiring;
 
 /**
  * The ExtensionManager class is used in several ways.
@@ -115,6 +119,7 @@ class ExtensionManager extends URLStream
     }
 
     private final Logger m_logger;
+    private final Map m_configMap;
     private final Map m_headerMap = new StringMap(false);
     private final BundleRevision m_systemBundleRevision;
     private List<BundleCapability> m_capabilities = null;
@@ -130,6 +135,7 @@ class ExtensionManager extends URLStream
     private ExtensionManager()
     {
         m_logger = null;
+        m_configMap = null;
         m_systemBundleRevision = null;
         m_extensions = new ArrayList();
         m_extensionsCache = new Bundle[0];
@@ -148,19 +154,20 @@ class ExtensionManager extends URLStream
      * @param config the configuration to read properties from.
      * @param systemBundleInfo the info to change if we need to add exports.
      */
-    ExtensionManager(Logger logger, Felix felix)
+    ExtensionManager(Logger logger, Map configMap, Felix felix)
     {
+        m_logger = logger;
+        m_configMap = configMap;
         m_systemBundleRevision = new ExtensionManagerRevision(felix);
         m_extensions = null;
         m_extensionsCache = null;
         m_names = null;
         m_sourceToExtensions = null;
-        m_logger = logger;
 
 // TODO: FRAMEWORK - Not all of this stuff really belongs here, probably only exports.
         // Populate system bundle header map.
         m_headerMap.put(FelixConstants.BUNDLE_VERSION,
-            felix.getConfig().get(FelixConstants.FELIX_VERSION_PROPERTY));
+            m_configMap.get(FelixConstants.FELIX_VERSION_PROPERTY));
         m_headerMap.put(FelixConstants.BUNDLE_SYMBOLICNAME,
             FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME);
         m_headerMap.put(FelixConstants.BUNDLE_NAME, "System Bundle");
@@ -176,21 +183,21 @@ class ExtensionManager extends URLStream
         // We must construct the system bundle's export metadata.
         // Get configuration property that specifies which class path
         // packages should be exported by the system bundle.
-        String syspkgs = (String) felix.getConfig().get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES);
+        String syspkgs = (String) m_configMap.get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES);
         // If no system packages were specified, load our default value.
         syspkgs = (syspkgs == null)
             ? Util.getDefaultProperty(logger, Constants.FRAMEWORK_SYSTEMPACKAGES)
             : syspkgs;
         syspkgs = (syspkgs == null) ? "" : syspkgs;
         // If any extra packages are specified, then append them.
-        String extra = (String) felix.getConfig().get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
+        String extra = (String) m_configMap.get(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
         syspkgs = (extra == null) ? syspkgs : syspkgs + "," + extra;
         m_headerMap.put(FelixConstants.BUNDLE_MANIFESTVERSION, "2");
         m_headerMap.put(FelixConstants.EXPORT_PACKAGE, syspkgs);
         try
         {
             ManifestParser mp = new ManifestParser(
-                m_logger, felix.getConfig(), m_systemBundleRevision, m_headerMap);
+                m_logger, m_configMap, m_systemBundleRevision, m_headerMap);
             List<BundleCapability> caps = aliasSymbolicName(mp.getCapabilities());
             setCapabilities(caps);
         }
@@ -635,14 +642,17 @@ class ExtensionManager extends URLStream
     class ExtensionManagerRevision extends BundleRevisionImpl
     {
         private final Version m_version;
+        private volatile BundleWiring m_wiring;
+
         ExtensionManagerRevision(Felix felix)
         {
-            super(m_logger, felix.getConfig(), felix, "0",
+            super(m_logger, m_configMap, felix, "0",
                 felix.getBootPackages(), felix.getBootPackageWildcards());
             m_version = new Version((String)
-                felix.getConfig().get(FelixConstants.FELIX_VERSION_PROPERTY));
+                m_configMap.get(FelixConstants.FELIX_VERSION_PROPERTY));
         }
 
+        @Override
         public Map getHeaders()
         {
             synchronized (ExtensionManager.this)
@@ -651,6 +661,7 @@ class ExtensionManager extends URLStream
             }
         }
 
+        @Override
         public List<BundleCapability> getDeclaredCapabilities(String namespace)
         {
             synchronized (ExtensionManager.this)
@@ -659,6 +670,85 @@ class ExtensionManager extends URLStream
             }
         }
 
+        @Override
+        public String getSymbolicName()
+        {
+            return FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME;
+        }
+
+        @Override
+        public Version getVersion()
+        {
+            return m_version;
+        }
+
+        @Override
+        public void close()
+        {
+            // Nothing needed here.
+        }
+
+        @Override
+        public Content getContent()
+        {
+            return ExtensionManager.this;
+        }
+
+        @Override
+        public URL getEntry(String name)
+        {
+            // There is no content for the system bundle, so return null.
+            return null;
+        }
+
+        @Override
+        public boolean hasInputStream(int index, String urlPath)
+        {
+            return (getClass().getClassLoader().getResource(urlPath) != null);
+        }
+
+        @Override
+        public InputStream getInputStream(int index, String urlPath)
+        {
+            return getClass().getClassLoader().getResourceAsStream(urlPath);
+        }
+
+        @Override
+        public URL getLocalURL(int index, String urlPath)
+        {
+            return getClass().getClassLoader().getResource(urlPath);
+        }
+
+        @Override
+        public void resolve(
+            List<BundleRevision> fragments, List<ResolverWire> rws,
+            Map<ResolverWire, Set<String>> requiredPkgWires) throws Exception
+        {
+            m_wiring = new ExtensionManagerWiring(
+                m_logger, m_configMap, null, this, fragments, rws, requiredPkgWires);
+        }
+
+        @Override
+        public BundleWiring getWiring()
+        {
+            return m_wiring;
+        }
+    }
+
+    class ExtensionManagerWiring extends BundleWiringImpl
+    {
+        ExtensionManagerWiring(
+            Logger logger, Map configMap, StatefulResolver resolver,
+            BundleRevisionImpl revision, List<BundleRevision> fragments,
+            List<ResolverWire> resolverWires,
+            Map<ResolverWire, Set<String>> requiredPkgWires)
+            throws Exception
+        {
+            super(logger, configMap, resolver, revision,
+                fragments, resolverWires, requiredPkgWires);
+        }
+
+        @Override
         public List<BundleCapability> getCapabilities(String namespace)
         {
             synchronized (ExtensionManager.this)
@@ -667,16 +757,13 @@ class ExtensionManager extends URLStream
             }
         }
 
-        public String getSymbolicName()
-        {
-            return FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME;
-        }
-
-        public Version getVersion()
+        @Override
+        public List<R4Library> getNativeLibraries()
         {
-            return m_version;
+            return Collections.EMPTY_LIST;
         }
 
+        @Override
         public Class getClassByDelegation(String name) throws ClassNotFoundException
         {
             Class clazz = null;
@@ -720,11 +807,13 @@ class ExtensionManager extends URLStream
             return clazz;
         }
 
+        @Override
         public URL getResourceByDelegation(String name)
         {
             return getClass().getClassLoader().getResource(name);
         }
 
+        @Override
         public Enumeration getResourcesByDelegation(String name)
         {
            try
@@ -737,53 +826,13 @@ class ExtensionManager extends URLStream
            }
         }
 
-        public Logger getLogger()
-        {
-            return m_logger;
-        }
-
-        public Map getConfig()
-        {
-            return null;
-        }
-
-        public StatefulResolver getResolver()
-        {
-            return null;
-        }
-
-        public void attachFragmentContents(Content[] fragmentContents)
-            throws Exception
-        {
-            throw new UnsupportedOperationException("Should not be used!");
-        }
-
-        public void close()
+        @Override
+        public void dispose()
         {
             // Nothing needed here.
         }
 
-        public Content getContent()
-        {
-            return ExtensionManager.this;
-        }
-
-        public URL getEntry(String name)
-        {
-            // There is no content for the system bundle, so return null.
-            return null;
-        }
-
-        public boolean hasInputStream(int index, String urlPath)
-        {
-            return (getClass().getClassLoader().getResource(urlPath) != null);
-        }
-
-        public InputStream getInputStream(int index, String urlPath)
-        {
-            return getClass().getClassLoader().getResourceAsStream(urlPath);
-        }
-
+        @Override
         public URL getLocalURL(int index, String urlPath)
         {
             return getClass().getClassLoader().getResource(urlPath);

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/Felix.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/Felix.java Wed Apr 27 20:51:10 2011
@@ -369,7 +369,7 @@ public class Felix extends BundleImpl im
 
         // Create the extension manager, which we will use as the
         // revision for the system bundle.
-        m_extensionManager = new ExtensionManager(m_logger, this);
+        m_extensionManager = new ExtensionManager(m_logger, m_configMap, this);
         try
         {
             addRevision(m_extensionManager.getRevision());
@@ -1451,7 +1451,21 @@ public class Felix extends BundleImpl im
         {
             return null;
         }
-        return ((BundleRevisionImpl) bundle.getCurrentRevision()).getResourceByDelegation(name);
+// TODO: OSGi R4.3 - Currently, we try to resolve resource requests in
+//       findClassOrResourceByDelegation() and fall back to local resource
+//       searching if it fails. Perhaps we should attempt the resolve here
+//       and do the local searching here. This means we could get rid of
+//       resolve attempts in findClassOrResourceByDelegation().
+        if (bundle.getCurrentRevision().getWiring() == null)
+        {
+            return ((BundleRevisionImpl) bundle.getCurrentRevision())
+                .getResourceLocal(name);
+        }
+        else
+        {
+            return ((BundleWiringImpl) bundle.getCurrentRevision().getWiring())
+                .getResourceByDelegation(name);
+        }
     }
 
     /**
@@ -1467,7 +1481,21 @@ public class Felix extends BundleImpl im
         {
             return null;
         }
-        return ((BundleRevisionImpl) bundle.getCurrentRevision()).getResourcesByDelegation(name);
+// TODO: OSGi R4.3 - Currently, we try to resolve resource requests in
+//       findResourcesByDelegation() and fall back to local resource
+//       searching if it fails. Perhaps we should attempt the resolve here
+//       and do the local searching here. This means we could get rid of
+//       resolve attempts in findResourcesByDelegation().
+        if (bundle.getCurrentRevision().getWiring() == null)
+        {
+            return ((BundleRevisionImpl) bundle.getCurrentRevision())
+                .getResourcesLocal(name);
+        }
+        else
+        {
+            return ((BundleWiringImpl) bundle.getCurrentRevision().getWiring())
+                .getResourcesByDelegation(name);
+        }
     }
 
     /**
@@ -1626,7 +1654,8 @@ public class Felix extends BundleImpl im
                 throw new ClassNotFoundException(name, ex);
             }
         }
-        return ((BundleRevisionImpl) bundle.getCurrentRevision()).getClassByDelegation(name);
+        return ((BundleWiringImpl)
+            bundle.getCurrentRevision().getWiring()).getClassByDelegation(name);
     }
 
     /**
@@ -3220,8 +3249,8 @@ public class Felix extends BundleImpl im
                 Class sbClass = null;
                 try
                 {
-                    sbClass = ((BundleRevisionImpl) m_extensionManager
-                        .getRevision()).getClassByDelegation(clazz.getName());
+                    sbClass = ((BundleWiringImpl) m_extensionManager
+                        .getRevision().getWiring()).getClassByDelegation(clazz.getName());
                 }
                 catch (ClassNotFoundException ex)
                 {
@@ -3416,24 +3445,19 @@ public class Felix extends BundleImpl im
                             BundleCapabilityImpl.PACKAGE_NAMESPACE,
                             Collections.EMPTY_MAP,
                             attrs);
-                        Set<BundleCapability> providers =
-                            m_resolver.getCandidates(req, false);
-                        // We only want resolved capabilities.
-                        for (Iterator<BundleCapability> it = providers.iterator();
-                            it.hasNext(); )
-                        {
-                            if (it.next().getRevision().getWiring() == null)
-                            {
-                                it.remove();
-                            }
-                        }
+                        Set<BundleCapability> providers = m_resolver.getCandidates(req, false);
 
                         // Search through the current providers to find the target revision.
-                        for (BundleCapability provider : providers)
+                        // We only want resolved capabilities.
+                        if (providers != null)
                         {
-                            if (provider == cap)
+                            for (BundleCapability provider : providers)
                             {
-                                list.add(new ExportedPackageImpl(this, bundle, br, cap));
+                                if ((provider.getRevision().getWiring() != null)
+                                    && (provider == cap))
+                                {
+                                    list.add(new ExportedPackageImpl(this, bundle, br, cap));
+                                }
                             }
                         }
                     }
@@ -3449,10 +3473,10 @@ public class Felix extends BundleImpl im
 
         // Get all dependent revisions from all exporter revisions.
         List<BundleRevision> revisions = exporter.getRevisions();
-        for (int modIdx = 0; modIdx < revisions.size(); modIdx++)
+        for (int revIdx = 0; revIdx < revisions.size(); revIdx++)
         {
             List<BundleRevision> dependents =
-                ((BundleRevisionImpl) revisions.get(modIdx)).getDependents();
+                ((BundleRevisionImpl) revisions.get(revIdx)).getDependents();
             for (int depIdx = 0;
                 (dependents != null) && (depIdx < dependents.size());
                 depIdx++)
@@ -3479,24 +3503,31 @@ public class Felix extends BundleImpl im
         {
             // Include any importers that have wires to the specific
             // exported package.
-            List<BundleRevision> dependents =
-                ((BundleRevisionImpl) expRevisions.get(expIdx)).getDependentImporters();
-            for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
+            if (expRevisions.get(expIdx).getWiring() != null)
             {
-                BundleRevision providerRevision =
-                    ((BundleRevisionImpl) dependents.get(depIdx))
-                        .getImportedPackageSource(ep.getName());                
-                if ((providerRevision != null)
-                    && (providerRevision == expRevisions.get(expIdx)))
+                List<BundleRevision> dependents = ((BundleRevisionImpl)
+                    expRevisions.get(expIdx)).getDependentImporters();
+                for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
+                {
+                    if (dependents.get(depIdx).getWiring() != null)
+                    {
+                        BundleRevision providerRevision =
+                            ((BundleWiringImpl) dependents.get(depIdx).getWiring())
+                                .getImportedPackageSource(ep.getName());                
+                        if ((providerRevision != null)
+                            && (providerRevision == expRevisions.get(expIdx)))
+                        {
+                            list.add(dependents.get(depIdx).getBundle());
+                        }
+                    }
+                }
+                dependents = ((BundleRevisionImpl)
+                    expRevisions.get(expIdx)).getDependentRequirers();
+                for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
                 {
                     list.add(dependents.get(depIdx).getBundle());
                 }
             }
-            dependents = ((BundleRevisionImpl) expRevisions.get(expIdx)).getDependentRequirers();
-            for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
-            {
-                list.add(dependents.get(depIdx).getBundle());
-            }
         }
 
         // Return the results.
@@ -3822,8 +3853,8 @@ public class Felix extends BundleImpl im
             Class clazz;
             try
             {
-                clazz = ((BundleRevisionImpl)
-                    impl.getCurrentRevision()).getClassByDelegation(className);
+                clazz = ((BundleWiringImpl)
+                    impl.getCurrentRevision().getWiring()).getClassByDelegation(className);
             }
             catch (ClassNotFoundException ex)
             {
@@ -4210,7 +4241,7 @@ public class Felix extends BundleImpl im
                     // dynamically importing the package, which can happen if two
                     // threads are racing to do so. If we have an existing wire,
                     // then just return it instead.
-                    provider = ((BundleRevisionImpl)revision)
+                    provider = ((BundleWiringImpl) revision.getWiring())
                         .getImportedPackageSource(pkgName);
                     if (provider == null)
                     {
@@ -4229,12 +4260,13 @@ public class Felix extends BundleImpl im
                             // Dynamically add new wire to importing revision.
                             if (dynamicWire != null)
                             {
-                                ((BundleRevisionImpl) revision).addDynamicWire(dynamicWire);
+                                ((BundleWiringImpl) revision.getWiring())
+                                    .addDynamicWire(dynamicWire);
                                 m_logger.log(
                                     Logger.LOG_DEBUG,
                                     "DYNAMIC WIRE: " + dynamicWire);
 
-                                provider = ((BundleRevisionImpl) revision)
+                                provider = ((BundleWiringImpl) revision.getWiring())
                                     .getImportedPackageSource(pkgName);
                             }
                         }
@@ -4266,7 +4298,7 @@ public class Felix extends BundleImpl im
             // If the revision doesn't have dynamic imports, then just return
             // immediately.
             List<BundleRequirement> dynamics =
-                ((BundleRevisionImpl) revision).getResolvedDynamicRequirements();
+                ((BundleWiringImpl) revision.getWiring()).getDynamicRequirements();
             if ((dynamics == null) || dynamics.isEmpty())
             {
                 return false;
@@ -4285,7 +4317,7 @@ public class Felix extends BundleImpl im
 
             // If this revision already imports or requires this package, then
             // we cannot dynamically import it.
-            if (((BundleRevisionImpl) revision).hasPackageSource(pkgName))
+            if (((BundleWiringImpl) revision.getWiring()).hasPackageSource(pkgName))
             {
                 return false;
             }
@@ -4365,64 +4397,54 @@ public class Felix extends BundleImpl im
                         }
                     }
 
-                    ((BundleRevisionImpl) revision).setWires(resolverWires, requiredPkgWires);
-
-                    // Attach fragments, if any.
                     List<BundleRevision> fragments = hosts.get(revision);
-                    if (fragments != null)
+                    try
                     {
-                        try
-                        {
-                            ((BundleRevisionImpl) revision).attachFragments(fragments);
-                        }
-                        catch (Exception ex)
+// TODO: OSGi R4.3 - Technically, this is where the revision becomes resolved,
+//       but we used to wait and mark it as resolved in the third phase below. 
+                        ((BundleRevisionImpl) revision).resolve(
+                            fragments, resolverWires, requiredPkgWires);
+                    }
+                    catch (Exception ex)
+                    {
+                        // This is a fatal error, so undo everything and
+                        // throw an exception.
+                        for (Entry<BundleRevision, List<ResolverWire>> reentry : wireMap.entrySet())
                         {
-                            // This is a fatal error, so undo everything and
-                            // throw an exception.
-                            for (Entry<BundleRevision, List<ResolverWire>> reentry : wireMap.entrySet())
-                            {
-                                revision = reentry.getKey();
-
-                                // Undo wires.
-                                ((BundleRevisionImpl) revision).setWires(null, null);
-
-                                fragments = hosts.get(revision);
-                                if (fragments != null)
-                                {
-                                    try
-                                    {
-                                        // Undo fragments.
-                                        ((BundleRevisionImpl) revision).attachFragments(null);
-                                    }
-                                    catch (Exception ex2)
-                                    {
-                                        // We are in big trouble.
-                                        RuntimeException rte = new RuntimeException(
-                                            "Unable to clean up resolver failure.", ex2);
-                                        m_logger.log(
-                                            Logger.LOG_ERROR,
-                                            rte.getMessage(), ex2);
-                                        throw rte;
-                                    }
+                            revision = reentry.getKey();
 
-                                    // Reindex host with no fragments.
-                                    m_resolverState.addRevision(revision);
-                                }
+                            // Undo wires.
+                            try
+                            {
+                                ((BundleRevisionImpl) revision).resolve(null, null, null);
+                            }
+                            catch (Exception ex2)
+                            {
+                                // We are in big trouble.
+                                RuntimeException rte = new RuntimeException(
+                                    "Unable to clean up resolver failure.", ex2);
+                                m_logger.log(
+                                    Logger.LOG_ERROR,
+                                    rte.getMessage(), ex2);
+                                throw rte;
                             }
 
-                            ResolveException re = new ResolveException(
-                                "Unable to attach fragments to " + revision,
-                                revision, null);
-                            re.initCause(ex);
-                            m_logger.log(
-                                Logger.LOG_ERROR,
-                                re.getMessage(), ex);
-                            throw re;
+                            // Reindex host with no fragments.
+                            m_resolverState.addRevision(revision);
                         }
 
-                        // Reindex host with attached fragments.
-                        m_resolverState.addRevision(revision);
+                        ResolveException re = new ResolveException(
+                            "Unable to resolve " + revision,
+                            revision, null);
+                        re.initCause(ex);
+                        m_logger.log(
+                            Logger.LOG_ERROR,
+                            re.getMessage(), ex);
+                        throw re;
                     }
+
+                    // Reindex host with attached fragments.
+                    m_resolverState.addRevision(revision);
                 }
 
                 // Third pass: Loop through the wire map to mark revision as resolved
@@ -4431,7 +4453,8 @@ public class Felix extends BundleImpl im
                 {
                     BundleRevision revision = entry.getKey();
                     // Mark revision as resolved.
-                    ((BundleRevisionImpl) revision).setResolved();
+// TODO: OSGi R4.3 - See message above when we call BundleRevisionImpl.resolve().
+//                    ((BundleRevisionImpl) revision).setResolved();
                     // Update resolver state to remove substituted capabilities.
                     if (!Util.isFragment(revision))
                     {
@@ -4496,7 +4519,8 @@ public class Felix extends BundleImpl im
                     BundleRevision revision = entry.getKey();
 
                     // Fire RESOLVED events for all fragments.
-                    List<BundleRevision> fragments = ((BundleRevisionImpl) revision).getFragments();
+                    List<BundleRevision> fragments =
+                        ((BundleWiringImpl) revision.getWiring()).getFragments();
                     for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
                     {
                         fireBundleEvent(BundleEvent.RESOLVED, fragments.get(i).getBundle());

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/PackageAdminImpl.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/PackageAdminImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/PackageAdminImpl.java Wed Apr 27 20:51:10 2011
@@ -197,14 +197,13 @@ class PackageAdminImpl implements Packag
         {
             List<Bundle> list = new ArrayList<Bundle>();
             // Iterate through revisions
-            List<BundleRevision> revisions = ((BundleImpl) bundle).getRevisions();
-            for (int modIdx = 0; modIdx < revisions.size(); modIdx++)
+            for (BundleRevision revision : ((BundleImpl) bundle).getRevisions())
             {
                 // Get attached fragments.
-                BundleRevisionImpl revision = (BundleRevisionImpl) revisions.get(modIdx);
-                if (revision.isResolved())
+                if (revision.getWiring() != null)
                 {
-                    List<BundleRevision> fragments = revision.getFragments();
+                    List<BundleRevision> fragments =
+                        ((BundleWiringImpl) revision.getWiring()).getFragments();
                     for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
                     {
                         Bundle b = fragments.get(i).getBundle();
@@ -230,14 +229,12 @@ class PackageAdminImpl implements Packag
         {
             List<Bundle> list = new ArrayList<Bundle>();
             // Iterate through revisions
-            List<BundleRevision> revisions = ((BundleImpl) bundle).getRevisions();
-            for (int modIdx = 0; modIdx < revisions.size(); modIdx++)
+            for (BundleRevision revision : ((BundleImpl) bundle).getRevisions())
             {
                 // Get hosts
-                BundleRevisionImpl revision = (BundleRevisionImpl) revisions.get(modIdx);
-                if (revision.isResolved())
+                if (revision.getWiring() != null)
                 {
-                    List<BundleWire> hostWires = revision.getWires();
+                    List<BundleWire> hostWires = revision.getWiring().getRequiredWires(null);
                     for (int i = 0; (hostWires != null) && (i < hostWires.size()); i++)
                     {
                         Bundle b = hostWires.get(i).getProviderWiring().getBundle();
@@ -259,14 +256,12 @@ class PackageAdminImpl implements Packag
     public RequiredBundle[] getRequiredBundles(String symbolicName)
     {
         List list = new ArrayList();
-        Bundle[] bundles = m_felix.getBundles();
-        for (int i = 0; i < bundles.length; i++)
+        for (Bundle bundle : m_felix.getBundles())
         {
-            BundleImpl impl = (BundleImpl) bundles[i];
             if ((symbolicName == null)
-                || (symbolicName.equals(impl.getCurrentRevision().getSymbolicName())))
+                || (symbolicName.equals(bundle.getSymbolicName())))
             {
-                list.add(new RequiredBundleImpl(m_felix, impl));
+                list.add(new RequiredBundleImpl(m_felix, (BundleImpl) bundle));
             }
         }
         return (list.isEmpty())

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java Wed Apr 27 20:51:10 2011
@@ -145,7 +145,7 @@ class ResolverStateImpl implements Resol
             // If so, then the framework must have chosen to have the revision
             // import rather than export the package, so we need to remove the
             // corresponding package capability from the package capability set.
-            for (BundleWire w : ((BundleRevisionImpl) br).getWires())
+            for (BundleWire w : br.getWiring().getRequiredWires(null))
             {
                 if (w.getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
                 {
@@ -274,7 +274,9 @@ class ResolverStateImpl implements Resol
     {
         // Next, try to resolve any native code, since the revision is
         // not resolvable if its native code cannot be loaded.
-        List<R4Library> libs = ((BundleRevisionImpl) revision).getNativeLibraries();
+// TODO: OSGi R4.3 - Is it sufficient to just check declared native libs here?
+//        List<R4Library> libs = ((BundleWiringImpl) revision.getWiring()).getNativeLibraries();
+        List<R4Library> libs = ((BundleRevisionImpl) revision).getDeclaredNativeLibraries();
         if (libs != null)
         {
             String msg = null;

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java Wed Apr 27 20:51:10 2011
@@ -519,7 +519,8 @@ class ServiceRegistrationImpl implements
                 try
                 {
                     Class requestClass =
-                        ((BundleRevisionImpl) requesterRevision).getClassByDelegation(className);
+                        ((BundleWiringImpl) requesterRevision.getWiring())
+                            .getClassByDelegation(className);
                     allow = getRegistration().isClassAccessible(requestClass);
                 }
                 catch (Exception ex)
@@ -544,14 +545,15 @@ class ServiceRegistrationImpl implements
                     try
                     {
                         // Try to load class from requester.
-                        Class requestClass =((BundleRevisionImpl)
-                            requesterRevision).getClassByDelegation(className);
+                        Class requestClass =((BundleWiringImpl)
+                            requesterRevision.getWiring()).getClassByDelegation(className);
                         try
                         {
                             // If requester has access to the class, verify it is the
                             // same class as the provider.
-                            allow = (((BundleRevisionImpl) providerRevision)
-                                .getClassByDelegation(className) == requestClass);
+                            allow = (((BundleWiringImpl)
+                                providerRevision.getWiring())
+                                    .getClassByDelegation(className) == requestClass);
                         }
                         catch (Exception ex)
                         {
@@ -585,8 +587,9 @@ class ServiceRegistrationImpl implements
                     try
                     {
                         // Load the class from the requesting bundle.
-                        Class requestClass = ((BundleRevisionImpl)
-                            requesterRevision).getClassByDelegation(className);
+                        Class requestClass = ((BundleWiringImpl)
+                            requesterRevision.getWiring())
+                                .getClassByDelegation(className);
                         // Get the service registration and ask it to check
                         // if the service object is assignable to the requesting
                         // bundle's class.

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java Wed Apr 27 20:51:10 2011
@@ -126,8 +126,8 @@ class URLHandlersBundleURLConnection ext
         if (!((BundleRevisionImpl) m_targetRevision)
             .hasInputStream(m_classPathIdx, url.getPath()))
         {
-            URL newurl = ((BundleRevisionImpl)
-                m_targetRevision).getResourceByDelegation(url.getPath());
+            URL newurl = ((BundleWiringImpl)
+                m_targetRevision.getWiring()).getResourceByDelegation(url.getPath());
             if (newurl == null)
             {
                 throw new IOException("Resource does not exist: " + url);

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/Candidates.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/Candidates.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/Candidates.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/Candidates.java Wed Apr 27 20:51:10 2011
@@ -31,6 +31,7 @@ import java.util.SortedSet;
 import java.util.TreeMap;
 import java.util.TreeSet;
 import org.apache.felix.framework.BundleRevisionImpl;
+import org.apache.felix.framework.BundleWiringImpl;
 import org.apache.felix.framework.resolver.Resolver.ResolverState;
 import org.apache.felix.framework.util.Util;
 import org.apache.felix.framework.wiring.BundleCapabilityImpl;
@@ -990,8 +991,11 @@ class Candidates
                     System.out.println("    " + req + ": " + candidates);
                 }
             }
+// TODO: OSGi R4.3 - We need to get dynamic requirements using public API
+//       then we might not need to make the BundleWiringImpl and BundleRevisionImpl
+//       classes public.
             reqs = (br.getWiring() != null)
-                ? ((BundleRevisionImpl) br).getResolvedDynamicRequirements()
+                ? ((BundleWiringImpl) br.getWiring()).getDynamicRequirements()
                 : ((BundleRevisionImpl) br).getDeclaredDynamicRequirements();
             for (BundleRequirement req : reqs)
             {

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java Wed Apr 27 20:51:10 2011
@@ -29,6 +29,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.SortedSet;
 import org.apache.felix.framework.BundleRevisionImpl;
+import org.apache.felix.framework.BundleWiringImpl;
 import org.apache.felix.framework.Logger;
 import org.apache.felix.framework.capabilityset.CapabilitySet;
 import org.apache.felix.framework.util.Util;
@@ -62,7 +63,7 @@ public class ResolverImpl implements Res
         Map<BundleRevision, List<ResolverWire>> wireMap = new HashMap<BundleRevision, List<ResolverWire>>();
         Map<BundleRevision, Packages> revisionPkgMap = new HashMap<BundleRevision, Packages>();
 
-        if (!((BundleRevisionImpl) revision).isResolved())
+        if (revision.getWiring() == null)
         {
             boolean retryFragments;
             do
@@ -360,7 +361,7 @@ public class ResolverImpl implements Res
         // If the revision doesn't have dynamic imports, then just return
         // immediately.
         List<BundleRequirement> dynamics =
-            ((BundleRevisionImpl) revision).getResolvedDynamicRequirements();
+            ((BundleWiringImpl) revision.getWiring()).getDynamicRequirements();
         if ((dynamics == null) || dynamics.isEmpty())
         {
             return null;
@@ -379,7 +380,7 @@ public class ResolverImpl implements Res
 
         // If this revision already imports or requires this package, then
         // we cannot dynamically import it.
-        if (((BundleRevisionImpl) revision).hasPackageSource(pkgName))
+        if (((BundleWiringImpl) revision.getWiring()).hasPackageSource(pkgName))
         {
             return null;
         }
@@ -466,7 +467,7 @@ public class ResolverImpl implements Res
         if (revision.getWiring() != null)
         {
             // Use wires to get actual requirements and satisfying capabilities.
-            for (BundleWire wire : ((BundleRevisionImpl) revision).getWires())
+            for (BundleWire wire : revision.getWiring().getRequiredWires(null))
             {
                 // Wrap the requirement as a hosted requirement
                 // if it comes from a fragment, since we will need
@@ -496,7 +497,7 @@ public class ResolverImpl implements Res
             // so check to see if there are candidates for any of its dynamic
             // imports.
             for (BundleRequirement req
-                : ((BundleRevisionImpl) revision).getResolvedDynamicRequirements())
+                : ((BundleWiringImpl) revision.getWiring()).getDynamicRequirements())
             {
                 // Get the candidates for the current requirement.
                 SortedSet<BundleCapability> candCaps =
@@ -1171,7 +1172,7 @@ public class ResolverImpl implements Res
         // exports are substitutable.
         if (revision.getWiring() != null)
         {
-            for (BundleWire wire : ((BundleRevisionImpl) revision).getWires())
+            for (BundleWire wire : revision.getWiring().getRequiredWires(null))
             {
                 if (wire.getRequirement().getNamespace().equals(
                     BundleCapabilityImpl.PACKAGE_NAMESPACE))

Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java?rev=1097233&r1=1097232&r2=1097233&view=diff
==============================================================================
--- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java (original)
+++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/util/Util.java Wed Apr 27 20:51:10 2011
@@ -329,17 +329,20 @@ public class Util
 
     public static BundleWire getWire(BundleRevision br, String name)
     {
-        List<BundleWire> wires = ((BundleRevisionImpl) br).getWires();
-        if (wires != null)
+        if (br.getWiring() != null)
         {
-            for (BundleWire w : wires)
+            List<BundleWire> wires = br.getWiring().getRequiredWires(null);
+            if (wires != null)
             {
-                if (w.getCapability().getNamespace()
-                        .equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
-                    w.getCapability().getAttributes()
-                        .get(BundleCapabilityImpl.PACKAGE_ATTR).equals(name))
+                for (BundleWire w : wires)
                 {
-                    return w;
+                    if (w.getCapability().getNamespace()
+                            .equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
+                        w.getCapability().getAttributes()
+                            .get(BundleCapabilityImpl.PACKAGE_ATTR).equals(name))
+                    {
+                        return w;
+                    }
                 }
             }
         }