use of org.osgi.framework.wiring.BundleWire in project camel by apache.
the class Activator method canSee.
/**
* Check if bundle can see the given class
*/
protected boolean canSee(Bundle bundle, Class<?> clazz) {
if (bundle.getBundleId() == bundleId) {
// Need extra handling of camel core as it does not import the api
return true;
}
BundleCapability packageCap = packageCapabilities.get(clazz.getPackage().getName());
if (packageCap != null) {
BundleWiring wiring = bundle.adapt(BundleWiring.class);
List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE);
for (BundleWire importWire : imports) {
if (packageCap.equals(importWire.getCapability())) {
return true;
}
}
}
// then we need to use a different canSee algorithm that works outside real OSGi
if (bundle.getBundleId() > 0) {
Bundle root = bundle.getBundleContext().getBundle(0);
if (root != null && "org.apache.felix.connect".equals(root.getSymbolicName())) {
return checkCompat(bundle, clazz);
}
}
return false;
}
use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class HttpExtension method getAttributes.
private Map<String, Object> getAttributes() {
BundleWiring bundleWiring = _bundle.adapt(BundleWiring.class);
List<BundleWire> wires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
Map<String, Object> cdiAttributes = Collections.emptyMap();
for (BundleWire wire : wires) {
BundleCapability capability = wire.getCapability();
Map<String, Object> attributes = capability.getAttributes();
String extender = (String) attributes.get(EXTENDER_NAMESPACE);
if (extender.equals(CDI_CAPABILITY_NAME)) {
BundleRequirement requirement = wire.getRequirement();
cdiAttributes = requirement.getAttributes();
break;
}
}
return cdiAttributes;
}
use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class Activator method requiresCdiExtender.
private boolean requiresCdiExtender(Bundle bundle) {
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
List<BundleWire> requiredBundleWires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
for (BundleWire bundleWire : requiredBundleWires) {
Map<String, Object> attributes = bundleWire.getCapability().getAttributes();
if (attributes.containsKey(EXTENDER_NAMESPACE) && attributes.get(EXTENDER_NAMESPACE).equals(CDI_CAPABILITY_NAME)) {
Bundle providerWiringBundle = bundleWire.getProviderWiring().getBundle();
if (providerWiringBundle.equals(_bundleContext.getBundle())) {
return true;
}
}
}
return false;
}
use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class AbstractTestCase method getCdiExtenderBundle.
Bundle getCdiExtenderBundle() {
BundleWiring bundleWiring = cdiBundle.adapt(BundleWiring.class);
List<BundleWire> requiredWires = bundleWiring.getRequiredWires(ExtenderNamespace.EXTENDER_NAMESPACE);
for (BundleWire wire : requiredWires) {
Map<String, Object> attributes = wire.getCapability().getAttributes();
String extender = (String) attributes.get(ExtenderNamespace.EXTENDER_NAMESPACE);
if (CdiConstants.CDI_CAPABILITY_NAME.equals(extender)) {
return wire.getProvider().getBundle();
}
}
return null;
}
use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class SubsystemDependencyTestBase method verifyRequireBundleWiring.
/**
* Verify that the Require-Bundle of wiredBundleName in subsystem s is met by a wire
* to expectedProvidingBundleName
* @param s
* @param wiredBundleName
* @param expectedProvidingBundleName
*/
protected void verifyRequireBundleWiring(Subsystem s, String wiredBundleName, String expectedProvidingBundleName) {
Bundle wiredBundle = context(s).getBundleByName(BUNDLE_D);
assertNotNull("Target bundle " + wiredBundleName + " not found", wiredBundle);
BundleWiring wiring = (BundleWiring) wiredBundle.adapt(BundleWiring.class);
List<BundleWire> wiredBundles = wiring.getRequiredWires(BUNDLE_NAMESPACE);
assertEquals("Only one bundle expected", 1, wiredBundles.size());
String requiredBundleName = (String) wiredBundles.get(0).getCapability().getAttributes().get(BUNDLE_NAMESPACE);
assertEquals("Wrong bundle requirement", BUNDLE_A, requiredBundleName);
String providingBundle = wiredBundles.get(0).getProvider().getSymbolicName();
assertEquals("Wrong bundle provider", expectedProvidingBundleName, providingBundle);
}
Aggregations