Replace internal Module abstraction with BundleRevision.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1102805 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 1c6e6f5..9e01017 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -18,6 +18,7 @@
*/
package org.apache.felix.framework;
+import com.sun.xml.internal.ws.api.server.Module;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -25,12 +26,12 @@
import java.util.*;
import org.apache.felix.framework.cache.BundleArchive;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.ext.SecurityProvider;
-import org.apache.felix.framework.resolver.Wire;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.framework.util.Util;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.*;
+import org.osgi.framework.wiring.BundleRevision;
class BundleImpl implements Bundle
{
@@ -38,7 +39,7 @@
private final Felix __m_felix;
private final BundleArchive m_archive;
- private final List<Module> m_modules = new ArrayList<Module>(0);
+ private final List<BundleRevision> m_revisions = new ArrayList<BundleRevision>(0);
private volatile int m_state;
private boolean m_useDeclaredActivationPolicy;
private BundleActivator m_activator = null;
@@ -78,8 +79,8 @@
m_activator = null;
m_context = null;
- Module module = createModule();
- addModule(module);
+ BundleRevision revision = createRevision();
+ addRevision(revision);
}
// This method exists because the system bundle extends BundleImpl
@@ -98,7 +99,7 @@
synchronized void close()
{
- closeModules();
+ closeRevisions();
try
{
m_archive.close();
@@ -116,38 +117,38 @@
{
// Mark the bundle as stale, since it is being deleted.
m_stale = true;
- // Close all modules.
- closeModules();
+ // Close all revisions.
+ closeRevisions();
// Delete bundle archive, which will close revisions.
m_archive.closeAndDelete();
}
- private void closeModules()
+ private void closeRevisions()
{
- // Remove the bundle's associated modules from the resolver state
+ // Remove the bundle's associated revisions from the resolver state
// and close them.
- for (Module m : m_modules)
+ for (BundleRevision br : m_revisions)
{
- // Remove the module from the resolver state.
- getFramework().getResolver().removeModule(m);
+ // Remove the revision from the resolver state.
+ getFramework().getResolver().removeRevision(br);
- // Set fragments to null, which will remove the module from all
- // of its dependent fragment modules.
+ // Set fragments to null, which will remove the revision from all
+ // of its dependent fragment revisions.
try
{
- ((ModuleImpl) m).attachFragments(null);
+ ((BundleRevisionImpl) br).attachFragments(null);
}
catch (Exception ex)
{
getFramework().getLogger().log(
- m.getBundle(), Logger.LOG_ERROR, "Error detaching fragments.", ex);
+ br.getBundle(), Logger.LOG_ERROR, "Error detaching fragments.", ex);
}
- // Set wires to null, which will remove the module from all
- // of its dependent modules.
- ((ModuleImpl) m).setWires(null);
+ // Set wires to null, which will remove the revision from all
+ // of its dependent revisions.
+ ((BundleRevisionImpl) br).setWires(null);
- // Close the module's content.
- ((ModuleImpl) m).close();
+ // Close the revision's content.
+ ((BundleRevisionImpl) br).close();
}
}
@@ -160,17 +161,17 @@
}
else
{
- // Dispose of the current modules.
- closeModules();
+ // Dispose of the current revisions.
+ closeRevisions();
// Now we will purge all old revisions, only keeping the newest one.
m_archive.purge();
// Lastly, we want to reset our bundle be reinitializing our state
- // and recreating a module for the newest revision.
- m_modules.clear();
- final Module module = createModule();
- addModule(module);
+ // and recreating a revision object for the newest revision.
+ m_revisions.clear();
+ final BundleRevision br = createRevision();
+ addRevision(br);
m_state = Bundle.INSTALLED;
m_stale = false;
m_cachedHeaders.clear();
@@ -323,7 +324,8 @@
// Spec says empty local returns raw headers.
if (locale.length() == 0)
{
- result = new StringMap(getCurrentModule().getHeaders(), false);
+ result = new StringMap(
+ ((BundleRevisionImpl) getCurrentRevision()).getHeaders(), false);
}
// If we have no result, try to get it from the cached headers.
@@ -359,7 +361,8 @@
if (result == null)
{
// Get a modifiable copy of the raw headers.
- Map headers = new StringMap(getCurrentModule().getHeaders(), false);
+ Map headers = new StringMap(
+ ((BundleRevisionImpl) getCurrentRevision()).getHeaders(), false);
// Assume for now that this will be the result.
result = headers;
@@ -388,23 +391,22 @@
basename = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
}
- // Create ordered list of modules to search for localization
+ // Create ordered list of revisions to search for localization
// property resources.
- List moduleList = createLocalizationModuleList(
- (ModuleImpl) getCurrentModule());
+ List<BundleRevision> revisionList = createLocalizationRevisionList(
+ (BundleRevisionImpl) getCurrentRevision());
// Create ordered list of files to load properties from
- List resourceList = createLocalizationResourceList(basename, locale);
+ List<String> resourceList = createLocalizationResourceList(basename, locale);
// Create a merged props file with all available props for this locale
boolean found = false;
Properties mergedProperties = new Properties();
- for (int modIdx = 0; modIdx < moduleList.size(); modIdx++)
+ for (BundleRevision br : revisionList)
{
- for (Iterator it = resourceList.iterator(); it.hasNext(); )
+ for (String res : resourceList)
{
- URL temp = ((Module) moduleList.get(modIdx)).getEntry(
- it.next() + ".properties");
+ URL temp = ((BundleRevisionImpl) br).getEntry(res + ".properties");
if (temp != null)
{
found = true;
@@ -466,36 +468,38 @@
}
}
- private static List createLocalizationModuleList(ModuleImpl module)
+ private static List<BundleRevision> createLocalizationRevisionList(
+ BundleRevisionImpl bri)
{
- // If the module is a fragment, then we actually need
+ // If the revision is a fragment, then we actually need
// to search its host and associated fragments for its
// localization information. So, check to see if there
// are any hosts and then use the one with the highest
// version instead of the fragment itself. If there are
- // no hosts, but the module is a fragment, then just
- // search the module itself.
- if (Util.isFragment(module))
+ // no hosts, but the revision is a fragment, then just
+ // search the revision itself.
+ if (Util.isFragment(bri))
{
- List<Wire> hostWires = module.getWires();
+ List<FelixBundleWire> hostWires = bri.getWires();
if ((hostWires != null) && (hostWires.size() > 0))
{
- module = (ModuleImpl) hostWires.get(0).getExporter();
+ bri = (BundleRevisionImpl) hostWires.get(0).getProviderWiring().getRevision();
for (int hostIdx = 1; hostIdx < hostWires.size(); hostIdx++)
{
- if (module.getVersion().compareTo(
- hostWires.get(hostIdx).getExporter().getVersion()) < 0)
+ if (bri.getVersion().compareTo(
+ hostWires.get(hostIdx).getProviderWiring().getRevision().getVersion()) < 0)
{
- module = (ModuleImpl) hostWires.get(hostIdx).getExporter();
+ bri = (BundleRevisionImpl)
+ hostWires.get(hostIdx).getProviderWiring().getRevision();
}
}
}
}
- // Create a list of the module and any attached fragments.
- List result = new ArrayList();
- result.add(module);
- List<Module> fragments = module.getFragments();
+ // Create a list of the revision and any attached fragment revisions.
+ List<BundleRevision> result = new ArrayList<BundleRevision>();
+ result.add(bri);
+ List<BundleRevision> fragments = bri.getFragments();
if (fragments != null)
{
result.addAll(fragments);
@@ -503,9 +507,9 @@
return result;
}
- private static List createLocalizationResourceList(String basename, String locale)
+ private static List<String> createLocalizationResourceList(String basename, String locale)
{
- List result = new ArrayList(4);
+ List<String> result = new ArrayList(4);
StringTokenizer tokens;
StringBuffer tempLocale = new StringBuffer(basename);
@@ -853,9 +857,9 @@
synchronized boolean isExtension()
{
- for (int i = (m_modules.size() - 1); i > -1; i--)
+ for (int i = (m_revisions.size() - 1); i > -1; i--)
{
- if (m_modules.get(i).isExtension())
+ if (((BundleRevisionImpl) m_revisions.get(i)).isExtension())
{
return true;
}
@@ -865,12 +869,12 @@
public String getSymbolicName()
{
- return getCurrentModule().getSymbolicName();
+ return getCurrentRevision().getSymbolicName();
}
public Version getVersion()
{
- return getCurrentModule().getVersion();
+ return getCurrentRevision().getVersion();
}
public boolean hasPermission(Object obj)
@@ -997,7 +1001,7 @@
public String toString()
{
- String sym = getCurrentModule().getSymbolicName();
+ String sym = getCurrentRevision().getSymbolicName();
if (sym != null)
{
return sym + " [" + getBundleId() +"]";
@@ -1007,11 +1011,11 @@
synchronized boolean isRemovalPending()
{
- return (m_state == Bundle.UNINSTALLED) || (m_modules.size() > 1) || m_stale;
+ return (m_state == Bundle.UNINSTALLED) || (m_revisions.size() > 1) || m_stale;
}
//
- // Module management.
+ // Revision management.
//
/**
@@ -1026,22 +1030,22 @@
* no limit on the potential number of bundle JAR file revisions.
* @return array of modules corresponding to the bundle JAR file revisions.
**/
- synchronized List<Module> getModules()
+ synchronized List<BundleRevision> getRevisions()
{
- return m_modules;
+ return m_revisions;
}
/**
* Determines if the specified module is associated with this bundle.
- * @param module the module to determine if it is associate with this bundle.
+ * @param revision the module to determine if it is associate with this bundle.
* @return <tt>true</tt> if the specified module is in the array of modules
* associated with this bundle, <tt>false</tt> otherwise.
**/
- synchronized boolean hasModule(Module module)
+ synchronized boolean hasRevision(BundleRevision revision)
{
- for (int i = 0; i < m_modules.size(); i++)
+ for (int i = 0; i < m_revisions.size(); i++)
{
- if (m_modules.get(i) == module)
+ if (m_revisions.get(i) == revision)
{
return true;
}
@@ -1054,28 +1058,29 @@
* in the module array.
* @return the newest module.
**/
- synchronized Module getCurrentModule()
+ synchronized BundleRevision getCurrentRevision()
{
- return m_modules.get(m_modules.size() - 1);
+ return m_revisions.get(m_revisions.size() - 1);
}
synchronized boolean isUsed()
{
boolean unresolved = true;
- for (int i = 0; unresolved && (i < m_modules.size()); i++)
+ for (int i = 0; unresolved && (i < m_revisions.size()); i++)
{
- if (m_modules.get(i).isResolved())
+ if (m_revisions.get(i).getWiring() != null)
{
unresolved = false;
}
}
boolean used = false;
- for (int i = 0; !unresolved && !used && (i < m_modules.size()); i++)
+ for (int i = 0; !unresolved && !used && (i < m_revisions.size()); i++)
{
- List<Module> dependents = ((ModuleImpl) m_modules.get(i)).getDependents();
+ List<BundleRevision> dependents =
+ ((BundleRevisionImpl) m_revisions.get(i)).getDependents();
for (int j = 0; (dependents != null) && (j < dependents.size()) && !used; j++)
{
- if (dependents.get(j) != m_modules.get(i))
+ if (dependents.get(j) != m_revisions.get(i))
{
used = true;
}
@@ -1091,8 +1096,8 @@
m_archive.revise(location, is);
try
{
- Module module = createModule();
- addModule(module);
+ BundleRevision revision = createRevision();
+ addRevision(revision);
}
catch (Exception ex)
{
@@ -1104,27 +1109,27 @@
synchronized boolean rollbackRevise() throws Exception
{
boolean isExtension = isExtension();
- Module m = m_modules.remove(m_modules.size() - 1);
+ BundleRevision br = m_revisions.remove(m_revisions.size() - 1);
if (!isExtension)
{
- // Since revising a module adds the module to the global
+ // Since revising a bundle adds a revision to the global
// state, we must remove it from the global state on rollback.
- getFramework().getResolver().removeModule(m);
+ getFramework().getResolver().removeRevision(br);
}
return m_archive.rollbackRevise();
}
// This method should be private, but is visible because the
- // system bundle needs to add its module directly to the bundle,
- // since it doesn't have an archive from which the module will
- // be created, which is the normal case.
- synchronized void addModule(Module module) throws Exception
+ // system bundle needs to add its revision directly to the bundle,
+ // since it doesn't have an archive from which it will be created,
+ // which is the normal case.
+ synchronized void addRevision(BundleRevision revision) throws Exception
{
- m_modules.add(module);
+ m_revisions.add(revision);
- // Set protection domain after adding the module to the bundle,
- // since this requires that the bundle has a module.
- ((ModuleImpl) module).setSecurityContext(
+ // Set protection domain after adding the revision to the bundle,
+ // since this requires that the bundle has a revision.
+ ((BundleRevisionImpl) revision).setSecurityContext(
new BundleProtectionDomain(getFramework(), this));
SecurityProvider sp = getFramework().getSecurityProvider();
@@ -1136,30 +1141,29 @@
}
catch (Exception ex)
{
- m_modules.remove(m_modules.size() - 1);
+ m_revisions.remove(m_revisions.size() - 1);
throw ex;
}
}
- // TODO: REFACTOR - consider moving ModuleImpl into the framework package
- // so we can null module capabilities for extension bundles so we don't
- // need this check anymore.
+ // TODO: REFACTOR - consider nulling capabilities for extension bundles
+ // so we don't need this check anymore.
if (!isExtension())
{
- // Now that the module is added to the bundle, we can update
- // the resolver's module state.
- getFramework().getResolver().addModule(module);
+ // Now that the revision is added to the bundle, we can update
+ // the resolver's state to be aware of any new capabilities.
+ getFramework().getResolver().addRevision(revision);
}
}
- private Module createModule() throws Exception
+ private BundleRevision createRevision() throws Exception
{
- // Get and parse the manifest from the most recent revision to
- // create an associated module for it.
+ // Get and parse the manifest from the most recent revision and
+ // create an associated revision object for it.
Map headerMap = m_archive.getCurrentRevision().getManifestHeader();
- // Create the module instance.
- ModuleImpl module = new ModuleImpl(
+ // Create the bundle revision instance.
+ BundleRevisionImpl revision = new BundleRevisionImpl(
getFramework().getLogger(),
getFramework().getConfig(),
getFramework().getResolver(),
@@ -1173,11 +1177,11 @@
getFramework().getBootPackageWildcards());
// Verify that the bundle symbolic name + version is unique.
- if (module.getManifestVersion().equals("2"))
+ if (revision.getManifestVersion().equals("2"))
{
- Version bundleVersion = module.getVersion();
+ Version bundleVersion = revision.getVersion();
bundleVersion = (bundleVersion == null) ? Version.emptyVersion : bundleVersion;
- String symName = module.getSymbolicName();
+ String symName = revision.getSymbolicName();
Bundle[] bundles = getFramework().getBundles();
for (int i = 0; (bundles != null) && (i < bundles.length); i++)
@@ -1186,8 +1190,8 @@
if (id != getBundleId())
{
String sym = bundles[i].getSymbolicName();
- Version ver = ((ModuleImpl)
- ((BundleImpl) bundles[i]).getCurrentModule()).getVersion();
+ Version ver = ((BundleRevisionImpl)
+ ((BundleImpl) bundles[i]).getCurrentRevision()).getVersion();
if ((symName != null) && (sym != null) && symName.equals(sym) && bundleVersion.equals(ver))
{
throw new BundleException(
@@ -1198,16 +1202,17 @@
}
}
- return module;
+ return revision;
}
synchronized ProtectionDomain getProtectionDomain()
{
ProtectionDomain pd = null;
- for (int i = m_modules.size() - 1; (i >= 0) && (pd == null); i--)
+ for (int i = m_revisions.size() - 1; (i >= 0) && (pd == null); i--)
{
- pd = (ProtectionDomain) m_modules.get(i).getSecurityContext();
+ pd = (ProtectionDomain)
+ ((BundleRevisionImpl) m_revisions.get(i)).getSecurityContext();
}
return pd;
@@ -1258,4 +1263,4 @@
{
return m_context;
}
-}
+}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java b/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
index 2ba8f92..8e424ee 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
@@ -25,7 +25,7 @@
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
-import org.apache.felix.framework.resolver.Module;
+import org.osgi.framework.wiring.BundleRevision;
public class BundleProtectionDomain extends ProtectionDomain
{
@@ -33,9 +33,9 @@
private final WeakReference m_bundle;
private final int m_hashCode;
private final String m_toString;
- private final WeakReference m_module;
+ private final WeakReference m_revision;
- // TODO: SECURITY - This should probably take a module, not a bundle.
+ // TODO: SECURITY - This should probably take a revision, not a bundle.
BundleProtectionDomain(Felix felix, BundleImpl bundle)
throws MalformedURLException
{
@@ -50,14 +50,14 @@
null);
m_felix = new WeakReference(felix);
m_bundle = new WeakReference(bundle);
- m_module = new WeakReference(bundle.getCurrentModule());
+ m_revision = new WeakReference(bundle.getCurrentRevision());
m_hashCode = bundle.hashCode();
m_toString = "[" + bundle + "]";
}
- Module getModule()
+ BundleRevision getRevision()
{
- return (Module) m_module.get();
+ return (BundleRevision) m_revision.get();
}
public boolean implies(Permission permission)
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
similarity index 85%
rename from framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
rename to framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
index 0c9d719..18aa2fa 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -31,6 +31,7 @@
import java.security.ProtectionDomain;
import java.security.SecureClassLoader;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -41,16 +42,13 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
-
import org.apache.felix.framework.Felix.StatefulResolver;
import org.apache.felix.framework.cache.JarContent;
import org.apache.felix.framework.resolver.Content;
import org.apache.felix.framework.resolver.HostedCapability;
import org.apache.felix.framework.resolver.HostedRequirement;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.resolver.ResolveException;
import org.apache.felix.framework.resolver.ResourceNotFoundException;
-import org.apache.felix.framework.resolver.Wire;
import org.apache.felix.framework.util.CompoundEnumeration;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.SecureAction;
@@ -60,14 +58,23 @@
import org.apache.felix.framework.util.manifestparser.R4Library;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleReference;
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;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
-public class ModuleImpl implements Module
+public class BundleRevisionImpl implements BundleRevision, BundleWiring
{
+ public final static int EAGER_ACTIVATION = 0;
+ public final static int LAZY_ACTIVATION = 1;
+
private final Logger m_logger;
private final Map m_configMap;
private final StatefulResolver m_resolver;
@@ -81,12 +88,12 @@
private final String m_symbolicName;
private final Version m_version;
- private final List<BundleCapabilityImpl> m_declaredCaps;
- private List<BundleCapabilityImpl> m_resolvedCaps = null;
- private final List<BundleRequirementImpl> m_declaredReqs;
- private List<BundleRequirementImpl> m_resolvedReqs = null;
- private final List<BundleRequirementImpl> m_declaredDynReqs;
- private List<BundleRequirementImpl> m_resolvedDynReqs = null;
+ private final List<BundleCapability> m_declaredCaps;
+ private List<BundleCapability> m_resolvedCaps = null;
+ private final List<BundleRequirement> m_declaredReqs;
+ private List<BundleRequirement> m_resolvedReqs = null;
+ private final List<BundleRequirement> m_declaredDynReqs;
+ private List<BundleRequirement> m_resolvedDynReqs = null;
private final List<R4Library> m_nativeLibraries;
private final int m_declaredActivationPolicy;
private final List<String> m_activationIncludes;
@@ -94,15 +101,15 @@
private final Bundle m_bundle;
- private List<Module> m_fragments = null;
- private List<Wire> m_wires = null;
- private List<Module> m_dependentImporters = new ArrayList<Module>(0);
- private List<Module> m_dependentRequirers = new ArrayList<Module>(0);
+ private List<BundleRevision> m_fragments = null;
+ private List<FelixBundleWire> m_wires = null;
+ private List<BundleRevision> m_dependentImporters = new ArrayList<BundleRevision>(0);
+ private List<BundleRevision> m_dependentRequirers = new ArrayList<BundleRevision>(0);
private volatile boolean m_isResolved = false;
private Content[] m_contentPath;
private Content[] m_fragmentContents = null;
- private ModuleClassLoader m_classLoader;
+ private BundleClassLoader m_classLoader;
private boolean m_isActivationTriggered = false;
private ProtectionDomain m_protectionDomain = null;
private final static SecureAction m_secureAction = new SecureAction();
@@ -165,7 +172,7 @@
* @param bootPkgWildcards
* @throws org.osgi.framework.BundleException
*/
- public ModuleImpl(
+ public BundleRevisionImpl(
Logger logger, Map configMap, Bundle bundle, String id,
String[] bootPkgs, boolean[] bootPkgWildcards)
{
@@ -197,7 +204,7 @@
m_bootClassLoader = m_defBootClassLoader;
}
- ModuleImpl(
+ BundleRevisionImpl(
Logger logger, Map configMap, StatefulResolver resolver,
Bundle bundle, String id, Map headerMap, Content content,
URLStreamHandler streamHandler, String[] bootPkgs,
@@ -260,9 +267,259 @@
}
//
- // Metadata access methods.
+ // BundleRevision methods.
//
+ public String getSymbolicName()
+ {
+ return m_symbolicName;
+ }
+
+ public Version getVersion()
+ {
+ return m_version;
+ }
+
+ public synchronized List<BundleCapability> getDeclaredCapabilities(String namespace)
+ {
+ List<BundleCapability> result = m_declaredCaps;
+ if (namespace != null)
+ {
+ result = new ArrayList<BundleCapability>();
+ for (BundleCapability cap : m_declaredCaps)
+ {
+ if (cap.getNamespace().equals(namespace))
+ {
+ result.add(cap);
+ }
+ }
+ }
+ return result;
+ }
+
+ public synchronized List<BundleRequirement> getDeclaredRequirements(String namespace)
+ {
+ List<BundleRequirement> result = m_declaredReqs;
+ if (namespace != null)
+ {
+ result = new ArrayList<BundleRequirement>();
+ for (BundleRequirement req : m_declaredReqs)
+ {
+ if (req.getNamespace().equals(namespace))
+ {
+ result.add(req);
+ }
+ }
+ }
+ return result;
+ }
+
+ public synchronized List<BundleRequirement> getDeclaredDynamicRequirements()
+ {
+ return m_declaredDynReqs;
+ }
+
+ public int getTypes()
+ {
+ if (getHeaders().containsKey(Constants.FRAGMENT_HOST))
+ {
+ return BundleRevision.TYPE_FRAGMENT;
+ }
+ return 0;
+ }
+
+ public BundleWiring getWiring()
+ {
+ return (m_isResolved) ? this : null;
+ }
+
+ public Bundle getBundle()
+ {
+ return m_bundle;
+ }
+
+ //
+ // BundleWiring methods.
+ //
+
+ public boolean isCurrent()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isInUse()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public synchronized List<BundleCapability> getCapabilities(String namespace)
+ {
+ if (m_isResolved && (m_resolvedCaps == null))
+ {
+ List capList = (m_declaredCaps == null)
+ ? new ArrayList<BundleCapability>()
+ : new ArrayList<BundleCapability>(m_declaredCaps);
+ for (int fragIdx = 0;
+ (m_fragments != null) && (fragIdx < m_fragments.size());
+ fragIdx++)
+ {
+ List<BundleCapability> caps =
+ m_fragments.get(fragIdx).getDeclaredCapabilities(null);
+ for (int capIdx = 0;
+ (caps != null) && (capIdx < caps.size());
+ capIdx++)
+ {
+ if (caps.get(capIdx).getNamespace().equals(
+ BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ capList.add(
+ new HostedCapability(
+ this, (BundleCapabilityImpl) caps.get(capIdx)));
+ }
+ }
+ }
+ m_resolvedCaps = Collections.unmodifiableList(capList);
+ }
+ List<BundleCapability> result = m_resolvedCaps;
+ if (namespace != null)
+ {
+ result = new ArrayList<BundleCapability>();
+ for (BundleCapability cap : m_resolvedCaps)
+ {
+ if (cap.getNamespace().equals(namespace))
+ {
+ result.add(cap);
+ }
+ }
+ }
+ return result;
+ }
+
+ public synchronized List<BundleRequirement> getRequirements(String namespace)
+ {
+ if (m_isResolved && (m_resolvedReqs == null))
+ {
+ List<BundleRequirement> reqList = (m_declaredReqs == null)
+ ? new ArrayList() : new ArrayList(m_declaredReqs);
+ for (int fragIdx = 0;
+ (m_fragments != null) && (fragIdx < m_fragments.size());
+ fragIdx++)
+ {
+ List<BundleRequirement> reqs =
+ m_fragments.get(fragIdx).getDeclaredRequirements(null);
+ for (int reqIdx = 0;
+ (reqs != null) && (reqIdx < reqs.size());
+ reqIdx++)
+ {
+ if (reqs.get(reqIdx).getNamespace().equals(
+ BundleCapabilityImpl.PACKAGE_NAMESPACE)
+ || reqs.get(reqIdx).getNamespace().equals(
+ BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ reqList.add(
+ new HostedRequirement(
+ this, (BundleRequirementImpl) reqs.get(reqIdx)));
+ }
+ }
+ }
+ m_resolvedReqs = Collections.unmodifiableList(reqList);
+ }
+ List<BundleRequirement> result = m_resolvedReqs;
+ if (namespace != null)
+ {
+ result = new ArrayList<BundleRequirement>();
+ for (BundleRequirement req : m_resolvedReqs)
+ {
+ if (req.getNamespace().equals(namespace))
+ {
+ result.add(req);
+ }
+ }
+ }
+ return result;
+ }
+
+ public List<BundleWire> getProvidedWires(String namespace)
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<BundleWire> getRequiredWires(String namespace)
+ {
+ return asBundleWires(m_wires);
+ }
+
+ private static List<BundleWire> asBundleWires(List<? extends BundleWire> l)
+ {
+ return (List<BundleWire>) l;
+ }
+
+ public BundleRevision getRevision()
+ {
+ return this;
+ }
+
+ public synchronized ClassLoader getClassLoader()
+ {
+ if (m_classLoader == null)
+ {
+ // Determine which class loader to use based on which
+ // Java platform we are running on.
+ Class clazz;
+ if (m_isPreJava5)
+ {
+ clazz = BundleClassLoader.class;
+ }
+ else
+ {
+ try
+ {
+ clazz = BundleClassLoaderJava5.class;
+ }
+ catch (Throwable th)
+ {
+ // If we are on pre-Java5 then we will get a verify error
+ // here since we try to override a getResources() which is
+ // a final method in pre-Java5.
+ m_isPreJava5 = true;
+ clazz = BundleClassLoader.class;
+ }
+ }
+
+ // Use SecureAction to create the class loader if security is
+ // enabled; otherwise, create it directly.
+ try
+ {
+ Constructor ctor = (Constructor) m_secureAction.getConstructor(
+ clazz, new Class[] { BundleRevisionImpl.class, ClassLoader.class });
+ m_classLoader = (BundleClassLoader)
+ m_secureAction.invoke(ctor,
+ new Object[] { this, determineParentClassLoader() });
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException("Unable to create module class loader: "
+ + ex.getMessage() + " [" + ex.getClass().getName() + "]");
+ }
+ }
+ return m_classLoader;
+ }
+
+ public List<URL> findEntries(String path, String filePattern, int options)
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Collection<String> listResources(String path, String filePattern, int options)
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ //
+ // Implementating details.
+ //
+
+
public Map getHeaders()
{
return m_headerMap;
@@ -273,109 +530,24 @@
return m_isExtension;
}
- public String getSymbolicName()
- {
- return m_symbolicName;
- }
-
public String getManifestVersion()
{
return m_manifestVersion;
}
- public Version getVersion()
- {
- return m_version;
- }
-
- public synchronized List<BundleCapabilityImpl> getDeclaredCapabilities()
- {
- return m_declaredCaps;
- }
-
- public synchronized List<BundleCapabilityImpl> getResolvedCapabilities()
- {
- if (m_isResolved && (m_resolvedCaps == null))
- {
- List capList = (m_declaredCaps == null)
- ? new ArrayList<BundleCapabilityImpl>()
- : new ArrayList<BundleCapabilityImpl>(m_declaredCaps);
- for (int fragIdx = 0;
- (m_fragments != null) && (fragIdx < m_fragments.size());
- fragIdx++)
- {
- List<BundleCapabilityImpl> caps =
- m_fragments.get(fragIdx).getDeclaredCapabilities();
- for (int capIdx = 0;
- (caps != null) && (capIdx < caps.size());
- capIdx++)
- {
- if (caps.get(capIdx).getNamespace().equals(
- BundleCapabilityImpl.PACKAGE_NAMESPACE))
- {
- capList.add(
- new HostedCapability(this, caps.get(capIdx)));
- }
- }
- }
- m_resolvedCaps = Collections.unmodifiableList(capList);
- }
- return m_resolvedCaps;
- }
-
- public synchronized List<BundleRequirementImpl> getDeclaredRequirements()
- {
- return m_declaredReqs;
- }
-
- public synchronized List<BundleRequirementImpl> getResolvedRequirements()
- {
- if (m_isResolved && (m_resolvedReqs == null))
- {
- List<BundleRequirementImpl> reqList = (m_declaredReqs == null)
- ? new ArrayList() : new ArrayList(m_declaredReqs);
- for (int fragIdx = 0;
- (m_fragments != null) && (fragIdx < m_fragments.size());
- fragIdx++)
- {
- List<BundleRequirementImpl> reqs =
- m_fragments.get(fragIdx).getDeclaredRequirements();
- for (int reqIdx = 0;
- (reqs != null) && (reqIdx < reqs.size());
- reqIdx++)
- {
- if (reqs.get(reqIdx).getNamespace().equals(
- BundleCapabilityImpl.PACKAGE_NAMESPACE)
- || reqs.get(reqIdx).getNamespace().equals(
- BundleCapabilityImpl.MODULE_NAMESPACE))
- {
- reqList.add(
- new HostedRequirement(this, reqs.get(reqIdx)));
- }
- }
- }
- m_resolvedReqs = Collections.unmodifiableList(reqList);
- }
- return m_resolvedReqs;
- }
-
- public synchronized List<BundleRequirementImpl> getDeclaredDynamicRequirements()
- {
- return m_declaredDynReqs;
- }
-
- public synchronized List<BundleRequirementImpl> getResolvedDynamicRequirements()
+ public synchronized List<BundleRequirement> getResolvedDynamicRequirements()
{
if (m_isResolved && (m_resolvedDynReqs == null))
{
- List<BundleRequirementImpl> reqList = (m_declaredDynReqs == null)
+ List<BundleRequirement> reqList = (m_declaredDynReqs == null)
? new ArrayList() : new ArrayList(m_declaredDynReqs);
for (int fragIdx = 0;
(m_fragments != null) && (fragIdx < m_fragments.size());
fragIdx++)
{
- List<BundleRequirementImpl> reqs =
- m_fragments.get(fragIdx).getDeclaredDynamicRequirements();
+ List<BundleRequirement> reqs =
+ ((BundleRevisionImpl) m_fragments.get(fragIdx))
+ .getDeclaredDynamicRequirements();
for (int reqIdx = 0;
(reqs != null) && (reqIdx < reqs.size());
reqIdx++)
@@ -403,7 +575,9 @@
(m_fragments != null) && (fragIdx < m_fragments.size());
fragIdx++)
{
- List<R4Library> libs = m_fragments.get(fragIdx).getNativeLibraries();
+ List<R4Library> libs =
+ ((BundleRevisionImpl) m_fragments.get(fragIdx))
+ .getNativeLibraries();
for (int reqIdx = 0;
(libs != null) && (reqIdx < libs.size());
reqIdx++)
@@ -466,26 +640,17 @@
return included && !excluded;
}
- //
- // Run-time data access.
- //
-
- public Bundle getBundle()
- {
- return m_bundle;
- }
-
public String getId()
{
return m_id;
}
- public synchronized List<Wire> getWires()
+ public synchronized List<FelixBundleWire> getWires()
{
return m_wires;
}
- public synchronized void setWires(List<Wire> wires)
+ public synchronized void setWires(List<FelixBundleWire> wires)
{
// This not only sets the wires for the module, but it also records
// the dependencies this module has on other modules (i.e., the provider
@@ -501,13 +666,15 @@
// from the old wires.
for (int i = 0; !isFragment && (m_wires != null) && (i < m_wires.size()); i++)
{
- if (m_wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ if (m_wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
- ((ModuleImpl) m_wires.get(i).getExporter()).removeDependentRequirer(this);
+ ((BundleRevisionImpl) m_wires.get(i).getProviderWiring().getRevision())
+ .removeDependentRequirer(this);
}
else if (m_wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
- ((ModuleImpl) m_wires.get(i).getExporter()).removeDependentImporter(this);
+ ((BundleRevisionImpl) m_wires.get(i).getProviderWiring().getRevision())
+ .removeDependentImporter(this);
}
}
@@ -516,13 +683,21 @@
// Add ourself as a dependent to the new wires' modules.
for (int i = 0; !isFragment && (m_wires != null) && (i < m_wires.size()); i++)
{
- if (m_wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ if (m_wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
- ((ModuleImpl) m_wires.get(i).getExporter()).addDependentRequirer(this);
+// TODO: OSGi R4.3 - What's the correct way to handle this?
+// ((BundleRevisionImpl) m_wires.get(i).getProviderWiring().getRevision())
+// .addDependentRequirer(this);
+ ((BundleRevisionImpl) ((FelixBundleWire)
+ m_wires.get(i)).getProvider()).addDependentRequirer(this);
}
else if (m_wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
- ((ModuleImpl) m_wires.get(i).getExporter()).addDependentImporter(this);
+// TODO: OSGi R4.3 - What's the correct way to handle this?
+// ((BundleRevisionImpl) m_wires.get(i).getProviderWiring().getRevision())
+// .addDependentImporter(this);
+ ((BundleRevisionImpl) ((FelixBundleWire)
+ m_wires.get(i)).getProvider()).addDependentImporter(this);
}
}
}
@@ -555,7 +730,7 @@
public boolean isRemovalPending()
{
return (m_bundle.getState() == Bundle.UNINSTALLED)
- || (this != ((BundleImpl) m_bundle).getCurrentModule());
+ || (this != ((BundleImpl) m_bundle).getCurrentRevision());
}
//
@@ -596,7 +771,7 @@
}
private List calculateContentPath(
- Module module, Content content, List contentList, boolean searchFragments)
+ BundleRevision revision, Content content, List contentList, boolean searchFragments)
throws Exception
{
// Creating the content path entails examining the bundle's
@@ -608,7 +783,8 @@
List localContentList = new ArrayList();
// Find class path meta-data.
- String classPath = (String) module.getHeaders().get(FelixConstants.BUNDLE_CLASSPATH);
+ String classPath = (String) ((BundleRevisionImpl) revision)
+ .getHeaders().get(FelixConstants.BUNDLE_CLASSPATH);
// Parse the class path into strings.
List<String> classPathStrings = ManifestParser.parseDelimitedString(
classPath, FelixConstants.CLASS_PATH_SEPARATOR);
@@ -723,7 +899,7 @@
{
try
{
- // First, try to resolve the originating module.
+ // First, try to resolve the originating revision.
m_resolver.resolve(this);
// Get the package of the target class/resource.
@@ -760,19 +936,19 @@
}
}
- // Look in the module's imports. Note that the search may
+ // Look in the revision's imports. Note that the search may
// be aborted if this method throws an exception, otherwise
// it continues if a null is returned.
result = searchImports(name, isClass);
- // If not found, try the module's own class path.
+ // If not found, try the revision's own class path.
if (result == null)
{
result = (isClass)
- ? (Object) getClassLoader().findClass(name)
+ ? (Object) ((BundleClassLoader) getClassLoader()).findClass(name)
: (Object) getResourceLocal(name);
- // If still not found, then try the module's dynamic imports.
+ // If still not found, then try the revision's dynamic imports.
if (result == null)
{
result = searchDynamicImports(name, pkgName, isClass);
@@ -951,7 +1127,7 @@
// Note that the search may be aborted if this method throws an
// exception, otherwise it continues if a null is returned.
- List<Wire> wires = getWires();
+ List<FelixBundleWire> wires = getWires();
for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
if (wires.get(i).getRequirement().getNamespace()
@@ -981,7 +1157,7 @@
for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
if (wires.get(i).getRequirement().getNamespace()
- .equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ .equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
try
{
@@ -1013,7 +1189,7 @@
// At this point, the module's imports were searched and so was the
// the module's content. Now we make an attempt to load the
// class/resource via a dynamic import, if possible.
- Wire wire = null;
+ FelixBundleWire wire = null;
try
{
wire = m_resolver.resolve(this, pkgName);
@@ -1187,12 +1363,12 @@
// Fragment and dependency management methods.
//
- public synchronized List<Module> getFragments()
+ public synchronized List<BundleRevision> getFragments()
{
return m_fragments;
}
- public synchronized void attachFragments(List<Module> fragments) throws Exception
+ public synchronized void attachFragments(List<BundleRevision> fragments) throws Exception
{
// Remove the host wires for this module from old fragments.
// We will generally only remove host wires when we are uninstalling
@@ -1202,16 +1378,17 @@
// If the fragment has no wires, then there is no reason to try to
// remove ourself from its wires since it has apparently already
// been refreshed.
- if (m_fragments.get(i).getWires() != null)
+ if (((BundleRevisionImpl) m_fragments.get(i)).getWires() != null)
{
- List<Wire> hostWires = new ArrayList<Wire>(m_fragments.get(i).getWires());
- for (Iterator<Wire> it = hostWires.iterator(); it.hasNext(); )
+ List<FelixBundleWire> hostWires = new ArrayList<FelixBundleWire>(
+ ((BundleRevisionImpl) m_fragments.get(i)).getWires());
+ for (Iterator<FelixBundleWire> it = hostWires.iterator(); it.hasNext(); )
{
- Wire hostWire = it.next();
- if (hostWire.getExporter().equals(this))
+ FelixBundleWire hostWire = it.next();
+ if (hostWire.getProviderWiring().getRevision().equals(this))
{
it.remove();
- ((ModuleImpl) m_fragments.get(i)).setWires(hostWires);
+ ((BundleRevisionImpl) m_fragments.get(i)).setWires(hostWires);
break;
}
}
@@ -1256,10 +1433,10 @@
// avoids having to create more objects.
if (m_fragments.size() > 1)
{
- SortedMap<String, Module> sorted = new TreeMap<String, Module>();
- for (Module f : m_fragments)
+ SortedMap<String, BundleRevision> sorted = new TreeMap<String, BundleRevision>();
+ for (BundleRevision f : m_fragments)
{
- sorted.put(f.getId(), f);
+ sorted.put(((BundleRevisionImpl) f).getId(), f);
}
m_fragments = new ArrayList(sorted.values());
}
@@ -1267,7 +1444,7 @@
for (int i = 0; (m_fragments != null) && (i < m_fragments.size()); i++)
{
m_fragmentContents[i] =
- m_fragments.get(i).getContent()
+ ((BundleRevisionImpl) m_fragments.get(i)).getContent()
.getEntryAsContent(FelixConstants.CLASS_PATH_DOT);
}
// Recalculate the content path for the new fragments.
@@ -1275,56 +1452,56 @@
}
}
- public synchronized List<Module> getDependentImporters()
+ public synchronized List<BundleRevision> getDependentImporters()
{
return m_dependentImporters;
}
- public synchronized void addDependentImporter(Module module)
+ public synchronized void addDependentImporter(BundleRevision br)
{
- if (!m_dependentImporters.contains(module))
+ if (!m_dependentImporters.contains(br))
{
- m_dependentImporters.add(module);
+ m_dependentImporters.add(br);
}
}
- public synchronized void removeDependentImporter(Module module)
+ public synchronized void removeDependentImporter(BundleRevision br)
{
- m_dependentImporters.remove(module);
+ m_dependentImporters.remove(br);
}
- public synchronized List<Module> getDependentRequirers()
+ public synchronized List<BundleRevision> getDependentRequirers()
{
return m_dependentRequirers;
}
- public synchronized void addDependentRequirer(Module module)
+ public synchronized void addDependentRequirer(BundleRevision br)
{
- if (!m_dependentRequirers.contains(module))
+ if (!m_dependentRequirers.contains(br))
{
- m_dependentRequirers.add(module);
+ m_dependentRequirers.add(br);
}
}
- public synchronized void removeDependentRequirer(Module module)
+ public synchronized void removeDependentRequirer(BundleRevision br)
{
- m_dependentRequirers.remove(module);
+ m_dependentRequirers.remove(br);
}
- public synchronized List<Module> getDependents()
+ public synchronized List<BundleRevision> getDependents()
{
- List<Module> dependents;
+ List<BundleRevision> dependents;
if (Util.isFragment(this))
{
- dependents = new ArrayList<Module>();
+ dependents = new ArrayList<BundleRevision>();
for (int i = 0; (m_wires != null) && (i < m_wires.size()); i++)
{
- dependents.add(m_wires.get(i).getExporter());
+ dependents.add(m_wires.get(i).getCapability().getRevision());
}
}
else
{
- dependents = new ArrayList<Module>
+ dependents = new ArrayList<BundleRevision>
(m_dependentImporters.size() + m_dependentRequirers.size());
dependents.addAll(m_dependentImporters);
dependents.addAll(m_dependentRequirers);
@@ -1354,52 +1531,6 @@
return m_id;
}
- private synchronized ModuleClassLoader getClassLoader()
- {
- if (m_classLoader == null)
- {
- // Determine which class loader to use based on which
- // Java platform we are running on.
- Class clazz;
- if (m_isPreJava5)
- {
- clazz = ModuleClassLoader.class;
- }
- else
- {
- try
- {
- clazz = ModuleClassLoaderJava5.class;
- }
- catch (Throwable th)
- {
- // If we are on pre-Java5 then we will get a verify error
- // here since we try to override a getResources() which is
- // a final method in pre-Java5.
- m_isPreJava5 = true;
- clazz = ModuleClassLoader.class;
- }
- }
-
- // Use SecureAction to create the class loader if security is
- // enabled; otherwise, create it directly.
- try
- {
- Constructor ctor = (Constructor) m_secureAction.getConstructor(
- clazz, new Class[] { ModuleImpl.class, ClassLoader.class });
- m_classLoader = (ModuleClassLoader)
- m_secureAction.invoke(ctor,
- new Object[] { this, determineParentClassLoader() });
- }
- catch (Exception ex)
- {
- throw new RuntimeException("Unable to create module class loader: "
- + ex.getMessage() + " [" + ex.getClass().getName() + "]");
- }
- }
- return m_classLoader;
- }
-
private ClassLoader determineParentClassLoader()
{
// Determine the class loader's parent based on the
@@ -1418,7 +1549,7 @@
}
else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK))
{
- parent = m_secureAction.getClassLoader(ModuleImpl.class);
+ parent = m_secureAction.getClassLoader(BundleRevisionImpl.class);
}
// On Android we cannot set the parent class loader to be null, so
// we special case that situation here and set it to the system
@@ -1438,7 +1569,7 @@
throws ClassNotFoundException, ResourceNotFoundException
{
// We delegate to the module's wires to find the class or resource.
- List<Wire> wires = getWires();
+ List<FelixBundleWire> wires = getWires();
for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
// If we find the class or resource, then return it.
@@ -1461,7 +1592,7 @@
// At this point, the module's imports were searched and so was the
// the module's content. Now we make an attempt to load the
// class/resource via a dynamic import, if possible.
- Wire wire = null;
+ FelixBundleWire wire = null;
try
{
wire = m_resolver.resolve(this, pkgName);
@@ -1560,11 +1691,11 @@
// TODO: FRAMEWORK - This check is a hack and we should see if we can think
// of another way to do it, since it won't necessarily work in all situations.
// Since Felix uses threads for changing the start level
- // and refreshing packages, it is possible that there is no
- // module classes on the call stack; therefore, as soon as we
+ // and refreshing packages, it is possible that there are no
+ // bundle classes on the call stack; therefore, as soon as we
// see Thread on the call stack we exit this loop. Other cases
- // where modules actually use threads are not an issue because
- // the module classes will be on the call stack before the
+ // where bundles actually use threads are not an issue because
+ // the bundle classes will be on the call stack before the
// Thread class.
if (Thread.class.equals(classes[i]))
{
@@ -1572,7 +1703,7 @@
}
// Break if the current class came from a bundle, since we should
// not implicitly boot delegate in that case.
- else if (isClassLoadedFromModule(classes[i]))
+ else if (isClassLoadedFromBundleRevision(classes[i]))
{
break;
}
@@ -1602,24 +1733,24 @@
return null;
}
- private boolean isClassLoadedFromModule(Class clazz)
+ private boolean isClassLoadedFromBundleRevision(Class clazz)
{
- // The target class is loaded by a module class loader,
+ // The target class is loaded by a bundle class loader,
// then return true.
- if (ModuleClassLoader.class.isInstance(m_secureAction.getClassLoader(clazz)))
+ if (BundleClassLoader.class.isInstance(m_secureAction.getClassLoader(clazz)))
{
return true;
}
// If the target class was loaded from a class loader that
- // came from a module, then return true.
+ // came from a bundle, then return true.
ClassLoader last = null;
for (ClassLoader cl = m_secureAction.getClassLoader(clazz);
(cl != null) && (last != cl);
cl = m_secureAction.getClassLoader(cl.getClass()))
{
last = cl;
- if (ModuleClassLoader.class.isInstance(cl))
+ if (BundleClassLoader.class.isInstance(cl))
{
return true;
}
@@ -1757,9 +1888,9 @@
m_dexFileClassLoadClass = dexFileClassLoadClass;
}
- public class ModuleClassLoaderJava5 extends ModuleClassLoader
+ public class BundleClassLoaderJava5 extends BundleClassLoader
{
- public ModuleClassLoaderJava5(ClassLoader parent)
+ public BundleClassLoaderJava5(ClassLoader parent)
{
super(parent);
}
@@ -1767,7 +1898,7 @@
@Override
public Enumeration getResources(String name)
{
- Enumeration urls = ModuleImpl.this.getResourcesByDelegation(name);
+ Enumeration urls = BundleRevisionImpl.this.getResourcesByDelegation(name);
if (m_useLocalURLs)
{
urls = new ToLocalUrlEnumeration(urls);
@@ -1778,18 +1909,18 @@
@Override
protected Enumeration findResources(String name)
{
- return ModuleImpl.this.getResourcesLocal(name);
+ return BundleRevisionImpl.this.getResourcesLocal(name);
}
}
- public class ModuleClassLoader extends SecureClassLoader implements BundleReference
+ public class BundleClassLoader extends SecureClassLoader implements BundleReference
{
private final Map m_jarContentToDexFile;
private Object[][] m_cachedLibs = new Object[0][];
private static final int LIBNAME_IDX = 0;
private static final int LIBPATH_IDX = 1;
- public ModuleClassLoader(ClassLoader parent)
+ public BundleClassLoader(ClassLoader parent)
{
super(parent);
if (m_dexFileClassLoadClass != null)
@@ -1804,7 +1935,7 @@
public Bundle getBundle()
{
- return ModuleImpl.this.getBundle();
+ return BundleRevisionImpl.this.getBundle();
}
@Override
@@ -1836,7 +1967,7 @@
String msg = name;
if (m_logger.getLogLevel() >= Logger.LOG_DEBUG)
{
- msg = diagnoseClassLoadError(m_resolver, ModuleImpl.this, name);
+ msg = diagnoseClassLoadError(m_resolver, BundleRevisionImpl.this, name);
ex = (msg != null)
? new ClassNotFoundException(msg, cnfe)
: ex;
@@ -1858,14 +1989,14 @@
{
Class clazz = null;
- // Search for class in module.
+ // Search for class in bundle revision.
if (clazz == null)
{
String actual = name.replace('.', '/') + ".class";
byte[] bytes = null;
- // Check the module class path.
+ // Check the bundle class path.
Content[] contentPath = getContentPath();
Content content = null;
for (int i = 0;
@@ -1892,19 +2023,20 @@
{
int activationPolicy =
((BundleImpl) getBundle()).isDeclaredActivationPolicyUsed()
- ? ((BundleImpl) getBundle()).getCurrentModule().getDeclaredActivationPolicy()
- : Module.EAGER_ACTIVATION;
+ ? ((BundleRevisionImpl) ((BundleImpl) getBundle())
+ .getCurrentRevision()).getDeclaredActivationPolicy()
+ : EAGER_ACTIVATION;
- // If the module is using deferred activation, then if
- // we load this class from this module we need to activate
- // the module before returning the class. We will short
+ // If the revision is using deferred activation, then if
+ // we load this class from this revision we need to activate
+ // the bundle before returning the class. We will short
// circuit the trigger matching if the trigger is already
// tripped.
boolean isTriggerClass = m_isActivationTriggered
? false : isActivationTrigger(pkgName);
if (!m_isActivationTriggered
&& isTriggerClass
- && (activationPolicy == Module.LAZY_ACTIVATION)
+ && (activationPolicy == BundleRevisionImpl.LAZY_ACTIVATION)
&& (getBundle().getState() == Bundle.STARTING))
{
List deferredList = (List) m_deferredActivation.get();
@@ -2077,7 +2209,7 @@
@Override
public URL getResource(String name)
{
- URL url = ModuleImpl.this.getResourceByDelegation(name);
+ URL url = BundleRevisionImpl.this.getResourceByDelegation(name);
if (m_useLocalURLs)
{
url = convertToLocalUrl(url);
@@ -2088,10 +2220,10 @@
@Override
protected URL findResource(String name)
{
- return ModuleImpl.this.getResourceLocal(name);
+ return BundleRevisionImpl.this.getResourceLocal(name);
}
- // The findResources() method should only look at the module itself, but
+ // The findResources() method should only look at the revision itself, but
// instead it tries to delegate because in Java version prior to 1.5 the
// getResources() method was final and could not be overridden. We should
// override getResources() like getResource() to make it delegate, but we
@@ -2099,7 +2231,7 @@
@Override
protected Enumeration findResources(String name)
{
- Enumeration urls = ModuleImpl.this.getResourcesByDelegation(name);
+ Enumeration urls = BundleRevisionImpl.this.getResourcesByDelegation(name);
if (m_useLocalURLs)
{
urls = new ToLocalUrlEnumeration(urls);
@@ -2172,7 +2304,7 @@
@Override
public String toString()
{
- return ModuleImpl.this.toString();
+ return BundleRevisionImpl.this.toString();
}
}
@@ -2214,7 +2346,7 @@
}
private static String diagnoseClassLoadError(
- StatefulResolver resolver, ModuleImpl module, String name)
+ StatefulResolver resolver, BundleRevisionImpl revision, String name)
{
// We will try to do some diagnostics here to help the developer
// deal with this exception.
@@ -2226,17 +2358,17 @@
return null;
}
- // First, get the bundle string of the module doing the class loader.
- String importer = module.getBundle().toString();
+ // First, get the bundle string of the revision doing the class loader.
+ String importer = revision.getBundle().toString();
- // Next, check to see if the module imports the package.
- List<Wire> wires = module.getWires();
+ // Next, check to see if the revision imports the package.
+ List<FelixBundleWire> wires = revision.getWires();
for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
if (wires.get(i).getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
wires.get(i).getCapability().getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
{
- String exporter = wires.get(i).getExporter().getBundle().toString();
+ String exporter = wires.get(i).getProviderWiring().getBundle().toString();
StringBuffer sb = new StringBuffer("*** Package '");
sb.append(pkgName);
@@ -2260,7 +2392,7 @@
// Next, check to see if the package was optionally imported and
// whether or not there is an exporter available.
- List<BundleRequirementImpl> reqs = module.getResolvedRequirements();
+ List<BundleRequirement> reqs = revision.getWiring().getRequirements(null);
/*
* TODO: RB - Fix diagnostic message for optional imports.
for (int i = 0; (reqs != null) && (i < reqs.length); i++)
@@ -2319,21 +2451,21 @@
}
}
*/
- // Next, check to see if the package is dynamically imported by the module.
- if (resolver.isAllowedDynamicImport(module, pkgName))
+ // Next, check to see if the package is dynamically imported by the revision.
+ if (resolver.isAllowedDynamicImport(revision, pkgName))
{
// Try to see if there is an exporter available.
Map<String, String> dirs = Collections.EMPTY_MAP;
Map<String, Object> attrs = new HashMap<String, Object>(1);
attrs.put(BundleCapabilityImpl.PACKAGE_ATTR, pkgName);
BundleRequirementImpl req = new BundleRequirementImpl(
- module, BundleCapabilityImpl.PACKAGE_NAMESPACE, dirs, attrs);
- Set<BundleCapabilityImpl> exporters = resolver.getCandidates(req, false);
+ revision, BundleCapabilityImpl.PACKAGE_NAMESPACE, dirs, attrs);
+ Set<BundleCapability> exporters = resolver.getCandidates(req, false);
- Wire wire = null;
+ FelixBundleWire wire = null;
try
{
- wire = resolver.resolve(module, pkgName);
+ wire = resolver.resolve(revision, pkgName);
}
catch (Exception ex)
{
@@ -2341,7 +2473,7 @@
}
String exporter = (exporters.isEmpty())
- ? null : exporters.iterator().next().getModule().getBundle().toString();
+ ? null : exporters.iterator().next().getRevision().getBundle().toString();
StringBuffer sb = new StringBuffer("*** Class '");
sb.append(name);
@@ -2366,14 +2498,14 @@
Map<String, Object> attrs = new HashMap<String, Object>(1);
attrs.put(BundleCapabilityImpl.PACKAGE_ATTR, pkgName);
BundleRequirementImpl req = new BundleRequirementImpl(
- module, BundleCapabilityImpl.PACKAGE_NAMESPACE, dirs, attrs);
- Set<BundleCapabilityImpl> exports = resolver.getCandidates(req, false);
+ revision, BundleCapabilityImpl.PACKAGE_NAMESPACE, dirs, attrs);
+ Set<BundleCapability> exports = resolver.getCandidates(req, false);
if (exports.size() > 0)
{
boolean classpath = false;
try
{
- m_secureAction.getClassLoader(ModuleClassLoader.class).loadClass(name);
+ m_secureAction.getClassLoader(BundleClassLoader.class).loadClass(name);
classpath = true;
}
catch (NoClassDefFoundError err)
@@ -2385,7 +2517,7 @@
// Ignore
}
- String exporter = exports.iterator().next().getModule().getBundle().toString();
+ String exporter = exports.iterator().next().getRevision().getBundle().toString();
StringBuffer sb = new StringBuffer("*** Class '");
sb.append(name);
@@ -2426,7 +2558,7 @@
// class loader.
try
{
- m_secureAction.getClassLoader(ModuleClassLoader.class).loadClass(name);
+ m_secureAction.getClassLoader(BundleClassLoader.class).loadClass(name);
StringBuffer sb = new StringBuffer("*** Package '");
sb.append(pkgName);
@@ -2469,4 +2601,4 @@
return sb.toString();
}
-}
\ No newline at end of file
+}
diff --git a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
index fcf8e39..51c17f8 100644
--- a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
+++ b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
@@ -22,14 +22,14 @@
import java.net.URL;
import java.util.*;
import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Module;
+import org.osgi.framework.wiring.BundleRevision;
class EntryFilterEnumeration implements Enumeration
{
private final BundleImpl m_bundle;
private final List<Enumeration> m_enumerations;
- private final List<Module> m_modules;
- private int m_moduleIndex = 0;
+ private final List<BundleRevision> m_revisions;
+ private int m_revisionIndex = 0;
private final String m_path;
private final List<String> m_filePattern;
private final boolean m_recurse;
@@ -42,23 +42,23 @@
String filePattern, boolean recurse, boolean isURLValues)
{
m_bundle = bundle;
- Module bundleModule = m_bundle.getCurrentModule();
- List<Module> fragmentModules = ((ModuleImpl) bundleModule).getFragments();
- if (includeFragments && (fragmentModules != null))
+ BundleRevision br = m_bundle.getCurrentRevision();
+ List<BundleRevision> fragments = ((BundleRevisionImpl) br).getFragments();
+ if (includeFragments && (fragments != null))
{
- m_modules = new ArrayList(fragmentModules.size() + 1);
- m_modules.addAll(fragmentModules);
+ m_revisions = new ArrayList(fragments.size() + 1);
+ m_revisions.addAll(fragments);
}
else
{
- m_modules = new ArrayList(1);
+ m_revisions = new ArrayList(1);
}
- m_modules.add(0, bundleModule);
- m_enumerations = new ArrayList(m_modules.size());
- for (int i = 0; i < m_modules.size(); i++)
+ m_revisions.add(0, br);
+ m_enumerations = new ArrayList(m_revisions.size());
+ for (int i = 0; i < m_revisions.size(); i++)
{
- m_enumerations.add(m_modules.get(i).getContent() != null ?
- m_modules.get(i).getContent().getEntries() : null);
+ m_enumerations.add(((BundleRevisionImpl) m_revisions.get(i)).getContent() != null ?
+ ((BundleRevisionImpl) m_revisions.get(i)).getContent().getEntries() : null);
}
m_recurse = recurse;
m_isURLValues = isURLValues;
@@ -114,19 +114,19 @@
{
return;
}
- while ((m_moduleIndex < m_enumerations.size()) && m_nextEntries.isEmpty())
+ while ((m_revisionIndex < m_enumerations.size()) && m_nextEntries.isEmpty())
{
- while (m_enumerations.get(m_moduleIndex) != null
- && m_enumerations.get(m_moduleIndex).hasMoreElements()
+ while (m_enumerations.get(m_revisionIndex) != null
+ && m_enumerations.get(m_revisionIndex).hasMoreElements()
&& m_nextEntries.isEmpty())
{
// Get the current entry to determine if it should be filtered or not.
- String entryName = (String) m_enumerations.get(m_moduleIndex).nextElement();
+ String entryName = (String) m_enumerations.get(m_revisionIndex).nextElement();
// Check to see if the current entry is a descendent of the specified path.
if (!entryName.equals(m_path) && entryName.startsWith(m_path))
{
// Cached entry URL. If we are returning URLs, we use this
- // cached URL to avoid doing multiple URL lookups from a module
+ // cached URL to avoid doing multiple URL lookups from a revision
// when synthesizing directory URLs.
URL entryURL = null;
@@ -170,11 +170,14 @@
if (m_isURLValues)
{
entryURL = (entryURL == null)
- ? m_modules.get(m_moduleIndex).getEntry(entryName)
+ ? ((BundleRevisionImpl)
+ m_revisions.get(m_revisionIndex))
+ .getEntry(entryName)
: entryURL;
try
{
- m_nextEntries.add(new URL(entryURL, "/" + dir));
+ m_nextEntries.add(
+ new URL(entryURL, "/" + dir));
}
catch (MalformedURLException ex)
{
@@ -209,7 +212,8 @@
if (m_isURLValues)
{
entryURL = (entryURL == null)
- ? m_modules.get(m_moduleIndex).getEntry(entryName)
+ ? ((BundleRevisionImpl)
+ m_revisions.get(m_revisionIndex)).getEntry(entryName)
: entryURL;
m_nextEntries.add(entryURL);
}
@@ -223,7 +227,7 @@
}
if (m_nextEntries.isEmpty())
{
- m_moduleIndex++;
+ m_revisionIndex++;
}
}
}
@@ -238,4 +242,4 @@
: entryName.lastIndexOf('/', endIdx) + 1;
return entryName.substring(startIdx, endIdx);
}
-}
\ No newline at end of file
+}
diff --git a/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java b/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
index ede1cf2..0275069 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
@@ -19,27 +19,28 @@
package org.apache.felix.framework;
import java.util.List;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
import org.osgi.service.packageadmin.ExportedPackage;
class ExportedPackageImpl implements ExportedPackage
{
private final Felix m_felix;
private final BundleImpl m_exportingBundle;
- private final Module m_exportingModule;
- private final BundleCapabilityImpl m_export;
+ private final BundleRevision m_exportingRevision;
+ private final BundleCapability m_export;
private final String m_pkgName;
private final Version m_version;
public ExportedPackageImpl(
- Felix felix, BundleImpl exporter, Module module, BundleCapabilityImpl export)
+ Felix felix, BundleImpl exporter, BundleRevision revision, BundleCapability export)
{
m_felix = felix;
m_exportingBundle = exporter;
- m_exportingModule = module;
+ m_exportingRevision = revision;
m_export = export;
m_pkgName = (String) m_export.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR);
m_version = (!m_export.getAttributes().containsKey(BundleCapabilityImpl.VERSION_ATTR))
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index 7b34e7f..f463c3a 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -38,7 +38,6 @@
import java.util.Set;
import org.apache.felix.framework.Felix.StatefulResolver;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.framework.util.Util;
@@ -52,6 +51,8 @@
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
/**
* The ExtensionManager class is used in several ways.
@@ -115,8 +116,8 @@
private final Logger m_logger;
private final Map m_headerMap = new StringMap(false);
- private final Module m_systemBundleModule;
- private List<BundleCapabilityImpl> m_capabilities = null;
+ private final BundleRevision m_systemBundleRevision;
+ private List<BundleCapability> m_capabilities = null;
private Set m_exportNames = null;
private Object m_securityContext = null;
private final List m_extensions;
@@ -129,7 +130,7 @@
private ExtensionManager()
{
m_logger = null;
- m_systemBundleModule = null;
+ m_systemBundleRevision = null;
m_extensions = new ArrayList();
m_extensionsCache = new Bundle[0];
m_names = new HashSet();
@@ -149,7 +150,7 @@
*/
ExtensionManager(Logger logger, Felix felix)
{
- m_systemBundleModule = new ExtensionManagerModule(felix);
+ m_systemBundleRevision = new ExtensionManagerRevision(felix);
m_extensions = null;
m_extensionsCache = null;
m_names = null;
@@ -189,13 +190,13 @@
try
{
ManifestParser mp = new ManifestParser(
- m_logger, felix.getConfig(), m_systemBundleModule, m_headerMap);
- List<BundleCapabilityImpl> caps = aliasSymbolicName(mp.getCapabilities());
+ m_logger, felix.getConfig(), m_systemBundleRevision, m_headerMap);
+ List<BundleCapability> caps = aliasSymbolicName(mp.getCapabilities());
setCapabilities(caps);
}
catch (Exception ex)
{
- m_capabilities = new ArrayList<BundleCapabilityImpl>(0);
+ m_capabilities = new ArrayList<BundleCapability>(0);
m_logger.log(
Logger.LOG_ERROR,
"Error parsing system bundle export statement: "
@@ -203,14 +204,14 @@
}
}
- private static List<BundleCapabilityImpl> aliasSymbolicName(List<BundleCapabilityImpl> caps)
+ private static List<BundleCapability> aliasSymbolicName(List<BundleCapability> caps)
{
if (caps == null)
{
- return new ArrayList<BundleCapabilityImpl>(0);
+ return new ArrayList<BundleCapability>(0);
}
- List<BundleCapabilityImpl> aliasCaps = new ArrayList<BundleCapabilityImpl>(caps);
+ List<BundleCapability> aliasCaps = new ArrayList<BundleCapability>(caps);
for (int capIdx = 0; capIdx < aliasCaps.size(); capIdx++)
{
@@ -232,7 +233,7 @@
Constants.SYSTEM_BUNDLE_SYMBOLICNAME});
// Create the aliased capability to replace the old capability.
aliasCaps.set(capIdx, new BundleCapabilityImpl(
- caps.get(capIdx).getModule(),
+ caps.get(capIdx).getRevision(),
caps.get(capIdx).getNamespace(),
caps.get(capIdx).getDirectives(),
aliasAttrs));
@@ -245,9 +246,9 @@
return aliasCaps;
}
- public Module getModule()
+ public BundleRevision getRevision()
{
- return m_systemBundleModule;
+ return m_systemBundleRevision;
}
public synchronized Object getSecurityContext()
@@ -298,7 +299,8 @@
}
String directive = ManifestParser.parseExtensionBundleHeader((String)
- bundle.getCurrentModule().getHeaders().get(Constants.FRAGMENT_HOST));
+ ((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getHeaders().get(Constants.FRAGMENT_HOST));
// We only support classpath extensions (not bootclasspath).
if (!Constants.EXTENSION_FRAMEWORK.equals(directive))
@@ -311,13 +313,14 @@
try
{
// Merge the exported packages with the exported packages of the systembundle.
- List<BundleCapabilityImpl> exports = null;
+ List<BundleCapability> exports = null;
try
{
exports = ManifestParser.parseExportHeader(
- m_logger, m_systemBundleModule,
- (String) bundle.getCurrentModule().getHeaders().get(Constants.EXPORT_PACKAGE),
- m_systemBundleModule.getSymbolicName(), m_systemBundleModule.getVersion());
+ m_logger, m_systemBundleRevision,
+ (String) ((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getHeaders().get(Constants.EXPORT_PACKAGE),
+ m_systemBundleRevision.getSymbolicName(), m_systemBundleRevision.getVersion());
exports = aliasSymbolicName(exports);
}
catch (Exception ex)
@@ -326,7 +329,8 @@
bundle,
Logger.LOG_ERROR,
"Error parsing extension bundle export statement: "
- + bundle.getCurrentModule().getHeaders().get(Constants.EXPORT_PACKAGE), ex);
+ + ((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getHeaders().get(Constants.EXPORT_PACKAGE), ex);
return;
}
@@ -344,8 +348,8 @@
throw new UnsupportedOperationException(
"Unable to add extension bundle to FrameworkClassLoader - Maybe not an URLClassLoader?");
}
- List<BundleCapabilityImpl> temp =
- new ArrayList<BundleCapabilityImpl>(m_capabilities.size() + exports.size());
+ List<BundleCapability> temp =
+ new ArrayList<BundleCapability>(m_capabilities.size() + exports.size());
temp.addAll(m_capabilities);
temp.addAll(exports);
setCapabilities(temp);
@@ -368,8 +372,8 @@
void startExtensionBundle(Felix felix, BundleImpl bundle)
{
String activatorClass = (String)
- bundle.getCurrentModule().getHeaders().get(
- FelixConstants.FELIX_EXTENSION_ACTIVATOR);
+ ((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getHeaders().get(FelixConstants.FELIX_EXTENSION_ACTIVATOR);
if (activatorClass != null)
{
@@ -415,7 +419,7 @@
}
}
- private void setCapabilities(List<BundleCapabilityImpl> capabilities)
+ private void setCapabilities(List<BundleCapability> capabilities)
{
m_capabilities = capabilities;
m_headerMap.put(Constants.EXPORT_PACKAGE, convertCapabilitiesToHeaders(m_headerMap));
@@ -497,7 +501,8 @@
{
try
{
- result = ((ModuleImpl) ((BundleImpl) extBundle).getCurrentModule()).getResourceLocal(path);
+ result = ((BundleRevisionImpl) ((BundleImpl)
+ extBundle).getCurrentRevision()).getResourceLocal(path);
}
catch (Exception ex)
{
@@ -627,10 +632,10 @@
// Utility methods.
//
- class ExtensionManagerModule extends ModuleImpl
+ class ExtensionManagerRevision extends BundleRevisionImpl
{
private final Version m_version;
- ExtensionManagerModule(Felix felix)
+ ExtensionManagerRevision(Felix felix)
{
super(m_logger, felix.getConfig(), felix, "0",
felix.getBootPackages(), felix.getBootPackageWildcards());
@@ -646,7 +651,7 @@
}
}
- public List<BundleCapabilityImpl> getDeclaredCapabilities()
+ public List<BundleCapability> getDeclaredCapabilities(String namespace)
{
synchronized (ExtensionManager.this)
{
@@ -654,7 +659,7 @@
}
}
- public List<BundleCapabilityImpl> getResolvedCapabilities()
+ public List<BundleCapability> getCapabilities(String namespace)
{
synchronized (ExtensionManager.this)
{
@@ -784,4 +789,4 @@
return getClass().getClassLoader().getResource(urlPath);
}
}
-}
+}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index a7f1603..98b8183 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -28,9 +28,8 @@
import org.apache.felix.framework.cache.BundleArchive;
import org.apache.felix.framework.cache.BundleCache;
import org.apache.felix.framework.capabilityset.CapabilitySet;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Wire;
+import org.apache.felix.framework.resolver.ResolverWire;
import org.apache.felix.framework.ext.SecurityProvider;
import org.apache.felix.framework.resolver.ResolveException;
import org.apache.felix.framework.resolver.Resolver;
@@ -47,6 +46,8 @@
import org.apache.felix.framework.util.manifestparser.R4LibraryClause;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
+import org.apache.felix.framework.wiring.FelixBundleWireImpl;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
@@ -70,6 +71,9 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.FindHook;
import org.osgi.framework.hooks.service.ListenerHook;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.startlevel.StartLevel;
@@ -364,12 +368,12 @@
m_logger,
(String) m_configMap.get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT)));
- // Create the extension manager, which we will use as the module
- // definition for creating the system bundle module.
+ // Create the extension manager, which we will use as the
+ // revision for the system bundle.
m_extensionManager = new ExtensionManager(m_logger, this);
try
{
- addModule(m_extensionManager.getModule());
+ addRevision(m_extensionManager.getRevision());
}
catch (Exception ex)
{
@@ -637,7 +641,7 @@
// state to be set to RESOLVED.
try
{
- m_resolver.resolve(getCurrentModule());
+ m_resolver.resolve(getCurrentRevision());
}
catch (ResolveException ex)
{
@@ -1469,11 +1473,11 @@
{
throw new IllegalStateException("The bundle is uninstalled.");
}
- else if (Util.isFragment(bundle.getCurrentModule()))
+ else if (Util.isFragment(bundle.getCurrentRevision()))
{
return null;
}
- return bundle.getCurrentModule().getResourceByDelegation(name);
+ return ((BundleRevisionImpl) bundle.getCurrentRevision()).getResourceByDelegation(name);
}
/**
@@ -1485,11 +1489,11 @@
{
throw new IllegalStateException("The bundle is uninstalled.");
}
- else if (Util.isFragment(bundle.getCurrentModule()))
+ else if (Util.isFragment(bundle.getCurrentRevision()))
{
return null;
}
- return bundle.getCurrentModule().getResourcesByDelegation(name);
+ return ((BundleRevisionImpl) bundle.getCurrentRevision()).getResourcesByDelegation(name);
}
/**
@@ -1502,7 +1506,7 @@
throw new IllegalStateException("The bundle is uninstalled.");
}
- URL url = bundle.getCurrentModule().getEntry(name);
+ URL url = ((BundleRevisionImpl) bundle.getCurrentRevision()).getEntry(name);
// Some JAR files do not contain directory entries, so if
// the entry wasn't found and is a directory, scan the entries
@@ -1541,7 +1545,7 @@
throw new IllegalStateException("The bundle is uninstalled.");
}
- // Get the entry enumeration from the module content and
+ // Get the entry enumeration from the revision content and
// create a wrapper enumeration to filter it.
Enumeration enumeration =
new EntryFilterEnumeration(bundle, false, path, "*", false, false);
@@ -1559,7 +1563,7 @@
// Try to resolve the bundle per the spec.
resolveBundles(new Bundle[] { bundle });
- // Get the entry enumeration from the module content and
+ // Get the entry enumeration from the revision content and
// create a wrapper enumeration to filter it.
Enumeration enumeration =
new EntryFilterEnumeration(bundle, true, path, filePattern, recurse, true);
@@ -1630,7 +1634,7 @@
{
throw new IllegalStateException("Bundle is uninstalled");
}
- else if (Util.isFragment(bundle.getCurrentModule()))
+ else if (Util.isFragment(bundle.getCurrentRevision()))
{
throw new ClassNotFoundException("Fragments cannot load classes.");
}
@@ -1648,7 +1652,7 @@
throw new ClassNotFoundException(name, ex);
}
}
- return bundle.getCurrentModule().getClassByDelegation(name);
+ return ((BundleRevisionImpl) bundle.getCurrentRevision()).getClassByDelegation(name);
}
/**
@@ -1687,7 +1691,8 @@
// Record whether the bundle is using its declared activation policy.
boolean wasDeferred = bundle.isDeclaredActivationPolicyUsed()
- && (bundle.getCurrentModule().getDeclaredActivationPolicy() == Module.LAZY_ACTIVATION);
+ && (((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getDeclaredActivationPolicy() == BundleRevisionImpl.LAZY_ACTIVATION);
bundle.setDeclaredActivationPolicyUsed(
(options & Bundle.START_ACTIVATION_POLICY) != 0);
@@ -1703,7 +1708,7 @@
// As per the OSGi spec, fragment bundles can not be started and must
// throw a BundleException when there is an attempt to start one.
- if (Util.isFragment(bundle.getCurrentModule()))
+ if (Util.isFragment(bundle.getCurrentRevision()))
{
throw new BundleException("Fragment bundles can not be started.");
}
@@ -1808,8 +1813,9 @@
// If the bundle's activation policy is eager or activation has already
// been triggered, then activate the bundle immediately.
if (!bundle.isDeclaredActivationPolicyUsed()
- || (bundle.getCurrentModule().getDeclaredActivationPolicy() != Module.LAZY_ACTIVATION)
- || ((ModuleImpl) bundle.getCurrentModule()).isActivationTriggered())
+ || (((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getDeclaredActivationPolicy() != BundleRevisionImpl.LAZY_ACTIVATION)
+ || ((BundleRevisionImpl) bundle.getCurrentRevision()).isActivationTriggered())
{
// Record the event type for the final event and activate.
eventType = BundleEvent.STARTED;
@@ -1998,8 +2004,8 @@
// First get the update-URL from our header.
String updateLocation = (String)
- bundle.getCurrentModule().getHeaders().get(
- Constants.BUNDLE_UPDATELOCATION);
+ ((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
// If no update location specified, use original location.
if (updateLocation == null)
@@ -2016,7 +2022,7 @@
try
{
- // Revising the bundle creates a new module, which modifies
+ // Revising the bundle creates a new revision, which modifies
// the global state, so we need to acquire the global lock
// before revising.
boolean locked = acquireGlobalLock();
@@ -2048,7 +2054,7 @@
{
m_extensionManager.addExtensionBundle(this, bundle);
// TODO: REFACTOR - Perhaps we could move this into extension manager.
- m_resolver.addModule(m_extensionManager.getModule());
+ m_resolver.addRevision(m_extensionManager.getRevision());
// TODO: REFACTOR - Not clear why this is here. We should look at all of these steps more closely.
setBundleStateAndNotify(bundle, Bundle.RESOLVED);
}
@@ -2134,9 +2140,9 @@
}
}
- // If the old state was active, but the new module is a fragment,
+ // If the old state was active, but the new revision is a fragment,
// then mark the persistent state to inactive.
- if ((oldState == Bundle.ACTIVE) && Util.isFragment(bundle.getCurrentModule()))
+ if ((oldState == Bundle.ACTIVE) && Util.isFragment(bundle.getCurrentRevision()))
{
bundle.setPersistentStateInactive();
m_logger.log(bundle, Logger.LOG_WARNING,
@@ -2229,7 +2235,7 @@
// As per the OSGi spec, fragment bundles can not be stopped and must
// throw a BundleException when there is an attempt to stop one.
- if (Util.isFragment(bundle.getCurrentModule()))
+ if (Util.isFragment(bundle.getCurrentRevision()))
{
throw new BundleException("Fragment bundles can not be stopped: " + bundle);
}
@@ -2241,7 +2247,8 @@
throw new IllegalStateException("Cannot stop an uninstalled bundle.");
case Bundle.STARTING:
if (bundle.isDeclaredActivationPolicyUsed()
- && bundle.getCurrentModule().getDeclaredActivationPolicy() != Module.LAZY_ACTIVATION)
+ && ((BundleRevisionImpl) bundle.getCurrentRevision())
+ .getDeclaredActivationPolicy() != BundleRevisionImpl.LAZY_ACTIVATION)
{
throw new BundleException(
"Stopping a starting or stopping bundle is currently not supported.");
@@ -2607,7 +2614,7 @@
else
{
m_extensionManager.addExtensionBundle(this, bundle);
- m_resolver.addModule(m_extensionManager.getModule());
+ m_resolver.addRevision(m_extensionManager.getRevision());
}
}
catch (Throwable ex)
@@ -3210,8 +3217,8 @@
Class sbClass = null;
try
{
- sbClass = m_extensionManager
- .getModule().getClassByDelegation(clazz.getName());
+ sbClass = ((BundleRevisionImpl) m_extensionManager
+ .getRevision()).getClassByDelegation(clazz.getName());
}
catch (ClassNotFoundException ex)
{
@@ -3253,12 +3260,12 @@
BundleCapabilityImpl.PACKAGE_NAMESPACE,
Collections.EMPTY_MAP,
attrs);
- Set<BundleCapabilityImpl> exports = m_resolver.getCandidates(req, false);
+ Set<BundleCapability> exports = m_resolver.getCandidates(req, false);
// We only want resolved capabilities.
- for (Iterator<BundleCapabilityImpl> it = exports.iterator(); it.hasNext(); )
+ for (Iterator<BundleCapability> it = exports.iterator(); it.hasNext(); )
{
- if (!it.next().getModule().isResolved())
+ if (it.next().getRevision().getWiring() == null)
{
it.remove();
}
@@ -3268,34 +3275,33 @@
{
List pkgs = new ArrayList();
- for (Iterator<BundleCapabilityImpl> it = exports.iterator(); it.hasNext(); )
+ for (Iterator<BundleCapability> it = exports.iterator(); it.hasNext(); )
{
- // Get the bundle associated with the current exporting module.
- BundleImpl bundle = (BundleImpl) it.next().getModule().getBundle();
+ // Get the bundle associated with the current exporting revision.
+ BundleImpl bundle = (BundleImpl) it.next().getRevision().getBundle();
// We need to find the version of the exported package, but this
// is tricky since there may be multiple versions of the package
// offered by a given bundle, since multiple revisions of the
// bundle JAR file may exist if the bundle was updated without
// refreshing the framework. In this case, each revision of the
- // bundle JAR file is represented as a module in the BundleInfo
- // module array, which is ordered from oldest to newest. We assume
- // that the first module found to be exporting the package is the
- // provider of the package, which makes sense since it must have
- // been resolved first.
- for (Module m : bundle.getModules())
+ // bundle JAR file is represented as a revision ordered from
+ // oldest to newest. We assume that the first revision found to
+ // be exporting the package is the provider of the package,
+ // which makes sense since it must have been resolved first.
+ for (BundleRevision br : bundle.getRevisions())
{
- List<BundleCapabilityImpl> caps = (m.isResolved())
- ? m.getResolvedCapabilities()
- : m.getDeclaredCapabilities();
- for (BundleCapabilityImpl cap : caps)
+ List<BundleCapability> caps = (br.getWiring() == null)
+ ? br.getDeclaredCapabilities(null)
+ : br.getWiring().getCapabilities(null);
+ for (BundleCapability cap : caps)
{
if (cap.getNamespace().equals(req.getNamespace())
&& CapabilitySet.matches(cap, req.getFilter()))
{
pkgs.add(
new ExportedPackageImpl(
- this, bundle, m, cap));
+ this, bundle, br, cap));
}
}
}
@@ -3381,19 +3387,19 @@
**/
private void getExportedPackages(BundleImpl bundle, List list)
{
- // Since a bundle may have many modules associated with it,
- // one for each revision in the cache, search each module
- // for each revision to get all exports.
- for (Module m : bundle.getModules())
+ // Since a bundle may have many revisions associated with it,
+ // one for each revision in the cache, search each revision
+ // to get all exports.
+ for (BundleRevision br : bundle.getRevisions())
{
- List<BundleCapabilityImpl> caps = (m.isResolved())
- ? m.getResolvedCapabilities()
- : m.getDeclaredCapabilities();
+ List<BundleCapability> caps = (br.getWiring() == null)
+ ? br.getDeclaredCapabilities(null)
+ : br.getWiring().getCapabilities(null);
if ((caps != null) && (caps.size() > 0))
{
- for (BundleCapabilityImpl cap : caps)
+ for (BundleCapability cap : caps)
{
- // See if the target bundle's module is one of the
+ // See if the target bundle's revisions is one of the
// resolved exporters of the package.
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
@@ -3407,24 +3413,24 @@
BundleCapabilityImpl.PACKAGE_NAMESPACE,
Collections.EMPTY_MAP,
attrs);
- Set<BundleCapabilityImpl> providers =
+ Set<BundleCapability> providers =
m_resolver.getCandidates(req, false);
// We only want resolved capabilities.
- for (Iterator<BundleCapabilityImpl> it = providers.iterator();
+ for (Iterator<BundleCapability> it = providers.iterator();
it.hasNext(); )
{
- if (!it.next().getModule().isResolved())
+ if (it.next().getRevision().getWiring() == null)
{
it.remove();
}
}
- // Search through the current providers to find the target module.
- for (BundleCapabilityImpl provider : providers)
+ // Search through the current providers to find the target revision.
+ for (BundleCapability provider : providers)
{
if (provider == cap)
{
- list.add(new ExportedPackageImpl(this, bundle, m, cap));
+ list.add(new ExportedPackageImpl(this, bundle, br, cap));
}
}
}
@@ -3438,11 +3444,12 @@
// Create list for storing importing bundles.
List<Bundle> list = new ArrayList();
- // Get all dependent modules from all exporter module revisions.
- List<Module> modules = exporter.getModules();
- for (int modIdx = 0; modIdx < modules.size(); modIdx++)
+ // Get all dependent revisions from all exporter revisions.
+ List<BundleRevision> revisions = exporter.getRevisions();
+ for (int modIdx = 0; modIdx < revisions.size(); modIdx++)
{
- List<Module> dependents = ((ModuleImpl) modules.get(modIdx)).getDependents();
+ List<BundleRevision> dependents =
+ ((BundleRevisionImpl) revisions.get(modIdx)).getDependents();
for (int depIdx = 0;
(dependents != null) && (depIdx < dependents.size());
depIdx++)
@@ -3464,25 +3471,27 @@
// Get all importers and requirers for all revisions of the bundle.
// The spec says that require-bundle should be returned with importers.
- List<Module> expModules = exporter.getModules();
- for (int expIdx = 0; (expModules != null) && (expIdx < expModules.size()); expIdx++)
+ List<BundleRevision> expRevisions = exporter.getRevisions();
+ for (int expIdx = 0; (expRevisions != null) && (expIdx < expRevisions.size()); expIdx++)
{
// Include any importers that have wires to the specific
// exported package.
- List<Module> dependents = ((ModuleImpl) expModules.get(expIdx)).getDependentImporters();
+ List<BundleRevision> dependents =
+ ((BundleRevisionImpl) expRevisions.get(expIdx)).getDependentImporters();
for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
{
- List<Wire> wires = dependents.get(depIdx).getWires();
+ List<FelixBundleWire> wires =
+ ((BundleRevisionImpl) dependents.get(depIdx)).getWires();
for (int wireIdx = 0; (wires != null) && (wireIdx < wires.size()); wireIdx++)
{
- if ((wires.get(wireIdx).getExporter() == expModules.get(expIdx))
+ if ((wires.get(wireIdx).getProviderWiring().getRevision() == expRevisions.get(expIdx))
&& (wires.get(wireIdx).hasPackage(ep.getName())))
{
list.add(dependents.get(depIdx).getBundle());
}
}
}
- dependents = ((ModuleImpl) expModules.get(expIdx)).getDependentRequirers();
+ dependents = ((BundleRevisionImpl) expRevisions.get(expIdx)).getDependentRequirers();
for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
{
list.add(dependents.get(depIdx).getBundle());
@@ -3561,13 +3570,13 @@
{
try
{
- m_resolver.resolve(bundle.getCurrentModule());
+ m_resolver.resolve(bundle.getCurrentRevision());
}
catch (ResolveException ex)
{
- if (ex.getModule() != null)
+ if (ex.getRevision() != null)
{
- Bundle b = ex.getModule().getBundle();
+ Bundle b = ex.getRevision().getBundle();
throw new BundleException(
"Unresolved constraint in bundle "
+ b + ": " + ex.getMessage());
@@ -3803,7 +3812,7 @@
// Get the activator class from the header map.
BundleActivator activator = null;
- Map headerMap = impl.getCurrentModule().getHeaders();
+ Map headerMap = ((BundleRevisionImpl) impl.getCurrentRevision()).getHeaders();
String className = (String) headerMap.get(Constants.BUNDLE_ACTIVATOR);
// Try to instantiate activator class if present.
if (className != null)
@@ -3812,7 +3821,8 @@
Class clazz;
try
{
- clazz = impl.getCurrentModule().getClassByDelegation(className);
+ clazz = ((BundleRevisionImpl)
+ impl.getCurrentRevision()).getClassByDelegation(className);
}
catch (ClassNotFoundException ex)
{
@@ -4110,42 +4120,44 @@
m_resolverState = resolverState;
}
- void addModule(Module m)
+ void addRevision(BundleRevision br)
{
- m_resolverState.addModule(m);
+ m_resolverState.addRevision(br);
}
- void removeModule(Module m)
+ void removeRevision(BundleRevision br)
{
- m_resolverState.removeModule(m);
+ m_resolverState.removeRevision(br);
}
- Set<BundleCapabilityImpl> getCandidates(BundleRequirementImpl req, boolean obeyMandatory)
+ Set<BundleCapability> getCandidates(BundleRequirementImpl req, boolean obeyMandatory)
{
return m_resolverState.getCandidates(req, obeyMandatory);
}
- void resolve(Module rootModule) throws ResolveException
+ void resolve(BundleRevision rootRevision) throws ResolveException
{
// Although there is a race condition to check the bundle state
// then lock it, we do this because we don't want to acquire the
- // a lock just to check if the module is resolved, which itself
- // is a safe read. If the module isn't resolved, we end up double
+ // a lock just to check if the revision is resolved, which itself
+ // is a safe read. If the revision isn't resolved, we end up double
// check the resolved status later.
- if (!rootModule.isResolved())
+// TODO: OSGi R4.3 - This locking strategy here depends on how we ultimately
+// implement getWiring(), which may change.
+ if (rootRevision.getWiring() == null)
{
// Acquire global lock.
boolean locked = acquireGlobalLock();
if (!locked)
{
throw new ResolveException(
- "Unable to acquire global lock for resolve.", rootModule, null);
+ "Unable to acquire global lock for resolve.", rootRevision, null);
}
- Map<Module, List<Wire>> wireMap = null;
+ Map<BundleRevision, List<ResolverWire>> wireMap = null;
try
{
- BundleImpl bundle = (BundleImpl) rootModule.getBundle();
+ BundleImpl bundle = (BundleImpl) rootRevision.getBundle();
// Extensions are resolved differently.
if (bundle.isExtension())
@@ -4153,12 +4165,12 @@
return;
}
- // Resolve the module.
+ // Resolve the revision.
wireMap = m_resolver.resolve(
- m_resolverState, rootModule, m_resolverState.getFragments());
+ m_resolverState, rootRevision, m_resolverState.getFragments());
- // Mark all modules as resolved.
- markResolvedModules(wireMap);
+ // Mark all revisions as resolved.
+ markResolvedRevisions(wireMap);
}
finally
{
@@ -4170,32 +4182,32 @@
}
}
- Wire resolve(Module module, String pkgName) throws ResolveException
+ FelixBundleWire resolve(BundleRevision revision, String pkgName) throws ResolveException
{
- Wire candidateWire = null;
- // We cannot dynamically import if the module is not already resolved
+ FelixBundleWire candidateWire = null;
+ // We cannot dynamically import if the revision is not already resolved
// or if it is not allowed, so check that first. Note: We check if the
// dynamic import is allowed without holding any locks, but this is
// okay since the resolver will double check later after we have
// acquired the global lock below.
- if (module.isResolved() && isAllowedDynamicImport(module, pkgName))
+ if ((revision.getWiring() != null) && isAllowedDynamicImport(revision, pkgName))
{
// Acquire global lock.
boolean locked = acquireGlobalLock();
if (!locked)
{
throw new ResolveException(
- "Unable to acquire global lock for resolve.", module, null);
+ "Unable to acquire global lock for resolve.", revision, null);
}
- Map<Module, List<Wire>> wireMap = null;
+ Map<BundleRevision, List<ResolverWire>> wireMap = null;
try
{
// Double check to make sure that someone hasn't beaten us to
// 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.
- List<Wire> wires = module.getWires();
+ List<FelixBundleWire> wires = ((BundleRevisionImpl) revision).getWires();
for (int i = 0; (wires != null) && (i < wires.size()); i++)
{
if (wires.get(i).hasPackage(pkgName))
@@ -4205,23 +4217,28 @@
}
wireMap = m_resolver.resolve(
- m_resolverState, module, pkgName, m_resolverState.getFragments());
+ m_resolverState, revision, pkgName, m_resolverState.getFragments());
- if ((wireMap != null) && wireMap.containsKey(module))
+ if ((wireMap != null) && wireMap.containsKey(revision))
{
- List<Wire> dynamicWires = wireMap.remove(module);
- candidateWire = dynamicWires.get(0);
+ List<ResolverWire> dynamicWires = wireMap.remove(revision);
+ ResolverWire rw = dynamicWires.get(0);
+ candidateWire = new FelixBundleWireImpl(
+ rw.getRequirer(),
+ rw.getRequirement(),
+ rw.getProvider(),
+ rw.getCapability());
- // Mark all modules as resolved.
- markResolvedModules(wireMap);
+ // Mark all revisions as resolved.
+ markResolvedRevisions(wireMap);
- // Dynamically add new wire to importing module.
+ // Dynamically add new wire to importing revision.
if (candidateWire != null)
{
wires = new ArrayList(wires.size() + 1);
- wires.addAll(module.getWires());
+ wires.addAll(((BundleRevisionImpl) revision).getWires());
wires.add(candidateWire);
- ((ModuleImpl) module).setWires(wires);
+ ((BundleRevisionImpl) revision).setWires(wires);
m_logger.log(
Logger.LOG_DEBUG,
"DYNAMIC WIRE: " + wires.get(wires.size() - 1));
@@ -4242,26 +4259,27 @@
// This method duplicates a lot of logic from:
// ResolverImpl.getDynamicImportCandidates()
- boolean isAllowedDynamicImport(Module module, String pkgName)
+ boolean isAllowedDynamicImport(BundleRevision revision, String pkgName)
{
- // Unresolved modules cannot dynamically import, nor can the default
+ // Unresolved revisions cannot dynamically import, nor can the default
// package be dynamically imported.
- if (!module.isResolved() || pkgName.length() == 0)
+ if ((revision.getWiring() == null) || pkgName.length() == 0)
{
return false;
}
- // If the module doesn't have dynamic imports, then just return
+ // If the revision doesn't have dynamic imports, then just return
// immediately.
- List<BundleRequirementImpl> dynamics = module.getResolvedDynamicRequirements();
+ List<BundleRequirement> dynamics =
+ ((BundleRevisionImpl) revision).getResolvedDynamicRequirements();
if ((dynamics == null) || dynamics.isEmpty())
{
return false;
}
- // If any of the module exports this package, then we cannot
+ // If the revision exports this package, then we cannot
// attempt to dynamically import it.
- for (BundleCapabilityImpl cap : module.getResolvedCapabilities())
+ for (BundleCapability cap : revision.getWiring().getCapabilities(null))
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
&& cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
@@ -4271,7 +4289,7 @@
}
// If any of our wires have this package, then we cannot
// attempt to dynamically import it.
- for (Wire w : module.getWires())
+ for (FelixBundleWire w : ((BundleRevisionImpl) revision).getWires())
{
if (w.hasPackage(pkgName))
{
@@ -4285,16 +4303,16 @@
Map<String, Object> attrs = new HashMap(1);
attrs.put(BundleCapabilityImpl.PACKAGE_ATTR, pkgName);
BundleRequirementImpl req = new BundleRequirementImpl(
- module,
+ revision,
BundleCapabilityImpl.PACKAGE_NAMESPACE,
Collections.EMPTY_MAP,
attrs);
- Set<BundleCapabilityImpl> candidates = m_resolverState.getCandidates(req, false);
+ Set<BundleCapability> candidates = m_resolverState.getCandidates(req, false);
return !candidates.isEmpty();
}
- private void markResolvedModules(Map<Module, List<Wire>> wireMap)
+ private void markResolvedRevisions(Map<BundleRevision, List<ResolverWire>> wireMap)
throws ResolveException
{
// DO THIS IN THREE PASSES:
@@ -4306,87 +4324,98 @@
{
// First pass: Loop through the wire map to find the host wires
// for any fragments and map a host to all of its fragments.
- Map<Module, List<Module>> hosts = new HashMap<Module, List<Module>>();
- for (Entry<Module, List<Wire>> entry : wireMap.entrySet())
+ Map<BundleRevision, List<BundleRevision>> hosts =
+ new HashMap<BundleRevision, List<BundleRevision>>();
+ for (Entry<BundleRevision, List<ResolverWire>> entry : wireMap.entrySet())
{
- Module module = entry.getKey();
- List<Wire> wires = entry.getValue();
+ BundleRevision revision = entry.getKey();
+ List<ResolverWire> wires = entry.getValue();
- if (Util.isFragment(module))
+ if (Util.isFragment(revision))
{
- for (Iterator<Wire> itWires = wires.iterator(); itWires.hasNext(); )
+ for (Iterator<ResolverWire> itWires = wires.iterator();
+ itWires.hasNext(); )
{
- Wire w = itWires.next();
- List<Module> fragments = hosts.get(w.getExporter());
+ ResolverWire w = itWires.next();
+ List<BundleRevision> fragments = hosts.get(w.getProvider());
if (fragments == null)
{
- fragments = new ArrayList<Module>();
- hosts.put(w.getExporter(), fragments);
+ fragments = new ArrayList<BundleRevision>();
+ hosts.put(w.getProvider(), fragments);
}
- fragments.add(w.getImporter());
+ fragments.add(w.getRequirer());
}
}
}
// Second pass: Loop through the wire map to set wires and attach
// fragments, if any.
- for (Entry<Module, List<Wire>> entry : wireMap.entrySet())
+ for (Entry<BundleRevision, List<ResolverWire>> entry : wireMap.entrySet())
{
- Module module = entry.getKey();
- List<Wire> wires = entry.getValue();
+ BundleRevision revision = entry.getKey();
+ List<ResolverWire> resolverWires = entry.getValue();
+ List<FelixBundleWire> wires = new ArrayList<FelixBundleWire>();
-// TODO: FRAGMENT RESOLVER - Better way to handle log level?
- for (Iterator<Wire> itWires = wires.iterator(); itWires.hasNext(); )
+ // Convert resolver wires into bundle wires.
+ for (Iterator<ResolverWire> itWires = resolverWires.iterator();
+ itWires.hasNext(); )
{
- Wire w = itWires.next();
- if (!Util.isFragment(module))
+ ResolverWire rw = itWires.next();
+ if (!Util.isFragment(revision))
{
- m_logger.log(Logger.LOG_DEBUG, "WIRE: " + w);
+ m_logger.log(Logger.LOG_DEBUG, "WIRE: " + rw);
}
else
{
m_logger.log(
Logger.LOG_DEBUG,
"FRAGMENT WIRE: "
- + module + " -> hosted by -> " + w.getExporter());
+ + revision + " -> hosted by -> " + rw.getProvider());
}
+ wires.add(
+ new FelixBundleWireImpl(
+ rw.getRequirer(),
+ rw.getRequirement(),
+ rw.getProvider(),
+ rw.getCapability()));
}
- // Set the module's wires. If the module is a resolved
+ // Set the revision's wires. If the revision is a resolved
// fragment, then we must actually append any new host
- // wires to the existing ones.
- if (Util.isFragment(module) && module.isResolved())
+ // wires to the existing ones, since fragments can be attached
+ // to multiple hosts spanning multiple resolve operations.
+ if (Util.isFragment(revision) && (revision.getWiring() != null))
{
- wires.addAll(module.getWires());
+ wires.addAll(((BundleRevisionImpl) revision).getWires());
}
- ((ModuleImpl) module).setWires(wires);
+ ((BundleRevisionImpl) revision).setWires(wires);
// Attach fragments, if any.
- List<Module> fragments = hosts.get(module);
+ List<BundleRevision> fragments = hosts.get(revision);
if (fragments != null)
{
try
{
- ((ModuleImpl) module).attachFragments(fragments);
+ ((BundleRevisionImpl) revision).attachFragments(fragments);
}
catch (Exception ex)
{
// This is a fatal error, so undo everything and
// throw an exception.
- for (Entry<Module, List<Wire>> reentry : wireMap.entrySet())
+ for (Entry<BundleRevision, List<ResolverWire>> reentry : wireMap.entrySet())
{
- module = reentry.getKey();
+ revision = reentry.getKey();
// Undo wires.
- ((ModuleImpl) module).setWires(null);
+ ((BundleRevisionImpl) revision).setWires(null);
- fragments = hosts.get(module);
+ fragments = hosts.get(revision);
if (fragments != null)
{
try
{
// Undo fragments.
- ((ModuleImpl) module).attachFragments(null);
+ ((BundleRevisionImpl) revision).attachFragments(null);
}
catch (Exception ex2)
{
@@ -4400,13 +4429,13 @@
}
// Reindex host with no fragments.
- m_resolverState.addModule(module);
+ m_resolverState.addRevision(revision);
}
}
ResolveException re = new ResolveException(
- "Unable to attach fragments to " + module,
- module, null);
+ "Unable to attach fragments to " + revision,
+ revision, null);
re.initCause(ex);
m_logger.log(
Logger.LOG_ERROR,
@@ -4415,36 +4444,36 @@
}
// Reindex host with attached fragments.
- m_resolverState.addModule(module);
+ m_resolverState.addRevision(revision);
}
}
- // Third pass: Loop through the wire map to mark modules as resolved
+ // Third pass: Loop through the wire map to mark revision as resolved
// and update the resolver state.
- for (Entry<Module, List<Wire>> entry : wireMap.entrySet())
+ for (Entry<BundleRevision, List<ResolverWire>> entry : wireMap.entrySet())
{
- Module module = entry.getKey();
- // Mark module as resolved.
- ((ModuleImpl) module).setResolved();
+ BundleRevision revision = entry.getKey();
+ // Mark revision as resolved.
+ ((BundleRevisionImpl) revision).setResolved();
// Update resolver state to remove substituted capabilities.
- if (!Util.isFragment(module))
+ if (!Util.isFragment(revision))
{
- m_resolverState.removeSubstitutedCapabilities(module);
+ m_resolverState.removeSubstitutedCapabilities(revision);
}
- // Update the state of the module's bundle to resolved as well.
- markBundleResolved(module);
+ // Update the state of the revision's bundle to resolved as well.
+ markBundleResolved(revision);
}
}
}
- private void markBundleResolved(Module module)
+ private void markBundleResolved(BundleRevision revision)
{
// Update the bundle's state to resolved when the
- // current module is resolved; just ignore resolve
+ // current revision is resolved; just ignore resolve
// events for older revisions since this only occurs
// when an update is done on an unresolved bundle
// and there was no refresh performed.
- BundleImpl bundle = (BundleImpl) module.getBundle();
+ BundleImpl bundle = (BundleImpl) revision.getBundle();
// Lock the bundle first.
try
@@ -4458,7 +4487,7 @@
{
// There is nothing we can do.
}
- if (bundle.getCurrentModule() == module)
+ if (bundle.getCurrentRevision() == revision)
{
if (bundle.getState() != Bundle.INSTALLED)
{
@@ -4478,24 +4507,24 @@
}
}
- private void fireResolvedEvents(Map<Module, List<Wire>> wireMap)
+ private void fireResolvedEvents(Map<BundleRevision, List<ResolverWire>> wireMap)
{
if (wireMap != null)
{
- Iterator<Entry<Module, List<Wire>>> iter = wireMap.entrySet().iterator();
+ Iterator<Entry<BundleRevision, List<ResolverWire>>> iter = wireMap.entrySet().iterator();
// Iterate over the map to fire necessary RESOLVED events.
while (iter.hasNext())
{
- Entry<Module, List<Wire>> entry = iter.next();
- Module module = entry.getKey();
+ Entry<BundleRevision, List<ResolverWire>> entry = iter.next();
+ BundleRevision revision = entry.getKey();
// Fire RESOLVED events for all fragments.
- List<Module> fragments = ((ModuleImpl) module).getFragments();
+ List<BundleRevision> fragments = ((BundleRevisionImpl) revision).getFragments();
for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
{
fireBundleEvent(BundleEvent.RESOLVED, fragments.get(i).getBundle());
}
- fireBundleEvent(BundleEvent.RESOLVED, module.getBundle());
+ fireBundleEvent(BundleEvent.RESOLVED, revision.getBundle());
}
}
}
@@ -4694,9 +4723,9 @@
}
else
{
- // This removes all old bundle modules from memory and
- // all old revisions from disk. It only maintains the
- // newest version in the bundle cache.
+ // This removes all old bundle revisions from memory and
+ // from disk. It only maintains the newest revision in the
+ // bundle cache.
refreshBundle(m_bundle);
}
}
diff --git a/framework/src/main/java/org/apache/felix/framework/FilterImpl.java b/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
index 5d5733d..4b2fdb1 100644
--- a/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/FilterImpl.java
@@ -29,12 +29,12 @@
import org.apache.felix.framework.ServiceRegistrationImpl.ServiceReferenceImpl;
import org.apache.felix.framework.capabilityset.CapabilitySet;
import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.wiring.BundleRevision;
public class FilterImpl implements Filter
{
@@ -93,7 +93,7 @@
}
@Override
- public Module getModule()
+ public BundleRevision getRevision()
{
throw new UnsupportedOperationException("Not supported yet.");
}
diff --git a/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java b/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
index 09ac0bc..3718642 100644
--- a/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
@@ -19,14 +19,14 @@
package org.apache.felix.framework;
import java.util.*;
-import org.apache.felix.framework.resolver.Module;
-import org.apache.felix.framework.resolver.Wire;
import org.apache.felix.framework.util.VersionRange;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleRevision;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.packageadmin.RequiredBundle;
@@ -114,7 +114,7 @@
String sym = bundles[i].getSymbolicName();
if ((sym != null) && sym.equals(symbolicName))
{
- Version v = ((BundleImpl) bundles[i]).getCurrentModule().getVersion();
+ Version v = ((BundleImpl) bundles[i]).getCurrentRevision().getVersion();
if ((vr == null) || vr.isInRange(v))
{
list.add(bundles[i]);
@@ -129,8 +129,8 @@
Arrays.sort(bundles,new Comparator() {
public int compare(Object o1, Object o2)
{
- Version v1 = ((BundleImpl) o1).getCurrentModule().getVersion();
- Version v2 = ((BundleImpl) o2).getCurrentModule().getVersion();
+ Version v1 = ((BundleImpl) o1).getCurrentRevision().getVersion();
+ Version v2 = ((BundleImpl) o2).getCurrentRevision().getVersion();
// Compare in reverse order to get descending sort.
return v2.compareTo(v1);
}
@@ -140,7 +140,8 @@
public int getBundleType(Bundle bundle)
{
- Map headerMap = ((BundleImpl) bundle).getCurrentModule().getHeaders();
+ Map headerMap = ((BundleRevisionImpl)
+ ((BundleImpl) bundle).getCurrentRevision()).getHeaders();
if (headerMap.containsKey(Constants.FRAGMENT_HOST))
{
return PackageAdmin.BUNDLE_TYPE_FRAGMENT;
@@ -195,15 +196,15 @@
if ((getBundleType(bundle) & BUNDLE_TYPE_FRAGMENT) == 0)
{
List<Bundle> list = new ArrayList<Bundle>();
- // Iterate through modules
- List<Module> modules = ((BundleImpl) bundle).getModules();
- for (int modIdx = 0; modIdx < modules.size(); modIdx++)
+ // Iterate through revisions
+ List<BundleRevision> revisions = ((BundleImpl) bundle).getRevisions();
+ for (int modIdx = 0; modIdx < revisions.size(); modIdx++)
{
// Get attached fragments.
- ModuleImpl module = (ModuleImpl) modules.get(modIdx);
- if (module.isResolved())
+ BundleRevisionImpl revision = (BundleRevisionImpl) revisions.get(modIdx);
+ if (revision.isResolved())
{
- List<Module> fragments = module.getFragments();
+ List<BundleRevision> fragments = revision.getFragments();
for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
{
Bundle b = fragments.get(i).getBundle();
@@ -215,7 +216,7 @@
}
}
// Convert list to an array.
- return (list.size() == 0)
+ return (list.isEmpty())
? null
: (Bundle[]) list.toArray(new Bundle[list.size()]);
}
@@ -228,18 +229,18 @@
if ((getBundleType(bundle) & BUNDLE_TYPE_FRAGMENT) != 0)
{
List<Bundle> list = new ArrayList<Bundle>();
- // Iterate through modules
- List<Module> modules = ((BundleImpl) bundle).getModules();
- for (int modIdx = 0; modIdx < modules.size(); modIdx++)
+ // Iterate through revisions
+ List<BundleRevision> revisions = ((BundleImpl) bundle).getRevisions();
+ for (int modIdx = 0; modIdx < revisions.size(); modIdx++)
{
// Get hosts
- ModuleImpl module = (ModuleImpl) modules.get(modIdx);
- if (module.isResolved())
+ BundleRevisionImpl revision = (BundleRevisionImpl) revisions.get(modIdx);
+ if (revision.isResolved())
{
- List<Wire> hostWires = module.getWires();
+ List<FelixBundleWire> hostWires = revision.getWires();
for (int i = 0; (hostWires != null) && (i < hostWires.size()); i++)
{
- Bundle b = hostWires.get(i).getExporter().getBundle();
+ Bundle b = hostWires.get(i).getProviderWiring().getBundle();
if (b != null)
{
list.add(b);
@@ -263,12 +264,12 @@
{
BundleImpl impl = (BundleImpl) bundles[i];
if ((symbolicName == null)
- || (symbolicName.equals(impl.getCurrentModule().getSymbolicName())))
+ || (symbolicName.equals(impl.getCurrentRevision().getSymbolicName())))
{
list.add(new RequiredBundleImpl(m_felix, impl));
}
}
- return (list.size() == 0)
+ return (list.isEmpty())
? null
: (RequiredBundle[]) list.toArray(new RequiredBundle[list.size()]);
}
diff --git a/framework/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java b/framework/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java
index 9f013a6..0518172 100644
--- a/framework/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/RequiredBundleImpl.java
@@ -21,9 +21,9 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.apache.felix.framework.resolver.Module;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleRevision;
import org.osgi.service.packageadmin.RequiredBundle;
class RequiredBundleImpl implements RequiredBundle
@@ -57,17 +57,18 @@
return null;
}
- // We need to find all modules that require any of the modules
+ // We need to find all revisions that require any of the revisions
// associated with this bundle and save the associated bundle
- // of the dependent modules.
+ // of the dependent revisions.
Set bundleSet = new HashSet();
- // Loop through all of this bundle's modules.
- List<Module> modules = m_bundle.getModules();
- for (int modIdx = 0; (modules != null) && (modIdx < modules.size()); modIdx++)
+ // Loop through all of this bundle's revisions.
+ List<BundleRevision> revisions = m_bundle.getRevisions();
+ for (int modIdx = 0; (revisions != null) && (modIdx < revisions.size()); modIdx++)
{
- // For each of this bundle's modules, loop through all of the
- // modules that require it and add them to the module list.
- List<Module> dependents = ((ModuleImpl) modules.get(modIdx)).getDependentRequirers();
+ // For each of this bundle's revisions, loop through all of the
+ // revisions that require it and add them to the dependents list.
+ List<BundleRevision> dependents =
+ ((BundleRevisionImpl) revisions.get(modIdx)).getDependentRequirers();
for (int depIdx = 0; (dependents != null) && (depIdx < dependents.size()); depIdx++)
{
if (dependents.get(depIdx).getBundle() != null)
@@ -82,7 +83,7 @@
public Version getVersion()
{
- return m_bundle.getCurrentModule().getVersion();
+ return m_bundle.getVersion();
}
public boolean isRemovalPending()
@@ -95,7 +96,7 @@
if (m_toString == null)
{
m_toString = m_bundle.getSymbolicName()
- + "; version=" + m_bundle.getCurrentModule().getVersion();
+ + "; version=" + m_bundle.getVersion();
}
return m_toString;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java b/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
index 7f26dcf..ff69464 100644
--- a/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ResolverStateImpl.java
@@ -29,25 +29,26 @@
import java.util.TreeSet;
import org.apache.felix.framework.capabilityset.CapabilitySet;
import org.apache.felix.framework.resolver.CandidateComparator;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.resolver.ResolveException;
import org.apache.felix.framework.resolver.Resolver;
-import org.apache.felix.framework.resolver.Wire;
import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.util.manifestparser.R4Library;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.BundlePermission;
import org.osgi.framework.Constants;
import org.osgi.framework.PackagePermission;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
class ResolverStateImpl implements Resolver.ResolverState
{
private final Logger m_logger;
- // Set of all modules.
- private final Set<Module> m_modules;
+ // Set of all revisions.
+ private final Set<BundleRevision> m_revisions;
// Set of all fragments.
- private final Set<Module> m_fragments;
+ private final Set<BundleRevision> m_fragments;
// Capability sets.
private final Map<String, CapabilitySet> m_capSets;
// Execution environment.
@@ -58,8 +59,8 @@
ResolverStateImpl(Logger logger, String fwkExecEnvStr)
{
m_logger = logger;
- m_modules = new HashSet<Module>();
- m_fragments = new HashSet<Module>();
+ m_revisions = new HashSet<BundleRevision>();
+ m_fragments = new HashSet<BundleRevision>();
m_capSets = new HashMap<String, CapabilitySet>();
m_fwkExecEnvStr = (fwkExecEnvStr != null) ? fwkExecEnvStr.trim() : null;
@@ -67,7 +68,7 @@
List<String> indices = new ArrayList<String>();
indices.add(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
- m_capSets.put(BundleCapabilityImpl.MODULE_NAMESPACE, new CapabilitySet(indices, true));
+ m_capSets.put(BundleCapabilityImpl.BUNDLE_NAMESPACE, new CapabilitySet(indices, true));
indices = new ArrayList<String>();
indices.add(BundleCapabilityImpl.PACKAGE_ATTR);
@@ -78,15 +79,15 @@
m_capSets.put(BundleCapabilityImpl.HOST_NAMESPACE, new CapabilitySet(indices, true));
}
- synchronized void addModule(Module m)
+ synchronized void addRevision(BundleRevision br)
{
- m_modules.add(m);
- List<BundleCapabilityImpl> caps = (m.isResolved())
- ? m.getResolvedCapabilities()
- : m.getDeclaredCapabilities();
+ m_revisions.add(br);
+ List<BundleCapability> caps = (br.getWiring() == null)
+ ? br.getDeclaredCapabilities(null)
+ : br.getWiring().getCapabilities(null);
if (caps != null)
{
- for (BundleCapabilityImpl cap : caps)
+ for (BundleCapability cap : caps)
{
CapabilitySet capSet = m_capSets.get(cap.getNamespace());
if (capSet == null)
@@ -98,21 +99,21 @@
}
}
- if (Util.isFragment(m))
+ if (Util.isFragment(br))
{
- m_fragments.add(m);
+ m_fragments.add(br);
}
}
- synchronized void removeModule(Module m)
+ synchronized void removeRevision(BundleRevision br)
{
- m_modules.remove(m);
- List<BundleCapabilityImpl> caps = (m.isResolved())
- ? m.getResolvedCapabilities()
- : m.getDeclaredCapabilities();
+ m_revisions.remove(br);
+ List<BundleCapability> caps = (br.getWiring() == null)
+ ? br.getDeclaredCapabilities(null)
+ : br.getWiring().getCapabilities(null);
if (caps != null)
{
- for (BundleCapabilityImpl cap : caps)
+ for (BundleCapability cap : caps)
{
CapabilitySet capSet = m_capSets.get(cap.getNamespace());
if (capSet != null)
@@ -122,31 +123,33 @@
}
}
- if (Util.isFragment(m))
+ if (Util.isFragment(br))
{
- m_fragments.remove(m);
+ m_fragments.remove(br);
}
}
- synchronized Set<Module> getFragments()
+ synchronized Set<BundleRevision> getFragments()
{
return new HashSet(m_fragments);
}
- synchronized void removeSubstitutedCapabilities(Module m)
+// TODO: OSGi R4.3 - This will need to be changed once BundleWiring.getCapabilities()
+// is correctly implemented, since they already has to remove substituted caps.
+ synchronized void removeSubstitutedCapabilities(BundleRevision br)
{
- if (m.isResolved())
+ if (br.getWiring() != null)
{
- // Loop through the module's package wires and determine if any
- // of them overlap any of the packages exported by the module.
- // If so, then the framework must have chosen to have the module
+ // Loop through the revision's package wires and determine if any
+ // of them overlap any of the packages exported by the revision.
+ // 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 (Wire w : m.getWires())
+ for (FelixBundleWire w : ((BundleRevisionImpl) br).getWires())
{
if (w.getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
- for (BundleCapabilityImpl cap : m.getResolvedCapabilities())
+ for (BundleCapability cap : br.getWiring().getCapabilities(null))
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
&& w.getCapability().getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR)
@@ -165,53 +168,54 @@
// ResolverState methods.
//
- public synchronized SortedSet<BundleCapabilityImpl> getCandidates(
+ public synchronized SortedSet<BundleCapability> getCandidates(
BundleRequirementImpl req, boolean obeyMandatory)
{
- Module module = req.getModule();
- SortedSet<BundleCapabilityImpl> result = new TreeSet<BundleCapabilityImpl>(new CandidateComparator());
+ BundleRevisionImpl reqRevision = (BundleRevisionImpl) req.getRevision();
+ SortedSet<BundleCapability> result =
+ new TreeSet<BundleCapability>(new CandidateComparator());
CapabilitySet capSet = m_capSets.get(req.getNamespace());
if (capSet != null)
{
- Set<BundleCapabilityImpl> matches = capSet.match(req.getFilter(), obeyMandatory);
- for (BundleCapabilityImpl cap : matches)
+ Set<BundleCapability> matches = capSet.match(req.getFilter(), obeyMandatory);
+ for (BundleCapability cap : matches)
{
if (System.getSecurityManager() != null)
{
if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) && (
- !((BundleProtectionDomain) cap.getModule().getSecurityContext()).impliesDirect(
+ !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getSecurityContext()).impliesDirect(
new PackagePermission((String) cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR),
PackagePermission.EXPORTONLY)) ||
- !((module == null) ||
- ((BundleProtectionDomain) module.getSecurityContext()).impliesDirect(
+ !((reqRevision == null) ||
+ ((BundleProtectionDomain) reqRevision.getSecurityContext()).impliesDirect(
new PackagePermission((String) cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR),
- cap.getModule().getBundle(),PackagePermission.IMPORT))
+ cap.getRevision().getBundle(),PackagePermission.IMPORT))
)))
{
- if (module != cap.getModule())
+ if (reqRevision != cap.getRevision())
{
continue;
}
}
- else if (req.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE) && (
- !((BundleProtectionDomain) cap.getModule().getSecurityContext()).impliesDirect(
- new BundlePermission(cap.getModule().getSymbolicName(), BundlePermission.PROVIDE)) ||
- !((module == null) ||
- ((BundleProtectionDomain) module.getSecurityContext()).impliesDirect(
- new BundlePermission(module.getSymbolicName(), BundlePermission.REQUIRE))
+ else if (req.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE) && (
+ !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getSecurityContext()).impliesDirect(
+ new BundlePermission(cap.getRevision().getSymbolicName(), BundlePermission.PROVIDE)) ||
+ !((reqRevision == null) ||
+ ((BundleProtectionDomain) reqRevision.getSecurityContext()).impliesDirect(
+ new BundlePermission(reqRevision.getSymbolicName(), BundlePermission.REQUIRE))
)))
{
continue;
}
else if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE) &&
- (!((BundleProtectionDomain) req.getModule().getSecurityContext())
+ (!((BundleProtectionDomain) reqRevision.getSecurityContext())
.impliesDirect(new BundlePermission(
- req.getModule().getSymbolicName(),
+ reqRevision.getSymbolicName(),
BundlePermission.FRAGMENT))
- || !((BundleProtectionDomain) cap.getModule().getSecurityContext())
+ || !((BundleProtectionDomain) ((BundleRevisionImpl) cap.getRevision()).getSecurityContext())
.impliesDirect(new BundlePermission(
- cap.getModule().getSymbolicName(),
+ cap.getRevision().getSymbolicName(),
BundlePermission.HOST))))
{
continue;
@@ -219,7 +223,7 @@
}
if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE)
- && cap.getModule().isResolved())
+ && (cap.getRevision().getWiring() != null))
{
continue;
}
@@ -231,10 +235,11 @@
return result;
}
- public void checkExecutionEnvironment(Module module) throws ResolveException
+ public void checkExecutionEnvironment(BundleRevision revision) throws ResolveException
{
String bundleExecEnvStr = (String)
- module.getHeaders().get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
+ ((BundleRevisionImpl) revision).getHeaders().get(
+ Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
if (bundleExecEnvStr != null)
{
bundleExecEnvStr = bundleExecEnvStr.trim();
@@ -259,17 +264,17 @@
{
throw new ResolveException(
"Execution environment not supported: "
- + bundleExecEnvStr, module, null);
+ + bundleExecEnvStr, revision, null);
}
}
}
}
- public void checkNativeLibraries(Module module) throws ResolveException
+ public void checkNativeLibraries(BundleRevision revision) throws ResolveException
{
- // Next, try to resolve any native code, since the module is
+ // Next, try to resolve any native code, since the revision is
// not resolvable if its native code cannot be loaded.
- List<R4Library> libs = module.getNativeLibraries();
+ List<R4Library> libs = ((BundleRevisionImpl) revision).getNativeLibraries();
if (libs != null)
{
String msg = null;
@@ -280,7 +285,7 @@
String entryName = libs.get(libIdx).getEntryName();
if (entryName != null)
{
- if (!module.getContent().hasEntry(entryName))
+ if (!((BundleRevisionImpl) revision).getContent().hasEntry(entryName))
{
msg = "Native library does not exist: " + entryName;
}
@@ -295,7 +300,7 @@
}
if (msg != null)
{
- throw new ResolveException(msg, module, null);
+ throw new ResolveException(msg, revision, null);
}
}
}
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
index fa96d9b..7cfb8cb 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
@@ -22,15 +22,15 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.*;
-import org.apache.felix.framework.resolver.Module;
-import org.apache.felix.framework.resolver.Wire;
import org.apache.felix.framework.util.MapToDictionary;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.*;
import org.osgi.framework.BundleReference;
+import org.osgi.framework.wiring.BundleRevision;
class ServiceRegistrationImpl implements ServiceRegistration
{
@@ -403,7 +403,7 @@
//
@Override
- public Module getModule()
+ public BundleRevision getRevision()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -485,12 +485,12 @@
// Get the package.
String pkgName =
Util.getClassPackage(className);
- Module requesterModule = ((BundleImpl) requester).getCurrentModule();
+ BundleRevision requesterRevision = ((BundleImpl) requester).getCurrentRevision();
// Get package wiring from service requester.
- Wire requesterWire = Util.getWire(requesterModule, pkgName);
+ FelixBundleWire requesterWire = Util.getWire(requesterRevision, pkgName);
// Get package wiring from service provider.
- Module providerModule = ((BundleImpl) m_bundle).getCurrentModule();
- Wire providerWire = Util.getWire(providerModule, pkgName);
+ BundleRevision providerRevision = ((BundleImpl) m_bundle).getCurrentRevision();
+ FelixBundleWire providerWire = Util.getWire(providerRevision, pkgName);
// There are four situations that may occur here:
// 1. Neither the requester, nor provider have wires for the package.
@@ -505,10 +505,10 @@
// the service is wired. Otherwise, as in case 1, if the requester
// does not have access to the class at all, we do not filter, but if
// it does have access we check if it is the same class accessible to
- // the providing module. For case 3, the provider will not have a wire
+ // the providing revision. For case 3, the provider will not have a wire
// if it is exporting the package, so we determine if the requester
// is wired to it or somehow using the same class. For case 4, we
- // simply compare the exporting modules from the package wiring to
+ // simply compare the exporting revisions from the package wiring to
// determine if we need to filter the service reference.
// Case 1: Both requester and provider have no wire.
@@ -518,7 +518,8 @@
// registration must have same class as requester.
try
{
- Class requestClass = requesterModule.getClassByDelegation(className);
+ Class requestClass =
+ ((BundleRevisionImpl) requesterRevision).getClassByDelegation(className);
allow = getRegistration().isClassAccessible(requestClass);
}
catch (Exception ex)
@@ -532,7 +533,7 @@
else if ((requesterWire == null) && (providerWire != null))
{
// Allow if the requester is the exporter of the provider's wire.
- if (providerWire.getExporter().equals(requesterModule))
+ if (providerWire.getProviderWiring().getRevision().equals(requesterRevision))
{
allow = true;
}
@@ -543,7 +544,8 @@
try
{
// Try to load class from requester.
- Class requestClass = requesterModule.getClassByDelegation(className);
+ Class requestClass =((BundleRevisionImpl)
+ requesterRevision).getClassByDelegation(className);
try
{
// If requester has access to the class, verify it is the
@@ -569,9 +571,10 @@
// If the provider is the exporter of the requester's package, then check
// if the requester is wired to the latest version of the provider, if so
// then allow else don't (the provider has been updated but not refreshed).
- if (((BundleImpl) m_bundle).hasModule(requesterWire.getExporter()))
+ if (((BundleImpl) m_bundle).hasRevision(
+ requesterWire.getProviderWiring().getRevision()))
{
- allow = providerModule.equals(requesterWire.getExporter());
+ allow = providerRevision.equals(requesterWire.getProviderWiring().getRevision());
}
// If the provider is not the exporter of the requester's package,
// then try to use the service registration to see if the requester's
@@ -581,7 +584,8 @@
try
{
// Load the class from the requesting bundle.
- Class requestClass = requesterModule.getClassByDelegation(className);
+ Class requestClass = ((BundleRevisionImpl)
+ requesterRevision).getClassByDelegation(className);
// Get the service registration and ask it to check
// if the service object is assignable to the requesting
// bundle's class.
@@ -598,8 +602,9 @@
else
{
// Include service reference if the wires have the
- // same source module.
- allow = providerWire.getExporter().equals(requesterWire.getExporter());
+ // same source revision.
+ allow = providerWire.getProviderWiring().getRevision()
+ .equals(requesterWire.getProviderWiring().getRevision());
}
return allow;
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index b0a2cfa..1dfe6a5 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -26,6 +26,7 @@
import org.osgi.framework.*;
import org.osgi.framework.hooks.service.*;
import org.osgi.framework.launch.Framework;
+import org.osgi.framework.wiring.BundleCapability;
public class ServiceRegistry
{
@@ -208,7 +209,7 @@
}
// else just use the specified filter.
- Set<BundleCapabilityImpl> matches = m_regCapSet.match(filter, false);
+ Set<BundleCapability> matches = m_regCapSet.match(filter, false);
return new ArrayList(matches);
}
diff --git a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java
index 7e856a7..e701477 100644
--- a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java
+++ b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java
@@ -132,7 +132,7 @@
}
}
Felix felix = (Felix) framework;
- long bundleId = Util.getBundleIdFromModuleId(u.getHost());
+ long bundleId = Util.getBundleIdFromRevisionId(u.getHost());
Bundle bundle = felix.getBundle(bundleId);
if (bundle != null)
{
diff --git a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
index f5bddb8..54f34c5 100644
--- a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
+++ b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
@@ -24,14 +24,14 @@
import java.net.URLConnection;
import java.security.Permission;
import java.util.List;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.Util;
+import org.osgi.framework.wiring.BundleRevision;
class URLHandlersBundleURLConnection extends URLConnection
{
private Felix m_framework;
- private Module m_targetModule;
+ private BundleRevision m_targetRevision;
private int m_classPathIdx = -1;
private int m_contentLength;
private long m_contentTime;
@@ -78,9 +78,9 @@
}
// Verify that the resource pointed to by the URL exists.
// The URL is constructed like this:
- // bundle://<module-id>:<bundle-classpath-index>/<resource-path>
- // Where <module-id> = <bundle-id>.<revision>
- long bundleId = Util.getBundleIdFromModuleId(url.getHost());
+ // bundle://<revision-id>:<bundle-classpath-index>/<resource-path>
+ // Where <revision-id> = <bundle-id>.<revision>
+ long bundleId = Util.getBundleIdFromRevisionId(url.getHost());
BundleImpl bundle = (BundleImpl) m_framework.getBundle(bundleId);
if (bundle == null)
{
@@ -88,27 +88,27 @@
}
m_contentTime = bundle.getLastModified();
- // Get the bundle's modules to find the target module.
- List<Module> modules = bundle.getModules();
- if ((modules == null) || modules.isEmpty())
+ // Get the bundle's revisions to find the target revision.
+ List<BundleRevision> revisions = bundle.getRevisions();
+ if ((revisions == null) || revisions.isEmpty())
{
throw new IOException("Resource does not exist: " + url);
}
- // Search for matching module name.
- for (Module m : modules)
+ // Search for matching revision name.
+ for (BundleRevision br : revisions)
{
- if (m.getId().equals(url.getHost()))
+ if (((BundleRevisionImpl) br).getId().equals(url.getHost()))
{
- m_targetModule = m;
+ m_targetRevision = br;
break;
}
}
- // If not found, assume the current module.
- if (m_targetModule == null)
+ // If not found, assume the current revision.
+ if (m_targetRevision == null)
{
- m_targetModule = modules.get(modules.size() - 1);
+ m_targetRevision = revisions.get(revisions.size() - 1);
}
// If the resource cannot be found at the current class path index,
@@ -123,9 +123,11 @@
{
m_classPathIdx = 0;
}
- if (!m_targetModule.hasInputStream(m_classPathIdx, url.getPath()))
+ if (!((BundleRevisionImpl) m_targetRevision)
+ .hasInputStream(m_classPathIdx, url.getPath()))
{
- URL newurl = m_targetModule.getResourceByDelegation(url.getPath());
+ URL newurl = ((BundleRevisionImpl)
+ m_targetRevision).getResourceByDelegation(url.getPath());
if (newurl == null)
{
throw new IOException("Resource does not exist: " + url);
@@ -138,11 +140,12 @@
{
if (!connected)
{
- if ((m_targetModule == null) || (m_classPathIdx < 0))
+ if ((m_targetRevision == null) || (m_classPathIdx < 0))
{
throw new IOException("Resource does not exist: " + url);
}
- m_is = m_targetModule.getInputStream(m_classPathIdx, url.getPath());
+ m_is = ((BundleRevisionImpl)
+ m_targetRevision).getInputStream(m_classPathIdx, url.getPath());
m_contentLength = (m_is == null) ? 0 : m_is.available();
m_contentType = URLConnection.guessContentTypeFromName(url.getFile());
connected = true;
@@ -223,10 +226,11 @@
*/
URL getLocalURL()
{
- if ((m_targetModule == null) || (m_classPathIdx < 0))
+ if ((m_targetRevision == null) || (m_classPathIdx < 0))
{
return url;
}
- return m_targetModule.getLocalURL(m_classPathIdx, url.getPath());
+ return ((BundleRevisionImpl)
+ m_targetRevision).getLocalURL(m_classPathIdx, url.getPath());
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
index df3e1c0..1dfe525 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
@@ -33,32 +33,33 @@
import org.apache.felix.framework.util.SecureAction;
import org.apache.felix.framework.util.StringComparator;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
+import org.osgi.framework.wiring.BundleCapability;
public class CapabilitySet
{
- private final Map<String, Map<Object, Set<BundleCapabilityImpl>>> m_indices;
- private final Set<BundleCapabilityImpl> m_capSet = new HashSet<BundleCapabilityImpl>();
+ private final Map<String, Map<Object, Set<BundleCapability>>> m_indices;
+ private final Set<BundleCapability> m_capSet = new HashSet<BundleCapability>();
private final static SecureAction m_secureAction = new SecureAction();
public CapabilitySet(List<String> indexProps, boolean caseSensitive)
{
m_indices = (caseSensitive)
- ? new TreeMap<String, Map<Object, Set<BundleCapabilityImpl>>>()
- : new TreeMap<String, Map<Object, Set<BundleCapabilityImpl>>>(
+ ? new TreeMap<String, Map<Object, Set<BundleCapability>>>()
+ : new TreeMap<String, Map<Object, Set<BundleCapability>>>(
new StringComparator(false));
for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++)
{
m_indices.put(
- indexProps.get(i), new HashMap<Object, Set<BundleCapabilityImpl>>());
+ indexProps.get(i), new HashMap<Object, Set<BundleCapability>>());
}
}
- public void addCapability(BundleCapabilityImpl cap)
+ public void addCapability(BundleCapability cap)
{
m_capSet.add(cap);
// Index capability.
- for (Entry<String, Map<Object, Set<BundleCapabilityImpl>>> entry : m_indices.entrySet())
+ for (Entry<String, Map<Object, Set<BundleCapability>>> entry : m_indices.entrySet())
{
Object value = cap.getAttributes().get(entry.getKey());
if (value != null)
@@ -68,7 +69,7 @@
value = convertArrayToList(value);
}
- Map<Object, Set<BundleCapabilityImpl>> index = entry.getValue();
+ Map<Object, Set<BundleCapability>> index = entry.getValue();
if (value instanceof Collection)
{
@@ -87,22 +88,22 @@
}
private void indexCapability(
- Map<Object, Set<BundleCapabilityImpl>> index, BundleCapabilityImpl cap, Object capValue)
+ Map<Object, Set<BundleCapability>> index, BundleCapability cap, Object capValue)
{
- Set<BundleCapabilityImpl> caps = index.get(capValue);
+ Set<BundleCapability> caps = index.get(capValue);
if (caps == null)
{
- caps = new HashSet<BundleCapabilityImpl>();
+ caps = new HashSet<BundleCapability>();
index.put(capValue, caps);
}
caps.add(cap);
}
- public void removeCapability(BundleCapabilityImpl cap)
+ public void removeCapability(BundleCapability cap)
{
if (m_capSet.remove(cap))
{
- for (Entry<String, Map<Object, Set<BundleCapabilityImpl>>> entry : m_indices.entrySet())
+ for (Entry<String, Map<Object, Set<BundleCapability>>> entry : m_indices.entrySet())
{
Object value = cap.getAttributes().get(entry.getKey());
if (value != null)
@@ -112,7 +113,7 @@
value = convertArrayToList(value);
}
- Map<Object, Set<BundleCapabilityImpl>> index = entry.getValue();
+ Map<Object, Set<BundleCapability>> index = entry.getValue();
if (value instanceof Collection)
{
@@ -132,9 +133,9 @@
}
private void deindexCapability(
- Map<Object, Set<BundleCapabilityImpl>> index, BundleCapabilityImpl cap, Object value)
+ Map<Object, Set<BundleCapability>> index, BundleCapability cap, Object value)
{
- Set<BundleCapabilityImpl> caps = index.get(value);
+ Set<BundleCapability> caps = index.get(value);
if (caps != null)
{
caps.remove(cap);
@@ -145,17 +146,17 @@
}
}
- public Set<BundleCapabilityImpl> match(SimpleFilter sf, boolean obeyMandatory)
+ public Set<BundleCapability> match(SimpleFilter sf, boolean obeyMandatory)
{
- Set<BundleCapabilityImpl> matches = match(m_capSet, sf);
+ Set<BundleCapability> matches = match(m_capSet, sf);
return (obeyMandatory)
? matchMandatory(matches, sf)
: matches;
}
- private Set<BundleCapabilityImpl> match(Set<BundleCapabilityImpl> caps, SimpleFilter sf)
+ private Set<BundleCapability> match(Set<BundleCapability> caps, SimpleFilter sf)
{
- Set<BundleCapabilityImpl> matches = new HashSet<BundleCapabilityImpl>();
+ Set<BundleCapability> matches = new HashSet<BundleCapability>();
if (sf.getOperation() == SimpleFilter.MATCH_ALL)
{
@@ -197,10 +198,10 @@
}
else
{
- Map<Object, Set<BundleCapabilityImpl>> index = m_indices.get(sf.getName());
+ Map<Object, Set<BundleCapability>> index = m_indices.get(sf.getName());
if ((sf.getOperation() == SimpleFilter.EQ) && (index != null))
{
- Set<BundleCapabilityImpl> existingCaps = index.get(sf.getValue());
+ Set<BundleCapability> existingCaps = index.get(sf.getValue());
if (existingCaps != null)
{
matches.addAll(existingCaps);
@@ -209,9 +210,9 @@
}
else
{
- for (Iterator<BundleCapabilityImpl> it = caps.iterator(); it.hasNext(); )
+ for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
{
- BundleCapabilityImpl cap = it.next();
+ BundleCapability cap = it.next();
Object lhs = cap.getAttributes().get(sf.getName());
if (lhs != null)
{
@@ -227,12 +228,12 @@
return matches;
}
- public static boolean matches(BundleCapabilityImpl cap, SimpleFilter sf)
+ public static boolean matches(BundleCapability cap, SimpleFilter sf)
{
return matchesInternal(cap, sf) && matchMandatory(cap, sf);
}
- private static boolean matchesInternal(BundleCapabilityImpl cap, SimpleFilter sf)
+ private static boolean matchesInternal(BundleCapability cap, SimpleFilter sf)
{
boolean matched = true;
@@ -282,12 +283,12 @@
return matched;
}
- private static Set<BundleCapabilityImpl> matchMandatory(
- Set<BundleCapabilityImpl> caps, SimpleFilter sf)
+ private static Set<BundleCapability> matchMandatory(
+ Set<BundleCapability> caps, SimpleFilter sf)
{
- for (Iterator<BundleCapabilityImpl> it = caps.iterator(); it.hasNext(); )
+ for (Iterator<BundleCapability> it = caps.iterator(); it.hasNext(); )
{
- BundleCapabilityImpl cap = it.next();
+ BundleCapability cap = it.next();
if (!matchMandatory(cap, sf))
{
it.remove();
@@ -296,12 +297,12 @@
return caps;
}
- private static boolean matchMandatory(BundleCapabilityImpl cap, SimpleFilter sf)
+ private static boolean matchMandatory(BundleCapability cap, SimpleFilter sf)
{
Map<String, Object> attrs = cap.getAttributes();
for (Entry<String, Object> entry : attrs.entrySet())
{
- if (cap.isAttributeMandatory(entry.getKey())
+ if (((BundleCapabilityImpl) cap).isAttributeMandatory(entry.getKey())
&& !matchMandatoryAttrbute(entry.getKey(), sf))
{
return false;
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java b/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
index c42c6bd..7a96ad1 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java
@@ -22,26 +22,29 @@
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleCapability;
-public class CandidateComparator implements Comparator<BundleCapabilityImpl>
+public class CandidateComparator implements Comparator<BundleCapability>
{
- public int compare(BundleCapabilityImpl cap1, BundleCapabilityImpl cap2)
+ public int compare(BundleCapability cap1, BundleCapability cap2)
{
// First check resolved state, since resolved capabilities have priority
// over unresolved ones. Compare in reverse order since we want to sort
// in descending order.
int c = 0;
- if (cap1.getModule().isResolved() && !cap2.getModule().isResolved())
+ if ((cap1.getRevision().getWiring() != null)
+ && (cap2.getRevision().getWiring() == null))
{
c = -1;
}
- else if (!cap1.getModule().isResolved() && cap2.getModule().isResolved())
+ else if ((cap1.getRevision().getWiring() == null)
+ && (cap2.getRevision().getWiring() != null))
{
c = 1;
}
- // Compare module capabilities.
- if ((c == 0) && cap1.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ // Compare revision capabilities.
+ if ((c == 0) && cap1.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
c = ((Comparable) cap1.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE))
.compareTo(cap2.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
@@ -77,16 +80,16 @@
}
}
- // Finally, compare module identity.
+ // Finally, compare bundle identity.
if (c == 0)
{
- if (cap1.getModule().getBundle().getBundleId() <
- cap2.getModule().getBundle().getBundleId())
+ if (cap1.getRevision().getBundle().getBundleId() <
+ cap2.getRevision().getBundle().getBundleId())
{
c = -1;
}
- else if (cap1.getModule().getBundle().getBundleId() >
- cap2.getModule().getBundle().getBundleId())
+ else if (cap1.getRevision().getBundle().getBundleId() >
+ cap2.getRevision().getBundle().getBundleId())
{
c = 1;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
index 83ff55f..2d01768 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
@@ -30,34 +30,38 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import org.apache.felix.framework.BundleRevisionImpl;
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 Module m_root;
+ private final BundleRevision m_root;
- // Set of all candidate modules.
- private final Set<Module> m_candidateModules;
+ // Set of all candidate bundle revisions.
+ private final Set<BundleRevision> m_candidateRevisions;
// Maps a capability to requirements that match it.
- private final Map<BundleCapabilityImpl, Set<BundleRequirementImpl>> m_dependentMap;
+ private final Map<BundleCapability, Set<BundleRequirement>> m_dependentMap;
// Maps a requirement to the capability it matches.
- private final Map<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> m_candidateMap;
+ private final Map<BundleRequirement, SortedSet<BundleCapability>> 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<BundleCapabilityImpl,
- Map<String, Map<Version, List<BundleRequirementImpl>>>> 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;
+ 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;
// Map used when populating candidates to hold intermediate and final results.
- private final Map<Module, Object> m_populateResultCache;
+ private final Map<BundleRevision, Object> m_populateResultCache;
// Flag to signal if fragments are present in the candidate map.
private boolean m_fragmentsPresent = false;
@@ -71,16 +75,16 @@
* @param wrappedHosts the wrapped hosts map.
**/
private Candidates(
- Module root,
- Set<Module> candidateModules,
- Map<BundleCapabilityImpl, Set<BundleRequirementImpl>> dependentMap,
- Map<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> candidateMap,
- Map<BundleCapabilityImpl, Map<String, Map<Version, List<BundleRequirementImpl>>>> hostFragments,
- Map<Module, HostModule> wrappedHosts, Map<Module, Object> populateResultCache,
+ 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,
boolean fragmentsPresent)
{
m_root = root;
- m_candidateModules = candidateModules;
+ m_candidateRevisions = candidateRevisions;
m_dependentMap = dependentMap;
m_candidateMap = candidateMap;
m_hostFragments = hostFragments;
@@ -94,16 +98,16 @@
* @param state the resolver state used for populating the candidates.
* @param root the root module for the resolve.
**/
- public Candidates(ResolverState state, Module root)
+ public Candidates(ResolverState state, BundleRevision root)
{
m_root = root;
- m_candidateModules = new HashSet<Module>();
- m_dependentMap = new HashMap<BundleCapabilityImpl, Set<BundleRequirementImpl>>();
- m_candidateMap = new HashMap<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>>();
+ m_candidateRevisions = new HashSet<BundleRevision>();
+ m_dependentMap = new HashMap<BundleCapability, Set<BundleRequirement>>();
+ m_candidateMap = new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
m_hostFragments =
- new HashMap<BundleCapabilityImpl, Map<String, Map<Version, List<BundleRequirementImpl>>>>();
- m_allWrappedHosts = new HashMap<Module, HostModule>();
- m_populateResultCache = new HashMap<Module, Object>();
+ new HashMap<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>>();
+ m_allWrappedHosts = new HashMap<BundleRevision, HostBundleRevision>();
+ m_populateResultCache = new HashMap<BundleRevision, Object>();
populate(state, m_root);
}
@@ -118,17 +122,17 @@
* @param req the requirement being resolved.
* @param candidates the potential candidates matching the requirement.
**/
- public Candidates(ResolverState state, Module root,
- BundleRequirementImpl req, SortedSet<BundleCapabilityImpl> candidates)
+ public Candidates(ResolverState state, BundleRevision root,
+ BundleRequirement req, SortedSet<BundleCapability> candidates)
{
m_root = root;
- m_candidateModules = new HashSet<Module>();
- m_dependentMap = new HashMap<BundleCapabilityImpl, Set<BundleRequirementImpl>>();
- m_candidateMap = new HashMap<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>>();
+ m_candidateRevisions = new HashSet<BundleRevision>();
+ m_dependentMap = new HashMap<BundleCapability, Set<BundleRequirement>>();
+ m_candidateMap = new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
m_hostFragments =
- new HashMap<BundleCapabilityImpl, Map<String, Map<Version, List<BundleRequirementImpl>>>>();
- m_allWrappedHosts = new HashMap<Module, HostModule>();
- m_populateResultCache = new HashMap<Module, Object>();
+ new HashMap<BundleCapability, Map<String, Map<Version, List<BundleRequirement>>>>();
+ m_allWrappedHosts = new HashMap<BundleRevision, HostBundleRevision>();
+ m_populateResultCache = new HashMap<BundleRevision, Object>();
add(req, candidates);
@@ -138,17 +142,17 @@
/**
* Populates additional candidates for the specified module.
* @param state the resolver state used for populating the candidates.
- * @param module the module whose candidates should be populated.
+ * @param revision the module whose candidates should be populated.
*/
// TODO: FELIX3 - Modify to not be recursive.
- public final void populate(ResolverState state, Module module)
+ public final void populate(ResolverState state, BundleRevision revision)
{
- // Determine if we've already calculated this module's candidates.
+ // Determine if we've already calculated this revision's candidates.
// The result cache will have one of three values:
// 1. A resolve exception if we've already attempted to populate the
- // module's candidates but were unsuccessful.
+ // revision's candidates but were unsuccessful.
// 2. Boolean.TRUE indicating we've already attempted to populate the
- // module's candidates and were successful.
+ // revision'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.
@@ -158,19 +162,19 @@
// until we've popped completely out of the cycle.
// Keeps track of the number of times we've reentered this method
- // for the current module.
+ // for the current revision.
Integer cycleCount = null;
// Keeps track of the candidates we've already calculated for the
- // current module's requirements.
- Map<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> localCandidateMap = null;
+ // current revision's requirements.
+ Map<BundleRequirement, SortedSet<BundleCapability>> localCandidateMap = null;
- // Keeps track of the current module's requirements for which we
+ // Keeps track of the current revision's requirements for which we
// haven't yet found candidates.
- List<BundleRequirementImpl> remainingReqs = null;
+ List<BundleRequirement> remainingReqs = null;
- // Get the cache value for the current module.
- Object cacheValue = m_populateResultCache.get(module);
+ // Get the cache value for the current revision.
+ Object cacheValue = m_populateResultCache.get(revision);
// This is case 1.
if (cacheValue instanceof ResolveException)
@@ -195,66 +199,67 @@
remainingReqs = (List) ((Object[]) cacheValue)[2];
}
- // If there is no cache value for the current module, then this is
+ // If there is no cache value for the current revision, 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(module);
+ state.checkExecutionEnvironment(revision);
// Verify that any native libraries match the current platform.
- state.checkNativeLibraries(module);
+ state.checkNativeLibraries(revision);
// Record cycle count.
cycleCount = new Integer(0);
// Create a local map for populating candidates first, just in case
- // the module is not resolvable.
+ // the revision is not resolvable.
localCandidateMap = new HashMap();
- // Create a modifiable list of the module's requirements.
- remainingReqs = new ArrayList(module.getDeclaredRequirements());
+ // Create a modifiable list of the revision's requirements.
+ remainingReqs = new ArrayList(revision.getDeclaredRequirements(null));
// Add these value to the result cache so we know we are
// in the middle of populating candidates for the current
- // module.
- m_populateResultCache.put(module,
+ // revision.
+ m_populateResultCache.put(revision,
cacheValue = new Object[] { cycleCount, localCandidateMap, remainingReqs });
}
// If we have requirements remaining, then find candidates for them.
while (remainingReqs.size() > 0)
{
- BundleRequirementImpl req = remainingReqs.remove(0);
+ BundleRequirement req = remainingReqs.remove(0);
// Get satisfying candidates and populate their candidates if necessary.
ResolveException rethrow = null;
- SortedSet<BundleCapabilityImpl> candidates = state.getCandidates(req, true);
- for (Iterator<BundleCapabilityImpl> itCandCap = candidates.iterator();
+ SortedSet<BundleCapability> candidates =
+ state.getCandidates((BundleRequirementImpl) req, true);
+ for (Iterator<BundleCapability> itCandCap = candidates.iterator();
itCandCap.hasNext(); )
{
- BundleCapabilityImpl candCap = itCandCap.next();
+ BundleCapability candCap = itCandCap.next();
- // If the candidate module is a fragment, then always attempt
+ // If the candidate revision 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
- // module is not already resolved and is not the current module
+ // revision is not already resolved and is not the current version
// 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 module is equal to the current module, but this
+ // candidate revision is equal to the current revision, 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.getModule())
- || (!candCap.getModule().isResolved()
- && !candCap.getModule().equals(module)))
+ if (Util.isFragment(candCap.getRevision())
+ || ((candCap.getRevision().getWiring() == null)
+ && !candCap.getRevision().equals(revision)))
{
try
{
- populate(state, candCap.getModule());
+ populate(state, candCap.getRevision());
}
catch (ResolveException ex)
{
@@ -272,16 +277,16 @@
// 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() && !req.isOptional())
+ if (candidates.isEmpty() && !((BundleRequirementImpl) req).isOptional())
{
- String msg = "Unable to resolve " + module
+ String msg = "Unable to resolve " + revision
+ ": missing requirement " + req;
if (rethrow != null)
{
msg = msg + " [caused by: " + rethrow.getMessage() + "]";
}
- rethrow = new ResolveException(msg, module, req);
- m_populateResultCache.put(module, rethrow);
+ rethrow = new ResolveException(msg, revision, req);
+ m_populateResultCache.put(revision, rethrow);
throw rethrow;
}
// If we actually have candidates for the requirement, then
@@ -300,8 +305,8 @@
}
else if (cycleCount.intValue() == 0)
{
- // Record that the module was successfully populated.
- m_populateResultCache.put(module, Boolean.TRUE);
+ // Record that the revision was successfully populated.
+ m_populateResultCache.put(revision, Boolean.TRUE);
// Merge local candidate map into global candidate map.
if (localCandidateMap.size() > 0)
@@ -311,42 +316,42 @@
}
}
- public final void populateOptional(ResolverState state, Module module)
+ public final void populateOptional(ResolverState state, BundleRevision revision)
{
// 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 modules if they aren't
+ // attempt to populate optional non-fragment revisions if they aren't
// already resolved.
- boolean isFragment = Util.isFragment(module);
- if (!isFragment && module.isResolved())
+ boolean isFragment = Util.isFragment(revision);
+ if (!isFragment && (revision.getWiring() != null))
{
return;
}
try
{
- // If the optional module is a fragment, then we only want to populate
+ // If the optional revision is a fragment, then we only want to populate
// the fragment if it has a candidate host in the set of already populated
- // modules. We do this to avoid unnecessary work in prepare(). If the
+ // revisions. 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().
if (isFragment)
{
- // Get the current result cache value, to make sure the module
+ // Get the current result cache value, to make sure the revision
// hasn't already been populated.
- Object cacheValue = m_populateResultCache.get(module);
+ Object cacheValue = m_populateResultCache.get(revision);
if (cacheValue == null)
{
- // Create a modifiable list of the module's requirements.
- List<BundleRequirementImpl> remainingReqs =
- new ArrayList(module.getDeclaredRequirements());
+ // Create a modifiable list of the revision's requirements.
+ List<BundleRequirement> remainingReqs =
+ new ArrayList(revision.getDeclaredRequirements(null));
// Find the host requirement.
- BundleRequirementImpl hostReq = null;
- for (Iterator<BundleRequirementImpl> it = remainingReqs.iterator();
+ BundleRequirement hostReq = null;
+ for (Iterator<BundleRequirement> it = remainingReqs.iterator();
it.hasNext(); )
{
- BundleRequirementImpl r = it.next();
+ BundleRequirement r = it.next();
if (r.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
{
hostReq = r;
@@ -355,11 +360,12 @@
}
// Get candidates hosts and keep any that have been populated.
- SortedSet<BundleCapabilityImpl> hosts = state.getCandidates(hostReq, false);
- for (Iterator<BundleCapabilityImpl> it = hosts.iterator(); it.hasNext(); )
+ SortedSet<BundleCapability> hosts =
+ state.getCandidates((BundleRequirementImpl) hostReq, false);
+ for (Iterator<BundleCapability> it = hosts.iterator(); it.hasNext(); )
{
- BundleCapabilityImpl host = it.next();
- if (!isPopulated(host.getModule()))
+ BundleCapability host = it.next();
+ if (!isPopulated(host.getRevision()))
{
it.remove();
}
@@ -377,65 +383,65 @@
// the work we've done so far.
// Verify that any required execution environment is satisfied.
- state.checkExecutionEnvironment(module);
+ state.checkExecutionEnvironment(revision);
// Verify that any native libraries match the current platform.
- state.checkNativeLibraries(module);
+ state.checkNativeLibraries(revision);
// 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 module is not resolvable.
- Map<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> localCandidateMap =
- new HashMap<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>>();
+ // the revision is not resolvable.
+ Map<BundleRequirement, SortedSet<BundleCapability>> localCandidateMap =
+ new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
// 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
- // module.
- m_populateResultCache.put(module,
+ // revision.
+ m_populateResultCache.put(revision,
new Object[] { cycleCount, localCandidateMap, remainingReqs });
}
}
- // Try to populate candidates for the optional module.
- populate(state, module);
+ // Try to populate candidates for the optional revision.
+ populate(state, revision);
}
catch (ResolveException ex)
{
- // Ignore since the module is optional.
+ // Ignore since the revision is optional.
}
}
- private boolean isPopulated(Module module)
+ private boolean isPopulated(BundleRevision revision)
{
- Object value = m_populateResultCache.get(module);
+ Object value = m_populateResultCache.get(revision);
return ((value != null) && (value instanceof Boolean));
}
- private void populateDynamic(ResolverState state, Module module)
+ private void populateDynamic(ResolverState state, BundleRevision revision)
{
// 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<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> entry =
+ Entry<BundleRequirement, SortedSet<BundleCapability>> entry =
m_candidateMap.entrySet().iterator().next();
- BundleRequirementImpl dynReq = entry.getKey();
- SortedSet<BundleCapabilityImpl> candidates = entry.getValue();
- for (Iterator<BundleCapabilityImpl> itCandCap = candidates.iterator();
+ BundleRequirement dynReq = entry.getKey();
+ SortedSet<BundleCapability> candidates = entry.getValue();
+ for (Iterator<BundleCapability> itCandCap = candidates.iterator();
itCandCap.hasNext(); )
{
- BundleCapabilityImpl candCap = itCandCap.next();
- if (!candCap.getModule().isResolved())
+ BundleCapability candCap = itCandCap.next();
+ if (candCap.getRevision().getWiring() == null)
{
try
{
- populate(state, candCap.getModule());
+ populate(state, candCap.getRevision());
}
catch (ResolveException ex)
{
@@ -452,7 +458,7 @@
{
if (rethrow == null)
{
- rethrow = new ResolveException("Dynamic import failed.", module, dynReq);
+ rethrow = new ResolveException("Dynamic import failed.", revision, dynReq);
}
throw rethrow;
}
@@ -467,7 +473,7 @@
* @param req the requirement to add.
* @param candidates the candidates matching the requirement.
**/
- private void add(BundleRequirementImpl req, SortedSet<BundleCapabilityImpl> candidates)
+ private void add(BundleRequirement req, SortedSet<BundleCapability> candidates)
{
if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
{
@@ -477,14 +483,14 @@
// Record the candidates.
m_candidateMap.put(req, candidates);
- // Make a list of all candidate modules for determining singetons.
+ // Make a list of all candidate revisions for determining singetons.
// Add the requirement as a dependent on the candidates. Keep track
// of fragments for hosts.
- for (BundleCapabilityImpl cap : candidates)
+ for (BundleCapability cap : candidates)
{
- // Remember the module for all capabilities so we can
+ // Remember the revision for all capabilities so we can
// determine which ones are singletons.
- m_candidateModules.add(cap.getModule());
+ m_candidateRevisions.add(cap.getRevision());
}
}
@@ -494,9 +500,9 @@
* be further modified by the caller.
* @param candidates the bulk requirements and candidates to add.
**/
- private void add(Map<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> candidates)
+ private void add(Map<BundleRequirement, SortedSet<BundleCapability>> candidates)
{
- for (Entry<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> entry : candidates.entrySet())
+ for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry : candidates.entrySet())
{
add(entry.getKey(), entry.getValue());
}
@@ -509,9 +515,9 @@
* @param m the module whose wrapper is desired.
* @return the wrapper module or the module itself if it was not wrapped.
**/
- public Module getWrappedHost(Module m)
+ public BundleRevision getWrappedHost(BundleRevision m)
{
- Module wrapped = m_allWrappedHosts.get(m);
+ BundleRevision wrapped = m_allWrappedHosts.get(m);
return (wrapped == null) ? m : wrapped;
}
@@ -520,7 +526,7 @@
* @param req the requirement whose candidates are desired.
* @return the matching candidates or null.
**/
- public SortedSet<BundleCapabilityImpl> getCandidates(BundleRequirementImpl req)
+ public SortedSet<BundleCapability> getCandidates(BundleRequirement req)
{
return m_candidateMap.get(req);
}
@@ -541,7 +547,7 @@
* @throws ResolveException if the removal of any unselected fragments result
* in the root module being unable to resolve.
**/
- public void prepare(List<Module> existingSingletons)
+ public void prepare(List<BundleRevision> existingSingletons)
{
boolean init = false;
@@ -551,12 +557,12 @@
init = true;
}
- final Map<String, Module> singletons = new HashMap<String, Module>();
+ final Map<String, BundleRevision> singletons = new HashMap<String, BundleRevision>();
- for (Iterator<Module> it = m_candidateModules.iterator(); it.hasNext(); )
+ for (Iterator<BundleRevision> it = m_candidateRevisions.iterator(); it.hasNext(); )
{
- Module m = it.next();
- if (isSingleton(m))
+ BundleRevision br = it.next();
+ if (isSingleton(br))
{
if (!init)
{
@@ -565,28 +571,28 @@
}
// See if there is an existing singleton for the
- // 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
+ // 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
// and the existing singleton is not resolved, then select
- // this module as the singleton.
+ // this revision as the singleton.
if ((singleton == null)
- || m.isResolved()
- || ((m.getVersion().compareTo(singleton.getVersion()) > 0)
- && !singleton.isResolved()))
+ || (br.getWiring() != null)
+ || ((br.getVersion().compareTo(singleton.getVersion()) > 0)
+ && (singleton.getWiring() == null)))
{
- singletons.put(m.getSymbolicName(), m);
- // Remove the singleton module from the candidates
+ singletons.put(br.getSymbolicName(), br);
+ // Remove the singleton revision from the candidates
// if it wasn't selected.
if (singleton != null)
{
- removeModule(singleton);
+ removeRevision(singleton);
}
}
else
{
- removeModule(m);
+ removeRevision(br);
}
}
}
@@ -594,11 +600,11 @@
// If the root is a singleton, then prefer it over any other singleton.
if (isSingleton(m_root))
{
- Module singleton = singletons.get(m_root.getSymbolicName());
+ BundleRevision singleton = singletons.get(m_root.getSymbolicName());
singletons.put(m_root.getSymbolicName(), m_root);
if ((singleton != null) && !singleton.equals(m_root))
{
- if (singleton.isResolved())
+ if (singleton.getWiring() != null)
{
throw new ResolveException(
"Cannot resolve singleton "
@@ -608,7 +614,7 @@
+ " singleton is already resolved.",
m_root, null);
}
- removeModule(singleton);
+ removeRevision(singleton);
}
}
@@ -616,12 +622,12 @@
// singletons passed into this method.
for (int i = 0; (existingSingletons != null) && (i < existingSingletons.size()); i++)
{
- Module existing = existingSingletons.get(i);
- Module singleton = singletons.get(existing.getSymbolicName());
+ BundleRevision existing = existingSingletons.get(i);
+ BundleRevision singleton = singletons.get(existing.getSymbolicName());
if ((singleton != null) && (singleton != existing))
{
singletons.remove(singleton.getSymbolicName());
- removeModule(singleton);
+ removeRevision(singleton);
}
}
@@ -629,9 +635,9 @@
// 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 modules may depend on the capabilities of unselected
+ // other revisions may depend on the capabilities of unselected
// fragments, so we need to remove the unselected fragments and
- // any modules that depends on them, which could ultimately cause
+ // any revisions 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).
@@ -640,30 +646,31 @@
// with host's attached fragment capabilities.
// Steps 1 and 2
- List<HostModule> hostModules = new ArrayList<HostModule>();
- List<Module> unselectedFragments = new ArrayList<Module>();
- for (Entry<BundleCapabilityImpl, Map<String, Map<Version, List<BundleRequirementImpl>>>>
+ 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())
{
// Step 1
- BundleCapabilityImpl hostCap = hostEntry.getKey();
- Map<String, Map<Version, List<BundleRequirementImpl>>> fragments
+ BundleCapability hostCap = hostEntry.getKey();
+ Map<String, Map<Version, List<BundleRequirement>>> fragments
= hostEntry.getValue();
- List<Module> selectedFragments = new ArrayList<Module>();
- for (Entry<String, Map<Version, List<BundleRequirementImpl>>> fragEntry
+ List<BundleRevision> selectedFragments = new ArrayList<BundleRevision>();
+ for (Entry<String, Map<Version, List<BundleRequirement>>> fragEntry
: fragments.entrySet())
{
boolean isFirst = true;
- for (Entry<Version, List<BundleRequirementImpl>> versionEntry
+ for (Entry<Version, List<BundleRequirement>> versionEntry
: fragEntry.getValue().entrySet())
{
- for (BundleRequirementImpl hostReq : versionEntry.getValue())
+ for (BundleRequirement hostReq : versionEntry.getValue())
{
// Select the highest version of the fragment that
// is not removal pending.
- if (isFirst && !hostReq.getModule().isRemovalPending())
+ if (isFirst
+ && !((BundleRevisionImpl) hostReq.getRevision()).isRemovalPending())
{
- selectedFragments.add(hostReq.getModule());
+ selectedFragments.add(hostReq.getRevision());
isFirst = false;
}
// For any fragment that wasn't selected, remove the
@@ -674,11 +681,11 @@
else
{
m_dependentMap.get(hostCap).remove(hostReq);
- SortedSet<BundleCapabilityImpl> hosts = m_candidateMap.get(hostReq);
+ SortedSet<BundleCapability> hosts = m_candidateMap.get(hostReq);
hosts.remove(hostCap);
if (hosts.isEmpty())
{
- unselectedFragments.add(hostReq.getModule());
+ unselectedFragments.add(hostReq.getRevision());
}
}
}
@@ -686,31 +693,32 @@
}
// Step 2
- HostModule wrappedHost = new HostModule(hostCap.getModule(), selectedFragments);
- hostModules.add(wrappedHost);
- m_allWrappedHosts.put(hostCap.getModule(), wrappedHost);
+ HostBundleRevision wrappedHost =
+ new HostBundleRevision(hostCap.getRevision(), selectedFragments);
+ hostRevisions.add(wrappedHost);
+ m_allWrappedHosts.put(hostCap.getRevision(), wrappedHost);
}
// Step 3
- for (Module m : unselectedFragments)
+ for (BundleRevision br : unselectedFragments)
{
- removeModule(m);
+ removeRevision(br);
}
// Step 4
- for (HostModule hostModule : hostModules)
+ for (HostBundleRevision hostRevision : hostRevisions)
{
// Replaces capabilities from fragments with the capabilities
// from the merged host.
- for (BundleCapabilityImpl c : hostModule.getDeclaredCapabilities())
+ for (BundleCapability c : hostRevision.getDeclaredCapabilities(null))
{
- Set<BundleRequirementImpl> dependents =
+ Set<BundleRequirement> dependents =
m_dependentMap.get(((HostedCapability) c).getDeclaredCapability());
if (dependents != null)
{
- for (BundleRequirementImpl r : dependents)
+ for (BundleRequirement r : dependents)
{
- Set<BundleCapabilityImpl> cands = m_candidateMap.get(r);
+ Set<BundleCapability> cands = m_candidateMap.get(r);
cands.remove(((HostedCapability) c).getDeclaredCapability());
cands.add(c);
}
@@ -720,13 +728,13 @@
// 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 (BundleRequirementImpl r : hostModule.getDeclaredRequirements())
+ for (BundleRequirement r : hostRevision.getDeclaredRequirements(null))
{
- SortedSet<BundleCapabilityImpl> cands =
+ SortedSet<BundleCapability> cands =
m_candidateMap.get(((HostedRequirement) r).getDeclaredRequirement());
if (cands != null)
{
- m_candidateMap.put(r, new TreeSet<BundleCapabilityImpl>(cands));
+ m_candidateMap.put(r, new TreeSet<BundleCapability>(cands));
}
}
}
@@ -734,18 +742,18 @@
private void populateDependents()
{
- for (Entry<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> entry
+ for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry
: m_candidateMap.entrySet())
{
- BundleRequirementImpl req = entry.getKey();
- SortedSet<BundleCapabilityImpl> caps = entry.getValue();
- for (BundleCapabilityImpl cap : caps)
+ BundleRequirement req = entry.getKey();
+ SortedSet<BundleCapability> caps = entry.getValue();
+ for (BundleCapability cap : caps)
{
// Record the requirement as dependent on the capability.
- Set<BundleRequirementImpl> dependents = m_dependentMap.get(cap);
+ Set<BundleRequirement> dependents = m_dependentMap.get(cap);
if (dependents == null)
{
- dependents = new HashSet<BundleRequirementImpl>();
+ dependents = new HashSet<BundleRequirement>();
m_dependentMap.put(cap, dependents);
}
dependents.add(req);
@@ -753,26 +761,26 @@
// Keep track of hosts and associated fragments.
if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
{
- Map<String, Map<Version, List<BundleRequirementImpl>>>
+ Map<String, Map<Version, List<BundleRequirement>>>
fragments = m_hostFragments.get(cap);
if (fragments == null)
{
- fragments = new HashMap<String, Map<Version, List<BundleRequirementImpl>>>();
+ fragments = new HashMap<String, Map<Version, List<BundleRequirement>>>();
m_hostFragments.put(cap, fragments);
}
- Map<Version, List<BundleRequirementImpl>> fragmentVersions =
- fragments.get(req.getModule().getSymbolicName());
+ Map<Version, List<BundleRequirement>> fragmentVersions =
+ fragments.get(req.getRevision().getSymbolicName());
if (fragmentVersions == null)
{
fragmentVersions =
- new TreeMap<Version, List<BundleRequirementImpl>>(Collections.reverseOrder());
- fragments.put(req.getModule().getSymbolicName(), fragmentVersions);
+ new TreeMap<Version, List<BundleRequirement>>(Collections.reverseOrder());
+ fragments.put(req.getRevision().getSymbolicName(), fragmentVersions);
}
- List<BundleRequirementImpl> actual = fragmentVersions.get(req.getModule().getVersion());
+ List<BundleRequirement> actual = fragmentVersions.get(req.getRevision().getVersion());
if (actual == null)
{
- actual = new ArrayList<BundleRequirementImpl>();
- fragmentVersions.put(req.getModule().getVersion(), actual);
+ actual = new ArrayList<BundleRequirement>();
+ fragmentVersions.put(req.getRevision().getVersion(), actual);
}
actual.add(req);
}
@@ -785,26 +793,26 @@
* 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 module the module to remove.
+ * @param revision the module to remove.
* @throws ResolveException if removing the module caused the resolve to fail.
**/
- private void removeModule(Module module) throws ResolveException
+ private void removeRevision(BundleRevision revision) throws ResolveException
{
- if (m_root.equals(module))
+ if (m_root.equals(revision))
{
// TODO: SINGLETON RESOLVER - Improve this message.
String msg = "Unable to resolve " + m_root;
ResolveException ex = new ResolveException(msg, m_root, null);
throw ex;
}
- Set<Module> unresolvedModules = new HashSet<Module>();
- remove(module, unresolvedModules);
- while (!unresolvedModules.isEmpty())
+ Set<BundleRevision> unresolvedRevisions = new HashSet<BundleRevision>();
+ remove(revision, unresolvedRevisions);
+ while (!unresolvedRevisions.isEmpty())
{
- Iterator<Module> it = unresolvedModules.iterator();
- module = it.next();
+ Iterator<BundleRevision> it = unresolvedRevisions.iterator();
+ revision = it.next();
it.remove();
- remove(module, unresolvedModules);
+ remove(revision, unresolvedRevisions);
}
}
@@ -812,22 +820,23 @@
* 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 m the module to remove.
- * @param unresolvedModules a list to containing any additional modules that
+ * @param br the module to remove.
+ * @param unresolvedRevisions 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(Module m, Set<Module> unresolvedModules) throws ResolveException
+ private void remove(BundleRevision br, Set<BundleRevision> unresolvedRevisions)
+ throws ResolveException
{
- for (BundleRequirementImpl r : m.getDeclaredRequirements())
+ for (BundleRequirement r : br.getDeclaredRequirements(null))
{
remove(r);
}
- for (BundleCapabilityImpl c : m.getDeclaredCapabilities())
+ for (BundleCapability c : br.getDeclaredCapabilities(null))
{
- remove(c, unresolvedModules);
+ remove(c, unresolvedRevisions);
}
}
@@ -835,16 +844,16 @@
* Removes a requirement from the internal data structures.
* @param req the requirement to remove.
**/
- private void remove(BundleRequirementImpl req)
+ private void remove(BundleRequirement req)
{
boolean isFragment = req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE);
- SortedSet<BundleCapabilityImpl> candidates = m_candidateMap.remove(req);
+ SortedSet<BundleCapability> candidates = m_candidateMap.remove(req);
if (candidates != null)
{
- for (BundleCapabilityImpl cap : candidates)
+ for (BundleCapability cap : candidates)
{
- Set<BundleRequirementImpl> dependents = m_dependentMap.get(cap);
+ Set<BundleRequirement> dependents = m_dependentMap.get(cap);
if (dependents != null)
{
dependents.remove(req);
@@ -852,25 +861,25 @@
if (isFragment)
{
- Map<String, Map<Version, List<BundleRequirementImpl>>>
+ Map<String, Map<Version, List<BundleRequirement>>>
fragments = m_hostFragments.get(cap);
if (fragments != null)
{
- Map<Version, List<BundleRequirementImpl>> fragmentVersions =
- fragments.get(req.getModule().getSymbolicName());
+ Map<Version, List<BundleRequirement>> fragmentVersions =
+ fragments.get(req.getRevision().getSymbolicName());
if (fragmentVersions != null)
{
- List<BundleRequirementImpl> actual =
- fragmentVersions.get(req.getModule().getVersion());
+ List<BundleRequirement> actual =
+ fragmentVersions.get(req.getRevision().getVersion());
if (actual != null)
{
actual.remove(req);
if (actual.isEmpty())
{
- fragmentVersions.remove(req.getModule().getVersion());
+ fragmentVersions.remove(req.getRevision().getVersion());
if (fragmentVersions.isEmpty())
{
- fragments.remove(req.getModule().getSymbolicName());
+ fragments.remove(req.getRevision().getSymbolicName());
if (fragments.isEmpty())
{
m_hostFragments.remove(cap);
@@ -889,34 +898,34 @@
* 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 unresolvedModules a list to containing any additional modules that
+ * @param unresolvedRevisions 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(BundleCapabilityImpl c, Set<Module> unresolvedModules)
+ private void remove(BundleCapability c, Set<BundleRevision> unresolvedRevisions)
throws ResolveException
{
- Set<BundleRequirementImpl> dependents = m_dependentMap.remove(c);
+ Set<BundleRequirement> dependents = m_dependentMap.remove(c);
if (dependents != null)
{
- for (BundleRequirementImpl r : dependents)
+ for (BundleRequirement r : dependents)
{
- SortedSet<BundleCapabilityImpl> candidates = m_candidateMap.get(r);
+ SortedSet<BundleCapability> candidates = m_candidateMap.get(r);
candidates.remove(c);
if (candidates.isEmpty())
{
m_candidateMap.remove(r);
- if (!r.isOptional())
+ if (!((BundleRequirementImpl) r).isOptional())
{
- if (m_root.equals(r.getModule()))
+ if (m_root.equals(r.getRevision()))
{
String msg = "Unable to resolve " + m_root
+ ": missing requirement " + r;
ResolveException ex = new ResolveException(msg, m_root, r);
throw ex;
}
- unresolvedModules.add(r.getModule());
+ unresolvedRevisions.add(r.getRevision());
}
}
}
@@ -930,62 +939,62 @@
**/
public Candidates copy()
{
- Map<BundleCapabilityImpl, Set<BundleRequirementImpl>> dependentMap =
- new HashMap<BundleCapabilityImpl, Set<BundleRequirementImpl>>();
- for (Entry<BundleCapabilityImpl, Set<BundleRequirementImpl>> entry : m_dependentMap.entrySet())
+ Map<BundleCapability, Set<BundleRequirement>> dependentMap =
+ new HashMap<BundleCapability, Set<BundleRequirement>>();
+ for (Entry<BundleCapability, Set<BundleRequirement>> entry : m_dependentMap.entrySet())
{
- Set<BundleRequirementImpl> dependents = new HashSet<BundleRequirementImpl>(entry.getValue());
+ Set<BundleRequirement> dependents = new HashSet<BundleRequirement>(entry.getValue());
dependentMap.put(entry.getKey(), dependents);
}
- Map<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> candidateMap =
- new HashMap<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>>();
- for (Entry<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> entry
+ Map<BundleRequirement, SortedSet<BundleCapability>> candidateMap =
+ new HashMap<BundleRequirement, SortedSet<BundleCapability>>();
+ for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry
: m_candidateMap.entrySet())
{
- SortedSet<BundleCapabilityImpl> candidates =
- new TreeSet<BundleCapabilityImpl>(entry.getValue());
+ SortedSet<BundleCapability> candidates =
+ new TreeSet<BundleCapability>(entry.getValue());
candidateMap.put(entry.getKey(), candidates);
}
return new Candidates(
- m_root, m_candidateModules, dependentMap, candidateMap,
+ m_root, m_candidateRevisions, dependentMap, candidateMap,
m_hostFragments, m_allWrappedHosts, m_populateResultCache,
m_fragmentsPresent);
}
public void dump()
{
- // Create set of all modules from requirements.
- Set<Module> modules = new HashSet();
- for (Entry<BundleRequirementImpl, SortedSet<BundleCapabilityImpl>> entry
+ // Create set of all revisions from requirements.
+ Set<BundleRevision> revisions = new HashSet<BundleRevision>();
+ for (Entry<BundleRequirement, SortedSet<BundleCapability>> entry
: m_candidateMap.entrySet())
{
- modules.add(entry.getKey().getModule());
+ revisions.add(entry.getKey().getRevision());
}
- // Now dump the modules.
+ // Now dump the revisions.
System.out.println("=== BEGIN CANDIDATE MAP ===");
- for (Module module : modules)
+ for (BundleRevision br : revisions)
{
- System.out.println(" " + module
- + " (" + (module.isResolved() ? "RESOLVED)" : "UNRESOLVED)"));
- List<BundleRequirementImpl> reqs = (module.isResolved())
- ? module.getResolvedRequirements()
- : module.getDeclaredRequirements();
- for (BundleRequirementImpl req : reqs)
+ 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)
{
- Set<BundleCapabilityImpl> candidates = m_candidateMap.get(req);
+ Set<BundleCapability> candidates = m_candidateMap.get(req);
if ((candidates != null) && (candidates.size() > 0))
{
System.out.println(" " + req + ": " + candidates);
}
}
- reqs = (module.isResolved())
- ? module.getResolvedDynamicRequirements()
- : module.getDeclaredDynamicRequirements();
- for (BundleRequirementImpl req : reqs)
+ reqs = (br.getWiring() != null)
+ ? ((BundleRevisionImpl) br).getResolvedDynamicRequirements()
+ : ((BundleRevisionImpl) br).getDeclaredDynamicRequirements();
+ for (BundleRequirement req : reqs)
{
- Set<BundleCapabilityImpl> candidates = m_candidateMap.get(req);
+ Set<BundleCapability> candidates = m_candidateMap.get(req);
if ((candidates != null) && (candidates.size() > 0))
{
System.out.println(" " + req + ": " + candidates);
@@ -999,14 +1008,14 @@
* Returns true if the specified module is a singleton
* (i.e., directive singleton:=true).
*
- * @param module the module to check for singleton status.
+ * @param revision the module to check for singleton status.
* @return true if the module is a singleton, false otherwise.
**/
- private static boolean isSingleton(Module module)
+ private static boolean isSingleton(BundleRevision revision)
{
- final List<BundleCapabilityImpl> modCaps =
+ final List<BundleCapability> modCaps =
Util.getCapabilityByNamespace(
- module, BundleCapabilityImpl.MODULE_NAMESPACE);
+ revision, BundleCapabilityImpl.BUNDLE_NAMESPACE);
if (modCaps == null || modCaps.isEmpty())
{
return false;
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/HostBundleRevision.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostBundleRevision.java
new file mode 100644
index 0000000..9551ec1
--- /dev/null
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostBundleRevision.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.felix.framework.wiring.BundleCapabilityImpl;
+import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWiring;
+
+class HostBundleRevision implements BundleRevision
+{
+ private final BundleRevision m_host;
+ private final List<BundleRevision> m_fragments;
+ private List<BundleCapability> m_cachedCapabilities = null;
+ private List<BundleRequirement> m_cachedRequirements = null;
+
+ public HostBundleRevision(BundleRevision host, List<BundleRevision> fragments)
+ {
+ m_host = host;
+ m_fragments = fragments;
+ }
+
+ public BundleRevision getHost()
+ {
+ return m_host;
+ }
+
+ public List<BundleRevision> getFragments()
+ {
+ return m_fragments;
+ }
+
+ public String getSymbolicName()
+ {
+ return m_host.getSymbolicName();
+ }
+
+ public Version getVersion()
+ {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public List<BundleCapability> getDeclaredCapabilities(String namespace)
+ {
+ if (m_cachedCapabilities == null)
+ {
+ List<BundleCapability> caps = new ArrayList<BundleCapability>();
+
+ // Wrap host capabilities.
+ for (BundleCapability cap : m_host.getDeclaredCapabilities(null))
+ {
+ caps.add(new HostedCapability(this, (BundleCapabilityImpl) cap));
+ }
+
+ // Wrap fragment capabilities.
+ if (m_fragments != null)
+ {
+ for (BundleRevision fragment : m_fragments)
+ {
+ for (BundleCapability cap : fragment.getDeclaredCapabilities(null))
+ {
+ if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ caps.add(new HostedCapability(this, (BundleCapabilityImpl) cap));
+ }
+ }
+ }
+ }
+ m_cachedCapabilities = Collections.unmodifiableList(caps);
+ }
+ return m_cachedCapabilities;
+ }
+
+ public List<BundleRequirement> getDeclaredRequirements(String namespace)
+ {
+ if (m_cachedRequirements == null)
+ {
+ List<BundleRequirement> reqs = new ArrayList<BundleRequirement>();
+
+ // Wrap host requirements.
+ for (BundleRequirement req : m_host.getDeclaredRequirements(null))
+ {
+ reqs.add(new HostedRequirement(this, (BundleRequirementImpl) req));
+ }
+
+ // Wrap fragment requirements.
+ if (m_fragments != null)
+ {
+ for (BundleRevision fragment : m_fragments)
+ {
+ for (BundleRequirement req : fragment.getDeclaredRequirements(null))
+ {
+ if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
+ || req.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ reqs.add(new HostedRequirement(this, (BundleRequirementImpl) req));
+ }
+ }
+ }
+ }
+ m_cachedRequirements = Collections.unmodifiableList(reqs);
+ }
+ return m_cachedRequirements;
+ }
+
+ public int getTypes()
+ {
+ return m_host.getTypes();
+ }
+
+ public BundleWiring getWiring()
+ {
+ return null;
+ }
+
+ public Bundle getBundle()
+ {
+ return m_host.getBundle();
+ }
+
+ public String toString()
+ {
+ return m_host.toString();
+ }
+}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/HostModule.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostModule.java
deleted file mode 100644
index 0bf4037..0000000
--- a/framework/src/main/java/org/apache/felix/framework/resolver/HostModule.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.framework.resolver;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import org.apache.felix.framework.util.manifestparser.R4Library;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
-
-class HostModule implements Module
-{
- private final Module m_host;
- private final List<Module> m_fragments;
- private List<BundleCapabilityImpl> m_cachedCapabilities = null;
- private List<BundleRequirementImpl> m_cachedRequirements = null;
-
- public HostModule(Module module, List<Module> fragments)
- {
- m_host = module;
- m_fragments = fragments;
- }
-
- public Module getHost()
- {
- return m_host;
- }
-
- public List<Module> getFragments()
- {
- return m_fragments;
- }
-
- public String getId()
- {
- return m_host.getId();
- }
-
- public List<BundleCapabilityImpl> getDeclaredCapabilities()
- {
- if (m_cachedCapabilities == null)
- {
- List<BundleCapabilityImpl> caps = new ArrayList<BundleCapabilityImpl>();
-
- // Wrap host capabilities.
- for (BundleCapabilityImpl cap : m_host.getDeclaredCapabilities())
- {
- caps.add(new HostedCapability(this, cap));
- }
-
- // Wrap fragment capabilities.
- if (m_fragments != null)
- {
- for (Module fragment : m_fragments)
- {
- for (BundleCapabilityImpl cap : fragment.getDeclaredCapabilities())
- {
- if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
- {
- caps.add(new HostedCapability(this, cap));
- }
- }
- }
- }
- m_cachedCapabilities = Collections.unmodifiableList(caps);
- }
- return m_cachedCapabilities;
- }
-
- public List<BundleCapabilityImpl> getResolvedCapabilities()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public List<BundleRequirementImpl> getDeclaredRequirements()
- {
- if (m_cachedRequirements == null)
- {
- List<BundleRequirementImpl> reqs = new ArrayList<BundleRequirementImpl>();
-
- // Wrap host requirements.
- for (BundleRequirementImpl req : m_host.getDeclaredRequirements())
- {
- reqs.add(new HostedRequirement(this, req));
- }
-
- // Wrap fragment requirements.
- if (m_fragments != null)
- {
- for (Module fragment : m_fragments)
- {
- for (BundleRequirementImpl req : fragment.getDeclaredRequirements())
- {
- if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
- || req.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
- {
- reqs.add(new HostedRequirement(this, req));
- }
- }
- }
- }
- m_cachedRequirements = Collections.unmodifiableList(reqs);
- }
- return m_cachedRequirements;
- }
-
- public List<BundleRequirementImpl> getResolvedRequirements()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public String toString()
- {
- return m_host.getId();
- }
-
- public Map getHeaders()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public boolean isExtension()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public String getSymbolicName()
- {
- return m_host.getSymbolicName();
- }
-
- public Version getVersion()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public List<BundleRequirementImpl> getDeclaredDynamicRequirements()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public List<BundleRequirementImpl> getResolvedDynamicRequirements()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public List<R4Library> getNativeLibraries()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public int getDeclaredActivationPolicy()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public Bundle getBundle()
- {
- return m_host.getBundle();
- }
-
- public List<Wire> getWires()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public boolean isResolved()
- {
- return false;
- }
-
- public Object getSecurityContext()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public boolean isRemovalPending()
- {
- return m_host.isRemovalPending();
- }
-
- public Content getContent()
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public Class getClassByDelegation(String name) throws ClassNotFoundException
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public URL getResourceByDelegation(String name)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public Enumeration getResourcesByDelegation(String name)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public URL getEntry(String name)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public boolean hasInputStream(int index, String urlPath) throws IOException
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public InputStream getInputStream(int index, String urlPath) throws IOException
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public URL getLocalURL(int index, String urlPath)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
index f5666be..70c282e 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
@@ -21,16 +21,18 @@
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;
public class HostedCapability extends BundleCapabilityImpl
{
- private final Module m_host;
+ private final BundleRevision m_host;
private final BundleCapabilityImpl m_cap;
- public HostedCapability(Module module, BundleCapabilityImpl cap)
+ public HostedCapability(BundleRevision host, BundleCapabilityImpl cap)
{
- super(module, cap.getNamespace(), cap.getDirectives(), cap.getAttributes());
- m_host = module;
+ super(host, cap.getNamespace(), cap.getDirectives(), cap.getAttributes());
+ m_host = host;
m_cap = cap;
}
@@ -72,7 +74,7 @@
}
@Override
- public Module getModule()
+ public BundleRevision getRevision()
{
return m_host;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
index 2f54284..7af7a14 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
@@ -21,16 +21,17 @@
import java.util.Map;
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
{
- private final Module m_host;
+ private final BundleRevision m_host;
private final BundleRequirementImpl m_req;
- public HostedRequirement(Module module, BundleRequirementImpl req)
+ public HostedRequirement(BundleRevision host, BundleRequirementImpl req)
{
- super(module, req.getNamespace(), req.getDirectives(), req.getAttributes());
- m_host = module;
+ super(host, req.getNamespace(), req.getDirectives(), req.getAttributes());
+ m_host = host;
m_req = req;
}
@@ -72,7 +73,7 @@
}
@Override
- public Module getModule()
+ public BundleRevision getRevision()
{
return m_host;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Module.java b/framework/src/main/java/org/apache/felix/framework/resolver/Module.java
deleted file mode 100644
index 823d3cb..0000000
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Module.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.framework.resolver;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import org.apache.felix.framework.util.manifestparser.R4Library;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
-
-public interface Module
-{
- final static int EAGER_ACTIVATION = 0;
- final static int LAZY_ACTIVATION = 1;
-
- // Metadata access methods.
- Map getHeaders();
- boolean isExtension();
- String getSymbolicName();
- Version getVersion();
- List<BundleCapabilityImpl> getDeclaredCapabilities();
- List<BundleRequirementImpl> getDeclaredRequirements();
- List<BundleRequirementImpl> getDeclaredDynamicRequirements();
- List<R4Library> getNativeLibraries();
- int getDeclaredActivationPolicy();
-
- // Run-time data access methods.
- Bundle getBundle();
- String getId();
- List<BundleCapabilityImpl> getResolvedCapabilities();
- List<BundleRequirementImpl> getResolvedRequirements();
- List<BundleRequirementImpl> getResolvedDynamicRequirements();
- List<Wire> getWires();
- boolean isResolved();
- Object getSecurityContext();
- // TODO: FRAGMENT RESOLVER - Technically, this is only necessary for fragments.
- // When we refactoring for the new R4.3 framework API, we'll have to see
- // if this is still necessary, since the new BundleWirings API will give
- // us another way to detect it.
- boolean isRemovalPending();
-
- // Content access methods.
- Content getContent();
- Class getClassByDelegation(String name) throws ClassNotFoundException;
- URL getResourceByDelegation(String name);
- Enumeration getResourcesByDelegation(String name);
- URL getEntry(String name);
-
- // TODO: ML - For expediency, the index argument was added to these methods
- // but it is not clear that this makes sense in the long run. This needs to
- // be readdressed in the future, perhaps by the spec to clearly indicate
- // how resources on the bundle class path are searched, which is why we
- // need the index number in the first place -- to differentiate among
- // resources with the same name on the bundle class path. This was previously
- // handled as part of the resource path, but that approach is not spec
- // compliant.
- boolean hasInputStream(int index, String urlPath)
- throws IOException;
- InputStream getInputStream(int index, String urlPath)
- throws IOException;
- URL getLocalURL(int index, String urlPath);
-}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
index fd423d2..360ef3d 100755
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolveException.java
@@ -18,30 +18,31 @@
*/
package org.apache.felix.framework.resolver;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
public class ResolveException extends RuntimeException
{
- private final Module m_module;
- private final BundleRequirementImpl m_req;
+ private final BundleRevision m_revision;
+ private final BundleRequirement m_req;
/**
* Constructs an instance of <code>ResolveException</code> with the specified detail message.
* @param msg the detail message.
*/
- public ResolveException(String msg, Module module, BundleRequirementImpl req)
+ public ResolveException(String msg, BundleRevision revision, BundleRequirement req)
{
super(msg);
- m_module = module;
+ m_revision = revision;
m_req = req;
}
- public Module getModule()
+ public BundleRevision getRevision()
{
- return m_module;
+ return m_revision;
}
- public BundleRequirementImpl getRequirement()
+ public BundleRequirement getRequirement()
{
return m_req;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java b/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
index e7c7892..25e0ad0 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/Resolver.java
@@ -22,20 +22,23 @@
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
public interface Resolver
{
- 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);
+ 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);
public static interface ResolverState
{
- SortedSet<BundleCapabilityImpl> getCandidates(
+ SortedSet<BundleCapability> getCandidates(
BundleRequirementImpl req, boolean obeyMandatory);
- void checkExecutionEnvironment(Module module) throws ResolveException;
- void checkNativeLibraries(Module module) throws ResolveException;
+ void checkExecutionEnvironment(BundleRevision revision) throws ResolveException;
+ void checkNativeLibraries(BundleRevision revision) throws ResolveException;
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
index a7db0f9..9dc122d 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
@@ -28,12 +28,17 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
+import org.apache.felix.framework.BundleRevisionImpl;
import org.apache.felix.framework.Logger;
import org.apache.felix.framework.capabilityset.CapabilitySet;
import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
public class ResolverImpl implements Resolver
{
@@ -51,13 +56,13 @@
m_logger = logger;
}
- public Map<Module, List<Wire>> resolve(
- ResolverState state, Module module, Set<Module> fragments)
+ public Map<BundleRevision, List<ResolverWire>> resolve(
+ ResolverState state, BundleRevision revision, Set<BundleRevision> optional)
{
- Map<Module, List<Wire>> wireMap = new HashMap<Module, List<Wire>>();
- Map<Module, Packages> modulePkgMap = new HashMap<Module, Packages>();
+ Map<BundleRevision, List<ResolverWire>> wireMap = new HashMap<BundleRevision, List<ResolverWire>>();
+ Map<BundleRevision, Packages> revisionPkgMap = new HashMap<BundleRevision, Packages>();
- if (!module.isResolved())
+ if (!((BundleRevisionImpl) revision).isResolved())
{
boolean retryFragments;
do
@@ -67,12 +72,12 @@
try
{
// Populate all candidates.
- Candidates allCandidates = new Candidates(state, module);
+ Candidates allCandidates = new Candidates(state, revision);
// Try to populate optional fragments.
- for (Module fragment : fragments)
+ for (BundleRevision br : optional)
{
- allCandidates.populateOptional(state, fragment);
+ allCandidates.populateOptional(state, br);
}
// Merge any fragments into hosts.
@@ -83,16 +88,16 @@
ResolveException rethrow = null;
- // If the requested module is a fragment, then
+ // If the requested revision is a fragment, then
// ultimately we will verify the host.
- BundleRequirementImpl hostReq = getHostRequirement(module);
- Module target = module;
+ BundleRequirementImpl hostReq = getHostRequirement(revision);
+ BundleRevision target = revision;
do
{
rethrow = null;
- modulePkgMap.clear();
+ revisionPkgMap.clear();
m_packageSourcesCache.clear();
allCandidates = (m_usesPermutations.size() > 0)
@@ -105,21 +110,21 @@
if (hostReq != null)
{
target = allCandidates.getCandidates(hostReq)
- .iterator().next().getModule();
+ .iterator().next().getRevision();
}
calculatePackageSpaces(
- allCandidates.getWrappedHost(target), allCandidates, modulePkgMap,
+ allCandidates.getWrappedHost(target), allCandidates, revisionPkgMap,
new HashMap(), new HashSet());
//System.out.println("+++ PACKAGE SPACES START +++");
-//dumpModulePkgMap(modulePkgMap);
+//dumpRevisionPkgMap(revisionPkgMap);
//System.out.println("+++ PACKAGE SPACES END +++");
try
{
checkPackageSpaceConsistency(
false, allCandidates.getWrappedHost(target),
- allCandidates, modulePkgMap, new HashMap());
+ allCandidates, revisionPkgMap, new HashMap());
}
catch (ResolveException ex)
{
@@ -130,19 +135,20 @@
&& ((m_usesPermutations.size() > 0) || (m_importPermutations.size() > 0)));
// If there is a resolve exception, then determine if an
- // optionally resolved module is to blame (typically a fragment).
- // If so, then remove the optionally resolved module and try
+ // optionally resolved revision is to blame (typically a fragment).
+ // If so, then remove the optionally resolved resolved and try
// again; otherwise, rethrow the resolve exception.
if (rethrow != null)
{
- Module faultyModule = getActualModule(rethrow.getModule());
+ BundleRevision faultyRevision =
+ getActualBundleRevision(rethrow.getRevision());
if (rethrow.getRequirement() instanceof HostedRequirement)
{
- faultyModule =
+ faultyRevision =
((HostedRequirement) rethrow.getRequirement())
- .getDeclaredRequirement().getModule();
+ .getDeclaredRequirement().getRevision();
}
- if (fragments.remove(faultyModule))
+ if (optional.remove(faultyRevision))
{
retryFragments = true;
}
@@ -158,7 +164,7 @@
wireMap =
populateWireMap(
allCandidates.getWrappedHost(target),
- modulePkgMap, wireMap, allCandidates);
+ revisionPkgMap, wireMap, allCandidates);
}
}
finally
@@ -174,24 +180,25 @@
return wireMap;
}
- public Map<Module, List<Wire>> resolve(
- ResolverState state, Module module, String pkgName, Set<Module> fragments)
+ public Map<BundleRevision, List<ResolverWire>> resolve(
+ ResolverState state, BundleRevision revision, String pkgName,
+ Set<BundleRevision> optional)
{
// We can only create a dynamic import if the following
// conditions are met:
- // 1. The specified module is resolved.
+ // 1. The specified revision is resolved.
// 2. The package in question is not already imported.
// 3. The package in question is not accessible via require-bundle.
- // 4. The package in question is not exported by the bundle.
- // 5. The package in question matches a dynamic import of the bundle.
+ // 4. The package in question is not exported by the revision.
+ // 5. The package in question matches a dynamic import of the revision.
// The following call checks all of these conditions and returns
// the associated dynamic import and matching capabilities.
Candidates allCandidates =
- getDynamicImportCandidates(state, module, pkgName);
+ getDynamicImportCandidates(state, revision, pkgName);
if (allCandidates != null)
{
- Map<Module, List<Wire>> wireMap = new HashMap<Module, List<Wire>>();
- Map<Module, Packages> modulePkgMap = new HashMap<Module, Packages>();
+ Map<BundleRevision, List<ResolverWire>> wireMap = new HashMap<BundleRevision, List<ResolverWire>>();
+ Map<BundleRevision, Packages> revisionPkgMap = new HashMap<BundleRevision, Packages>();
boolean retryFragments;
do
@@ -201,16 +208,16 @@
try
{
// Try to populate optional fragments.
- for (Module fragment : fragments)
+ for (BundleRevision br : optional)
{
- allCandidates.populateOptional(state, fragment);
+ allCandidates.populateOptional(state, br);
}
// Merge any fragments into hosts.
allCandidates.prepare(getResolvedSingletons(state));
// Record the initial candidate permutation.
- m_usesPermutations.add(allCandidates);
+ m_usesPermutations.add(allCandidates);
ResolveException rethrow = null;
@@ -218,7 +225,7 @@
{
rethrow = null;
- modulePkgMap.clear();
+ revisionPkgMap.clear();
m_packageSourcesCache.clear();
allCandidates = (m_usesPermutations.size() > 0)
@@ -226,23 +233,23 @@
: m_importPermutations.remove(0);
//allCandidates.dump();
- // For a dynamic import, the instigating module
+ // For a dynamic import, the instigating revision
// will never be a fragment since fragments never
// execute code, so we don't need to check for
// this case like we do for a normal resolve.
calculatePackageSpaces(
- allCandidates.getWrappedHost(module), allCandidates, modulePkgMap,
+ allCandidates.getWrappedHost(revision), allCandidates, revisionPkgMap,
new HashMap(), new HashSet());
//System.out.println("+++ PACKAGE SPACES START +++");
-//dumpModulePkgMap(modulePkgMap);
+//dumpRevisionPkgMap(revisionPkgMap);
//System.out.println("+++ PACKAGE SPACES END +++");
try
{
checkPackageSpaceConsistency(
- false, allCandidates.getWrappedHost(module),
- allCandidates, modulePkgMap, new HashMap());
+ false, allCandidates.getWrappedHost(revision),
+ allCandidates, revisionPkgMap, new HashMap());
}
catch (ResolveException ex)
{
@@ -253,19 +260,20 @@
&& ((m_usesPermutations.size() > 0) || (m_importPermutations.size() > 0)));
// If there is a resolve exception, then determine if an
- // optionally resolved module is to blame (typically a fragment).
- // If so, then remove the optionally resolved module and try
+ // optionally resolved revision is to blame (typically a fragment).
+ // If so, then remove the optionally resolved revision and try
// again; otherwise, rethrow the resolve exception.
if (rethrow != null)
{
- Module faultyModule = getActualModule(rethrow.getModule());
+ BundleRevision faultyRevision =
+ getActualBundleRevision(rethrow.getRevision());
if (rethrow.getRequirement() instanceof HostedRequirement)
{
- faultyModule =
+ faultyRevision =
((HostedRequirement) rethrow.getRequirement())
- .getDeclaredRequirement().getModule();
+ .getDeclaredRequirement().getRevision();
}
- if (fragments.remove(faultyModule))
+ if (optional.remove(faultyRevision))
{
retryFragments = true;
}
@@ -279,7 +287,7 @@
else
{
wireMap = populateDynamicWireMap(
- module, pkgName, modulePkgMap, wireMap, allCandidates);
+ revision, pkgName, revisionPkgMap, wireMap, allCandidates);
return wireMap;
}
}
@@ -296,70 +304,71 @@
return null;
}
- private static List<Module> getResolvedSingletons(ResolverState state)
+ private static List<BundleRevision> getResolvedSingletons(ResolverState state)
{
BundleRequirementImpl req = new BundleRequirementImpl(
null,
BundleCapabilityImpl.SINGLETON_NAMESPACE,
Collections.EMPTY_MAP,
Collections.EMPTY_MAP);
- SortedSet<BundleCapabilityImpl> caps = state.getCandidates(req, true);
- List<Module> singletons = new ArrayList();
- for (BundleCapabilityImpl cap : caps)
+ SortedSet<BundleCapability> caps = state.getCandidates(req, true);
+ List<BundleRevision> singletons = new ArrayList();
+ for (BundleCapability cap : caps)
{
- if (cap.getModule().isResolved())
+ if (cap.getRevision().getWiring() != null)
{
- singletons.add(cap.getModule());
+ singletons.add(cap.getRevision());
}
}
return singletons;
}
- private static BundleCapabilityImpl getHostCapability(Module m)
+ private static BundleCapabilityImpl getHostCapability(BundleRevision br)
{
- for (BundleCapabilityImpl c : m.getDeclaredCapabilities())
+ for (BundleCapability c : br.getDeclaredCapabilities(null))
{
if (c.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
{
- return c;
+ return (BundleCapabilityImpl) c;
}
}
return null;
}
- private static BundleRequirementImpl getHostRequirement(Module m)
+ private static BundleRequirementImpl getHostRequirement(BundleRevision br)
{
- for (BundleRequirementImpl r : m.getDeclaredRequirements())
+ for (BundleRequirement r : br.getDeclaredRequirements(null))
{
if (r.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE))
{
- return r;
+ return (BundleRequirementImpl) r;
}
}
return null;
}
private static Candidates getDynamicImportCandidates(
- ResolverState state, Module module, String pkgName)
+ ResolverState state, BundleRevision revision, String pkgName)
{
- // Unresolved modules cannot dynamically import, nor can the default
+ // Unresolved revisions cannot dynamically import, nor can the default
// package be dynamically imported.
- if (!module.isResolved() || pkgName.length() == 0)
+ if ((revision.getWiring() == null) || pkgName.length() == 0)
{
return null;
}
- // If the module doesn't have dynamic imports, then just return
+ // If the revision doesn't have dynamic imports, then just return
// immediately.
- List<BundleRequirementImpl> dynamics = module.getResolvedDynamicRequirements();
+ List<BundleRequirement> dynamics =
+ ((BundleRevisionImpl) revision).getResolvedDynamicRequirements();
if ((dynamics == null) || dynamics.isEmpty())
{
return null;
}
- // If any of the module exports this package, then we cannot
+ // If the revision exports this package, then we cannot
// attempt to dynamically import it.
- for (BundleCapabilityImpl cap : module.getResolvedCapabilities())
+ for (BundleCapability cap : revision.getWiring().getCapabilities(null))
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
&& cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
@@ -369,7 +378,7 @@
}
// If any of our wires have this package, then we cannot
// attempt to dynamically import it.
- for (Wire w : module.getWires())
+ for (FelixBundleWire w : ((BundleRevisionImpl) revision).getWires())
{
if (w.hasPackage(pkgName))
{
@@ -383,11 +392,11 @@
Map<String, Object> attrs = new HashMap(1);
attrs.put(BundleCapabilityImpl.PACKAGE_ATTR, pkgName);
BundleRequirementImpl req = new BundleRequirementImpl(
- module,
+ revision,
BundleCapabilityImpl.PACKAGE_NAMESPACE,
Collections.EMPTY_MAP,
attrs);
- SortedSet<BundleCapabilityImpl> candidates = state.getCandidates(req, false);
+ SortedSet<BundleCapability> candidates = state.getCandidates(req, false);
// First find a dynamic requirement that matches the capabilities.
BundleRequirementImpl dynReq = null;
@@ -395,13 +404,15 @@
(candidates.size() > 0) && (dynReq == null) && (dynIdx < dynamics.size());
dynIdx++)
{
- for (Iterator<BundleCapabilityImpl> itCand = candidates.iterator();
+ for (Iterator<BundleCapability> itCand = candidates.iterator();
(dynReq == null) && itCand.hasNext(); )
{
- BundleCapabilityImpl cap = itCand.next();
- if (CapabilitySet.matches(cap, dynamics.get(dynIdx).getFilter()))
+ BundleCapability cap = itCand.next();
+ if (CapabilitySet.matches(
+ (BundleCapabilityImpl) cap,
+ ((BundleRequirementImpl) dynamics.get(dynIdx)).getFilter()))
{
- dynReq = dynamics.get(dynIdx);
+ dynReq = (BundleRequirementImpl) dynamics.get(dynIdx);
}
}
}
@@ -410,10 +421,12 @@
// any candidates that do not match it.
if (dynReq != null)
{
- for (Iterator<BundleCapabilityImpl> itCand = candidates.iterator(); itCand.hasNext(); )
+ for (Iterator<BundleCapability> itCand = candidates.iterator();
+ itCand.hasNext(); )
{
- BundleCapabilityImpl cap = itCand.next();
- if (!CapabilitySet.matches(cap, dynReq.getFilter()))
+ BundleCapability cap = itCand.next();
+ if (!CapabilitySet.matches(
+ (BundleCapabilityImpl) cap, dynReq.getFilter()))
{
itCand.remove();
}
@@ -428,72 +441,78 @@
if (candidates.size() > 0)
{
- allCandidates = new Candidates(state, module, dynReq, candidates);
+ allCandidates = new Candidates(state, revision, dynReq, candidates);
}
return allCandidates;
}
private void calculatePackageSpaces(
- Module module,
+ BundleRevision revision,
Candidates allCandidates,
- Map<Module, Packages> modulePkgMap,
- Map<BundleCapabilityImpl, List<Module>> usesCycleMap,
- Set<Module> cycle)
+ Map<BundleRevision, Packages> revisionPkgMap,
+ Map<BundleCapability, List<BundleRevision>> usesCycleMap,
+ Set<BundleRevision> cycle)
{
- if (cycle.contains(module))
+ if (cycle.contains(revision))
{
return;
}
- cycle.add(module);
+ cycle.add(revision);
// Create parallel arrays for requirement and proposed candidate
- // capability or actual capability if module is resolved or not.
+ // capability or actual capability if revision is resolved or not.
List<BundleRequirementImpl> reqs = new ArrayList();
List<BundleCapabilityImpl> caps = new ArrayList();
- boolean isDynamicImport = false;
- if (module.isResolved())
+ boolean isDynamicImporting = false;
+ if (revision.getWiring() != null)
{
// Use wires to get actual requirements and satisfying capabilities.
- for (Wire wire : module.getWires())
+ for (FelixBundleWire wire : ((BundleRevisionImpl) revision).getWires())
{
// Wrap the requirement as a hosted requirement
// if it comes from a fragment, since we will need
// to know the host.
- BundleRequirementImpl r = wire.getRequirement();
- if (!r.getModule().equals(wire.getImporter()))
+ BundleRequirement r = wire.getRequirement();
+ if (!r.getRevision().equals(wire.getRequirerWiring().getRevision()))
{
- r = new HostedRequirement(wire.getImporter(), r);
+ r = new HostedRequirement(
+ wire.getRequirerWiring().getRevision(),
+ (BundleRequirementImpl) r);
}
// Wrap the capability as a hosted capability
// if it comes from a fragment, since we will need
// to know the host.
- BundleCapabilityImpl c = wire.getCapability();
- if (!c.getModule().equals(wire.getExporter()))
+ BundleCapability c = wire.getCapability();
+ if (!c.getRevision().equals(wire.getProviderWiring().getRevision()))
{
- c = new HostedCapability(wire.getExporter(), c);
+ c = new HostedCapability(
+ wire.getProviderWiring().getRevision(),
+ (BundleCapabilityImpl) c);
}
- reqs.add(r);
- caps.add(c);
+ reqs.add((BundleRequirementImpl) r);
+ caps.add((BundleCapabilityImpl) c);
}
- // Since the module is resolved, it could be dynamically importing,
+ // Since the revision is resolved, it could be dynamically importing,
// so check to see if there are candidates for any of its dynamic
// imports.
- for (BundleRequirementImpl req : module.getResolvedDynamicRequirements())
+ for (BundleRequirement req
+ : ((BundleRevisionImpl) revision).getResolvedDynamicRequirements())
{
// Get the candidates for the current requirement.
- SortedSet<BundleCapabilityImpl> candCaps = allCandidates.getCandidates(req);
+ SortedSet<BundleCapability> candCaps =
+ allCandidates.getCandidates((BundleRequirementImpl) req);
// Optional requirements may not have any candidates.
if (candCaps == null)
{
continue;
}
- BundleCapabilityImpl cap = candCaps.iterator().next();
- reqs.add(req);
- caps.add(cap);
- isDynamicImport = true;
+ BundleCapability cap = candCaps.iterator().next();
+ reqs.add((BundleRequirementImpl) req);
+ caps.add((BundleCapabilityImpl) cap);
+ isDynamicImporting = true;
// Can only dynamically import one at a time, so break
// out of the loop after the first.
break;
@@ -501,76 +520,77 @@
}
else
{
- for (BundleRequirementImpl req : module.getDeclaredRequirements())
+ for (BundleRequirement req : revision.getDeclaredRequirements(null))
{
// Get the candidates for the current requirement.
- SortedSet<BundleCapabilityImpl> candCaps = allCandidates.getCandidates(req);
+ SortedSet<BundleCapability> candCaps =
+ allCandidates.getCandidates((BundleRequirementImpl) req);
// Optional requirements may not have any candidates.
if (candCaps == null)
{
continue;
}
- BundleCapabilityImpl cap = candCaps.iterator().next();
- reqs.add(req);
- caps.add(cap);
+ BundleCapability cap = candCaps.iterator().next();
+ reqs.add((BundleRequirementImpl) req);
+ caps.add((BundleCapabilityImpl) cap);
}
}
- // First, add all exported packages to the target module's package space.
- calculateExportedPackages(module, allCandidates, modulePkgMap);
- Packages modulePkgs = modulePkgMap.get(module);
+ // First, add all exported packages to the target revision's package space.
+ calculateExportedPackages(revision, allCandidates, revisionPkgMap);
+ Packages revisionPkgs = revisionPkgMap.get(revision);
- // Second, add all imported packages to the target module's package space.
+ // Second, add all imported packages to the target revision's package space.
for (int i = 0; i < reqs.size(); i++)
{
BundleRequirementImpl req = reqs.get(i);
BundleCapabilityImpl cap = caps.get(i);
- calculateExportedPackages(cap.getModule(), allCandidates, modulePkgMap);
- mergeCandidatePackages(module, req, cap, modulePkgMap, allCandidates);
+ calculateExportedPackages(cap.getRevision(), allCandidates, revisionPkgMap);
+ mergeCandidatePackages(revision, req, cap, revisionPkgMap, allCandidates);
}
// Third, have all candidates to calculate their package spaces.
for (int i = 0; i < caps.size(); i++)
{
calculatePackageSpaces(
- caps.get(i).getModule(), allCandidates, modulePkgMap,
+ caps.get(i).getRevision(), allCandidates, revisionPkgMap,
usesCycleMap, cycle);
}
- // Fourth, if the target module is unresolved or is dynamically importing,
+ // Fourth, if the target revision is unresolved or is dynamically importing,
// then add all the uses constraints implied by its imported and required
// packages to its package space.
- // NOTE: We do not need to do this for resolved modules because their
+ // NOTE: We do not need to do this for resolved revisions because their
// package space is consistent by definition and these uses constraints
- // are only needed to verify the consistency of a resolving module. The
- // only exception is if a resolve module is dynamically importing, then
+ // are only needed to verify the consistency of a resolving revision. The
+ // only exception is if a resolved revision is dynamically importing, then
// we need to calculate its uses constraints again to make sure the new
// import is consistent with the existing package space.
- if (!module.isResolved() || isDynamicImport)
+ if ((revision.getWiring() == null) || isDynamicImporting)
{
- for (Entry<String, List<Blame>> entry : modulePkgs.m_importedPkgs.entrySet())
+ for (Entry<String, List<Blame>> entry : revisionPkgs.m_importedPkgs.entrySet())
{
for (Blame blame : entry.getValue())
{
- // Ignore modules that import from themselves.
- if (!blame.m_cap.getModule().equals(module))
+ // Ignore revisions that import from themselves.
+ if (!blame.m_cap.getRevision().equals(revision))
{
List<BundleRequirementImpl> blameReqs = new ArrayList();
blameReqs.add(blame.m_reqs.get(0));
mergeUses(
- module,
- modulePkgs,
+ revision,
+ revisionPkgs,
blame.m_cap,
blameReqs,
- modulePkgMap,
+ revisionPkgMap,
allCandidates,
usesCycleMap);
}
}
}
- for (Entry<String, List<Blame>> entry : modulePkgs.m_requiredPkgs.entrySet())
+ for (Entry<String, List<Blame>> entry : revisionPkgs.m_requiredPkgs.entrySet())
{
for (Blame blame : entry.getValue())
{
@@ -578,11 +598,11 @@
blameReqs.add(blame.m_reqs.get(0));
mergeUses(
- module,
- modulePkgs,
+ revision,
+ revisionPkgs,
blame.m_cap,
blameReqs,
- modulePkgMap,
+ revisionPkgMap,
allCandidates,
usesCycleMap);
}
@@ -591,27 +611,27 @@
}
private void mergeCandidatePackages(
- Module current, BundleRequirementImpl currentReq, BundleCapabilityImpl candCap,
- Map<Module, Packages> modulePkgMap,
+ BundleRevision current, BundleRequirementImpl currentReq, BundleCapability candCap,
+ Map<BundleRevision, Packages> revisionPkgMap,
Candidates allCandidates)
{
if (candCap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
mergeCandidatePackage(
- current, false, currentReq, candCap, modulePkgMap);
+ current, false, currentReq, candCap, revisionPkgMap);
}
- else if (candCap.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ else if (candCap.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
// TODO: FELIX3 - THIS NEXT LINE IS A HACK. IMPROVE HOW/WHEN WE CALCULATE EXPORTS.
calculateExportedPackages(
- candCap.getModule(), allCandidates, modulePkgMap);
+ candCap.getRevision(), allCandidates, revisionPkgMap);
// Get the candidate's package space to determine which packages
- // will be visible to the current module.
- Packages candPkgs = modulePkgMap.get(candCap.getModule());
+ // will be visible to the current revision.
+ Packages candPkgs = revisionPkgMap.get(candCap.getRevision());
// We have to merge all exported packages from the candidate,
- // since the current module requires it.
+ // since the current revision requires it.
for (Entry<String, Blame> entry : candPkgs.m_exportedPkgs.entrySet())
{
mergeCandidatePackage(
@@ -619,17 +639,17 @@
true,
currentReq,
entry.getValue().m_cap,
- modulePkgMap);
+ revisionPkgMap);
}
// If the candidate requires any other bundles with reexport visibility,
// then we also need to merge their packages too.
- List<BundleRequirementImpl> reqs = (candCap.getModule().isResolved())
- ? candCap.getModule().getResolvedRequirements()
- : candCap.getModule().getDeclaredRequirements();
- for (BundleRequirementImpl req : reqs)
+ List<BundleRequirement> reqs = (candCap.getRevision().getWiring() != null)
+ ? candCap.getRevision().getWiring().getRequirements(null)
+ : candCap.getRevision().getDeclaredRequirements(null);
+ for (BundleRequirement req : reqs)
{
- if (req.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ if (req.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
String value = req.getDirectives().get(Constants.VISIBILITY_DIRECTIVE);
if ((value != null) && value.equals(Constants.VISIBILITY_REEXPORT)
@@ -639,7 +659,7 @@
current,
currentReq,
allCandidates.getCandidates(req).iterator().next(),
- modulePkgMap,
+ revisionPkgMap,
allCandidates);
}
}
@@ -648,9 +668,9 @@
}
private void mergeCandidatePackage(
- Module current, boolean requires,
- BundleRequirementImpl currentReq, BundleCapabilityImpl candCap,
- Map<Module, Packages> modulePkgMap)
+ BundleRevision current, boolean requires,
+ BundleRequirementImpl currentReq, BundleCapability candCap,
+ Map<BundleRevision, Packages> revisionPkgMap)
{
if (candCap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
@@ -658,7 +678,7 @@
candCap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR);
// Since this capability represents a package, it will become
- // a hard constraint on the module's package space, so we need
+ // a hard constraint on the revisions's package space, so we need
// to make sure it doesn't conflict with any other hard constraints
// or any other uses constraints.
@@ -670,7 +690,7 @@
// any existing hard constraints.
//
- Packages currentPkgs = modulePkgMap.get(current);
+ Packages currentPkgs = revisionPkgMap.get(current);
if (requires)
{
@@ -693,44 +713,44 @@
currentImportedBlames.add(new Blame(candCap, blameReqs));
}
-//dumpModulePkgs(current, currentPkgs);
+//dumpRevisionPkgs(current, currentPkgs);
}
}
private void mergeUses(
- Module current, Packages currentPkgs,
- BundleCapabilityImpl mergeCap, List<BundleRequirementImpl> blameReqs,
- Map<Module, Packages> modulePkgMap,
+ BundleRevision current, Packages currentPkgs,
+ BundleCapability mergeCap, List<BundleRequirementImpl> blameReqs,
+ Map<BundleRevision, Packages> revisionPkgMap,
Candidates allCandidates,
- Map<BundleCapabilityImpl, List<Module>> cycleMap)
+ Map<BundleCapability, List<BundleRevision>> cycleMap)
{
if (!mergeCap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
return;
}
- // If the candidate module is the same as the current module,
+ // If the candidate revision is the same as the current revision,
// then we don't need to verify and merge the uses constraints
// since this will happen as we build up the package space.
- else if (current == mergeCap.getModule())
+ else if (current.equals(mergeCap.getRevision()))
{
return;
}
// Check for cycles.
- List<Module> list = cycleMap.get(mergeCap);
+ List<BundleRevision> list = cycleMap.get(mergeCap);
if ((list != null) && list.contains(current))
{
return;
}
- list = (list == null) ? new ArrayList<Module>() : list;
+ list = (list == null) ? new ArrayList<BundleRevision>() : list;
list.add(current);
cycleMap.put(mergeCap, list);
- for (BundleCapabilityImpl candSourceCap : getPackageSources(mergeCap, modulePkgMap))
+ for (BundleCapability candSourceCap : getPackageSources(mergeCap, revisionPkgMap))
{
- for (String usedPkgName : candSourceCap.getUses())
+ for (String usedPkgName : ((BundleCapabilityImpl) candSourceCap).getUses())
{
- Packages candSourcePkgs = modulePkgMap.get(candSourceCap.getModule());
+ Packages candSourcePkgs = revisionPkgMap.get(candSourceCap.getRevision());
Blame candExportedBlame = candSourcePkgs.m_exportedPkgs.get(usedPkgName);
List<Blame> candSourceBlames = null;
if (candExportedBlame != null)
@@ -762,13 +782,13 @@
blameReqs2.add(blame.m_reqs.get(blame.m_reqs.size() - 1));
usedCaps.add(new Blame(blame.m_cap, blameReqs2));
mergeUses(current, currentPkgs, blame.m_cap, blameReqs2,
- modulePkgMap, allCandidates, cycleMap);
+ revisionPkgMap, allCandidates, cycleMap);
}
else
{
usedCaps.add(new Blame(blame.m_cap, blameReqs));
mergeUses(current, currentPkgs, blame.m_cap, blameReqs,
- modulePkgMap, allCandidates, cycleMap);
+ revisionPkgMap, allCandidates, cycleMap);
}
}
}
@@ -776,22 +796,22 @@
}
private void checkPackageSpaceConsistency(
- boolean isDynamicImport,
- Module module,
+ boolean isDynamicImporting,
+ BundleRevision revision,
Candidates allCandidates,
- Map<Module, Packages> modulePkgMap,
- Map<Module, Object> resultCache)
+ Map<BundleRevision, Packages> revisionPkgMap,
+ Map<BundleRevision, Object> resultCache)
{
- if (module.isResolved() && !isDynamicImport)
+ if ((revision.getWiring() != null) && !isDynamicImporting)
{
return;
}
- else if(resultCache.containsKey(module))
+ else if(resultCache.containsKey(revision))
{
return;
}
- Packages pkgs = modulePkgMap.get(module);
+ Packages pkgs = revisionPkgMap.get(revision);
ResolveException rethrow = null;
Candidates permutation = null;
@@ -809,7 +829,7 @@
{
sourceBlame = blame;
}
- else if (!sourceBlame.m_cap.getModule().equals(blame.m_cap.getModule()))
+ else if (!sourceBlame.m_cap.getRevision().equals(blame.m_cap.getRevision()))
{
// Try to permutate the conflicting requirement.
permutate(allCandidates, blame.m_reqs.get(0), m_importPermutations);
@@ -817,22 +837,22 @@
permutate(allCandidates, sourceBlame.m_reqs.get(0), m_importPermutations);
// Report conflict.
ResolveException ex = new ResolveException(
- "Uses constraint violation. Unable to resolve module "
- + module.getSymbolicName()
- + " [" + module
+ "Uses constraint violation. Unable to resolve bundle revision "
+ + revision.getSymbolicName()
+ + " [" + revision
+ "] because it is exposed to package '"
+ entry.getKey()
- + "' from modules "
- + sourceBlame.m_cap.getModule().getSymbolicName()
- + " [" + sourceBlame.m_cap.getModule()
+ + "' from bundle revisions "
+ + sourceBlame.m_cap.getRevision().getSymbolicName()
+ + " [" + sourceBlame.m_cap.getRevision()
+ "] and "
- + blame.m_cap.getModule().getSymbolicName()
- + " [" + blame.m_cap.getModule()
+ + blame.m_cap.getRevision().getSymbolicName()
+ + " [" + blame.m_cap.getRevision()
+ "] via two dependency chains.\n\nChain 1:\n"
+ toStringBlame(sourceBlame)
+ "\n\nChain 2:\n"
+ toStringBlame(blame),
- module,
+ revision,
blame.m_reqs.get(0));
m_logger.log(
Logger.LOG_DEBUG,
@@ -855,7 +875,7 @@
}
for (Blame usedBlame : pkgs.m_usedPkgs.get(pkgName))
{
- if (!isCompatible(exportBlame.m_cap, usedBlame.m_cap, modulePkgMap))
+ if (!isCompatible(exportBlame.m_cap, usedBlame.m_cap, revisionPkgMap))
{
// Create a candidate permutation that eliminates all candidates
// that conflict with existing selected candidates.
@@ -865,14 +885,14 @@
rethrow = (rethrow != null)
? rethrow
: new ResolveException(
- "Uses constraint violation. Unable to resolve module "
- + module.getSymbolicName()
- + " [" + module
+ "Uses constraint violation. Unable to resolve bundle revision "
+ + revision.getSymbolicName()
+ + " [" + revision
+ "] because it exports package '"
+ pkgName
- + "' and is also exposed to it from module "
- + usedBlame.m_cap.getModule().getSymbolicName()
- + " [" + usedBlame.m_cap.getModule()
+ + "' and is also exposed to it from bundle revision "
+ + usedBlame.m_cap.getRevision().getSymbolicName()
+ + " [" + usedBlame.m_cap.getRevision()
+ "] via the following dependency chain:\n\n"
+ toStringBlame(usedBlame),
null,
@@ -895,9 +915,9 @@
}
// See if we can permutate the candidates for blamed
- // requirement; there may be no candidates if the module
+ // requirement; there may be no candidates if the revision
// associated with the requirement is already resolved.
- SortedSet<BundleCapabilityImpl> candidates =
+ SortedSet<BundleCapability> candidates =
permutation.getCandidates(req);
if ((candidates != null) && (candidates.size() > 1))
{
@@ -939,7 +959,7 @@
}
for (Blame usedBlame : pkgs.m_usedPkgs.get(pkgName))
{
- if (!isCompatible(importBlame.m_cap, usedBlame.m_cap, modulePkgMap))
+ if (!isCompatible(importBlame.m_cap, usedBlame.m_cap, revisionPkgMap))
{
// Create a candidate permutation that eliminates any candidates
// that conflict with existing selected candidates.
@@ -949,17 +969,17 @@
rethrow = (rethrow != null)
? rethrow
: new ResolveException(
- "Uses constraint violation. Unable to resolve module "
- + module.getSymbolicName()
- + " [" + module
+ "Uses constraint violation. Unable to resolve bundle revision "
+ + revision.getSymbolicName()
+ + " [" + revision
+ "] because it is exposed to package '"
+ pkgName
- + "' from modules "
- + importBlame.m_cap.getModule().getSymbolicName()
- + " [" + importBlame.m_cap.getModule()
+ + "' from bundle revisions "
+ + importBlame.m_cap.getRevision().getSymbolicName()
+ + " [" + importBlame.m_cap.getRevision()
+ "] and "
- + usedBlame.m_cap.getModule().getSymbolicName()
- + " [" + usedBlame.m_cap.getModule()
+ + usedBlame.m_cap.getRevision().getSymbolicName()
+ + " [" + usedBlame.m_cap.getRevision()
+ "] via two dependency chains.\n\nChain 1:\n"
+ toStringBlame(importBlame)
+ "\n\nChain 2:\n"
@@ -984,9 +1004,9 @@
}
// See if we can permutate the candidates for blamed
- // requirement; there may be no candidates if the module
+ // requirement; there may be no candidates if the revision
// associated with the requirement is already resolved.
- SortedSet<BundleCapabilityImpl> candidates =
+ SortedSet<BundleCapability> candidates =
permutation.getCandidates(req);
if ((candidates != null) && (candidates.size() > 1))
{
@@ -1038,10 +1058,10 @@
}
}
- resultCache.put(module, Boolean.TRUE);
+ resultCache.put(revision, Boolean.TRUE);
- // Now check the consistency of all modules on which the
- // current module depends. Keep track of the current number
+ // Now check the consistency of all revisions on which the
+ // current revision depends. Keep track of the current number
// of permutations so we know if the lower level check was
// able to create a permutation or not in the case of failure.
int permCount = m_usesPermutations.size() + m_importPermutations.size();
@@ -1049,19 +1069,19 @@
{
for (Blame importBlame : entry.getValue())
{
- if (!module.equals(importBlame.m_cap.getModule()))
+ if (!revision.equals(importBlame.m_cap.getRevision()))
{
try
{
checkPackageSpaceConsistency(
- false, importBlame.m_cap.getModule(),
- allCandidates, modulePkgMap, resultCache);
+ false, importBlame.m_cap.getRevision(),
+ allCandidates, revisionPkgMap, resultCache);
}
catch (ResolveException ex)
{
// If the lower level check didn't create any permutations,
// then we should create an import permutation for the
- // requirement with the dependency on the failing module
+ // requirement with the dependency on the failing revision
// to backtrack on our current candidate selection.
if (permCount == (m_usesPermutations.size() + m_importPermutations.size()))
{
@@ -1078,7 +1098,7 @@
private static void permutate(
Candidates allCandidates, BundleRequirementImpl req, List<Candidates> permutations)
{
- SortedSet<BundleCapabilityImpl> candidates = allCandidates.getCandidates(req);
+ SortedSet<BundleCapability> candidates = allCandidates.getCandidates(req);
if (candidates.size() > 1)
{
Candidates perm = allCandidates.copy();
@@ -1093,7 +1113,7 @@
private static void permutateIfNeeded(
Candidates allCandidates, BundleRequirementImpl req, List<Candidates> permutations)
{
- SortedSet<BundleCapabilityImpl> candidates = allCandidates.getCandidates(req);
+ SortedSet<BundleCapability> candidates = allCandidates.getCandidates(req);
if (candidates.size() > 1)
{
// Check existing permutations to make sure we haven't
@@ -1105,7 +1125,7 @@
boolean permutated = false;
for (Candidates existingPerm : permutations)
{
- Set<BundleCapabilityImpl> existingPermCands = existingPerm.getCandidates(req);
+ Set<BundleCapability> existingPermCands = existingPerm.getCandidates(req);
if (!existingPermCands.iterator().next().equals(candidates.iterator().next()))
{
permutated = true;
@@ -1121,24 +1141,24 @@
}
private static void calculateExportedPackages(
- Module module,
+ BundleRevision revision,
Candidates allCandidates,
- Map<Module, Packages> modulePkgMap)
+ Map<BundleRevision, Packages> revisionPkgMap)
{
- Packages packages = modulePkgMap.get(module);
+ Packages packages = revisionPkgMap.get(revision);
if (packages != null)
{
return;
}
- packages = new Packages(module);
+ packages = new Packages(revision);
// Get all exported packages.
- List<BundleCapabilityImpl> caps = (module.isResolved())
- ? module.getResolvedCapabilities()
- : module.getDeclaredCapabilities();
- Map<String, BundleCapabilityImpl> exports =
- new HashMap<String, BundleCapabilityImpl>(caps.size());
- for (BundleCapabilityImpl cap : caps)
+ List<BundleCapability> caps = (revision.getWiring() != null)
+ ? revision.getWiring().getCapabilities(null)
+ : revision.getDeclaredCapabilities(null);
+ Map<String, BundleCapability> exports =
+ new HashMap<String, BundleCapability>(caps.size());
+ for (BundleCapability cap : caps)
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
@@ -1148,12 +1168,12 @@
}
}
// Remove substitutable exports that were imported.
- // For resolved modules look at the wires, for resolving
- // modules look in the candidate map to determine which
+ // For resolved revisions look at the wires, for resolving
+ // revisions look in the candidate map to determine which
// exports are substitutable.
- if (module.isResolved())
+ if (revision.getWiring() != null)
{
- for (Wire wire : module.getWires())
+ for (FelixBundleWire wire : ((BundleRevisionImpl) revision).getWires())
{
if (wire.getRequirement().getNamespace().equals(
BundleCapabilityImpl.PACKAGE_NAMESPACE))
@@ -1166,11 +1186,12 @@
}
else
{
- for (BundleRequirementImpl req : module.getDeclaredRequirements())
+ for (BundleRequirement req : revision.getDeclaredRequirements(null))
{
if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
- Set<BundleCapabilityImpl> cands = allCandidates.getCandidates(req);
+ Set<BundleCapability> cands =
+ allCandidates.getCandidates((BundleRequirementImpl) req);
if ((cands != null) && !cands.isEmpty())
{
String pkgName = (String) cands.iterator().next()
@@ -1180,19 +1201,19 @@
}
}
}
- // Add all non-substituted exports to the module's package space.
- for (Entry<String, BundleCapabilityImpl> entry : exports.entrySet())
+ // Add all non-substituted exports to the revisions's package space.
+ for (Entry<String, BundleCapability> entry : exports.entrySet())
{
packages.m_exportedPkgs.put(
- entry.getKey(), new Blame(entry.getValue(), null));
+ entry.getKey(), new Blame((BundleCapabilityImpl) entry.getValue(), null));
}
- modulePkgMap.put(module, packages);
+ revisionPkgMap.put(revision, packages);
}
private boolean isCompatible(
- BundleCapabilityImpl currentCap, BundleCapabilityImpl candCap,
- Map<Module, Packages> modulePkgMap)
+ BundleCapability currentCap, BundleCapability candCap,
+ Map<BundleRevision, Packages> revisionPkgMap)
{
if ((currentCap != null) && (candCap != null))
{
@@ -1201,14 +1222,14 @@
return true;
}
- List<BundleCapabilityImpl> currentSources =
+ List<BundleCapability> currentSources =
getPackageSources(
currentCap,
- modulePkgMap);
- List<BundleCapabilityImpl> candSources =
+ revisionPkgMap);
+ List<BundleCapability> candSources =
getPackageSources(
candCap,
- modulePkgMap);
+ revisionPkgMap);
return currentSources.containsAll(candSources)
|| candSources.containsAll(currentSources);
@@ -1216,19 +1237,19 @@
return true;
}
- private Map<BundleCapabilityImpl, List<BundleCapabilityImpl>> m_packageSourcesCache
+ private Map<BundleCapability, List<BundleCapability>> m_packageSourcesCache
= new HashMap();
- private List<BundleCapabilityImpl> getPackageSources(
- BundleCapabilityImpl cap, Map<Module, Packages> modulePkgMap)
+ private List<BundleCapability> getPackageSources(
+ BundleCapability cap, Map<BundleRevision, Packages> revisionPkgMap)
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
- List<BundleCapabilityImpl> sources = m_packageSourcesCache.get(cap);
+ List<BundleCapability> sources = m_packageSourcesCache.get(cap);
if (sources == null)
{
sources = getPackageSourcesInternal(
- cap, modulePkgMap, new ArrayList(), new HashSet());
+ cap, revisionPkgMap, new ArrayList(), new HashSet());
m_packageSourcesCache.put(cap, sources);
}
return sources;
@@ -1237,9 +1258,9 @@
return Collections.EMPTY_LIST;
}
- private static List<BundleCapabilityImpl> getPackageSourcesInternal(
- BundleCapabilityImpl cap, Map<Module, Packages> modulePkgMap,
- List<BundleCapabilityImpl> sources, Set<BundleCapabilityImpl> cycleMap)
+ private static List<BundleCapability> getPackageSourcesInternal(
+ BundleCapability cap, Map<BundleRevision, Packages> revisionPkgMap,
+ List<BundleCapability> sources, Set<BundleCapability> cycleMap)
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
@@ -1253,11 +1274,11 @@
String pkgName = cap.getAttributes()
.get(BundleCapabilityImpl.PACKAGE_ATTR).toString();
- // Since a module can export the same package more than once, get
+ // Since a revision can export the same package more than once, get
// all package capabilities for the specified package name.
- List<BundleCapabilityImpl> caps = (cap.getModule().isResolved())
- ? cap.getModule().getResolvedCapabilities()
- : cap.getModule().getDeclaredCapabilities();
+ List<BundleCapability> caps = (cap.getRevision().getWiring() != null)
+ ? cap.getRevision().getWiring().getCapabilities(null)
+ : cap.getRevision().getDeclaredCapabilities(null);
for (int capIdx = 0; capIdx < caps.size(); capIdx++)
{
if (caps.get(capIdx).getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
@@ -1268,13 +1289,13 @@
}
// Then get any addition sources for the package from required bundles.
- Packages pkgs = modulePkgMap.get(cap.getModule());
+ Packages pkgs = revisionPkgMap.get(cap.getRevision());
List<Blame> required = pkgs.m_requiredPkgs.get(pkgName);
if (required != null)
{
for (Blame blame : required)
{
- getPackageSourcesInternal(blame.m_cap, modulePkgMap, sources, cycleMap);
+ getPackageSourcesInternal(blame.m_cap, revisionPkgMap, sources, cycleMap);
}
}
}
@@ -1282,16 +1303,16 @@
return sources;
}
- private static Module getActualModule(Module m)
+ private static BundleRevision getActualBundleRevision(BundleRevision br)
{
- if (m instanceof HostModule)
+ if (br instanceof HostBundleRevision)
{
- return ((HostModule) m).getHost();
+ return ((HostBundleRevision) br).getHost();
}
- return m;
+ return br;
}
- private static BundleCapabilityImpl getActualCapability(BundleCapabilityImpl c)
+ private static BundleCapability getActualCapability(BundleCapability c)
{
if (c instanceof HostedCapability)
{
@@ -1300,7 +1321,7 @@
return c;
}
- private static BundleRequirementImpl getActualRequirement(BundleRequirementImpl r)
+ private static BundleRequirement getActualRequirement(BundleRequirement r)
{
if (r instanceof HostedRequirement)
{
@@ -1309,77 +1330,73 @@
return r;
}
- private static Map<Module, List<Wire>> populateWireMap(
- Module module, Map<Module, Packages> modulePkgMap,
- Map<Module, List<Wire>> wireMap,
+ private static Map<BundleRevision, List<ResolverWire>> populateWireMap(
+ BundleRevision revision, Map<BundleRevision, Packages> revisionPkgMap,
+ Map<BundleRevision, List<ResolverWire>> wireMap,
Candidates allCandidates)
{
- Module unwrappedModule = getActualModule(module);
- if (!unwrappedModule.isResolved() && !wireMap.containsKey(unwrappedModule))
+ BundleRevision unwrappedRevision = getActualBundleRevision(revision);
+ if ((unwrappedRevision.getWiring() == null)
+ && !wireMap.containsKey(unwrappedRevision))
{
- wireMap.put(unwrappedModule, (List<Wire>) Collections.EMPTY_LIST);
+ wireMap.put(unwrappedRevision, (List<ResolverWire>) Collections.EMPTY_LIST);
- List<Wire> packageWires = new ArrayList<Wire>();
- List<Wire> moduleWires = new ArrayList<Wire>();
+ List<ResolverWire> packageWires = new ArrayList<ResolverWire>();
+ List<ResolverWire> requireWires = new ArrayList<ResolverWire>();
- for (BundleRequirementImpl req : module.getDeclaredRequirements())
+ for (BundleRequirement req : revision.getDeclaredRequirements(null))
{
- SortedSet<BundleCapabilityImpl> cands = allCandidates.getCandidates(req);
+ SortedSet<BundleCapability> cands = allCandidates.getCandidates(req);
if ((cands != null) && (cands.size() > 0))
{
- BundleCapabilityImpl cand = cands.iterator().next();
- if (!cand.getModule().isResolved())
+ BundleCapability cand = cands.iterator().next();
+ if (cand.getRevision().getWiring() == null)
{
- populateWireMap(cand.getModule(),
- modulePkgMap, wireMap, allCandidates);
+ populateWireMap(cand.getRevision(),
+ revisionPkgMap, wireMap, allCandidates);
}
- // Ignore modules that import themselves.
- if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE)
- && !module.equals(cand.getModule()))
+ // Ignore revisions that import themselves.
+ if (!revision.equals(cand.getRevision()))
{
- packageWires.add(
- new WireImpl(
- unwrappedModule,
- getActualRequirement(req),
- getActualModule(cand.getModule()),
- getActualCapability(cand)));
- }
- else if (req.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
- {
- Packages candPkgs = modulePkgMap.get(cand.getModule());
- moduleWires.add(
- new WireModuleImpl(
- unwrappedModule,
- getActualRequirement(req),
- getActualModule(cand.getModule()),
- getActualCapability(cand),
- candPkgs.getExportedAndReexportedPackages()));
+ ResolverWire wire = new ResolverWireImpl(
+ unwrappedRevision,
+ (BundleRequirementImpl) getActualRequirement(req),
+ getActualBundleRevision(cand.getRevision()),
+ (BundleCapabilityImpl) getActualCapability(cand));
+ if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ packageWires.add(wire);
+ }
+ else if (req.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ requireWires.add(wire);
+ }
}
}
}
- // Combine wires with module wires last.
- packageWires.addAll(moduleWires);
- wireMap.put(unwrappedModule, packageWires);
+ // Combine package wires with require wires last.
+ packageWires.addAll(requireWires);
+ wireMap.put(unwrappedRevision, packageWires);
// Add host wire for any fragments.
- if (module instanceof HostModule)
+ if (revision instanceof HostBundleRevision)
{
- List<Module> fragments = ((HostModule) module).getFragments();
- for (Module fragment : fragments)
+ List<BundleRevision> fragments = ((HostBundleRevision) revision).getFragments();
+ for (BundleRevision fragment : fragments)
{
- List<Wire> hostWires = wireMap.get(fragment);
+ List<ResolverWire> hostWires = wireMap.get(fragment);
if (hostWires == null)
{
- hostWires = new ArrayList<Wire>();
+ hostWires = new ArrayList<ResolverWire>();
wireMap.put(fragment, hostWires);
}
hostWires.add(
- new WireImpl(
- getActualModule(fragment),
+ new ResolverWireImpl(
+ getActualBundleRevision(fragment),
getHostRequirement(fragment),
- unwrappedModule,
- getHostCapability(unwrappedModule)));
+ unwrappedRevision,
+ getHostCapability(unwrappedRevision)));
}
}
}
@@ -1387,65 +1404,67 @@
return wireMap;
}
- private static Map<Module, List<Wire>> populateDynamicWireMap(
- Module module, String pkgName, Map<Module, Packages> modulePkgMap,
- Map<Module, List<Wire>> wireMap, Candidates allCandidates)
+ private static Map<BundleRevision, List<ResolverWire>> populateDynamicWireMap(
+ BundleRevision revision, String pkgName, Map<BundleRevision, Packages> revisionPkgMap,
+ Map<BundleRevision, List<ResolverWire>> wireMap, Candidates allCandidates)
{
- wireMap.put(module, (List<Wire>) Collections.EMPTY_LIST);
+ wireMap.put(revision, (List<ResolverWire>) Collections.EMPTY_LIST);
- List<Wire> packageWires = new ArrayList<Wire>();
+ List<ResolverWire> packageWires = new ArrayList<ResolverWire>();
- Packages pkgs = modulePkgMap.get(module);
+ Packages pkgs = revisionPkgMap.get(revision);
for (Entry<String, List<Blame>> entry : pkgs.m_importedPkgs.entrySet())
{
for (Blame blame : entry.getValue())
{
- // Ignore modules that import themselves.
- if (!module.equals(blame.m_cap.getModule())
- && blame.m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
+ // Ignore revisions that import themselves.
+ if (!revision.equals(blame.m_cap.getRevision())
+ && blame.m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR)
+ .equals(pkgName))
{
- if (!blame.m_cap.getModule().isResolved())
+ if (blame.m_cap.getRevision().getWiring() == null)
{
- populateWireMap(blame.m_cap.getModule(), modulePkgMap, wireMap,
+ populateWireMap(blame.m_cap.getRevision(), revisionPkgMap, wireMap,
allCandidates);
}
Map<String, Object> attrs = new HashMap(1);
attrs.put(BundleCapabilityImpl.PACKAGE_ATTR, pkgName);
packageWires.add(
- new WireImpl(
- module,
+ new ResolverWireImpl(
+ revision,
// We need an unique requirement here or else subsequent
// dynamic imports for the same dynamic requirement will
// conflict with previous ones.
new BundleRequirementImpl(
- module,
+ revision,
BundleCapabilityImpl.PACKAGE_NAMESPACE,
Collections.EMPTY_MAP,
attrs),
- getActualModule(blame.m_cap.getModule()),
- getActualCapability(blame.m_cap)));
+ getActualBundleRevision(blame.m_cap.getRevision()),
+ (BundleCapabilityImpl) getActualCapability(blame.m_cap)));
}
}
}
- wireMap.put(module, packageWires);
+ wireMap.put(revision, packageWires);
return wireMap;
}
- private static void dumpModulePkgMap(Map<Module, Packages> modulePkgMap)
+ private static void dumpRevisionPkgMap(Map<BundleRevision, Packages> revisionPkgMap)
{
- System.out.println("+++MODULE PKG MAP+++");
- for (Entry<Module, Packages> entry : modulePkgMap.entrySet())
+ System.out.println("+++BUNDLE REVISION PKG MAP+++");
+ for (Entry<BundleRevision, Packages> entry : revisionPkgMap.entrySet())
{
- dumpModulePkgs(entry.getKey(), entry.getValue());
+ dumpRevisionPkgs(entry.getKey(), entry.getValue());
}
}
- private static void dumpModulePkgs(Module module, Packages packages)
+ private static void dumpRevisionPkgs(BundleRevision revision, Packages packages)
{
- System.out.println(module + " (" + (module.isResolved() ? "RESOLVED)" : "UNRESOLVED)"));
+ System.out.println(revision
+ + " (" + ((revision.getWiring() != null) ? "RESOLVED)" : "UNRESOLVED)"));
System.out.println(" EXPORTED");
for (Entry<String, Blame> entry : packages.m_exportedPkgs.entrySet())
{
@@ -1477,9 +1496,9 @@
{
BundleRequirementImpl req = blame.m_reqs.get(i);
sb.append(" ");
- sb.append(req.getModule().getSymbolicName());
+ sb.append(req.getRevision().getSymbolicName());
sb.append(" [");
- sb.append(req.getModule().toString());
+ sb.append(req.getRevision().toString());
sb.append("]\n");
if (req.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
@@ -1501,25 +1520,25 @@
}
if ((i + 1) < blame.m_reqs.size())
{
- BundleCapabilityImpl cap = Util.getSatisfyingCapability(
- blame.m_reqs.get(i + 1).getModule(),
+ BundleCapability cap = Util.getSatisfyingCapability(
+ blame.m_reqs.get(i + 1).getRevision(),
blame.m_reqs.get(i));
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
sb.append(BundleCapabilityImpl.PACKAGE_ATTR);
sb.append("=");
sb.append(cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).toString());
- BundleCapabilityImpl usedCap;
+ BundleCapability usedCap;
if ((i + 2) < blame.m_reqs.size())
{
usedCap = Util.getSatisfyingCapability(
- blame.m_reqs.get(i + 2).getModule(),
+ blame.m_reqs.get(i + 2).getRevision(),
blame.m_reqs.get(i + 1));
}
else
{
usedCap = Util.getSatisfyingCapability(
- blame.m_cap.getModule(),
+ blame.m_cap.getRevision(),
blame.m_reqs.get(i + 1));
}
sb.append("; uses:=");
@@ -1533,8 +1552,8 @@
}
else
{
- BundleCapabilityImpl export = Util.getSatisfyingCapability(
- blame.m_cap.getModule(),
+ BundleCapability export = Util.getSatisfyingCapability(
+ blame.m_cap.getRevision(),
blame.m_reqs.get(i));
sb.append(BundleCapabilityImpl.PACKAGE_ATTR);
sb.append("=");
@@ -1550,45 +1569,45 @@
sb.append(blame.m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).toString());
}
sb.append("\n ");
- sb.append(blame.m_cap.getModule().getSymbolicName());
+ sb.append(blame.m_cap.getRevision().getSymbolicName());
sb.append(" [");
- sb.append(blame.m_cap.getModule().toString());
+ sb.append(blame.m_cap.getRevision().toString());
sb.append("]");
}
}
}
else
{
- sb.append(blame.m_cap.getModule().toString());
+ sb.append(blame.m_cap.getRevision().toString());
}
return sb.toString();
}
private static class Packages
{
- private final Module m_module;
+ private final BundleRevision m_revision;
public final Map<String, Blame> m_exportedPkgs = new HashMap();
public final Map<String, List<Blame>> m_importedPkgs = new HashMap();
public final Map<String, List<Blame>> m_requiredPkgs = new HashMap();
public final Map<String, List<Blame>> m_usedPkgs = new HashMap();
- public Packages(Module module)
+ public Packages(BundleRevision revision)
{
- m_module = module;
+ m_revision = revision;
}
public List<String> getExportedAndReexportedPackages()
{
List<String> pkgs = new ArrayList();
- // Grab the module's actual exported packages.
+ // Grab the revision's actual exported packages.
// Note that we ignore the calculated exported packages here,
// because bundles that import their own exports still continue
// to provide access to their exports when they are required; i.e.,
// the implicitly reexport the packages if wired to another provider.
- List<BundleCapabilityImpl> caps = (m_module.isResolved())
- ? m_module.getResolvedCapabilities()
- : m_module.getDeclaredCapabilities();
- for (BundleCapabilityImpl cap : caps)
+ List<BundleCapability> caps = (m_revision.getWiring() != null)
+ ? m_revision.getWiring().getCapabilities(null)
+ : m_revision.getDeclaredCapabilities(null);
+ for (BundleCapability cap : caps)
{
if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
{
@@ -1618,10 +1637,10 @@
private static class Blame
{
- public final BundleCapabilityImpl m_cap;
+ public final BundleCapability m_cap;
public final List<BundleRequirementImpl> m_reqs;
- public Blame(BundleCapabilityImpl cap, List<BundleRequirementImpl> reqs)
+ public Blame(BundleCapability cap, List<BundleRequirementImpl> reqs)
{
m_cap = cap;
m_reqs = reqs;
@@ -1630,7 +1649,7 @@
@Override
public String toString()
{
- return m_cap.getModule()
+ return m_cap.getRevision()
+ "." + m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR)
+ (((m_reqs == null) || m_reqs.isEmpty())
? " NO BLAME"
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWire.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWire.java
new file mode 100644
index 0000000..69162b9
--- /dev/null
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWire.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.resolver;
+
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+
+public interface ResolverWire
+{
+ /**
+ * Returns the importing bundle revision.
+ * @return The importing bundle revision.
+ **/
+ public BundleRevision getRequirer();
+ /**
+ * Returns the associated requirement from the importing bundle revision
+ * that resulted in the creation of this wire.
+ * @return
+ **/
+ public BundleRequirement getRequirement();
+ /**
+ * Returns the exporting bundle revision.
+ * @return The exporting bundle revision.
+ **/
+ public BundleRevision getProvider();
+ /**
+ * Returns the associated capability from the exporting bundle revision
+ * that satisfies the requirement of the importing bundle revision.
+ * @return
+ **/
+ public BundleCapability getCapability();
+}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java
new file mode 100644
index 0000000..7a51877
--- /dev/null
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.resolver;
+
+import org.apache.felix.framework.wiring.BundleCapabilityImpl;
+import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+
+class ResolverWireImpl implements ResolverWire
+{
+ private final BundleRevision m_requirer;
+ private final BundleRequirement m_req;
+ private final BundleRevision m_provider;
+ private final BundleCapability m_cap;
+
+ public ResolverWireImpl(BundleRevision requirer, BundleRequirement req,
+ BundleRevision provider, BundleCapability cap)
+ {
+ m_requirer = requirer;
+ m_req = req;
+ m_provider = provider;
+ m_cap = cap;
+ }
+
+ public BundleRevision getRequirer()
+ {
+ return m_requirer;
+ }
+
+ public BundleRequirement getRequirement()
+ {
+ return m_req;
+ }
+
+ public BundleRevision getProvider()
+ {
+ return m_provider;
+ }
+
+ public BundleCapability getCapability()
+ {
+ return m_cap;
+ }
+
+ public String toString()
+ {
+ return "[" + m_requirer + "] "
+ + m_req
+ + " -> "
+ + "[" + m_provider + "]";
+ }
+}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/WireImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/WireImpl.java
deleted file mode 100755
index 39ddf0f..0000000
--- a/framework/src/main/java/org/apache/felix/framework/resolver/WireImpl.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.framework.resolver;
-
-import java.net.URL;
-import java.util.Enumeration;
-import org.apache.felix.framework.util.Util;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
-
-class WireImpl implements Wire
-{
- private final Module m_importer;
- private final BundleRequirementImpl m_req;
- private final Module m_exporter;
- private final BundleCapabilityImpl m_cap;
-
- public WireImpl(Module importer, BundleRequirementImpl ip,
- Module exporter, BundleCapabilityImpl cap)
- {
- m_importer = importer;
- m_req = ip;
- m_exporter = exporter;
- m_cap = cap;
- }
-
- public Module getImporter()
- {
- return m_importer;
- }
-
- public BundleRequirementImpl getRequirement()
- {
- return m_req;
- }
-
- public Module getExporter()
- {
- return m_exporter;
- }
-
- public BundleCapabilityImpl getCapability()
- {
- return m_cap;
- }
-
- public String toString()
- {
- return "[" + m_importer + "] "
- + m_req.getNamespace() + "; "
- + m_req.getFilter() + " -> "
- + "[" + m_exporter + "]";
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
- */
- public boolean hasPackage(String pkgName)
- {
- return (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
- m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName));
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
- */
- public Class getClass(String name) throws ClassNotFoundException
- {
- Class clazz = null;
-
- // Get the package of the target class.
- String pkgName = Util.getClassPackage(name);
-
- // Only check when the package of the target class is
- // the same as the package for the wire.
- if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
- m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
- {
- // Check the include/exclude filters from the target package
- // to make sure that the class is actually visible. We delegate
- // to the exporting module, rather than its content, so it can
- // it can follow any internal wires it may have (e.g., if the
- // package has multiple sources).
- if (m_cap.isIncluded(name))
- {
- clazz = m_exporter.getClassByDelegation(name);
- }
-
- // If no class was found, then we must throw an exception
- // since the exporter for this package did not contain the
- // requested class.
- if (clazz == null)
- {
- throw new ClassNotFoundException(name);
- }
- }
-
- return clazz;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
- */
- public URL getResource(String name) throws ResourceNotFoundException
- {
- URL url = null;
-
- // Get the package of the target class.
- String pkgName = Util.getResourcePackage(name);
-
- // Only check when the package of the target resource is
- // the same as the package for the wire.
- if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
- m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
- {
- // Delegate to the exporting module, rather than its
- // content, so that it can follow any internal wires it may have
- // (e.g., if the package has multiple sources).
- url = m_exporter.getResourceByDelegation(name);
-
- // If no resource was found, then we must throw an exception
- // since the exporter for this package did not contain the
- // requested class.
- if (url == null)
- {
- throw new ResourceNotFoundException(name);
- }
- }
-
- return url;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getResources(java.lang.String)
- */
- public Enumeration getResources(String name) throws ResourceNotFoundException
- {
- Enumeration urls = null;
-
- // Get the package of the target class.
- String pkgName = Util.getResourcePackage(name);
-
- // Only check when the package of the target resource is
- // the same as the package for the wire.
- if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
- m_cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName))
- {
- urls = m_exporter.getResourcesByDelegation(name);
-
- // If no resource was found, then we must throw an exception
- // since the exporter for this package did not contain the
- // requested class.
- if ((urls == null) || !urls.hasMoreElements())
- {
- throw new ResourceNotFoundException(name);
- }
- }
-
- return urls;
- }
-}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/WireModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/WireModuleImpl.java
deleted file mode 100644
index 293c2b1..0000000
--- a/framework/src/main/java/org/apache/felix/framework/resolver/WireModuleImpl.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.framework.resolver;
-
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.List;
-import org.apache.felix.framework.util.Util;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
-
-class WireModuleImpl implements Wire
-{
- private final Module m_importer;
- private final BundleRequirementImpl m_req;
- private final Module m_exporter;
- private final BundleCapabilityImpl m_cap;
- private final List<String> m_packages;
-
- public WireModuleImpl(Module importer, BundleRequirementImpl requirement,
- Module exporter, BundleCapabilityImpl cap, List<String> packages)
- {
- m_importer = importer;
- m_req = requirement;
- m_exporter = exporter;
- m_cap = cap;
- m_packages = packages;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getImporter()
- */
- public Module getImporter()
- {
- return m_importer;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getRequirement()
- */
- public BundleRequirementImpl getRequirement()
- {
- return m_req;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getExporter()
- */
- public Module getExporter()
- {
- return m_exporter;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getCapability()
- */
- public BundleCapabilityImpl getCapability()
- {
- return m_cap;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#hasPackage(java.lang.String)
- */
- public boolean hasPackage(String pkgName)
- {
- return m_packages.contains(pkgName);
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
- */
- public Class getClass(String name) throws ClassNotFoundException
- {
- // Get the package of the target class.
- String pkgName = Util.getClassPackage(name);
- if (m_packages.contains(pkgName))
- {
- try
- {
- Class clazz = m_exporter.getClassByDelegation(name);
- if (clazz != null)
- {
- return clazz;
- }
- }
- catch (ClassNotFoundException ex)
- {
- // Do not throw the exception here, since we want
- // to continue search other package sources and
- // ultimately the module's own content.
- }
- }
-
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
- */
- public URL getResource(String name) throws ResourceNotFoundException
- {
- // Get the package of the target class.
- String pkgName = Util.getResourcePackage(name);
- if (m_packages.contains(pkgName))
- {
- URL url = m_exporter.getResourceByDelegation(name);
- if (url != null)
- {
- return url;
- }
-
- // Don't throw ResourceNotFoundException because module
- // dependencies support split packages.
- }
-
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.apache.felix.framework.searchpolicy.IWire#getResources(java.lang.String)
- */
- public Enumeration getResources(String name) throws ResourceNotFoundException
- {
- // Get the package of the target class.
- String pkgName = Util.getResourcePackage(name);
-
- // See if we have a resolved package for the resource's package.
- if (m_packages.contains(pkgName))
- {
- Enumeration urls = m_exporter.getResourcesByDelegation(name);
- if ((urls != null) && urls.hasMoreElements())
- {
- return urls;
- }
-
- // Don't throw ResourceNotFoundException because module
- // dependencies support split packages.
- }
-
- return null;
- }
-
- public String toString()
- {
- return m_req + " -> " + "[" + m_exporter + "]";
- }
-}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/util/Util.java b/framework/src/main/java/org/apache/felix/framework/util/Util.java
index 842a63b..38f8ecf 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/Util.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/Util.java
@@ -26,16 +26,17 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import org.apache.felix.framework.BundleRevisionImpl;
import org.apache.felix.framework.Logger;
import org.apache.felix.framework.capabilityset.CapabilitySet;
-import org.apache.felix.framework.resolver.Module;
-import org.apache.felix.framework.resolver.Wire;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.wiring.FelixBundleWire;
import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
public class Util
{
@@ -85,11 +86,11 @@
}
/**
- * Converts a module identifier to a bundle identifier. Module IDs
+ * Converts a revision identifier to a bundle identifier. Revision IDs
* are typically <tt><bundle-id>.<revision></tt>; this
* method returns only the portion corresponding to the bundle ID.
**/
- public static long getBundleIdFromModuleId(String id)
+ public static long getBundleIdFromRevisionId(String id)
{
try
{
@@ -279,17 +280,18 @@
return allow;
}
- public static BundleCapabilityImpl getSatisfyingCapability(Module m, BundleRequirementImpl req)
+ public static BundleCapability getSatisfyingCapability(
+ BundleRevision br, BundleRequirementImpl req)
{
- List<BundleCapabilityImpl> caps = (m.isResolved())
- ? m.getResolvedCapabilities()
- : m.getDeclaredCapabilities();
+ List<BundleCapability> caps = (br.getWiring() != null)
+ ? br.getWiring().getCapabilities(null)
+ : br.getDeclaredCapabilities(null);
if (caps != null)
{
- for (BundleCapabilityImpl cap : caps)
+ for (BundleCapability cap : caps)
{
if (cap.getNamespace().equals(req.getNamespace())
- && CapabilitySet.matches(cap, req.getFilter()))
+ && CapabilitySet.matches((BundleCapabilityImpl) cap, req.getFilter()))
{
return cap;
}
@@ -301,19 +303,20 @@
/**
* Returns all the capabilities from a module that has a specified namespace.
*
- * @param m module providing capabilities
+ * @param br module providing capabilities
* @param namespace capability namespace
* @return array of matching capabilities or empty if none found
*/
- public static List<BundleCapabilityImpl> getCapabilityByNamespace(Module m, String namespace)
+ public static List<BundleCapability> getCapabilityByNamespace(
+ BundleRevision br, String namespace)
{
- final List<BundleCapabilityImpl> matching = new ArrayList();
- final List<BundleCapabilityImpl> caps = (m.isResolved())
- ? m.getResolvedCapabilities()
- : m.getDeclaredCapabilities();
+ final List<BundleCapability> matching = new ArrayList();
+ final List<BundleCapability> caps = (br.getWiring() != null)
+ ? br.getWiring().getCapabilities(null)
+ : br.getDeclaredCapabilities(null);
if (caps != null)
{
- for (BundleCapabilityImpl cap : caps)
+ for (BundleCapability cap : caps)
{
if (cap.getNamespace().equals(namespace))
{
@@ -324,12 +327,12 @@
return matching;
}
- public static Wire getWire(Module m, String name)
+ public static FelixBundleWire getWire(BundleRevision br, String name)
{
- List<Wire> wires = m.getWires();
+ List<FelixBundleWire> wires = ((BundleRevisionImpl) br).getWires();
if (wires != null)
{
- for (Wire w : wires)
+ for (FelixBundleWire w : wires)
{
if (w.getCapability().getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE) &&
w.getCapability().getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR).equals(name))
@@ -587,9 +590,8 @@
* @return <code>true</code> if the module declares a fragment host, <code>false</code>
* otherwise.
*/
- public static boolean isFragment(Module module)
+ public static boolean isFragment(BundleRevision revision)
{
- Map headerMap = module.getHeaders();
- return headerMap.containsKey(Constants.FRAGMENT_HOST);
+ return ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) > 0);
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
index fed65bf..e4020e0 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
@@ -21,33 +21,36 @@
import java.util.*;
import java.util.ArrayList;
import java.util.Map.Entry;
+import org.apache.felix.framework.BundleRevisionImpl;
import org.apache.felix.framework.Logger;
import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.VersionRange;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
import org.osgi.framework.*;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
public class ManifestParser
{
private final Logger m_logger;
private final Map m_configMap;
private final Map m_headerMap;
- private volatile int m_activationPolicy = Module.EAGER_ACTIVATION;
+ private volatile int m_activationPolicy = BundleRevisionImpl.EAGER_ACTIVATION;
private volatile String m_activationIncludeDir;
private volatile String m_activationExcludeDir;
private volatile boolean m_isExtension = false;
private volatile String m_bundleSymbolicName;
private volatile Version m_bundleVersion;
- private volatile List<BundleCapabilityImpl> m_capabilities;
- private volatile List<BundleRequirementImpl> m_requirements;
- private volatile List<BundleRequirementImpl> m_dynamicRequirements;
+ private volatile List<BundleCapability> m_capabilities;
+ private volatile List<BundleRequirement> m_requirements;
+ private volatile List<BundleRequirement> m_dynamicRequirements;
private volatile List<R4LibraryClause> m_libraryClauses;
private volatile boolean m_libraryHeadersOptional = false;
- public ManifestParser(Logger logger, Map configMap, Module owner, Map headerMap)
+ public ManifestParser(Logger logger, Map configMap, BundleRevision owner, Map headerMap)
throws BundleException
{
m_logger = logger;
@@ -92,41 +95,41 @@
// Parse bundle symbolic name.
//
- BundleCapabilityImpl moduleCap = parseBundleSymbolicName(owner, m_headerMap);
- if (moduleCap != null)
+ BundleCapabilityImpl requireCap = parseBundleSymbolicName(owner, m_headerMap);
+ if (requireCap != null)
{
m_bundleSymbolicName = (String)
- moduleCap.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
+ requireCap.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
- // Add a module capability and a host capability to all
+ // Add a bundle capability and a host capability to all
// non-fragment bundles. A host capability is the same
- // as a module capability, but with a different capability
- // namespace. Module capabilities resolve required-bundle
+ // as a require capability, but with a different capability
+ // namespace. Bundle capabilities resolve required-bundle
// dependencies, while host capabilities resolve fragment-host
// dependencies.
if (headerMap.get(Constants.FRAGMENT_HOST) == null)
{
- capList.add(moduleCap);
+ capList.add(requireCap);
capList.add(new BundleCapabilityImpl(
owner, BundleCapabilityImpl.HOST_NAMESPACE,
Collections.EMPTY_MAP,
// TODO: OSGi R4.3 - Wraps map as unmodifiable twice.
- moduleCap.getAttributes()));
+ requireCap.getAttributes()));
}
// Add a singleton capability if the bundle is a singleton.
// This is sort of a hack, but we need this for the resolver
// to be able to resolve singletons. It is not possible to
- // attach this information to the module or host capabilities
+ // attach this information to the bundle or host capabilities
// because fragments don't have those capabilities, but fragments
// can be singletons too.
- if (isSingleton(moduleCap))
+ if (isSingleton(requireCap))
{
capList.add(new BundleCapabilityImpl(
owner, BundleCapabilityImpl.SINGLETON_NAMESPACE,
Collections.EMPTY_MAP,
// TODO: OSGi R4.3 - Wraps map as unmodifiable twice.
- moduleCap.getAttributes()));
+ requireCap.getAttributes()));
}
}
@@ -159,7 +162,7 @@
List<ParsedHeaderClause> importClauses =
parseStandardHeader((String) headerMap.get(Constants.IMPORT_PACKAGE));
importClauses = normalizeImportClauses(m_logger, importClauses, getManifestVersion());
- List<BundleRequirementImpl> importReqs = convertImports(importClauses, owner);
+ List<BundleRequirement> importReqs = convertImports(importClauses, owner);
//
// Parse DynamicImport-Package.
@@ -179,7 +182,7 @@
parseStandardHeader((String) headerMap.get(Constants.EXPORT_PACKAGE));
exportClauses = normalizeExportClauses(logger, exportClauses,
getManifestVersion(), m_bundleSymbolicName, m_bundleVersion);
- List<BundleCapabilityImpl> exportCaps = convertExports(exportClauses, owner);
+ List<BundleCapability> exportCaps = convertExports(exportClauses, owner);
//
// Calculate implicit imports.
@@ -216,7 +219,7 @@
// Parse Bundle-NativeCode.
//
- // Get native library entry names for module library sources.
+ // Parse native library clauses.
m_libraryClauses =
parseLibraryStrings(
m_logger,
@@ -244,7 +247,7 @@
private static boolean isSingleton(BundleCapabilityImpl cap)
{
- if (cap.getNamespace().equals(BundleCapabilityImpl.MODULE_NAMESPACE))
+ if (cap.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
{
String value = cap.getDirectives().get(Constants.SINGLETON_DIRECTIVE);
if ((value != null) && Boolean.valueOf(value))
@@ -382,8 +385,8 @@
return clauses;
}
- private static List<BundleRequirementImpl> convertImports(
- List<ParsedHeaderClause> clauses, Module owner)
+ private static List<BundleRequirement> convertImports(
+ List<ParsedHeaderClause> clauses, BundleRevision owner)
{
// Now convert generic header clauses into requirements.
List reqList = new ArrayList();
@@ -682,17 +685,17 @@
return m_bundleVersion;
}
- public List<BundleCapabilityImpl> getCapabilities()
+ public List<BundleCapability> getCapabilities()
{
return m_capabilities;
}
- public List<BundleRequirementImpl> getRequirements()
+ public List<BundleRequirement> getRequirements()
{
return m_requirements;
}
- public List<BundleRequirementImpl> getDynamicRequirements()
+ public List<BundleRequirement> getDynamicRequirements()
{
return m_dynamicRequirements;
}
@@ -917,7 +920,7 @@
}
private static List<ParsedHeaderClause> calculateImplicitImports(
- List<BundleCapabilityImpl> exports, List<ParsedHeaderClause> imports)
+ List<BundleCapability> exports, List<ParsedHeaderClause> imports)
throws BundleException
{
List<ParsedHeaderClause> clauseList = new ArrayList();
@@ -963,8 +966,8 @@
return clauseList;
}
- private static List<BundleCapabilityImpl> calculateImplicitUses(
- List<BundleCapabilityImpl> exports, List<ParsedHeaderClause> imports)
+ private static List<BundleCapability> calculateImplicitUses(
+ List<BundleCapability> exports, List<ParsedHeaderClause> imports)
throws BundleException
{
// Add a "uses" directive onto each export of R3 bundles
@@ -987,7 +990,7 @@
Map<String, String> dirs = new HashMap<String, String>(1);
dirs.put(Constants.USES_DIRECTIVE, usesValue);
exports.set(i, new BundleCapabilityImpl(
- exports.get(i).getModule(),
+ exports.get(i).getRevision(),
BundleCapabilityImpl.PACKAGE_NAMESPACE,
dirs,
exports.get(i).getAttributes()));
@@ -1022,7 +1025,8 @@
return false;
}
- private static BundleCapabilityImpl parseBundleSymbolicName(Module owner, Map headerMap)
+ private static BundleCapabilityImpl parseBundleSymbolicName(
+ BundleRevision owner, Map headerMap)
throws BundleException
{
List<ParsedHeaderClause> clauses = parseStandardHeader(
@@ -1063,14 +1067,14 @@
}
}
- // Create a module capability and return it.
+ // Create a require capability and return it.
String symName = (String) clauses.get(0).m_paths.get(0);
Map<String, Object> attrs = new HashMap<String, Object>(2);
attrs.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, symName);
attrs.put(Constants.BUNDLE_VERSION_ATTRIBUTE, bundleVersion);
return new BundleCapabilityImpl(
owner,
- BundleCapabilityImpl.MODULE_NAMESPACE,
+ BundleCapabilityImpl.BUNDLE_NAMESPACE,
clauses.get(0).m_dirs,
attrs);
}
@@ -1079,7 +1083,7 @@
}
private static List<BundleRequirementImpl> parseFragmentHost(
- Logger logger, Module owner, Map headerMap)
+ Logger logger, BundleRevision owner, Map headerMap)
throws BundleException
{
List<BundleRequirementImpl> reqs = new ArrayList();
@@ -1155,11 +1159,11 @@
return reqs;
}
- public static List<BundleCapabilityImpl> parseExportHeader(
- Logger logger, Module owner, String header, String bsn, Version bv)
+ public static List<BundleCapability> parseExportHeader(
+ Logger logger, BundleRevision owner, String header, String bsn, Version bv)
{
- List<BundleCapabilityImpl> caps = null;
+ List<BundleCapability> caps = null;
try
{
List<ParsedHeaderClause> exportClauses = parseStandardHeader(header);
@@ -1173,10 +1177,10 @@
return caps;
}
- private static List<BundleCapabilityImpl> convertExports(
- List<ParsedHeaderClause> clauses, Module owner)
+ private static List<BundleCapability> convertExports(
+ List<ParsedHeaderClause> clauses, BundleRevision owner)
{
- List<BundleCapabilityImpl> capList = new ArrayList();
+ List<BundleCapability> capList = new ArrayList();
for (int clauseIdx = 0; clauseIdx < clauses.size(); clauseIdx++)
{
for (int pathIdx = 0;
@@ -1232,7 +1236,7 @@
}
private static List<BundleRequirementImpl> convertRequires(
- List<ParsedHeaderClause> clauses, Module owner)
+ List<ParsedHeaderClause> clauses, BundleRevision owner)
{
List<BundleRequirementImpl> reqList = new ArrayList();
for (int clauseIdx = 0; clauseIdx < clauses.size(); clauseIdx++)
@@ -1259,7 +1263,7 @@
reqList.add(
new BundleRequirementImpl(
owner,
- BundleCapabilityImpl.MODULE_NAMESPACE,
+ BundleCapabilityImpl.BUNDLE_NAMESPACE,
clauses.get(clauseIdx).m_dirs,
newAttrs));
}
@@ -1303,7 +1307,7 @@
private void parseActivationPolicy(Map headerMap)
{
- m_activationPolicy = Module.EAGER_ACTIVATION;
+ m_activationPolicy = BundleRevisionImpl.EAGER_ACTIVATION;
List<ParsedHeaderClause> clauses = parseStandardHeader(
(String) headerMap.get(Constants.BUNDLE_ACTIVATIONPOLICY));
@@ -1316,7 +1320,7 @@
{
if (clauses.get(0).m_paths.get(clauseIdx).equals(Constants.ACTIVATION_LAZY))
{
- m_activationPolicy = Module.LAZY_ACTIVATION;
+ m_activationPolicy = BundleRevisionImpl.LAZY_ACTIVATION;
for (Entry<String, String> entry : clauses.get(0).m_dirs.entrySet())
{
if (entry.getKey().equalsIgnoreCase(Constants.INCLUDE_DIRECTIVE))
diff --git a/framework/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java b/framework/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java
index e0809d8..e8ffef7 100644
--- a/framework/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java
@@ -26,7 +26,6 @@
import java.util.List;
import java.util.StringTokenizer;
import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
import org.osgi.framework.Constants;
@@ -35,7 +34,7 @@
public class BundleCapabilityImpl implements BundleCapability
{
- public static final String MODULE_NAMESPACE = "module";
+ public static final String BUNDLE_NAMESPACE = "module";
public static final String HOST_NAMESPACE = "host";
public static final String PACKAGE_NAMESPACE = "package";
public static final String SINGLETON_NAMESPACE = "singleton";
@@ -43,7 +42,7 @@
public static final String PACKAGE_ATTR = "package";
public static final String VERSION_ATTR = "version";
- private final Module m_module;
+ private final BundleRevision m_revision;
private final String m_namespace;
private final Map<String, String> m_dirs;
private final Map<String, Object> m_attrs;
@@ -52,11 +51,11 @@
private final List<List<String>> m_excludeFilter;
private final Set<String> m_mandatory;
- public BundleCapabilityImpl(Module module, String namespace,
+ public BundleCapabilityImpl(BundleRevision revision, String namespace,
Map<String, String> dirs, Map<String, Object> attrs)
{
m_namespace = namespace;
- m_module = module;
+ m_revision = revision;
m_dirs = Collections.unmodifiableMap(dirs);
m_attrs = Collections.unmodifiableMap(attrs);
@@ -128,14 +127,9 @@
}
}
- public Module getModule()
- {
- return m_module;
- }
-
public BundleRevision getRevision()
{
- return null;
+ return m_revision;
}
public String getNamespace()
@@ -197,15 +191,15 @@
public String toString()
{
- if (m_module == null)
+ if (m_revision == null)
{
return m_attrs.toString();
}
if (m_namespace.equals(PACKAGE_NAMESPACE))
{
- return "[" + m_module + "] "
+ return "[" + m_revision + "] "
+ m_namespace + "; " + m_attrs.get(PACKAGE_ATTR);
}
- return "[" + m_module + "] " + m_namespace + "; " + m_attrs;
+ return "[" + m_revision + "] " + m_namespace + "; " + m_attrs;
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java b/framework/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java
index f64d088..00f579f 100644
--- a/framework/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java
@@ -20,13 +20,11 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.felix.framework.capabilityset.CapabilitySet;
import org.apache.felix.framework.capabilityset.SimpleFilter;
-import org.apache.felix.framework.resolver.Module;
import org.apache.felix.framework.util.VersionRange;
import org.osgi.framework.Constants;
import org.osgi.framework.wiring.BundleCapability;
@@ -35,7 +33,7 @@
public class BundleRequirementImpl implements BundleRequirement
{
- private final Module m_module;
+ private final BundleRevision m_revision;
private final String m_namespace;
private final SimpleFilter m_filter;
private final boolean m_optional;
@@ -43,10 +41,10 @@
private final Map<String, Object> m_attrs;
public BundleRequirementImpl(
- Module module, String namespace,
+ BundleRevision revision, String namespace,
Map<String, String> dirs, Map<String, Object> attrs)
{
- m_module = module;
+ m_revision = revision;
m_namespace = namespace;
m_dirs = Collections.unmodifiableMap(dirs);
m_attrs = Collections.unmodifiableMap(attrs);
@@ -77,14 +75,9 @@
return m_attrs;
}
- public Module getModule()
- {
- return m_module;
- }
-
public BundleRevision getRevision()
{
- throw new UnsupportedOperationException("Not supported yet.");
+ return m_revision;
}
public boolean matches(BundleCapability cap)
@@ -104,7 +97,7 @@
public String toString()
{
- return "[" + m_module + "] " + m_namespace + "; " + getFilter().toString();
+ return "[" + m_revision + "] " + m_namespace + "; " + getFilter().toString();
}
private static SimpleFilter convertToFilter(Map<String, Object> attrs)
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Wire.java b/framework/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java
similarity index 75%
rename from framework/src/main/java/org/apache/felix/framework/resolver/Wire.java
rename to framework/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java
index a4a91df..539e24b 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Wire.java
+++ b/framework/src/main/java/org/apache/felix/framework/wiring/FelixBundleWire.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -16,37 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.framework.resolver;
+package org.apache.felix.framework.wiring;
import java.net.URL;
import java.util.Enumeration;
-import org.apache.felix.framework.wiring.BundleCapabilityImpl;
-import org.apache.felix.framework.wiring.BundleRequirementImpl;
+import org.apache.felix.framework.resolver.ResourceNotFoundException;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
-public interface Wire
+public interface FelixBundleWire extends BundleWire
{
- /**
- * Returns the importing module.
- * @return The importing module.
- **/
- public Module getImporter();
- /**
- * Returns the associated requirement from the importing module that
- * resulted in the creation of this wire.
- * @return
- **/
- public BundleRequirementImpl getRequirement();
- /**
- * Returns the exporting module.
- * @return The exporting module.
- **/
- public Module getExporter();
- /**
- * Returns the associated capability from the exporting module that
- * satisfies the requirement of the importing module.
- * @return
- **/
- public BundleCapabilityImpl getCapability();
+ public BundleRevision getRequirer();
+
+ public BundleRevision getProvider();
+
/**
* Returns whether or not the wire has a given package name. For some
* wires, such as ones for Require-Bundle, there may be many packages.
@@ -57,7 +40,7 @@
* @return <tt>true</tt> if the package name is attainable from this wire,
* <tt>false</tt> otherwise.
**/
- public boolean hasPackage(String pkgName);
+ boolean hasPackage(String pkgName);
/**
* Requests a class from the exporting module. If the class is found, then
* it is returned. If the class is not found, then this method may or may
@@ -70,7 +53,7 @@
* @throws java.lang.ClassNotFoundException If the class was not found and
* the search should be aborted.
**/
- public Class getClass(String name) throws ClassNotFoundException;
+ Class getClass(String name) throws ClassNotFoundException;
/**
* Requests a resource from the exporting module. If the resource is found,
* then an URL is returned. If the resource is not found, then this method may
@@ -83,7 +66,7 @@
* @throws ResourceNotFoundException If the resource was not found and
* the search should be aborted.
**/
- public URL getResource(String name) throws ResourceNotFoundException;
+ URL getResource(String name) throws ResourceNotFoundException;
/**
* Requests resources from the exporting module. If the resources are found,
* then an enumeration of URLs is returned. If the resources are not found,
@@ -96,5 +79,5 @@
* @throws ResourceNotFoundException If the resource was not found and
* the search should be aborted.
**/
- public Enumeration getResources(String name) throws ResourceNotFoundException;
+ Enumeration getResources(String name) throws ResourceNotFoundException;
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java b/framework/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java
new file mode 100644
index 0000000..c075a02
--- /dev/null
+++ b/framework/src/main/java/org/apache/felix/framework/wiring/FelixBundleWireImpl.java
@@ -0,0 +1,278 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.wiring;
+
+import org.apache.felix.framework.resolver.*;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.felix.framework.BundleRevisionImpl;
+import org.apache.felix.framework.util.Util;
+import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
+
+// TODO: OSGi R4.3 - Should this be in framework package?
+public class FelixBundleWireImpl implements FelixBundleWire
+{
+ private final BundleRevision m_requirer;
+ private final BundleRequirement m_req;
+ private final BundleRevision m_provider;
+ private final BundleCapability m_cap;
+ private volatile Set<String> m_packages;
+
+ public FelixBundleWireImpl(BundleRevision requirer, BundleRequirement req,
+ BundleRevision provider, BundleCapability cap)
+ {
+ m_requirer = requirer;
+ m_req = req;
+ m_provider = provider;
+ m_cap = cap;
+ }
+
+ public BundleRevision getRequirer()
+ {
+ return m_requirer;
+ }
+
+ public BundleWiring getRequirerWiring()
+ {
+ return m_requirer.getWiring();
+ }
+
+ public BundleRequirement getRequirement()
+ {
+ return m_req;
+ }
+
+ public BundleRevision getProvider()
+ {
+ return m_provider;
+ }
+
+ public BundleWiring getProviderWiring()
+ {
+ return m_provider.getWiring();
+ }
+
+ public BundleCapability getCapability()
+ {
+ return m_cap;
+ }
+
+ public String toString()
+ {
+ return "[" + m_requirer + "] "
+ + m_req
+ + " -> "
+ + "[" + m_provider + "]";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+ */
+ public boolean hasPackage(String pkgName)
+ {
+ boolean result = false;
+ if (m_cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ result = m_cap.getAttributes()
+ .get(BundleCapabilityImpl.PACKAGE_ATTR).equals(pkgName);
+ }
+ else if (m_cap.getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ if (m_packages == null)
+ {
+ m_packages = calculateRequiredPackages(
+ m_provider.getWiring(), new HashSet<String>());
+ }
+ result = m_packages.contains(pkgName);
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+ */
+ public Class getClass(String name) throws ClassNotFoundException
+ {
+ Class clazz = null;
+
+ // Get the package of the target class.
+ String pkgName = Util.getClassPackage(name);
+
+ // Only check if this wire provides the target package.
+ if (hasPackage(pkgName))
+ {
+ String namespace = m_cap.getNamespace();
+ if (namespace.equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ // Check the include/exclude filters from the target package
+ // to make sure that the class is actually visible. We delegate
+ // to the exporting revision, rather than its content, so it can
+ // it can follow any internal wires it may have (e.g., if the
+ // package has multiple sources).
+ if (((BundleCapabilityImpl) m_cap).isIncluded(name))
+ {
+ clazz = ((BundleRevisionImpl) m_provider).getClassByDelegation(name);
+ }
+
+ // If no class was found, then we must throw an exception
+ // since the exporter for this package did not contain the
+ // requested class.
+ if (clazz == null)
+ {
+ throw new ClassNotFoundException(name);
+ }
+ }
+ else if (namespace.equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ try
+ {
+ clazz = ((BundleRevisionImpl) m_provider).getClassByDelegation(name);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // Do not throw the exception here, since we want
+ // to continue search other package sources and
+ // ultimately the revision's own content.
+ }
+ }
+ }
+
+ return clazz;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
+ */
+ public URL getResource(String name) throws ResourceNotFoundException
+ {
+ URL url = null;
+
+ // Get the package of the target class.
+ String pkgName = Util.getResourcePackage(name);
+
+ // Only check if this wire provides the target package.
+ if (hasPackage(pkgName))
+ {
+ String namespace = m_cap.getNamespace();
+ if (namespace.equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ // Delegate to the exporting revision, rather than its
+ // content, so that it can follow any internal wires it may have
+ // (e.g., if the package has multiple sources).
+ url = ((BundleRevisionImpl) m_provider).getResourceByDelegation(name);
+
+ // If no resource was found, then we must throw an exception
+ // since the exporter for this package did not contain the
+ // requested class.
+ if (url == null)
+ {
+ throw new ResourceNotFoundException(name);
+ }
+ }
+ else if (namespace.equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ url = ((BundleRevisionImpl) m_provider).getResourceByDelegation(name);
+
+ // Don't throw ResourceNotFoundException because require-bundle
+ // dependencies support split packages.
+ }
+
+ }
+
+ return url;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResources(java.lang.String)
+ */
+ public Enumeration getResources(String name) throws ResourceNotFoundException
+ {
+ Enumeration urls = null;
+
+ // Get the package of the target class.
+ String pkgName = Util.getResourcePackage(name);
+
+ // Only check if this wire provides the target package.
+ if (hasPackage(pkgName))
+ {
+ String namespace = m_cap.getNamespace();
+ if (namespace.equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ urls = ((BundleRevisionImpl) m_provider).getResourcesByDelegation(name);
+
+ // If no resource was found, then we must throw an exception
+ // since the exporter for this package did not contain the
+ // requested class.
+ if ((urls == null) || !urls.hasMoreElements())
+ {
+ throw new ResourceNotFoundException(name);
+ }
+ }
+ else if (namespace.equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ urls = ((BundleRevisionImpl) m_provider).getResourcesByDelegation(name);
+
+ // Don't throw ResourceNotFoundException because require-bundle
+ // dependencies support split packages.
+ }
+ }
+
+ return urls;
+ }
+
+ private static Set<String> calculateRequiredPackages(
+ BundleWiring providerWiring, Set<String> packages)
+ {
+// TODO: OSGi R4.3 - This might be calcualted differently when BundleWiring
+// returns the proper information.
+
+ // Add exported packages.
+ for (BundleCapability cap : providerWiring.getCapabilities(null))
+ {
+ if (cap.getNamespace().equals(BundleCapabilityImpl.PACKAGE_NAMESPACE))
+ {
+ packages.add(
+ (String) cap.getAttributes().get(BundleCapabilityImpl.PACKAGE_ATTR));
+ }
+ }
+
+ // Add re-exported packages for any required bundle dependencies
+ // that are re-exported.
+ for (BundleWire bw : providerWiring.getRequiredWires(null))
+ {
+ if (bw.getRequirement().getNamespace().equals(BundleCapabilityImpl.BUNDLE_NAMESPACE))
+ {
+ String dir =
+ bw.getRequirement().getDirectives().get(Constants.VISIBILITY_DIRECTIVE);
+ if ((dir != null) && (dir.equals(Constants.VISIBILITY_REEXPORT)))
+ {
+ calculateRequiredPackages(bw.getProviderWiring(), packages);
+ }
+ }
+ }
+ return packages;
+ }
+}
\ No newline at end of file