You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2011/05/16 23:49:05 UTC

svn commit: r1103918 [4/12] - in /felix/trunk/framework: ./ src/main/java/org/apache/felix/framework/ src/main/java/org/apache/felix/framework/cache/ src/main/java/org/apache/felix/framework/capabilityset/ src/main/java/org/apache/felix/framework/resol...

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java?rev=1103918&r1=1103917&r2=1103918&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java Mon May 16 21:49:02 2011
@@ -30,39 +30,34 @@ import java.util.Set;
 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.capabilityset.Capability;
+import org.apache.felix.framework.capabilityset.Directive;
+import org.apache.felix.framework.capabilityset.Requirement;
 import org.apache.felix.framework.resolver.Resolver.ResolverState;
 import org.apache.felix.framework.util.Util;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRequirement;
-import org.osgi.framework.wiring.BundleRevision;
 
 class Candidates
 {
-    private final BundleRevision m_root;
+    private final Module m_root;
 
-    // Set of all candidate bundle revisions.
-    private final Set<BundleRevision> m_candidateRevisions;
+    // Set of all candidate modules.
+    private final Set<Module> m_candidateModules;
     // Maps a capability to requirements that match it.
-    private final Map<BundleCapability, Set<BundleRequirement>> m_dependentMap;
+    private final Map<Capability, Set<Requirement>> m_dependentMap;
     // Maps a requirement to the capability it matches.
-    private final Map<BundleRequirement, SortedSet<BundleCapability>> m_candidateMap;
+    private final Map<Requirement, SortedSet<Capability>> m_candidateMap;
     // Maps a host capability to a map containing its potential fragments;
     // the fragment map maps a fragment symbolic name to a map that maps
     // a version to a list of fragments requirements matching that symbolic
     // name and version.
-    private final Map<BundleCapability,
-        Map<String, Map<Version, List<BundleRequirement>>>> m_hostFragments;
-    // Maps a bundle revision to its associated wrapped revision; this only happens
-    // when a revision being resolved has fragments to attach to it.
-    private final Map<BundleRevision, HostBundleRevision> m_allWrappedHosts;
+    private final Map<Capability, Map<String, Map<Version, List<Requirement>>>> m_hostFragments;
+    // Maps a module to its associated wrapped module; this only happens
+    // when a module being resolved has fragments to attach to it.
+    private final Map<Module, HostModule> m_allWrappedHosts;
     // Map used when populating candidates to hold intermediate and final results.
-    private final Map<BundleRevision, Object> m_populateResultCache;
+    private final Map<Module, Object> m_populateResultCache;
 
     // Flag to signal if fragments are present in the candidate map.
     private boolean m_fragmentsPresent = false;
@@ -76,16 +71,16 @@ class Candidates
      * @param wrappedHosts the wrapped hosts map.
     **/
     private Candidates(
-        BundleRevision root,
-        Set<BundleRevision> candidateRevisions,
-        Map<BundleCapability, Set<BundleRequirement>> dependentMap,
-        Map<BundleRequirement, SortedSet<BundleCapability>> candidateMap,
-        Map<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>> hostFragments,
-        Map<BundleRevision, HostBundleRevision> wrappedHosts, Map<BundleRevision, Object> populateResultCache,
+        Module root,
+        Set<Module> candidateModules,
+        Map<Capability, Set<Requirement>> dependentMap,
+        Map<Requirement, SortedSet<Capability>> candidateMap,
+        Map<Capability, Map<String, Map<Version, List<Requirement>>>> hostFragments,
+        Map<Module, HostModule> wrappedHosts, Map<Module, Object> populateResultCache,
         boolean fragmentsPresent)
     {
         m_root = root;
-        m_candidateRevisions = candidateRevisions;
+        m_candidateModules = candidateModules;
         m_dependentMap = dependentMap;
         m_candidateMap = candidateMap;
         m_hostFragments = hostFragments;
@@ -99,16 +94,16 @@ class Candidates
      * @param state the resolver state used for populating the candidates.
      * @param root the root module for the resolve.
     **/
-    public Candidates(ResolverState state, BundleRevision root)
+    public Candidates(ResolverState state, Module root)
     {
         m_root = root;
-        m_candidateRevisions = new HashSet<BundleRevision>();
-        m_dependentMap = new HashMap<BundleCapability, Set<BundleRequirement>>();
-        m_candidateMap = new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
+        m_candidateModules = new HashSet<Module>();
+        m_dependentMap = new HashMap<Capability, Set<Requirement>>();
+        m_candidateMap = new HashMap<Requirement, SortedSet<Capability>>();
         m_hostFragments =
-            new HashMap<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>>();
-        m_allWrappedHosts = new HashMap<BundleRevision, HostBundleRevision>();
-        m_populateResultCache = new HashMap<BundleRevision, Object>();
+            new HashMap<Capability, Map<String, Map<Version, List<Requirement>>>>();
+        m_allWrappedHosts = new HashMap<Module, HostModule>();
+        m_populateResultCache = new HashMap<Module, Object>();
 
         populate(state, m_root);
     }
@@ -123,17 +118,17 @@ class Candidates
      * @param req the requirement being resolved.
      * @param candidates the potential candidates matching the requirement.
     **/
-    public Candidates(ResolverState state, BundleRevision root,
-        BundleRequirement req, SortedSet<BundleCapability> candidates)
+    public Candidates(ResolverState state, Module root,
+        Requirement req, SortedSet<Capability> candidates)
     {
         m_root = root;
-        m_candidateRevisions = new HashSet<BundleRevision>();
-        m_dependentMap = new HashMap<BundleCapability, Set<BundleRequirement>>();
-        m_candidateMap = new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
+        m_candidateModules = new HashSet<Module>();
+        m_dependentMap = new HashMap<Capability, Set<Requirement>>();
+        m_candidateMap = new HashMap<Requirement, SortedSet<Capability>>();
         m_hostFragments =
-            new HashMap<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>>();
-        m_allWrappedHosts = new HashMap<BundleRevision, HostBundleRevision>();
-        m_populateResultCache = new HashMap<BundleRevision, Object>();
+            new HashMap<Capability, Map<String, Map<Version, List<Requirement>>>>();
+        m_allWrappedHosts = new HashMap<Module, HostModule>();
+        m_populateResultCache = new HashMap<Module, Object>();
 
         add(req, candidates);
 
@@ -143,17 +138,17 @@ class Candidates
     /**
      * Populates additional candidates for the specified module.
      * @param state the resolver state used for populating the candidates.
-     * @param revision the module whose candidates should be populated.
+     * @param module the module whose candidates should be populated.
      */
 // TODO: FELIX3 - Modify to not be recursive.
-    public final void populate(ResolverState state, BundleRevision revision)
+    public final void populate(ResolverState state, Module module)
     {
-        // Determine if we've already calculated this revision's candidates.
+        // Determine if we've already calculated this module's candidates.
         // The result cache will have one of three values:
         //   1. A resolve exception if we've already attempted to populate the
-        //      revision's candidates but were unsuccessful.
+        //      module's candidates but were unsuccessful.
         //   2. Boolean.TRUE indicating we've already attempted to populate the
-        //      revision's candidates and were successful.
+        //      module's candidates and were successful.
         //   3. An array containing the cycle count, current map of candidates
         //      for already processed requirements, and a list of remaining
         //      requirements whose candidates still need to be calculated.
@@ -163,19 +158,19 @@ class Candidates
         // until we've popped completely out of the cycle.
 
         // Keeps track of the number of times we've reentered this method
-        // for the current revision.
+        // for the current module.
         Integer cycleCount = null;
 
         // Keeps track of the candidates we've already calculated for the
-        // current revision's requirements.
-        Map<BundleRequirement, SortedSet<BundleCapability>> localCandidateMap = null;
+        // current module's requirements.
+        Map<Requirement, SortedSet<Capability>> localCandidateMap = null;
 
-        // Keeps track of the current revision's requirements for which we
+        // Keeps track of the current module's requirements for which we
         // haven't yet found candidates.
-        List<BundleRequirement> remainingReqs = null;
+        List<Requirement> remainingReqs = null;
 
-        // Get the cache value for the current revision.
-        Object cacheValue = m_populateResultCache.get(revision);
+        // Get the cache value for the current module.
+        Object cacheValue = m_populateResultCache.get(module);
 
         // This is case 1.
         if (cacheValue instanceof ResolveException)
@@ -200,75 +195,65 @@ class Candidates
             remainingReqs = (List) ((Object[]) cacheValue)[2];
         }
 
-        // If there is no cache value for the current revision, then this is
+        // If there is no cache value for the current module, then this is
         // the first time we are attempting to populate its candidates, so
         // do some one-time checks and initialization.
         if ((remainingReqs == null) && (localCandidateMap == null))
         {
             // Verify that any required execution environment is satisfied.
-            state.checkExecutionEnvironment(revision);
+            state.checkExecutionEnvironment(module);
 
             // Verify that any native libraries match the current platform.
-            state.checkNativeLibraries(revision);
+            state.checkNativeLibraries(module);
 
             // Record cycle count.
             cycleCount = new Integer(0);
 
             // Create a local map for populating candidates first, just in case
-            // the revision is not resolvable.
+            // the module is not resolvable.
             localCandidateMap = new HashMap();
 
-            // Create a modifiable list of the revision's requirements.
-            remainingReqs = new ArrayList(revision.getDeclaredRequirements(null));
+            // Create a modifiable list of the module's requirements.
+            remainingReqs = new ArrayList(module.getRequirements());
 
             // Add these value to the result cache so we know we are
             // in the middle of populating candidates for the current
-            // revision.
-            m_populateResultCache.put(revision,
+            // module.
+            m_populateResultCache.put(module,
                 cacheValue = new Object[] { cycleCount, localCandidateMap, remainingReqs });
         }
 
         // If we have requirements remaining, then find candidates for them.
         while (remainingReqs.size() > 0)
         {
-            BundleRequirement req = remainingReqs.remove(0);
-
-            // Ignore dynamic requirements.
-            String resolution = req.getDirectives().get(Constants.RESOLUTION_DIRECTIVE);
-// TODO: OSGi R4.3 - Use proper "dynamic" constant.
-            if ((resolution != null) && resolution.equals("dynamic"))
-            {
-                continue;
-            }
+            Requirement req = remainingReqs.remove(0);
 
             // Get satisfying candidates and populate their candidates if necessary.
             ResolveException rethrow = null;
-            SortedSet<BundleCapability> candidates =
-                state.getCandidates((BundleRequirementImpl) req, true);
-            for (Iterator<BundleCapability> itCandCap = candidates.iterator();
-                itCandCap.hasNext(); )
+            SortedSet<Capability> candidates = state.getCandidates(req, true);
+            for (Iterator<Capability> itCandCap = candidates.iterator(); itCandCap.hasNext(); )
             {
-                BundleCapability candCap = itCandCap.next();
+                Capability candCap = itCandCap.next();
 
-                // If the candidate revision is a fragment, then always attempt
+                // If the candidate module is a fragment, then always attempt
                 // to populate candidates for its dependency, since it must be
                 // attached to a host to be used. Otherwise, if the candidate
-                // revision is not already resolved and is not the current version
+                // module is not already resolved and is not the current module
                 // we are trying to populate, then populate the candidates for
                 // its dependencies as well.
                 // NOTE: Technically, we don't have to check to see if the
-                // candidate revision is equal to the current revision, but this
+                // candidate module is equal to the current module, but this
                 // saves us from recursing and also simplifies exceptions messages
                 // since we effectively chain exception messages for each level
                 // of recursion; thus, any avoided recursion results in fewer
                 // exceptions to chain when an error does occur.
-                if (Util.isFragment(candCap.getRevision())
-                    || ((candCap.getRevision().getWiring() == null)
-                        && !candCap.getRevision().equals(revision)))
+                if (Util.isFragment(candCap.getModule())
+                    || (!candCap.getModule().isResolved()
+                        && !candCap.getModule().equals(module)))
                 {
                     try
                     {
-                        populate(state, candCap.getRevision());
+                        populate(state, candCap.getModule());
                     }
                     catch (ResolveException ex)
                     {
@@ -286,16 +271,16 @@ class Candidates
             // If there are no candidates for the current requirement
             // and it is not optional, then create, cache, and throw
             // a resolve exception.
-            if (candidates.isEmpty() && !((BundleRequirementImpl) req).isOptional())
+            if (candidates.isEmpty() && !req.isOptional())
             {
-                String msg = "Unable to resolve " + revision
+                String msg = "Unable to resolve " + module
                     + ": missing requirement " + req;
                 if (rethrow != null)
                 {
                     msg = msg + " [caused by: " + rethrow.getMessage() + "]";
                 }
-                rethrow = new ResolveException(msg, revision, req);
-                m_populateResultCache.put(revision, rethrow);
+                rethrow = new ResolveException(msg, module, req);
+                m_populateResultCache.put(module, rethrow);
                 throw rethrow;
             }
             // If we actually have candidates for the requirement, then
@@ -314,8 +299,8 @@ class Candidates
         }
         else if (cycleCount.intValue() == 0)
         {
-            // Record that the revision was successfully populated.
-            m_populateResultCache.put(revision, Boolean.TRUE);
+            // Record that the module was successfully populated.
+            m_populateResultCache.put(module, Boolean.TRUE);
 
             // Merge local candidate map into global candidate map.
             if (localCandidateMap.size() > 0)
@@ -325,57 +310,44 @@ class Candidates
         }
     }
 
-    public final void populateOptional(ResolverState state, BundleRevision revision)
+    public final void populateOptional(ResolverState state, Module module)
     {
-        // We will always attempt to populate optional fragments, since this
-        // is necessary for greedy resolving of fragment. Howevere, we'll only
-        // attempt to populate optional non-fragment revisions if they aren't
-        // already resolved.
-        boolean isFragment = Util.isFragment(revision);
-        if (!isFragment && (revision.getWiring() != null))
-        {
-            return;
-        }
-
         try
         {
-            // If the optional revision is a fragment, then we only want to populate
+            // If the optional module is a fragment, then we only want to populate
             // the fragment if it has a candidate host in the set of already populated
-            // revisions. We do this to avoid unnecessary work in prepare(). If the
+            // modules. We do this to avoid unnecessary work in prepare(). If the
             // fragment has a host, we'll prepopulate the result cache here to avoid
             // having to do the host lookup again in populate().
+            boolean isFragment = Util.isFragment(module);
             if (isFragment)
             {
-                // Get the current result cache value, to make sure the revision
+                // Get the current result cache value, to make sure the module
                 // hasn't already been populated.
-                Object cacheValue = m_populateResultCache.get(revision);
+                Object cacheValue = m_populateResultCache.get(module);
                 if (cacheValue == null)
                 {
-                    // Create a modifiable list of the revision's requirements.
-                    List<BundleRequirement> remainingReqs =
-                        new ArrayList(revision.getDeclaredRequirements(null));
+                    // Create a modifiable list of the module's requirements.
+                    List<Requirement> remainingReqs = new ArrayList(module.getRequirements());
 
                     // Find the host requirement.
-                    BundleRequirement hostReq = null;
-                    for (Iterator<BundleRequirement> it = remainingReqs.iterator();
-                        it.hasNext(); )
+                    Requirement hostReq = null;
+                    for (Iterator<Requirement> it = remainingReqs.iterator(); it.hasNext(); )
                     {
-                        BundleRequirement r = it.next();
-                        if (r.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
+                        Requirement r = it.next();
+                        if (r.getNamespace().equals(Capability.HOST_NAMESPACE))
                         {
                             hostReq = r;
                             it.remove();
-                            break;
                         }
                     }
 
                     // Get candidates hosts and keep any that have been populated.
-                    SortedSet<BundleCapability> hosts =
-                        state.getCandidates((BundleRequirementImpl) hostReq, false);
-                    for (Iterator<BundleCapability> it = hosts.iterator(); it.hasNext(); )
+                    SortedSet<Capability> hosts = state.getCandidates(hostReq, false);
+                    for (Iterator<Capability> it = hosts.iterator(); it.hasNext(); )
                     {
-                        BundleCapability host = it.next();
-                        if (!isPopulated(host.getRevision()))
+                        Capability host = it.next();
+                        if (!isPopulated(host.getModule()))
                         {
                             it.remove();
                         }
@@ -393,65 +365,63 @@ class Candidates
                     // the work we've done so far.
                     
                     // Verify that any required execution environment is satisfied.
-                    state.checkExecutionEnvironment(revision);
+                    state.checkExecutionEnvironment(module);
 
                     // Verify that any native libraries match the current platform.
-                    state.checkNativeLibraries(revision);
+                    state.checkNativeLibraries(module);
 
                     // Record cycle count, but start at -1 since it will
                     // be incremented again in populate().
                     Integer cycleCount = new Integer(-1);
 
                     // Create a local map for populating candidates first, just in case
-                    // the revision is not resolvable.
-                    Map<BundleRequirement, SortedSet<BundleCapability>> localCandidateMap =
-                        new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
+                    // the module is not resolvable.
+                    Map<Requirement, SortedSet<Capability>> localCandidateMap = new HashMap();
 
                     // Add the discovered host candidates to the local candidate map.
                     localCandidateMap.put(hostReq, hosts);
 
                     // Add these value to the result cache so we know we are
                     // in the middle of populating candidates for the current
-                    // revision.
-                    m_populateResultCache.put(revision,
+                    // module.
+                    m_populateResultCache.put(module,
                         new Object[] { cycleCount, localCandidateMap, remainingReqs });
                 }
             }
 
-            // Try to populate candidates for the optional revision.
-            populate(state, revision);
+            // Try to populate candidates for the optional module.
+            populate(state, module);
         }
         catch (ResolveException ex)
         {
-            // Ignore since the revision is optional.
+            // Ignore since the module is optional.
         }
     }
 
-    private boolean isPopulated(BundleRevision revision)
+    private boolean isPopulated(Module module)
     {
-        Object value = m_populateResultCache.get(revision);
+        Object value = m_populateResultCache.get(module);
         return ((value != null) && (value instanceof Boolean));
     }
 
-    private void populateDynamic(ResolverState state, BundleRevision revision)
+    private void populateDynamic(ResolverState state, Module module)
     {
         // There should be one entry in the candidate map, which are the
         // the candidates for the matching dynamic requirement. Get the
         // matching candidates and populate their candidates if necessary.
         ResolveException rethrow = null;
-        Entry<BundleRequirement, SortedSet<BundleCapability>> entry =
+        Entry<Requirement, SortedSet<Capability>> entry =
             m_candidateMap.entrySet().iterator().next();
-        BundleRequirement dynReq = entry.getKey();
-        SortedSet<BundleCapability> candidates = entry.getValue();
-        for (Iterator<BundleCapability> itCandCap = candidates.iterator();
-            itCandCap.hasNext(); )
+        Requirement dynReq = entry.getKey();
+        SortedSet<Capability> candidates = entry.getValue();
+        for (Iterator<Capability> itCandCap = candidates.iterator(); itCandCap.hasNext(); )
         {
-            BundleCapability candCap = itCandCap.next();
-            if (candCap.getRevision().getWiring() == null)
+            Capability candCap = itCandCap.next();
+            if (!candCap.getModule().isResolved())
             {
                 try
                 {
-                    populate(state, candCap.getRevision());
+                    populate(state, candCap.getModule());
                 }
                 catch (ResolveException ex)
                 {
@@ -468,7 +438,7 @@ class Candidates
         {
             if (rethrow == null)
             {
-                rethrow = new ResolveException("Dynamic import failed.", revision, dynReq);
+                rethrow = new ResolveException("Dynamic import failed.", module, dynReq);
             }
             throw rethrow;
         }
@@ -483,9 +453,9 @@ class Candidates
      * @param req the requirement to add.
      * @param candidates the candidates matching the requirement.
     **/
-    private void add(BundleRequirement req, SortedSet<BundleCapability> candidates)
+    private void add(Requirement req, SortedSet<Capability> candidates)
     {
-        if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
+        if (req.getNamespace().equals(Capability.HOST_NAMESPACE))
         {
             m_fragmentsPresent = true;
         }
@@ -493,14 +463,14 @@ class Candidates
         // Record the candidates.
         m_candidateMap.put(req, candidates);
 
-        // Make a list of all candidate revisions for determining singetons.
+        // Make a list of all candidate modules for determining singetons.
         // Add the requirement as a dependent on the candidates. Keep track
         // of fragments for hosts.
-        for (BundleCapability cap : candidates)
+        for (Capability cap : candidates)
         {
-            // Remember the revision for all capabilities so we can
+            // Remember the module for all capabilities so we can
             // determine which ones are singletons.
-            m_candidateRevisions.add(cap.getRevision());
+            m_candidateModules.add(cap.getModule());
         }
     }
 
@@ -510,9 +480,9 @@ class Candidates
      * be further modified by the caller.
      * @param candidates the bulk requirements and candidates to add.
     **/
-    private void add(Map<BundleRequirement, SortedSet<BundleCapability>> candidates)
+    private void add(Map<Requirement, SortedSet<Capability>> candidates)
     {
-        for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry : candidates.entrySet())
+        for (Entry<Requirement, SortedSet<Capability>> entry : candidates.entrySet())
         {
             add(entry.getKey(), entry.getValue());
         }
@@ -525,9 +495,9 @@ class Candidates
      * @param m the module whose wrapper is desired.
      * @return the wrapper module or the module itself if it was not wrapped.
     **/
-    public BundleRevision getWrappedHost(BundleRevision m)
+    public Module getWrappedHost(Module m)
     {
-        BundleRevision wrapped = m_allWrappedHosts.get(m);
+        Module wrapped = m_allWrappedHosts.get(m);
         return (wrapped == null) ? m : wrapped;
     }
 
@@ -536,7 +506,7 @@ class Candidates
      * @param req the requirement whose candidates are desired.
      * @return the matching candidates or null.
     **/
-    public SortedSet<BundleCapability> getCandidates(BundleRequirement req)
+    public SortedSet<Capability> getCandidates(Requirement req)
     {
         return m_candidateMap.get(req);
     }
@@ -557,7 +527,7 @@ class Candidates
      * @throws ResolveException if the removal of any unselected fragments result
      *         in the root module being unable to resolve.
     **/
-    public void prepare(List<BundleRevision> existingSingletons)
+    public void prepare(List<Module> existingSingletons)
     {
         boolean init = false;
 
@@ -567,12 +537,12 @@ class Candidates
             init = true;
         }
 
-        final Map<String, BundleRevision> singletons = new HashMap<String, BundleRevision>();
+        final Map<String, Module> singletons = new HashMap<String, Module>();
 
-        for (Iterator<BundleRevision> it = m_candidateRevisions.iterator(); it.hasNext(); )
+        for (Iterator<Module> it = m_candidateModules.iterator(); it.hasNext(); )
         {
-            BundleRevision br = it.next();
-            if (isSingleton(br))
+            Module m = it.next();
+            if (isSingleton(m))
             {
                 if (!init)
                 {
@@ -581,28 +551,28 @@ class Candidates
                 }
 
                 // See if there is an existing singleton for the
-                // revision's symbolic name.
-                BundleRevision singleton = singletons.get(br.getSymbolicName());
-                // If there is no existing singleton or this revision is
-                // a resolved singleton or this revision has a higher version
+                // module's symbolic name.
+                Module singleton = singletons.get(m.getSymbolicName());
+                // If there is no existing singleton or this module is
+                // a resolved singleton or this module has a higher version
                 // and the existing singleton is not resolved, then select
-                // this revision as the singleton.
+                // this module as the singleton.
                 if ((singleton == null)
-                    || (br.getWiring() != null)
-                    || ((br.getVersion().compareTo(singleton.getVersion()) > 0)
-                        && (singleton.getWiring() == null)))
+                    || m.isResolved()
+                    || ((m.getVersion().compareTo(singleton.getVersion()) > 0)
+                        && !singleton.isResolved()))
                 {
-                    singletons.put(br.getSymbolicName(), br);
-                    // Remove the singleton revision from the candidates
+                    singletons.put(m.getSymbolicName(), m);
+                    // Remove the singleton module from the candidates
                     // if it wasn't selected.
                     if (singleton != null)
                     {
-                        removeRevision(singleton);
+                        removeModule(singleton);
                     }
                 }
                 else
                 {
-                    removeRevision(br);
+                    removeModule(m);
                 }
             }
         }
@@ -610,11 +580,11 @@ class Candidates
         // If the root is a singleton, then prefer it over any other singleton.
         if (isSingleton(m_root))
         {
-            BundleRevision singleton = singletons.get(m_root.getSymbolicName());
+            Module singleton = singletons.get(m_root.getSymbolicName());
             singletons.put(m_root.getSymbolicName(), m_root);
             if ((singleton != null) && !singleton.equals(m_root))
             {
-                if (singleton.getWiring() != null)
+                if (singleton.isResolved())
                 {
                     throw new ResolveException(
                         "Cannot resolve singleton "
@@ -624,7 +594,7 @@ class Candidates
                         + " singleton is already resolved.",
                         m_root, null);
                 }
-                removeRevision(singleton);
+                removeModule(singleton);
             }
         }
 
@@ -632,12 +602,12 @@ class Candidates
         // singletons passed into this method.
         for (int i = 0; (existingSingletons != null) && (i < existingSingletons.size()); i++)
         {
-            BundleRevision existing = existingSingletons.get(i);
-            BundleRevision singleton = singletons.get(existing.getSymbolicName());
+            Module existing = existingSingletons.get(i);
+            Module singleton = singletons.get(existing.getSymbolicName());
             if ((singleton != null) && (singleton != existing))
             {
                 singletons.remove(singleton.getSymbolicName());
-                removeRevision(singleton);
+                removeModule(singleton);
             }
         }
 
@@ -645,9 +615,9 @@ class Candidates
         // 1. Select the fragments to attach to a given host.
         // 2. Wrap hosts and attach fragments.
         // 3. Remove any unselected fragments. This is necessary because
-        //    other revisions may depend on the capabilities of unselected
+        //    other modules may depend on the capabilities of unselected
         //    fragments, so we need to remove the unselected fragments and
-        //    any revisions that depends on them, which could ultimately cause
+        //    any modules that depends on them, which could ultimately cause
         //    the entire resolve to fail.
         // 4. Replace all fragments with any host it was merged into
         //    (effectively multiplying it).
@@ -656,31 +626,28 @@ class Candidates
         //      with host's attached fragment capabilities.
 
         // Steps 1 and 2
-        List<HostBundleRevision> hostRevisions = new ArrayList<HostBundleRevision>();
-        List<BundleRevision> unselectedFragments = new ArrayList<BundleRevision>();
-        for (Entry<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>>
-            hostEntry : m_hostFragments.entrySet())
+        List<HostModule> wrappedHosts = new ArrayList<HostModule>();
+        List<Module> unselectedFragments = new ArrayList<Module>();
+        for (Entry<Capability, Map<String, Map<Version, List<Requirement>>>> hostEntry :
+            m_hostFragments.entrySet())
         {
             // Step 1
-            BundleCapability hostCap = hostEntry.getKey();
-            Map<String, Map<Version, List<BundleRequirement>>> fragments
-                = hostEntry.getValue();
-            List<BundleRevision> selectedFragments = new ArrayList<BundleRevision>();
-            for (Entry<String, Map<Version, List<BundleRequirement>>> fragEntry
-                : fragments.entrySet())
+            Capability hostCap = hostEntry.getKey();
+            Map<String, Map<Version, List<Requirement>>> fragments = hostEntry.getValue();
+            List<Module> selectedFragments = new ArrayList<Module>();
+            for (Entry<String, Map<Version, List<Requirement>>> fragEntry : fragments.entrySet())
             {
                 boolean isFirst = true;
-                for (Entry<Version, List<BundleRequirement>> versionEntry
+                for (Entry<Version, List<Requirement>> versionEntry
                     : fragEntry.getValue().entrySet())
                 {
-                    for (BundleRequirement hostReq : versionEntry.getValue())
+                    for (Requirement hostReq : versionEntry.getValue())
                     {
                         // Select the highest version of the fragment that
                         // is not removal pending.
-                        if (isFirst
-                            && !((BundleRevisionImpl) hostReq.getRevision()).isRemovalPending())
+                        if (isFirst && !hostReq.getModule().isRemovalPending())
                         {
-                            selectedFragments.add(hostReq.getRevision());
+                            selectedFragments.add(hostReq.getModule());
                             isFirst = false;
                         }
                         // For any fragment that wasn't selected, remove the
@@ -691,11 +658,11 @@ class Candidates
                         else
                         {
                             m_dependentMap.get(hostCap).remove(hostReq);
-                            SortedSet<BundleCapability> hosts = m_candidateMap.get(hostReq);
+                            SortedSet<Capability> hosts = m_candidateMap.get(hostReq);
                             hosts.remove(hostCap);
                             if (hosts.isEmpty())
                             {
-                                unselectedFragments.add(hostReq.getRevision());
+                                unselectedFragments.add(hostReq.getModule());
                             }
                         }
                     }
@@ -703,48 +670,47 @@ class Candidates
             }
 
             // Step 2
-            HostBundleRevision wrappedHost =
-                new HostBundleRevision(hostCap.getRevision(), selectedFragments);
-            hostRevisions.add(wrappedHost);
-            m_allWrappedHosts.put(hostCap.getRevision(), wrappedHost);
+            HostModule wrappedHost = new HostModule(hostCap.getModule(), selectedFragments);
+            wrappedHosts.add(wrappedHost);
+            m_allWrappedHosts.put(hostCap.getModule(), wrappedHost);
         }
 
         // Step 3
-        for (BundleRevision br : unselectedFragments)
+        for (Module m : unselectedFragments)
         {
-            removeRevision(br);
+            removeModule(m);
         }
 
         // Step 4
-        for (HostBundleRevision hostRevision : hostRevisions)
+        for (HostModule wrappedHost : wrappedHosts)
         {
             // Replaces capabilities from fragments with the capabilities
             // from the merged host.
-            for (BundleCapability c : hostRevision.getDeclaredCapabilities(null))
+            for (Capability c : wrappedHost.getCapabilities())
             {
-                Set<BundleRequirement> dependents =
+                Set<Requirement> dependents =
                     m_dependentMap.get(((HostedCapability) c).getDeclaredCapability());
                 if (dependents != null)
                 {
-                    for (BundleRequirement r : dependents)
+                    for (Requirement r : dependents)
                     {
-                        Set<BundleCapability> cands = m_candidateMap.get(r);
+                        Set<Capability> cands = m_candidateMap.get(r);
                         cands.remove(((HostedCapability) c).getDeclaredCapability());
                         cands.add(c);
                     }
                 }
             }
 
-            // Copy candidates for fragment requirements to the host.
+            // Copies candidates for fragment requirements to the host.
             // This doesn't record the reverse dependency, but that
             // information should not be needed at this point anymore.
-            for (BundleRequirement r : hostRevision.getDeclaredRequirements(null))
+            for (Requirement r : wrappedHost.getRequirements())
             {
-                SortedSet<BundleCapability> cands =
+                SortedSet<Capability> cands =
                     m_candidateMap.get(((HostedRequirement) r).getDeclaredRequirement());
                 if (cands != null)
                 {
-                    m_candidateMap.put(r, new TreeSet<BundleCapability>(cands));
+                    m_candidateMap.put(r, new TreeSet<Capability>(cands));
                 }
             }
         }
@@ -752,45 +718,44 @@ class Candidates
 
     private void populateDependents()
     {
-        for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry
-            : m_candidateMap.entrySet())
+        for (Entry<Requirement, SortedSet<Capability>> entry : m_candidateMap.entrySet())
         {
-            BundleRequirement req = entry.getKey();
-            SortedSet<BundleCapability> caps = entry.getValue();
-            for (BundleCapability cap : caps)
+            Requirement req = entry.getKey();
+            SortedSet<Capability> caps = entry.getValue();
+            for (Capability cap : caps)
             {
                 // Record the requirement as dependent on the capability.
-                Set<BundleRequirement> dependents = m_dependentMap.get(cap);
+                Set<Requirement> dependents = m_dependentMap.get(cap);
                 if (dependents == null)
                 {
-                    dependents = new HashSet<BundleRequirement>();
+                    dependents = new HashSet<Requirement>();
                     m_dependentMap.put(cap, dependents);
                 }
                 dependents.add(req);
 
                 // Keep track of hosts and associated fragments.
-                if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
+                if (req.getNamespace().equals(Capability.HOST_NAMESPACE))
                 {
-                    Map<String, Map<Version, List<BundleRequirement>>>
+                    Map<String, Map<Version, List<Requirement>>>
                         fragments = m_hostFragments.get(cap);
                     if (fragments == null)
                     {
-                        fragments = new HashMap<String, Map<Version, List<BundleRequirement>>>();
+                        fragments = new HashMap<String, Map<Version, List<Requirement>>>();
                         m_hostFragments.put(cap, fragments);
                     }
-                    Map<Version, List<BundleRequirement>> fragmentVersions =
-                        fragments.get(req.getRevision().getSymbolicName());
+                    Map<Version, List<Requirement>> fragmentVersions =
+                        fragments.get(req.getModule().getSymbolicName());
                     if (fragmentVersions == null)
                     {
                         fragmentVersions =
-                            new TreeMap<Version, List<BundleRequirement>>(Collections.reverseOrder());
-                        fragments.put(req.getRevision().getSymbolicName(), fragmentVersions);
+                            new TreeMap<Version, List<Requirement>>(Collections.reverseOrder());
+                        fragments.put(req.getModule().getSymbolicName(), fragmentVersions);
                     }
-                    List<BundleRequirement> actual = fragmentVersions.get(req.getRevision().getVersion());
+                    List<Requirement> actual = fragmentVersions.get(req.getModule().getVersion());
                     if (actual == null)
                     {
-                        actual = new ArrayList<BundleRequirement>();
-                        fragmentVersions.put(req.getRevision().getVersion(), actual);
+                        actual = new ArrayList<Requirement>();
+                        fragmentVersions.put(req.getModule().getVersion(), actual);
                     }
                     actual.add(req);
                 }
@@ -803,26 +768,26 @@ class Candidates
      * as a fragment or a singleton. This process may cause other modules to
      * become unresolved if they depended on the module's capabilities and there
      * is no other candidate.
-     * @param revision the module to remove.
+     * @param module the module to remove.
      * @throws ResolveException if removing the module caused the resolve to fail.
     **/
-    private void removeRevision(BundleRevision revision) throws ResolveException
+    private void removeModule(Module module) throws ResolveException
     {
-        if (m_root.equals(revision))
+        if (m_root.equals(module))
         {
 // TODO: SINGLETON RESOLVER - Improve this message.
             String msg = "Unable to resolve " + m_root;
             ResolveException ex = new ResolveException(msg, m_root, null);
             throw ex;
         }
-        Set<BundleRevision> unresolvedRevisions = new HashSet<BundleRevision>();
-        remove(revision, unresolvedRevisions);
-        while (!unresolvedRevisions.isEmpty())
+        Set<Module> unresolvedModules = new HashSet<Module>();
+        remove(module, unresolvedModules);
+        while (!unresolvedModules.isEmpty())
         {
-            Iterator<BundleRevision> it = unresolvedRevisions.iterator();
-            revision = it.next();
+            Iterator<Module> it = unresolvedModules.iterator();
+            module = it.next();
             it.remove();
-            remove(revision, unresolvedRevisions);
+            remove(module, unresolvedModules);
         }
     }
 
@@ -830,23 +795,22 @@ class Candidates
      * Removes the specified module from the internal data structures, which
      * involves removing its requirements and its capabilities. This may cause
      * other modules to become unresolved as a result.
-     * @param br the module to remove.
-     * @param unresolvedRevisions a list to containing any additional modules that
+     * @param m the module to remove.
+     * @param unresolvedModules a list to containing any additional modules that
      *        that became unresolved as a result of removing this module and will
      *        also need to be removed.
      * @throws ResolveException if removing the module caused the resolve to fail.
     **/
-    private void remove(BundleRevision br, Set<BundleRevision> unresolvedRevisions)
-        throws ResolveException
+    private void remove(Module m, Set<Module> unresolvedModules) throws ResolveException
     {
-        for (BundleRequirement r : br.getDeclaredRequirements(null))
+        for (Requirement r : m.getRequirements())
         {
             remove(r);
         }
 
-        for (BundleCapability c : br.getDeclaredCapabilities(null))
+        for (Capability c : m.getCapabilities())
         {
-            remove(c, unresolvedRevisions);
+            remove(c, unresolvedModules);
         }
     }
 
@@ -854,16 +818,16 @@ class Candidates
      * Removes a requirement from the internal data structures.
      * @param req the requirement to remove.
     **/
-    private void remove(BundleRequirement req)
+    private void remove(Requirement req)
     {
-        boolean isFragment = req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE);
+        boolean isFragment = req.getNamespace().equals(Capability.HOST_NAMESPACE);
 
-        SortedSet<BundleCapability> candidates = m_candidateMap.remove(req);
+        SortedSet<Capability> candidates = m_candidateMap.remove(req);
         if (candidates != null)
         {
-            for (BundleCapability cap : candidates)
+            for (Capability cap : candidates)
             {
-                Set<BundleRequirement> dependents = m_dependentMap.get(cap);
+                Set<Requirement> dependents = m_dependentMap.get(cap);
                 if (dependents != null)
                 {
                     dependents.remove(req);
@@ -871,25 +835,25 @@ class Candidates
 
                 if (isFragment)
                 {
-                    Map<String, Map<Version, List<BundleRequirement>>>
+                    Map<String, Map<Version, List<Requirement>>>
                         fragments = m_hostFragments.get(cap);
                     if (fragments != null)
                     {
-                        Map<Version, List<BundleRequirement>> fragmentVersions =
-                            fragments.get(req.getRevision().getSymbolicName());
+                        Map<Version, List<Requirement>> fragmentVersions =
+                            fragments.get(req.getModule().getSymbolicName());
                         if (fragmentVersions != null)
                         {
-                            List<BundleRequirement> actual =
-                                fragmentVersions.get(req.getRevision().getVersion());
+                            List<Requirement> actual =
+                                fragmentVersions.get(req.getModule().getVersion());
                             if (actual != null)
                             {
                                 actual.remove(req);
                                 if (actual.isEmpty())
                                 {
-                                    fragmentVersions.remove(req.getRevision().getVersion());
+                                    fragmentVersions.remove(req.getModule().getVersion());
                                     if (fragmentVersions.isEmpty())
                                     {
-                                        fragments.remove(req.getRevision().getSymbolicName());
+                                        fragments.remove(req.getModule().getSymbolicName());
                                         if (fragments.isEmpty())
                                         {
                                             m_hostFragments.remove(cap);
@@ -908,34 +872,33 @@ class Candidates
      * Removes a capability from the internal data structures. This may cause
      * other modules to become unresolved as a result.
      * @param c the capability to remove.
-     * @param unresolvedRevisions a list to containing any additional modules that
+     * @param unresolvedModules a list to containing any additional modules that
      *        that became unresolved as a result of removing this module and will
      *        also need to be removed.
      * @throws ResolveException if removing the module caused the resolve to fail.
     **/
-    private void remove(BundleCapability c, Set<BundleRevision> unresolvedRevisions)
-        throws ResolveException
+    private void remove(Capability c, Set<Module> unresolvedModules) throws ResolveException
     {
-        Set<BundleRequirement> dependents = m_dependentMap.remove(c);
+        Set<Requirement> dependents = m_dependentMap.remove(c);
         if (dependents != null)
         {
-            for (BundleRequirement r : dependents)
+            for (Requirement r : dependents)
             {
-                SortedSet<BundleCapability> candidates = m_candidateMap.get(r);
+                SortedSet<Capability> candidates = m_candidateMap.get(r);
                 candidates.remove(c);
                 if (candidates.isEmpty())
                 {
                     m_candidateMap.remove(r);
-                    if (!((BundleRequirementImpl) r).isOptional())
+                    if (!r.isOptional())
                     {
-                        if (m_root.equals(r.getRevision()))
+                        if (m_root.equals(r.getModule()))
                         {
                             String msg = "Unable to resolve " + m_root
                                 + ": missing requirement " + r;
                             ResolveException ex = new ResolveException(msg, m_root, r);
                             throw ex;
                         }
-                        unresolvedRevisions.add(r.getRevision());
+                        unresolvedModules.add(r.getModule());
                     }
                 }
             }
@@ -949,65 +912,54 @@ class Candidates
     **/
     public Candidates copy()
     {
-        Map<BundleCapability, Set<BundleRequirement>> dependentMap =
-            new HashMap<BundleCapability, Set<BundleRequirement>>();
-        for (Entry<BundleCapability, Set<BundleRequirement>> entry : m_dependentMap.entrySet())
+        Map<Capability, Set<Requirement>> dependentMap =
+            new HashMap<Capability, Set<Requirement>>();
+        for (Entry<Capability, Set<Requirement>> entry : m_dependentMap.entrySet())
         {
-            Set<BundleRequirement> dependents = new HashSet<BundleRequirement>(entry.getValue());
+            Set<Requirement> dependents = new HashSet<Requirement>(entry.getValue());
             dependentMap.put(entry.getKey(), dependents);
         }
 
-        Map<BundleRequirement, SortedSet<BundleCapability>> candidateMap =
-            new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
-        for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry
-            : m_candidateMap.entrySet())
+        Map<Requirement, SortedSet<Capability>> candidateMap =
+            new HashMap<Requirement, SortedSet<Capability>>();
+        for (Entry<Requirement, SortedSet<Capability>> entry : m_candidateMap.entrySet())
         {
-            SortedSet<BundleCapability> candidates =
-                new TreeSet<BundleCapability>(entry.getValue());
+            SortedSet<Capability> candidates = new TreeSet<Capability>(entry.getValue());
             candidateMap.put(entry.getKey(), candidates);
         }
 
         return new Candidates(
-            m_root, m_candidateRevisions, dependentMap, candidateMap,
+            m_root, m_candidateModules, dependentMap, candidateMap,
             m_hostFragments, m_allWrappedHosts, m_populateResultCache,
             m_fragmentsPresent);
     }
 
     public void dump()
     {
-        // Create set of all revisions from requirements.
-        Set<BundleRevision> revisions = new HashSet<BundleRevision>();
-        for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry
+        // Create set of all modules from requirements.
+        Set<Module> modules = new HashSet();
+        for (Entry<Requirement, SortedSet<Capability>> entry
             : m_candidateMap.entrySet())
         {
-            revisions.add(entry.getKey().getRevision());
+            modules.add(entry.getKey().getModule());
         }
-        // Now dump the revisions.
+        // Now dump the modules.
         System.out.println("=== BEGIN CANDIDATE MAP ===");
-        for (BundleRevision br : revisions)
+        for (Module module : modules)
         {
-            System.out.println("  " + br
-                 + " (" + ((br.getWiring() != null) ? "RESOLVED)" : "UNRESOLVED)"));
-            List<BundleRequirement> reqs = (br.getWiring() != null)
-                ? br.getWiring().getRequirements(null)
-                : br.getDeclaredRequirements(null);
-            for (BundleRequirement req : reqs)
+            System.out.println("  " + module
+                 + " (" + (module.isResolved() ? "RESOLVED)" : "UNRESOLVED)"));
+            for (Requirement req : module.getRequirements())
             {
-                Set<BundleCapability> candidates = m_candidateMap.get(req);
+                Set<Capability> candidates = m_candidateMap.get(req);
                 if ((candidates != null) && (candidates.size() > 0))
                 {
                     System.out.println("    " + req + ": " + candidates);
                 }
             }
-// TODO: OSGi R4.3 - Need to check what getWiring().getRequirements() returns
-//       with respect to dynamic imports; is it the union of all declared
-//       dynamic imports from fragments and host?
-            reqs = (br.getWiring() != null)
-                ? Util.getDynamicRequirements(br.getWiring().getRequirements(null))
-                : Util.getDynamicRequirements(br.getDeclaredRequirements(null));
-            for (BundleRequirement req : reqs)
+            for (Requirement req : module.getDynamicRequirements())
             {
-                Set<BundleCapability> candidates = m_candidateMap.get(req);
+                Set<Capability> candidates = m_candidateMap.get(req);
                 if ((candidates != null) && (candidates.size() > 0))
                 {
                     System.out.println("    " + req + ": " + candidates);
@@ -1021,22 +973,26 @@ class Candidates
      * Returns true if the specified module is a singleton
      * (i.e., directive singleton:=true).
      *
-     * @param revision the module to check for singleton status.
+     * @param module the module to check for singleton status.
      * @return true if the module is a singleton, false otherwise.
     **/
-    private static boolean isSingleton(BundleRevision revision)
+    private static boolean isSingleton(Module module)
     {
-        final List<BundleCapability> modCaps =
+        final List<Capability> modCaps =
             Util.getCapabilityByNamespace(
-                revision, BundleCapabilityImpl.BUNDLE_NAMESPACE);
+                module, Capability.MODULE_NAMESPACE);
         if (modCaps == null || modCaps.isEmpty())
         {
             return false;
         }
-        String value = modCaps.get(0).getDirectives().get(Constants.SINGLETON_DIRECTIVE);
-        if (value != null)
+        final List<Directive> dirs = modCaps.get(0).getDirectives();
+        for (int dirIdx = 0; (dirs != null) && (dirIdx < dirs.size()); dirIdx++)
         {
-            return Boolean.valueOf(value);
+            if (dirs.get(dirIdx).getName().equalsIgnoreCase(Constants.SINGLETON_DIRECTIVE)
+                && Boolean.valueOf((String) dirs.get(dirIdx).getValue()))
+            {
+                return true;
+            }
         }
         return false;
     }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java?rev=1103918&r1=1103917&r2=1103918&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java Mon May 16 21:49:02 2011
@@ -19,20 +19,18 @@
 package org.apache.felix.framework.resolver;
 
 import java.util.List;
-import java.util.Map;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRevision;
+import org.apache.felix.framework.capabilityset.Attribute;
+import org.apache.felix.framework.capabilityset.Capability;
+import org.apache.felix.framework.capabilityset.Directive;
 
-public class HostedCapability extends BundleCapabilityImpl
+public class HostedCapability implements Capability
 {
-    private final BundleRevision m_host;
-    private final BundleCapabilityImpl m_cap;
+    private final Module m_host;
+    private final Capability m_cap;
 
-    public HostedCapability(BundleRevision host, BundleCapabilityImpl cap)
+    public HostedCapability(Module module, Capability cap)
     {
-        super(host, cap.getNamespace(), cap.getDirectives(), cap.getAttributes());
-        m_host = host;
+        m_host = module;
         m_cap = cap;
     }
 
@@ -68,36 +66,41 @@ public class HostedCapability extends Bu
         return hash;
     }
 
-    public BundleCapabilityImpl getDeclaredCapability()
+    public Capability getDeclaredCapability()
     {
         return m_cap;
     }
 
-    @Override
-    public BundleRevision getRevision()
+    public Module getModule()
     {
         return m_host;
     }
 
-    @Override
     public String getNamespace()
     {
         return m_cap.getNamespace();
     }
 
-    @Override
-    public Map<String, String> getDirectives()
+    public Directive getDirective(String name)
+    {
+        return m_cap.getDirective(name);
+    }
+
+    public List<Directive> getDirectives()
     {
         return m_cap.getDirectives();
     }
 
-    @Override
-    public Map<String, Object> getAttributes()
+    public Attribute getAttribute(String name)
+    {
+        return m_cap.getAttribute(name);
+    }
+
+    public List<Attribute> getAttributes()
     {
         return m_cap.getAttributes();
     }
 
-    @Override
     public List<String> getUses()
     {
         return m_cap.getUses();
@@ -110,10 +113,10 @@ public class HostedCapability extends Bu
         {
             return getAttributes().toString();
         }
-        if (getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+        if (getNamespace().equals(Capability.PACKAGE_NAMESPACE))
         {
             return "[" + m_host + "] "
-                + getNamespace() + "; " + getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR);
+                + getNamespace() + "; " + getAttribute(Capability.PACKAGE_ATTR);
         }
         return "[" + m_host + "] " + getNamespace() + "; " + getAttributes();
     }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java?rev=1103918&r1=1103917&r2=1103918&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java Mon May 16 21:49:02 2011
@@ -18,20 +18,19 @@
  */
 package org.apache.felix.framework.resolver;
 
-import java.util.Map;
+import java.util.List;
+import org.apache.felix.framework.capabilityset.Directive;
+import org.apache.felix.framework.capabilityset.Requirement;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
-import org.osgi.framework.wiring.BundleRevision;
 
-public class HostedRequirement extends BundleRequirementImpl
+public class HostedRequirement implements Requirement
 {
-    private final BundleRevision m_host;
-    private final BundleRequirementImpl m_req;
+    private final Module m_host;
+    private final Requirement m_req;
 
-    public HostedRequirement(BundleRevision host, BundleRequirementImpl req)
+    public HostedRequirement(Module module, Requirement req)
     {
-        super(host, req.getNamespace(), req.getDirectives(), req.getAttributes());
-        m_host = host;
+        m_host = module;
         m_req = req;
     }
 
@@ -67,48 +66,41 @@ public class HostedRequirement extends B
         return hash;
     }
 
-    public BundleRequirementImpl getDeclaredRequirement()
+    public Requirement getDeclaredRequirement()
     {
         return m_req;
     }
 
-    @Override
-    public BundleRevision getRevision()
+    public Module getModule()
     {
         return m_host;
     }
 
-    @Override
     public String getNamespace()
     {
         return m_req.getNamespace();
     }
 
-    @Override
     public SimpleFilter getFilter()
     {
         return m_req.getFilter();
     }
 
-    @Override
     public boolean isOptional()
     {
         return m_req.isOptional();
     }
 
-    @Override
-    public Map<String, String> getDirectives()
+    public Directive getDirective(String name)
     {
-        return m_req.getDirectives();
+        return m_req.getDirective(name);
     }
 
-    @Override
-    public Map<String, Object> getAttributes()
+    public List<Directive> getDirectives()
     {
-        return m_req.getAttributes();
+        return m_req.getDirectives();
     }
 
-    @Override
     public String toString()
     {
         return "[" + m_host + "] " + getNamespace() + "; " + getFilter().toString();

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java?rev=1103918&r1=1103917&r2=1103918&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java Mon May 16 21:49:02 2011
@@ -18,31 +18,30 @@
  */
 package org.apache.felix.framework.resolver;
 
-import org.osgi.framework.wiring.BundleRequirement;
-import org.osgi.framework.wiring.BundleRevision;
+import org.apache.felix.framework.capabilityset.Requirement;
 
 public class ResolveException extends RuntimeException
 {
-    private final BundleRevision m_revision;
-    private final BundleRequirement m_req;
+    private final Module m_module;
+    private final Requirement m_req;
 
     /**
      * Constructs an instance of <code>ResolveException</code> with the specified detail message.
      * @param msg the detail message.
      */
-    public ResolveException(String msg, BundleRevision revision, BundleRequirement req)
+    public ResolveException(String msg, Module module, Requirement req)
     {
         super(msg);
-        m_revision = revision;
+        m_module = module;
         m_req = req;
     }
 
-    public BundleRevision getRevision()
+    public Module getModule()
     {
-        return m_revision;
+        return m_module;
     }
 
-    public BundleRequirement getRequirement()
+    public Requirement getRequirement()
     {
         return m_req;
     }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java?rev=1103918&r1=1103917&r2=1103918&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java Mon May 16 21:49:02 2011
@@ -22,23 +22,19 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRevision;
+import org.apache.felix.framework.capabilityset.Capability;
+import org.apache.felix.framework.capabilityset.Requirement;
 
 public interface Resolver
 {
-    Map<BundleRevision, List<ResolverWire>> resolve(
-        ResolverState state, BundleRevision revision, Set<BundleRevision> optional);
-    Map<BundleRevision, List<ResolverWire>> resolve(
-        ResolverState state, BundleRevision revision, String pkgName,
-        Set<BundleRevision> fragments);
+    Map<Module, List<Wire>> resolve(ResolverState state, Module module, Set<Module> fragments);
+    Map<Module, List<Wire>> resolve(
+        ResolverState state, Module module, String pkgName, Set<Module> fragments);
 
     public static interface ResolverState
     {
-        SortedSet<BundleCapability> getCandidates(
-            BundleRequirementImpl req, boolean obeyMandatory);
-        void checkExecutionEnvironment(BundleRevision revision) throws ResolveException;
-        void checkNativeLibraries(BundleRevision revision) throws ResolveException;
+        SortedSet<Capability> getCandidates(Requirement req, boolean obeyMandatory);
+        void checkExecutionEnvironment(Module module) throws ResolveException;
+        void checkNativeLibraries(Module module) throws ResolveException;
     }
 }
\ No newline at end of file