org.osgi.framework.wiring.BundleRevision Java Examples

The following examples show how to use org.osgi.framework.wiring.BundleRevision. 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: NsToHtmlBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Requirement requirement)
{
  final StringBuffer sb = new StringBuffer(50);
  final String filter = requirement.getDirectives().get("filter");
  final String bundleName =
    Util.getFilterValue(filter, BundleRevision.BUNDLE_NAMESPACE);
  if (bundleName != null) {
    sb.append(bundleName);
    Util.appendVersion(sb, filter, Constants.BUNDLE_VERSION_ATTRIBUTE);
  } else {
    // Filter too complex to extract info from...
    sb.append(filter);
  }

  return sb.toString();
}
 
Example #2
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 #3
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.osgi.service.packageadmin.PackageAdmin#getRequiredBundles(java.lang.String)
 */
public RequiredBundle[] getRequiredBundles(final String symbolicName) {
	final Bundle[] bundles = context.getBundles();

	final ArrayList<RequiredBundle> result = new ArrayList<RequiredBundle>();

	for (final Bundle bundle : bundles) {
		if (bundle.getState() == Bundle.INSTALLED || bundle.getState() == Bundle.UNINSTALLED) {
			continue;
		}

		final BundleRevision rev = bundle.adapt(BundleRevision.class);
		if (isFragment(rev)) {
			continue;
		}

		if (symbolicName == null || symbolicName.equals(rev.getSymbolicName())) {
			result.add(new RequiredBundleImpl(rev));
		}
	}

	return toArrayOrNull(result, RequiredBundle.class);
}
 
Example #4
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine if the given bundle needs to be refreshed.
 *
 * <ol>
 * <li>A bundle with no bundle revisions does not need a refreshed. The bundle
 * has been uninstalled and does not have any active wires since there are no
 * bundle revisions.
 * <li>A bundle with more than one bundle revision needs to be refreshed.
 * <li>A fragment bundle can always be refreshed, since the refresh operation
 * will attach it to any matching host that it has not yet been attached to.
 * </ol>
 *
 * @param bundle
 *          the bundle to check.
 * @return {@code true} if the bundle needs to be refreshed.
 */
boolean refreshBundleNeeded(final Bundle bundle)
{
  final List<BundleRevision> bRevs =
    bundle.adapt(BundleRevisions.class).getRevisions();

  if (bRevs.isEmpty()) {
    // Uninstalled bundle with no active bundle revision.
    return false;
  }

  final BundleRevision bRevCur = bRevs.get(0);
  final boolean isFragment =
    bRevCur.getTypes() == BundleRevision.TYPE_FRAGMENT;

  if (isFragment) {
    // A fragment may attach to new hosts as the result of a refresh.
    return true;
  }

  // Are there any old bundle revisions pending deletion?
  return bRevs.size() > 1;
}
 
Example #5
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine if the given bundle can and needs to be stopped.
 *
 * <ol>
 * <li>A fragment bundle must never be stopped.
 * <li>If no start-level support is present in the framework then any bundle
 * in state starting, active can be stopped.
 * <li>A bundle that is persistently started can be stopped.
 * </ol>
 *
 * @param bundle
 *          the bundle to check.
 * @return {@code true} if the bundle needs to be stopped.
 */
boolean stopBundlePossible(final Bundle bundle)
{
  final BundleRevision bRevCur = bundle.adapt(BundleRevision.class);
  final boolean isFragment =
    bRevCur.getTypes() == BundleRevision.TYPE_FRAGMENT;

  if (isFragment) {
    return false;
  }

  final int state = bundle.getState();
  final boolean stoppable =
    (state & (Bundle.STARTING | Bundle.ACTIVE)) != 0;

  final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
  if (bsl == null) {
    return stoppable;
  }

  if (bsl.isPersistentlyStarted()) {
    return true;
  }

  return stoppable && bsl.getStartLevel() > getCurrentStartLevel();
}
 
