Java Code Examples for org.osgi.framework.wiring.BundleRevision#getWiring()

The following examples show how to use org.osgi.framework.wiring.BundleRevision#getWiring() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
private void getExportedPackages0(final Bundle bundle, final String name, final ArrayList<ExportedPackage> result) {
	if (bundle == null) {
		throw new IllegalArgumentException("bundle==null");
	}
	if (result == null) {
		throw new IllegalArgumentException("result==null");
	}

	final List<BundleRevision> revs = bundle.adapt(BundleRevisions.class).getRevisions();

	if (revs.isEmpty()) {
		return;
	}

	for (final BundleRevision r : revs) {
		final BundleWiring wiring = r.getWiring();
		if (wiring != null && wiring.isInUse()) {
			for (final Capability cap : wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
				if (name == null || name.equals(cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
					result.add(new ExportedPackageImpl((BundleCapability) cap));
				}
			}
		}
	}
}
 
Example 2
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
protected final BundleWiringDTO getBundleWiringDTO(BundleRevision revision){
	BundleWiringDTO dto = new BundleWiringDTO();
	dto.bundle = revision.getBundle().getBundleId();
	
	BundleWiring wiring = revision.getWiring();
	// TODO what is root
	dto.root = wiring.hashCode();
	
	dto.resources = new HashSet<BundleRevisionDTO>();
	dto.resources.add(getBundleRevisionDTO(revision));
	dto.nodes = new HashSet<BundleWiringDTO.NodeDTO>();
	
	addBundleWiringNodeDTO(wiring, dto.resources, dto.nodes);
	
	return dto;
}
 
Example 3
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.osgi.framework.wiring.FrameworkWiring#getRemovalPendingBundles()
 * @category FrameworkWiring
 */
public Collection<Bundle> getRemovalPendingBundles() {
	final ArrayList<Bundle> removalPending = new ArrayList<Bundle>();

	bundleLoop: for (final AbstractBundle bundle : bundles) {
		if (bundle instanceof BundleImpl) {
			final List<BundleRevision> revisions = bundle.getRevisions();
			for (final BundleRevision rev : revisions) {
				final BundleWiring wiring = rev.getWiring();
				if (wiring != null && !wiring.isCurrent()
						&& wiring.isInUse()) {
					removalPending.add(bundle);
					continue bundleLoop;
				}
			}
		}
	}

	return removalPending;
}
 
Example 4
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
private Collection<Bundle> getDependencies(final Collection<Bundle> bundles,
		final boolean allRevisions) {
	// build up the dependency graph. See specs for details.
	final ArrayList<Bundle> toProcess = new ArrayList<Bundle>(bundles);

	final Set<Bundle> dependencySet = new HashSet<Bundle>();
	while (!toProcess.isEmpty()) {
		final Bundle b = toProcess.remove(0);

		if (b == this) {
			dependencySet.add(b);
			continue;
		}

		if (dependencySet.contains(b)) {
			continue;
		}

		if (!(b instanceof BundleImpl)) {
			throw new IllegalArgumentException(
					"Bundles were not created by this framework instance "
							+ b.getClass().getName());
		}

		dependencySet.add(b);

		final BundleImpl bundle = (BundleImpl) b;

		for (final BundleRevision brev : bundle.revisions) {
			final BundleWiring wiring = brev.getWiring();

			// all package exports
			if (wiring != null) {

				for (final BundleRevision rev : ((ConciergeBundleWiring) wiring).inUseSet) {
					toProcess.add(rev.getBundle());
				}

				/*
				 * final List<BundleWire> importWires = wiring
				 * .getProvidedWires(null);
				 * 
				 * if (importWires != null) { for (final BundleWire
				 * importWire : importWires) {
				 * toProcess.add(importWire.getRequirer().getBundle()); } }
				 */
				final List<BundleWire> hostWires = wiring
						.getRequiredWires(HostNamespace.HOST_NAMESPACE);
				if (hostWires != null) {
					for (final BundleWire hostWire : hostWires) {
						toProcess.add(hostWire.getProvider().getBundle());
					}
				}
			}
		}
	}

	return dependencySet;
}
 
Example 5
Source File: FrameworkCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int cmdCapability(Dictionary<String, ?> opts,
                         Reader in,
                         PrintWriter out,
                         Session session)
{
  final Bundle[] b = getBundles((String[]) opts.get("bundle"),
                          opts.get("-i") != null);
  final boolean doRequirements = opts.get("-r")!=null;
  final boolean doProvides = opts.get("-p")!=null;
  final boolean doDetailed = opts.get("-l")!=null;
  final boolean doDeclared = opts.get("-d")!=null;

  boolean found = false;
  for (final Bundle element : b) {
    if (element != null) {
      out.println("Bundle: " + showBundle(element));
      found = true;
      final BundleRevision rev = element.adapt(BundleRevision.class);
      final BundleWiring wiring = rev.getWiring();
      if (!doDeclared && wiring == null) {
        out.println("  Bundle is unresolved, only declared capabilites are available.");
      } else {
        final String prefix = doDeclared ? "  Declared " : "  ";

        if (doRequirements || !doProvides) {
          out.print(prefix);
          out.println("Requirements: ");
          final List<BundleRequirement> reqs = doDeclared
            ? rev.getDeclaredRequirements(null)
            : rev.getWiring().getRequirements(null);
          for (final BundleRequirement req : reqs) {
            out.print("    ");
            out.print(req.getNamespace());
            out.print("  ");
            if (!doDetailed) {
              final String f = req.getDirectives().get(Constants.FILTER_DIRECTIVE);
              out.println(f != null ? f : "NO FILTER");
            } else {
              out.println(req.getDirectives());
            }
          }
        }

        if (doProvides || !doRequirements) {
          out.print(prefix);
          out.println("Capabilites: ");
          final List<BundleCapability> caps = doDeclared
            ? rev.getDeclaredCapabilities(null)
            : rev.getWiring().getCapabilities(null);
          for (final BundleCapability bc : caps) {
            out.print("    ");
            out.print(bc.getNamespace());
            out.print("  ");
            out.print(bc.getAttributes());
            if (doDetailed) {
              out.print(" ");
              out.print(bc.getDirectives());
            }
            out.println();
          }
        }
      }
    }
  }
  if (!found) {
    out.println("ERROR! No matching bundle");
    return 1;
  }
  return 0;
}