org.osgi.framework.wiring.BundleRequirement#org.osgi.framework.wiring.BundleRevision源码实例Demo

下面列出了org.osgi.framework.wiring.BundleRequirement#org.osgi.framework.wiring.BundleRevision 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: concierge   文件: PackageAdminImpl.java
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));
				}
			}
		}
	}
}
 
源代码2 项目: concierge   文件: PackageAdminImpl.java
/**
 * @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);
}
 
源代码3 项目: concierge   文件: BundleImpl.java
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;
}
 
源代码4 项目: concierge   文件: BundleImpl.java
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;
}
 
源代码5 项目: knopflerfish.org   文件: BundleCapabilityImpl.java
/**
 * 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());
}
 
源代码6 项目: concierge   文件: Concierge.java
/**
 * @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;
	}
}
 
源代码7 项目: concierge   文件: Concierge.java
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);
}
 
源代码8 项目: coming   文件: NPEfix8_eigth_s.java
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;
}
 
源代码9 项目: concierge   文件: Concierge.java
/**
 * 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;
}
 
源代码10 项目: 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.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);
      }
    }
  }
}
 
源代码11 项目: knopflerfish.org   文件: BundleRevisionImpl.java
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;
}
 
源代码12 项目: knopflerfish.org   文件: NsToHtmlBundle.java
@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();
}
 
源代码13 项目: knopflerfish.org   文件: NsToHtmlBundle.java
@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();
}
 
源代码14 项目: knopflerfish.org   文件: NsToHtmlHost.java
@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();
}
 
源代码15 项目: knopflerfish.org   文件: NsToHtmlPackage.java
@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();
}
 
源代码16 项目: knopflerfish.org   文件: WiringHTMLDisplayer.java
@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();
}
 
源代码17 项目: knopflerfish.org   文件: WiringHTMLDisplayer.java
@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();
}
 
源代码18 项目: knopflerfish.org   文件: Desktop.java
/**
 * 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();
}
 
源代码19 项目: knopflerfish.org   文件: Desktop.java
/**
 * 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();
}
 
源代码20 项目: knopflerfish.org   文件: Desktop.java
/**
 * 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;
}
 
源代码21 项目: vespa   文件: ClassLoaderOsgiFramework.java
@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;
    }
}
 
源代码22 项目: SimpleFlatMapper   文件: HostApplication.java
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);
    ;
}
 
源代码23 项目: knopflerfish.org   文件: Fragment.java
@Override
public boolean matches(BundleCapability capability) {
  if (BundleRevision.HOST_NAMESPACE.equals(capability.getNamespace())) {
    return toFilter().matches(capability.getAttributes());
  }
  return false;
}
 
源代码24 项目: knopflerfish.org   文件: RequireBundle.java
@Override
public boolean matches(BundleCapability capability)
{
  if (BundleRevision.BUNDLE_NAMESPACE.equals(capability.getNamespace())) {
    return toFilter().matches(capability.getAttributes());
  }
  return false;
}
 
源代码25 项目: knopflerfish.org   文件: ExportPkg.java
@Override
public Map<String, Object> getAttributes() {
  final Map<String,Object> res
    = new HashMap<String, Object>(4+attributes.size());

  res.put(BundleRevision.PACKAGE_NAMESPACE, name);
  res.put(Constants.VERSION_ATTRIBUTE, version);

  res.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, bpkgs.bg.symbolicName);
  res.put(Constants.BUNDLE_VERSION_ATTRIBUTE, bpkgs.bg.version);

  res.putAll(attributes);

  return Collections.unmodifiableMap(res);
}
 
源代码26 项目: knopflerfish.org   文件: RequireBundle.java
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());
  }
}
 
源代码27 项目: knopflerfish.org   文件: NativeRequirement.java
@Override
public boolean matches(BundleCapability capability) {
  if (BundleRevision.PACKAGE_NAMESPACE.equals(capability.getNamespace())) {
    for (NativeCodeEntry e : entries) {
      if (e.filter == null || e.filter.matches(capability.getAttributes())) {
        return true;
      }
    }
  }
  return false;
}
 
源代码28 项目: concierge   文件: Resources.java
public BundleRequirementImpl(final BundleRevision revision,
		final String namespace, final Map<String, String> directives,
		final Map<String, Object> attributes, final String prettyPrint) {
	super(namespace, directives, attributes);
	this.revision = revision;
	this.prettyPrint = "BundleRequirement{" + prettyPrint + "}";
}
 
源代码29 项目: knopflerfish.org   文件: BundleGeneration.java
/**
 * Construct a new BundleGeneration for the System Bundle.
 *
 * @param b BundleImpl this bundle data.
 * @param exportStr The value of the Export-Package header.
 * @param capabilityStr The value of the Provide-Capability header.
 */
BundleGeneration(BundleImpl b, String exportStr, String capabilityStr) {
  bundle = b;
  archive = null;
  generation = 0;
  v2Manifest = true;
  symbolicName = KNOPFLERFISH_SYMBOLICNAME;
  symbolicNameParameters = null;
  singleton = false;
  version = new Version(Util.readFrameworkVersion());
  attachPolicy = Constants.FRAGMENT_ATTACHMENT_ALWAYS;
  fragment = null;
  protectionDomain = null;
  lazyActivation = false;
  lazyIncludes = null;
  lazyExcludes = null;
  timeStamp = System.currentTimeMillis();
  bpkgs = new BundlePackages(this, exportStr);
  bundleRevision = new BundleRevisionImpl(this);
  classLoader = b.getClassLoader();
  processCapabilities(capabilityStr);
  capabilities.put(NativeNamespace.NATIVE_NAMESPACE, Collections.singletonList(new BundleCapabilityImpl(this, b.fwCtx.props)));
  identity = new BundleCapabilityImpl(this);
  bundleCapability = new BundleNameVersionCapability(this, BundleRevision.BUNDLE_NAMESPACE);
  hostCapability = new BundleNameVersionCapability(this, BundleRevision.HOST_NAMESPACE);
  nativeRequirement = null;
}
 
源代码30 项目: concierge   文件: BundleImpl.java
void refresh() {
	// iterate over old and current revisions
	for (final BundleRevision brev : revisions) {
		final Revision rev = (Revision) brev;

		if (rev.wiring != null) {
			rev.wiring.cleanup();
			rev.wiring = null;
		}
	}

	revisions.clear();

	if (currentRevision != null) {
		revisions.add(currentRevision);

		// detach fragments (if any) and reset classloader
		currentRevision.refresh();

		// remove from framework wirings
		framework.wirings.remove(currentRevision);

		// clear and restore dynamic imports
		currentRevision.dynamicImports.clear();
		for (final BundleRequirement req : currentRevision.requirements
				.lookup(PackageNamespace.PACKAGE_NAMESPACE)) {
			if (PackageNamespace.RESOLUTION_DYNAMIC
					.equals(req.getDirectives().get(
							Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE))) {
				currentRevision.dynamicImports.add(req);
			}

		}
	}
}