Example #6
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine if the given bundle can and needs to be started.
 *
 * <ol>
 * <li>A fragment bundle must never be started.
 * <li>If no start-level support is present in the framework then any bundle
 * in state installed, resolved or starting can be started.
 * <li>A bundle that is not persistently started can be started.
 * <li>A bundle that is persistently started and in any of the states
 * installed, resolved, starting and assigned to a start level that is lower
 * or equal to the current start level can be started.
 * </ol>
 *
 * @param bundle
 *          the bundle to check.
 * @return {@code true} if the bundle needs to be started.
 */
boolean startBundlePossible(final Bundle bundle)
{
  final BundleRevision bRevCur = bundle.adapt(BundleRevision.class);
  final boolean isFragment =
    bRevCur.getTypes() == BundleRevision.TYPE_FRAGMENT;

  if (isFragment) {
    return false;
  }

  final int state = bundle.getState();
  final boolean startable =
    (state & (Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING)) != 0;

  final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
  if (bsl == null) {
    return startable;
  }

  if (!bsl.isPersistentlyStarted()) {
    return true;
  }

  return startable && bsl.getStartLevel() <= getCurrentStartLevel();
}
 
Example #7
Source File: WiringHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
String getReqName(final BundleRequirement requirement)
{
  final StringBuffer sb = new StringBuffer(50);
  final String filter = requirement.getDirectives().get("filter");
  final String pkgName =
    getFilterValue(filter, BundleRevision.PACKAGE_NAMESPACE);
  if (pkgName != null) {
    sb.append(pkgName);
    appendVersionAndResolutionDirective(sb, requirement);
  } else {
    sb.append(filter);
  }

  final BundleWiring reqWiring = requirement.getRevision().getWiring();
  appendPendingRemovalOnRefresh(sb, reqWiring);

  return sb.toString();
}
 
Example #8
Source File: BundleImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
final InputStream getURLResource(final URL url, final int rev)
		throws IOException {
	String frag;
	try {
		frag = url.toURI().getFragment();
	} catch (final URISyntaxException e) {
		e.printStackTrace();
		frag = null;
	}

	for (final BundleRevision brevision : revisions) {
		final Revision revision = (Revision) brevision;
		if (revision.revId == rev) {
			if (frag == null) {
				return revision.retrieveFile(null, url.getPath());
			} else {
				return revision.retrieveFile(url.getPath(), frag);
			}
		}
	}

	return null;
}
 
Example #9
Source File: BundleImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean resolve(final boolean critical)
		throws BundleException {
	if (!resolveMetadata(critical)) {
		return false;
	}

	if (!framework.resolve(
			Collections.<BundleRevision> singletonList(this),
			critical)) {
		return false;
	}
	
	markResolved();
	
	return true;
}
 
Example #10
Source File: BundleCapabilityImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a {@link BundleCapability} from one entry of the Bundle-Capability
 * header.
 *
 * @param gen
 *          the owning bundle revision.
 * @param he
 *          the parsed bundle capability header entry.
 */
public BundleCapabilityImpl(final BundleGeneration gen, final HeaderEntry he)
{
  this.gen = gen;
  owner = gen;
  namespace = he.getKey();
  if (gen.bundle.id != 0) {
    for (final String ns : Arrays
           .asList(new String[] { BundleRevision.BUNDLE_NAMESPACE,
                                  BundleRevision.HOST_NAMESPACE,
                                  BundleRevision.PACKAGE_NAMESPACE,
                                  ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE,
                                  IdentityNamespace.IDENTITY_NAMESPACE,
                                  NativeNamespace.NATIVE_NAMESPACE})) {
      if (ns.equals(namespace)) {
        throw new IllegalArgumentException("Capability with name-space '" + ns
                                           + "' must not be provided in the "
                                           + Constants.PROVIDE_CAPABILITY
                                           + " manifest header.");
      }
    }
  }
  attributes = Collections.unmodifiableMap(he.getAttributes());
  directives = Collections.unmodifiableMap(he.getDirectives());
}
 
