Java 类org.osgi.framework.wiring.BundleWire 实例源码

项目:aries-jpa    文件:PersistenceBundleTracker.java   
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;
}
项目:aries-jpa    文件:Activator.java   
/**
 * Get all the relevant packages that the EclipseLink JPA provider exports or persistence packages it uses itself. These are needed
 * so that the woven proxy (for runtime enhancement) can be used later on :)
 * 
 * Note that differently to OpenJPA the relevant classes are actually in more than just one bundle (org.eclipse.persistence.jpa and org.eclipse.persistence.core
 * at the time of this writing). Hence, we have to take more than just the packages of the JPA provider bundle into account ...
 * 
 * @param jpaBundle
 * @return
 */
private String[] getJPAPackages(Bundle jpaBundle) {
    Set<String> result = new HashSet<String>();

    for (Bundle b : context.getBundles()) {
        BundleWiring bw = b.adapt(BundleWiring.class);
        if (bw == null) {
            continue;
        }
        boolean isJpaBundle = b.equals(jpaBundle);
        List<BundleWire> wires = bw.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
        for (BundleWire w : wires) {
            String pkgName = (String)w.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
            boolean add = isJpaBundle || pkgName.startsWith("org.eclipse.persistence");
            if (add) {
                result.add(getPkg(b, pkgName));
            }
        }
    }

    result.add(getPkg(context.getBundle(), "org.apache.aries.jpa.eclipselink.adapter.platform"));
    LOG.debug("Found JPA packages {}", result);
    return result.toArray(new String[0]);
}
项目:osgi-jpms-layer    文件:LayerFactoryImpl.java   
private Set<BundleWiring> getInUseBundleWirings() {
    Set<BundleWiring> wirings = new HashSet<>();
    Collection<BundleCapability> bundles = fwkWiring.findProviders(ALL_BUNDLES_REQUIREMENT);
    for (BundleCapability bundleCap : bundles) {
        // Only pay attention to non JPMS boot modules.
        // NOTE this means we will not create a real JPMS Module or Layer for this bundle
        if (bundleCap.getAttributes().get(BOOT_JPMS_MODULE) == null) {
            BundleRevision revision = bundleCap.getRevision();
            BundleWiring wiring = revision.getWiring();
            if (wiring != null && wiring.isInUse()) {
                wirings.add(wiring);
            }
            if (revision.getBundle().getBundleId() == 0) {
                // also store the system.bundle fragments because they may have exports unknown to JPMS
                List<BundleWire> hostWires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);
                for (BundleWire hostWire : hostWires) {
                    wirings.add(hostWire.getRequirerWiring());
                }
            }
        }
    }
    return wirings;
}
项目:Camel    文件:Activator.java   
private boolean extenderCapabilityWired(Bundle bundle) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    if (wiring == null) {
        return true;
    }
    List<BundleWire> requiredWires = wiring.getRequiredWires(EXTENDER_NAMESPACE);
    for (BundleWire requiredWire : requiredWires) {
        if (CAMEL_EXTENDER.equals(requiredWire.getCapability().getAttributes().get(EXTENDER_NAMESPACE))) {
            if (this.bundleId == requiredWire.getProviderWiring().getBundle().getBundleId()) {
                LOG.debug("Camel extender requirement of bundle {} correctly wired to this implementation", bundle.getBundleId());
                return true;
            } else {
                LOG.info("Not processing bundle {} as it requires a camel extender but is not wired to the this implementation", bundle.getBundleId());
                return false;
            }
        }
    }
    return true;
}
项目:nexus-public    文件:NexusBundleTracker.java   
private void prepareDependencies(final Bundle bundle) {
  final BundleWiring wiring = bundle.adapt(BundleWiring.class);
  final List<BundleWire> wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
  if (wires != null) {
    for (final BundleWire wire : wires) {
      try {
        final Bundle dependency = wire.getProviderWiring().getBundle();
        if (visited.add(dependency.getSymbolicName()) && hasComponents(dependency)) {
          if (!live(dependency)) {
            dependency.start();
          }
          if (live(dependency)) {
            // pseudo-event to trigger bundle activation
            addingBundle(dependency, null /* unused */);
          }
        }
      }
      catch (final Exception e) {
        log.warn("MISSING {}", wire, e);
      }
    }
  }
}
项目:ecm-extender-ri    文件:ECMCapabilityTracker.java   
private Collection<BundleRequirement> resolveWiredRequirements(final Bundle bundle) {
  BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
  List<BundleRequirement> result = new ArrayList<>();

  List<BundleWire> extenderWires =
      bundleWiring.getRequiredWires(ExtenderNamespace.EXTENDER_NAMESPACE);

  Bundle extenderBundle = context.getBundle();

  for (BundleWire bundleWire : extenderWires) {
    if (extenderBundle.equals(bundleWire.getProviderWiring().getBundle())) {

      Map<String, Object> capabilityAttributes = bundleWire.getCapability().getAttributes();
      if (ECMExtenderConstants.EXTENDER_SYMBOLIC_NAME
          .equals(capabilityAttributes.get(ExtenderNamespace.EXTENDER_NAMESPACE))) {
        BundleRequirement requirement = bundleWire.getRequirement();
        result.add(requirement);
      }
    }
  }
  return result;
}
项目:osgi.ee    文件:CdiBundleChangeListener.java   
@Override
public Object addingBundle(Bundle bundle, BundleEvent event) {
    // Get the wiring of the bundle.
    BundleWiring wiring = Helper.getWiring(bundle);
    // See it is wired to us as extender.
    List<BundleWire> requirements = wiring.getRequiredWires("osgi.extender");
    Context context = null;
    if (requirements != null &&
        requirements.stream().anyMatch((w) -> w.getProviderWiring().getBundle().equals(me))) {
        // Create the stuff.
        WeldContainer container = new WeldContainer(bundle);
        Hashtable<String, Object> dict = new Hashtable<>();
        dict.put(Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
        String cat = bundle.getHeaders().get(Constants.BUNDLE_CATEGORY);
        if (cat != null) {
            dict.put(Constants.BUNDLE_CATEGORY, cat);
        }
        ServiceRegistration<BeanManager> reg = bundle.getBundleContext().registerService(BeanManager.class, 
            container.getManager(), dict);
        context = new Context(container, reg);
    }
    return context;
}
项目:mqnaas    文件:BundleUtils.java   
/**
 * Retrieves the set of bundles from which given bundle depends.
 * 
 * @param bundle
 *            target bundle
 * @return set of ancestor bundles
 */
public static Set<Bundle> getAncestorBundles(Bundle bundle) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);

    // the set of bundles from which the bundle imports packages
    Set<Bundle> exporters = new HashSet<Bundle>();

    if (wiring != null) {
        List<BundleWire> bundleWires = wiring.getRequiredWires(null);

        if (bundleWires != null) {
            for (BundleWire pkg : bundleWires) {
                Bundle providerBundle = pkg.getProviderWiring().getBundle();
                exporters.add(providerBundle);
            }
        }
    }

    return exporters;
}
项目:everest    文件:PackageResource.java   
private void calculateImporters() {
    importers.clear();
    synchronized (importers) {
        // calculate importers
        Bundle bundle = m_bundleCapability.getRevision().getBundle();
        if (bundle != null) {
            BundleWiring wiring = bundle.adapt(BundleWiring.class);
            if (wiring != null) {
                List<BundleWire> wires = wiring.getProvidedWires(PACKAGE_NAMESPACE);
                if (wires != null) {
                    for (BundleWire wire : wires) {
                        if (wire.getCapability().equals(m_bundleCapability)) {
                            Bundle requirerBundle = wire.getRequirerWiring().getBundle();
                            importers.add(requirerBundle);
                        }
                    }
                }
            }
        }
    }
}
项目:logging-log4j2    文件:Activator.java   
@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();
}
项目:aries-jpa    文件:TempBundleDelegatingClassLoader.java   
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);
}
项目:osgi-jpms-layer    文件:BundleWiringLastModified.java   
public BundleWiringLastModified(BundleWiring hostWiring) {
    // get the host last modified
    if (hostWiring.isCurrent()) {
        // use the current bundle id and last modified
        lastModifieds.put(hostWiring.getBundle().getBundleId(), hostWiring.getBundle().getLastModified());
    } else {
        // use a unique negative id to indicate not current
        lastModifieds.put(nextNotCurrentID.getAndDecrement(), hostWiring.getBundle().getLastModified());
    }
    for (BundleWire hostWire : hostWiring.getProvidedWires(HostNamespace.HOST_NAMESPACE)) {
        // Always use the fragment id and last modified.
        // It makes no difference if it is current or not because the host wiring indicates that. 
        lastModifieds.put(hostWire.getRequirer().getBundle().getBundleId(), hostWire.getRequirer().getBundle().getLastModified());
    }
}
项目:Camel    文件:Activator.java   
/**
 * 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;
            }
        }
    }

    // it may be running outside real OSGi container such as when unit testing with camel-test-blueprint
    // 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;
}
项目:ApkLauncher    文件:OsgiUtil.java   
public static String toWiringString(Bundle bundle){
        String str = "";
        BundleWiring bw = bundle.adapt(BundleWiring.class);
        if (null != bw) {
            for (BundleWire wire : bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE)) {
                String packagee = (String) wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
                Bundle b = wire.getProviderWiring().getBundle();
//              str = str + "package: " + packagee + " bundle: " + b + "\n";
                str = str + "package: " + packagee + " " + BundleDetailFragment.SCHEMA_PLUGIN + "://?id=" + b.getBundleId() + "\n";
            }
        }
        return str;
    }
项目:openeos    文件:LiquibaseBundleTracker.java   
private Collection<Bundle> getDependantBundles(Bundle bundle) {
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    List<BundleWire> bundleWires = bundleWiring.getRequiredWires(null);
    HashSet<Bundle> bundles = new HashSet<Bundle>();
    for (BundleWire bundleWire : bundleWires) {
        bundles.add(bundleWire.getProvider().getBundle());
    }
    return bundles;
}
项目:mqnaas    文件:BundleTreeUtils.java   
protected Set<Bundle> getWiredBundles(Bundle bundle) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);

    // the set of bundles from which the bundle imports packages
    Set<Bundle> exporters = new HashSet<Bundle>();

    for (BundleWire pkg : wiring.getRequiredWires(null)) {
        Bundle providerBundle = pkg.getProviderWiring().getBundle();
        exporters.add(providerBundle);
    }

    return exporters;
}
项目:mqnaas    文件:BundleUtils.java   
/**
 * Retrieves the set of bundles dependent of given bundle.
 * 
 * @param bundle
 *            target bundle
 * @return set of child bundles
 */
