Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ResolverStateImpl.java Tue Apr 19 14:16:59 2011 @@ -29,25 +29,26 @@ import java.util.StringTokenizer; 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 @@ class ResolverStateImpl implements Resol 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 @@ class ResolverStateImpl implements Resol 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 @@ class ResolverStateImpl implements Resol 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 @@ class ResolverStateImpl implements Resol } } - 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 @@ class ResolverStateImpl implements Resol } } - 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 @@ class ResolverStateImpl implements Resol // 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 @@ class ResolverStateImpl implements Resol } if (req.getNamespace().equals(BundleCapabilityImpl.HOST_NAMESPACE) - && cap.getModule().isResolved()) + && (cap.getRevision().getWiring() != null)) { continue; } @@ -231,10 +235,11 @@ class ResolverStateImpl implements Resol 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 @@ class ResolverStateImpl implements Resol { 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 @@ class ResolverStateImpl implements Resol 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 @@ class ResolverStateImpl implements Resol } if (msg != null) { - throw new ResolveException(msg, module, null); + throw new ResolveException(msg, revision, null); } } }
Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java Tue Apr 19 14:16:59 2011 @@ -22,15 +22,15 @@ import java.security.AccessController; 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 @@ class ServiceRegistrationImpl implements // @Override - public Module getModule() + public BundleRevision getRevision() { throw new UnsupportedOperationException("Not supported yet."); } @@ -485,12 +485,12 @@ class ServiceRegistrationImpl implements // 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 @@ class ServiceRegistrationImpl implements // 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 @@ class ServiceRegistrationImpl implements // 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 @@ class ServiceRegistrationImpl implements 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 @@ class ServiceRegistrationImpl implements 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 @@ class ServiceRegistrationImpl implements // 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 @@ class ServiceRegistrationImpl implements 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 @@ class ServiceRegistrationImpl implements 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; Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistry.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistry.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistry.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/ServiceRegistry.java Tue Apr 19 14:16:59 2011 @@ -26,6 +26,7 @@ import org.apache.felix.framework.wiring 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 @@ public class ServiceRegistry } // 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); } Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleStreamHandler.java Tue Apr 19 14:16:59 2011 @@ -132,7 +132,7 @@ class URLHandlersBundleStreamHandler ext } } Felix felix = (Felix) framework; - long bundleId = Util.getBundleIdFromModuleId(u.getHost()); + long bundleId = Util.getBundleIdFromRevisionId(u.getHost()); Bundle bundle = felix.getBundle(bundleId); if (bundle != null) { Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java Tue Apr 19 14:16:59 2011 @@ -24,14 +24,14 @@ import java.net.URL; 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 @@ class URLHandlersBundleURLConnection ext } // 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 @@ class URLHandlersBundleURLConnection ext } 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 @@ class URLHandlersBundleURLConnection ext { 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 @@ class URLHandlersBundleURLConnection ext { 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 @@ class URLHandlersBundleURLConnection ext */ 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 Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java Tue Apr 19 14:16:59 2011 @@ -33,32 +33,33 @@ import java.util.TreeMap; 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 @@ public class CapabilitySet 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 @@ public class CapabilitySet } 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 @@ public class CapabilitySet 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 @@ public class CapabilitySet } 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 class CapabilitySet } } - 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 @@ public class CapabilitySet } 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 @@ public class CapabilitySet } 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 @@ public class CapabilitySet 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 @@ public class CapabilitySet 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 @@ public class CapabilitySet 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; Modified: felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java?rev=1095097&r1=1095096&r2=1095097&view=diff ============================================================================== --- felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java (original) +++ felix/sandbox/rickhall/framework-r43/src/main/java/org/apache/felix/framework/resolver/CandidateComparator.java Tue Apr 19 14:16:59 2011 @@ -22,26 +22,29 @@ import java.util.Comparator; 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 @@ public class CandidateComparator impleme } } - // 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; }