Example #11
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
protected void filterResources(final Collection<ResolverHook> hooks,
		final Collection<Resource> resources,
		final Collection<Resource> removed) {
	final ArrayList<BundleRevision> revisions = new ArrayList<BundleRevision>();
	removed.addAll(resources);
	for (final Iterator<Resource> iter = resources.iterator(); iter
			.hasNext();) {
		final Resource res = iter.next();
		if (res instanceof BundleRevision) {
			revisions.add((BundleRevision) res);
			iter.remove();
		}
	}

	final ConciergeCollections.RemoveOnlyList<BundleRevision> filteredResources = new ConciergeCollections.RemoveOnlyList<BundleRevision>(
			revisions);

	for (final ResolverHook hook : resolver.hooks.keySet()) {
		hook.filterResolvable(filteredResources);
	}

	resources.addAll(filteredResources);
	removed.removeAll(filteredResources);
}
 
Example #12
Source File: NPEfix8_eigth_s.java    From coming with MIT License 6 votes vote down vote up
private List<Content> initializeContentPath() throws Exception
{
    List<Content> contentList = new ArrayList();
    calculateContentPath(this, getContent(), contentList, true);

    List<BundleRevision> fragments = null;
    List<Content> fragmentContents = null;
    if (m_wiring != null)
    {
        // Get fragments and their contents from the wiring.
        // Note that we don't use Util.getFragments() here because
        // the wiring returns parallel arrays and the utility method
        // doesn't necessarily return the correct order.
        fragments = m_wiring.getFragments();
        fragmentContents = m_wiring.getFragmentContents();
    }
    if (fragments != null)
    {
        for (int i = 0; i < fragments.size(); i++)
        {
            calculateContentPath(
                    fragments.get(i), fragmentContents.get(i), contentList, false);
        }
    }
    return contentList;
}
 
Example #13
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get Fragments matching a host bundle.
 * 
 * @param hostBundle
 *            , the host bundle, for which fragments should be found
 * @return an array of fragments, which should be attached to the host
 *         bundle
 */
List<Revision> getFragments(final BundleRevision hostBundle) {
	final List<Revision> candidates = new ArrayList<Revision>(
			fragmentIndex.lookup(hostBundle.getSymbolicName()));

	if (!candidates.isEmpty()) {
		final Capability cap = hostBundle
				.getCapabilities(HostNamespace.HOST_NAMESPACE).get(0);
		for (final Iterator<Revision> iter = candidates.iterator(); iter
				.hasNext();) {
			final Requirement req = iter.next()
					.getRequirements(HostNamespace.HOST_NAMESPACE).get(0);
			if (!matches(req, cap)) {
				iter.remove();
			}
		}
	}

	return candidates;
}
 
Example #14
Source File: NsToHtmlPackage.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Requirement requirement)
{
  final StringBuffer sb = new StringBuffer(50);
  final String filter = requirement.getDirectives().get("filter");
  final String pkgName =
    Util.getFilterValue(filter, BundleRevision.PACKAGE_NAMESPACE);
  if (pkgName != null) {
    sb.append(pkgName);
    appendVersionAndResolutionDirective(sb, requirement);
  } else {
    sb.append(filter);
  }

  return sb.toString();
}
 
Example #15
Source File: NsToHtmlHost.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Requirement requirement)
{
  final StringBuffer sb = new StringBuffer(50);
  final String filter = requirement.getDirectives().get("filter");
  final String hostName =
    Util.getFilterValue(filter, BundleRevision.HOST_NAMESPACE);
  if (hostName != null) {
    sb.append(hostName);
    Util.appendVersion(sb, filter, Constants.BUNDLE_VERSION_ATTRIBUTE);
  } else {
    // Filter too complex to extract info from...
    sb.append(filter);
  }

  return sb.toString();
}
 