public static Set<Bundle> getChildBundles(Bundle bundle) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);

    Set<Bundle> dependencies = new HashSet<Bundle>();

    if (wiring != null) {
        for (BundleWire requiredWire : wiring.getProvidedWires(null)) {
            dependencies.add(requiredWire.getRequirerWiring().getBundle());
        }
    }

    return dependencies;
}
项目:everest    文件:BundleWireResource.java   
@Override
public <A> A adaptTo(Class<A> clazz) {
    if (BundleWire.class.equals(clazz)) {
        return (A) m_wire;
    } else if (BundleWireResource.class.equals(clazz)) {
        return (A) this;
    } else {
        return null;
    }
}
项目:everest    文件:BundleRequirementResource.java   
public List<BundleWire> getWires() {
    ArrayList<BundleWire> wires = new ArrayList<BundleWire>();
    wires.addAll(m_wires);
    return wires;
}
项目:everest    文件:BundleCapabilityResource.java   
/**
 * Constructor for bundle capability resource
 *
 * @param path
 * @param bundleCapability
 */
public BundleCapabilityResource(Path path, BundleWiring hostWiring, BundleCapability bundleCapability) {
    super(path.addElements(uniqueCapabilityId(bundleCapability)));
    m_capability = bundleCapability;
    isPackage = m_capability.getNamespace().equals(OsgiResourceUtils.PackageNamespace.PACKAGE_NAMESPACE);
    List<Relation> relations = new ArrayList<Relation>();
    // calculate wires coming from this capability
    BundleRevision revision = m_capability.getRevision();
    if (revision != null) {
        String bundleId = Long.toString(revision.getBundle().getBundleId());
        //BundleWiring wiring = revision.getWiring();
        BundleWiring wiring = hostWiring;
        if (wiring != null) {
            List<BundleWire> allWires = wiring.getProvidedWires(m_capability.getNamespace());
            for (BundleWire wire : allWires) {
                if (wire.getCapability().equals(m_capability)) {
                    // and add a relation link
                    m_wires.add(wire);
                    String wireId = uniqueWireId(wire);
                    Path wirePath = BundleResourceManager.getInstance().getPath().addElements(Long.toString(hostWiring.getBundle().getBundleId()),
                            BundleResource.WIRES_PATH,
                            wireId
                    );
                    relations.add(new DefaultRelation(wirePath, Action.READ, wireId));
                }
            }
        }

        if (isPackage) {
            // add relation to package
            String packageId = uniqueCapabilityId(m_capability);
            Path packagePath = PackageResourceManager.getInstance().getPath().addElements(packageId);
            relations.add(new DefaultRelation(packagePath, Action.READ, PACKAGE_RELATION));
            // add relation to bundle export package header
            Path exportPackagePath = BundleResourceManager.getInstance().getPath()
                    .addElements(bundleId, BundleHeadersResource.HEADERS_PATH, BundleHeadersResource.EXPORT_PACKAGE, packageId);
            relations.add(new DefaultRelation(exportPackagePath, Action.READ, BundleHeadersResource.EXPORT_PACKAGE));
        }
        setRelations(relations);
    }
}
项目:everest    文件:BundleCapabilityResource.java   
public List<BundleWire> getWires() {
    ArrayList<BundleWire> wires = new ArrayList<BundleWire>();
    wires.addAll(m_wires);
    return wires;
}
项目:everest    文件:OsgiResourceUtils.java   
/**
 * Generates a unique id for given bundle wire
 * Uses hashcode of the wire object
 *
 * @param wire {@code BundleWire} object
 * @return unique id in {@code String}
 */
public static String uniqueWireId(BundleWire wire) {
    return "wire-" + wire.hashCode();
}