/** * We consider a bundle to be a candidate for objects if it imports at least * one of the packages of our interfaces * * @param bundle * @return true if the bundle is improting. */ private boolean isImportingUs(Bundle bundle) { BundleWiring wiring = bundle.adapt(BundleWiring.class); List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE); for (BundleWire importWire : imports) { if (packageCapabilities.contains(importWire.getCapability())) { return true; } } return false; }
@Override public void start(final BundleContext bundleContext) throws Exception { ProviderUtil.STARTUP_LOCK.lock(); lockingProviderUtil = true; final BundleWiring self = bundleContext.getBundle().adapt(BundleWiring.class); final List<BundleWire> required = self.getRequiredWires(LoggerContextFactory.class.getName()); for (final BundleWire wire : required) { loadProvider(bundleContext, wire.getProviderWiring()); } bundleContext.addBundleListener(this); final Bundle[] bundles = bundleContext.getBundles(); for (final Bundle bundle : bundles) { loadProvider(bundle); } unlockIfReady(); }
/** * <p>isImportingPAXWicketAPI.</p> * * @return <code>true</code> if this bundle imports anything from the org.ops4j.pax.wicket.api Namespace */ public boolean isImportingPAXWicketAPI() { // Check if there is a package wiring (either static or dynamic) BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); boolean hasPackageImport = hasWireMatchingFilter(bundleWiring.getRequiredWires(OSGI_WIRING_PACKAGE_NAMESPACE), bundleContext.importPAXWicketAPI); // check if there is an require bundle wire... return hasPackageImport || hasWireMatchingFilter( bundleWiring.getRequiredWires(OSGI_WIRING_BUNDLE_NAMESPACE), bundleContext.requirePAXWicketBundle); }
/** * <p>isImportingPAXWicketAPI.</p> * * @return <code>true</code> if this bundle imports anything from the org.ops4j.pax.wicket.api Namespace */ public boolean isImportingPAXWicketAPI() { // Check if there is a package wiring (either static or dynamic) BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); boolean hasPackageImport = hasWireMatchingFilter(bundleWiring.getRequiredWires(OSGI_WIRING_PACKAGE_NAMESPACE), bundleContext.importPAXWicketAPI); // check if there is an require bundle wire... return hasPackageImport || hasWireMatchingFilter( bundleWiring.getRequiredWires(OSGI_WIRING_BUNDLE_NAMESPACE), bundleContext.requirePAXWicketBundle); }
/** * We consider a bundle to be a candidate for objects if it imports at least * one of the packages of our interfaces * * @param bundle * @return true if the bundle is improting. */ private boolean isImportingUs(Bundle bundle) { BundleWiring wiring = bundle.adapt(BundleWiring.class); List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE); for (BundleWire importWire : imports) { if (packageCapabilities.contains(importWire.getCapability())) { return true; } } return false; }
/** * We consider a bundle to be a candidate for objects if it imports at least * one of the packages of our interfaces * * @param bundle * @return true if the bundle is improting. */ private boolean isImportingUs(Bundle bundle) { BundleWiring wiring = bundle.adapt(BundleWiring.class); List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE); for (BundleWire importWire : imports) { if (packageCapabilities.contains(importWire.getCapability())) { return true; } } return false; }
private Map<String, List<PackageSource>> getPackagesInternal(BundleWiring wiring) { Map<String, List<PackageSource>> packages = new TreeMap<>(); // first get the imported packages List<BundleWire> packageWires = wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE); Set<String> importedPackageNames = new HashSet<>(); for (BundleWire packageWire : packageWires) { String packageName = (String) packageWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE); importedPackageNames.add(packageName); List<PackageSource> packageSources = new ArrayList<>(); packageSources.add(new PackageSource(packageWire.getCapability(), packageWire)); packages.put(packageName, packageSources); } // now get packages from required bundles for (BundleWire requiredWire : wiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE)) { getRequiredBundlePackages(requiredWire, importedPackageNames, packages); } return packages; }
private void updateContext(Bundle currentContext, String className) { Bundle contextToSet = (currentContext == null) ? bundle : currentContext; int idx = className.lastIndexOf('.'); String packageName = (idx == -1) ? "" : className.substring(0, idx); BundleWiring wiring = contextToSet.adapt(BundleWiring.class); for (BundleWire wire : wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE)) { if (wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).equals(packageName)) { contextToSet = wire.getProviderWiring().getBundle(); break; } } currentLoadingBundle.get().push(contextToSet); }
/** * We consider a bundle to be a candidate for objects if it imports at least * one of the packages of our interfaces * * @param bundle * @return true if the bundle is improting. */ private boolean isImportingUs(Bundle bundle) { BundleWiring wiring = bundle.adapt(BundleWiring.class); List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE); for (BundleWire importWire : imports) { if (packageCapabilities.contains(importWire.getCapability())) { return true; } } return false; }
private static LinkedHashSet<Bundle> getWiredBundles43(Bundle bundle) { LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>(); BundleWiring wiring = bundle.adapt(BundleWiring.class); if (wiring != null) { List<BundleWire> wires; wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE); for (BundleWire wire : wires) { wiredBundles.add(wire.getProviderWiring().getBundle()); } wires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE); for (BundleWire wire : wires) { wiredBundles.add(wire.getProviderWiring().getBundle()); } } return wiredBundles; }
private void getFragmentHosts(BundleRevision revision) { List<BundleWire> wires = revision.getWiring().getRequiredWires(BundleRevision.HOST_NAMESPACE); if (wires != null) { for (BundleWire w : wires) { Bundle b = w.getProviderWiring().getBundle(); if (b != null) { this.fragmentHosts.add(b); } } } }
private void getFragmentHosts(BundleRevision revision) { List<BundleWire> wires = revision.getWiring().getRequiredWires(BundleRevision.HOST_NAMESPACE); if (wires != null) { for (BundleWire w : wires) { Bundle b = w.getProviderWiring().getBundle(); if (b != null) { this.fragmentHosts.add(b); } } } }
private boolean checkBundleWiringForExtender(Bundle bundle) { boolean wired = false; BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); if (bundleWiring != null) { List<BundleWire> wires = bundleWiring.getRequiredWires(CAPABILITY_EXTENDER); if (wires != null) { for (BundleWire wire : wires) { if (wire.getProviderWiring().getBundle().equals(bundleContext.getBundle())) { wired = true; break; } } } } return wired; }
private boolean checkClassResource(String classPackageName, String classFileName, BundleWiring wiring) { if (wiring == null) { return false; } if ((wiring.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { // fragment case; need to get the host wiring wiring = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE).get(0).getProviderWiring(); } Collection<String> classResourcePaths = wiring.listResources(classPackageName, classFileName, 0); return classResourcePaths != null && !classResourcePaths.isEmpty(); } }
@Override public void start(final BundleContext context) throws Exception { ProviderUtil.STARTUP_LOCK.lock(); lockingProviderUtil = true; final BundleWiring self = context.getBundle().adapt(BundleWiring.class); final List<BundleWire> required = self.getRequiredWires(LoggerContextFactory.class.getName()); for (final BundleWire wire : required) { loadProvider(context, wire.getProviderWiring()); } context.addBundleListener(this); final Bundle[] bundles = context.getBundles(); for (final Bundle bundle : bundles) { loadProvider(bundle); } unlockIfReady(); }
BundleWires(Bundle bundle) { this.bundleId = bundle.getBundleId(); for (BundleWire wire : bundle.adapt(BundleWiring.class).getRequiredWires(null)) { String requirementId = getRequirementId(wire.getRequirement()); String capabilityId = getCapabilityId(wire.getCapability()); this.wiring.put(requirementId, capabilityId); } }
private boolean incompatibleExtender(Bundle bundle) { List<BundleWire> requiredWires = bundle.adapt(BundleWiring.class) .getRequiredWires(OSGI_EXTENDER_NS); for(BundleWire bw : requiredWires) { BundleCapability capability = bw.getCapability(); if(EntityManagerFactoryBuilder.JPA_CAPABILITY_NAME.equals( capability.getAttributes().get(OSGI_EXTENDER_NS))) { // If the persistence bundle requires a different revision for the // JPA extender then we are incompatible, otherwise we are return !capability.getRevision().equals(wiring.getRevision()); } } // If there is no requirement then we must assume that it's safe return false; }
public Map<String, Bundle> getWiredBundles(Bundle bundle) { // the set of bundles from which the bundle imports packages Map<String, Bundle> exporters = new HashMap<>(); for (BundleRevision revision : bundle.adapt(BundleRevisions.class).getRevisions()) { BundleWiring wiring = revision.getWiring(); if (wiring != null) { List<BundleWire> wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE); if (wires != null) { for (BundleWire wire : wires) { if (wire.getProviderWiring().getBundle().getBundleId() != 0) { exporters.put(wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString(), wire.getProviderWiring().getBundle()); } } } } } return exporters; }
private BundleWiringDTO.NodeDTO getBundleWiringNodeDTO(BundleWiring wiring) { if (wiring == null) { return null; } BundleWiringDTO.NodeDTO dto = wiringnodes.get(wiring); if (dto != null) { return dto; } dto = new BundleWiringDTO.NodeDTO(); dto.id = identifier(wiring); wiringnodes.put(wiring, dto); dto.current = wiring.isCurrent(); dto.inUse = wiring.isInUse(); dto.resource = getResourceId(wiring.getRevision()); dto.capabilities = getListCapabilityRefDTO(wiring.getCapabilities(null)); dto.requirements = getListRequirementRefDTO(wiring.getRequirements(null)); dto.providedWires = getListBundleWireDTO(wiring.getProvidedWires(null)); dto.requiredWires = getListBundleWireDTO(wiring.getRequiredWires(null)); return dto; }
private BundleWiringDTO.NodeDTO getBundleWiringNodeDTO(BundleWiring wiring) { if (wiring == null) { return null; } BundleWiringDTO.NodeDTO dto = wiringnodes.get(wiring); if (dto != null) { return dto; } dto = new BundleWiringDTO.NodeDTO(); dto.id = identifier(wiring); wiringnodes.put(wiring, dto); dto.current = wiring.isCurrent(); dto.inUse = wiring.isInUse(); dto.resource = getResourceId(wiring.getRevision()); dto.capabilities = getListCapabilityRefDTO(wiring.getCapabilities(null)); dto.requirements = getListRequirementRefDTO(wiring.getRequirements(null)); dto.providedWires = getListBundleWireDTO(wiring.getProvidedWires(null)); dto.requiredWires = getListBundleWireDTO(wiring.getRequiredWires(null)); return dto; }