Example #16
Source File: NexusBundleTracker.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
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.contains(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);
      }
    }
  }
}
 
Example #17
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.osgi.framework.wiring.FrameworkWiring#resolveBundles(java.util.Collection)
 * @category FrameworkWiring
 */
public boolean resolveBundles(final Collection<Bundle> bundles) {
	final ArrayList<BundleRevision> resources = new ArrayList<BundleRevision>();
	boolean resolved = true;

	for (final Bundle bundle : bundles == null ? Concierge.this.bundles
			: bundles) {
		if (bundle.getState() == UNINSTALLED) {
			resolved = false;
			continue;
		}

		resources.add(bundle.adapt(BundleRevision.class));
	}

	try {
		resolved &= resolve(resources, false);
		return resolved;
	} catch (final BundleException e) {
		// should not be thrown for critical==false
		return false;
	}
}
 
Example #18
Source File: WiringHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
String getReqName(final BundleRequirement requirement)
{
  final StringBuffer sb = new StringBuffer(50);
  final String filter = requirement.getDirectives().get("filter");
  final String hostName = getFilterValue(filter, BundleRevision.HOST_NAMESPACE);
  if (hostName != null) {
    sb.append(hostName);
    appendVersion(sb, requirement);
  } else {
    // Filter too complex to extract info from...
    sb.append(filter);
  }

  final BundleWiring reqWiring = requirement.getRevision().getWiring();
  appendPendingRemovalOnRefresh(sb, reqWiring);

  return sb.toString();
}
 
Example #19
Source File: BundleRevisionImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static int whichNameSpaces(String namespace) {
  int ns;
  if (namespace == null) {
    ns = NS_BUNDLE|NS_HOST|NS_IDENTITY|NS_PACKAGE|NS_OTHER;
  } else if (BundleRevision.BUNDLE_NAMESPACE.equals(namespace)) {
    ns = NS_BUNDLE;
  } else if (BundleRevision.HOST_NAMESPACE.equals(namespace)) {
    ns = NS_HOST;
  } else if (IdentityNamespace.IDENTITY_NAMESPACE.equals(namespace)) {
    ns = NS_IDENTITY;
  } else if (NativeNamespace.NATIVE_NAMESPACE.equals(namespace)) {
    ns = NS_NATIVE;
  } else if (BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
    ns = NS_PACKAGE;
  } else {
    ns = NS_OTHER;
  }
  return ns;
}
 
Example #20
Source File: NsToHtmlBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);
  sb.append(attrs.remove(BundleRevision.BUNDLE_NAMESPACE));

  final Version version =
    (Version) attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  if (version != null) {
    sb.append("&nbsp;");
    sb.append(version);
  }

  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  return sb.toString();
}
 
Example #21
Source File: ClassLoaderOsgiFramework.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T adapt(Class<T> clazz) {
    if (clazz.equals(BundleRevision.class)) {
        return (T) new BundleRevisionImpl();
    } else if (clazz.equals(BundleWiring.class)) {
        return (T) new BundleWiringImpl();
    } else {
        return null;
    }
}
 
Example #22
Source File: BundleRequirementImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a {@link BundleRequirement} from one entry in the parsed
 * "Require-Capability" manifest header.
 *
 * @param gen
 *          the owning bundle revision.
 * @param he
 *          the parsed entry from the "Require-Capability" manifest header.
 */
BundleRequirementImpl(final BundleGeneration gen, final HeaderEntry he)
{
  this.gen = gen;
  namespace = he.getKey();
  for (final String ns : Arrays
      .asList(new String[] { BundleRevision.BUNDLE_NAMESPACE,
                             BundleRevision.HOST_NAMESPACE,
                             BundleRevision.PACKAGE_NAMESPACE })) {
    if (ns.equals(namespace)) {
      throw new IllegalArgumentException("Capability with name-space '" + ns
                                         + "' must not be required in the "
                                         + Constants.REQUIRE_CAPABILITY
                                         + " manifest header.");
    }
  }

  final String filterStr = he.getDirectives().remove("filter");
  if (null!=filterStr && filterStr.length()>0) {
    try {
      filter = FrameworkUtil.createFilter(filterStr);
      he.getDirectives().put("filter", filter.toString());
    } catch (final InvalidSyntaxException ise) {
      final String msg = "Invalid filter '" + filterStr + "' in "
                         + Constants.REQUIRE_CAPABILITY
                         + " for name-space " + namespace + ": " + ise;
      throw (IllegalArgumentException)
        new IllegalArgumentException(msg).initCause(ise);
    }
  } else {
    filter = null;
  }
  directives = Collections.unmodifiableMap(he.getDirectives());
  attributes = Collections.unmodifiableMap(he.getAttributes());
}
 
Example #23
Source File: BundleInformation.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public BundleInformation ( final Bundle bundle )
{
    this.bundle = bundle;
    this.bundleRevision = bundle.adapt ( BundleRevision.class );

    this.aboutHtml = bundle.getEntry ( "about.html" );
    this.licenseTxt = bundle.getEntry ( "META-INF/LICENSE.txt" );
    this.noticeTxt = bundle.getEntry ( "META-INF/NOTICE.txt" );

    this.licenses = LicenseInformation.parse ( bundle.getHeaders ().get ( Constants.BUNDLE_LICENSE ) );
}
 
Example #24
Source File: HostApplication.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
private void debugBundle(Bundle b) {
    BundleRevision br = b.adapt(BundleRevision.class);

    br.getCapabilities(null).forEach(System.out::println);

    b.adapt(BundleWiring.class).getProvidedWires(null).forEach(System.out::println);
    ;
}
 
Example #25
Source File: BundleRevisionsImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public List<BundleRevision> getRevisions() {
  synchronized (generations) {
    List<BundleRevision> res = new ArrayList<BundleRevision>(generations.size());
    for (BundleGeneration bg : generations) {
      if (!bg.isUninstalled()) {
        res.add(bg.bundleRevision);
      }
    }
    return res;
  }
}
 
Example #26
Source File: WiringHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Append information about provided capabilities.
 *
 * @param sb Output buffer.
 * @param nameSpace The name space that we present capabilities for.
 * @param wiring The wiring that we present capabilities for.
 */
private void appendProvidedCapabilities(final StringBuffer sb,
                                        final String nameSpace,
                                        final BundleWiring wiring)
{
  WireFormatter wf;

  if (BundleRevision.PACKAGE_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterPackage(nameSpace, wiring);
  } else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterEE(nameSpace, wiring);
  } else if (BundleRevision.HOST_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterHost(nameSpace, wiring);
  } else if (BundleRevision.BUNDLE_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterBundle(nameSpace, wiring);
  } else if (IdentityNamespace.IDENTITY_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterID(nameSpace, wiring);
  } else {
    wf = new WireFormatter(nameSpace, wiring);
  }

  // Mapping from capability title to (string) to requesters (strings)
  final Map<String,List<String>> cap2requesters
    = new TreeMap<String, List<String>>();
  wf.providedCapabilitiesView(cap2requesters);
  appendCapabilityInfo(sb, cap2requesters);
}
 
Example #27
Source File: JHTMLBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get header text for selected bundle page.
 */
public static String getBundleSelectedHeader(Bundle b)
{
  final BundleRevision rev = b.adapt(BundleRevision.class);
  final boolean isFragment =
    rev != null
      ? (rev.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0
      : false;

  return "#" + b.getBundleId() + "  " + Util.getBundleName(b)
         + (isFragment ? "  (fragment)" : "");
}
 
Example #28
Source File: WiringHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Append information about required capabilities.
 *
 * @param sb Output buffer.
 * @param nameSpace The name-space that we present requirements for.
 * @param wiring The wiring that we present requirements for.
 */
private void appendRequiredCapabilities(final StringBuffer sb,
                                        final String nameSpace,
                                        final BundleWiring wiring)
{
  WireFormatter wf;

  if (BundleRevision.PACKAGE_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterPackage(nameSpace, wiring);
  } else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterEE(nameSpace, wiring);
  } else if (BundleRevision.HOST_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterHost(nameSpace, wiring);
  } else if (BundleRevision.BUNDLE_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterBundle(nameSpace, wiring);
  } else if (IdentityNamespace.IDENTITY_NAMESPACE.equals(nameSpace)) {
    wf = new WireFormatterID(nameSpace, wiring);
  } else {
    wf = new WireFormatter(nameSpace, wiring);
  }

  // Mapping from capability title to (string) to provider (strings)
  final Map<String,List<String>> cap2providers
    = new TreeMap<String, List<String>>();
  wf.requiredCapabilitiesView(cap2providers);
  appendCapabilityInfo(sb, cap2providers);
}
 
Example #29
Source File: RequireBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Filter toFilter()
{
  final StringBuffer sb = new StringBuffer(80);
  boolean multipleConditions = false;

  sb.append('(');
  sb.append(BundleRevision.BUNDLE_NAMESPACE);
  sb.append('=');
  sb.append(name);
  sb.append(')');

  if (bundleRange != null) {
    sb.append(bundleRange.toFilterString(Constants.BUNDLE_VERSION_ATTRIBUTE));
    multipleConditions = true;
  }

  for (final Entry<String,Object> entry : attributes.entrySet()) {
    sb.append('(');
    sb.append(entry.getKey());
    sb.append('=');
    sb.append(entry.getValue().toString());
    sb.append(')');
    multipleConditions = true;
  }

  if (multipleConditions) {
    sb.insert(0, "(&");
    sb.append(')');
  }
  try {
    return FrameworkUtil.createFilter(sb.toString());
  } catch (final InvalidSyntaxException _ise) {
    throw new RuntimeException("Internal error, createFilter: '" +sb.toString() +"': " +_ise.getMessage());
  }
}
 
Example #30
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
protected final BundleRevisionDTO getBundleRevisionDTO(BundleRevision revision){
	BundleRevisionDTO dto = new BundleRevisionDTO();
	dto.bundle = revision.getBundle().getBundleId();
	dto.id = revision.hashCode();
	dto.symbolicName = revision.getSymbolicName();
	dto.type = revision.getTypes();
	dto.version = getVersion().toString();
	
	// add requirement/capabilities
	List<Capability> caps = revision.getCapabilities(null);
	dto.capabilities = new ArrayList<CapabilityDTO>(caps.size());
	for(Capability c : caps){
		CapabilityDTO capDTO = new CapabilityDTO();
		capDTO.id = c.hashCode();
		capDTO.namespace = c.getNamespace();
		capDTO.resource = c.getResource().hashCode();
		capDTO.attributes = getDTOMap(c.getAttributes());
		capDTO.directives = new HashMap<String, String>(c.getDirectives());
		dto.capabilities.add(capDTO);
	}
	
	List<Requirement> reqs = revision.getRequirements(null);
	dto.requirements = new ArrayList<RequirementDTO>(reqs.size());
	for(Requirement r : reqs){
		RequirementDTO reqDTO = new RequirementDTO();
		reqDTO.id = r.hashCode();
		reqDTO.namespace = r.getNamespace();
		reqDTO.resource = r.getResource().hashCode();
		reqDTO.attributes = getDTOMap(r.getAttributes());
		reqDTO.directives = new HashMap<String, String>(r.getDirectives());
		dto.requirements.add(reqDTO);
	}
	return dto;
}