org.osgi.framework.BundleException#REJECTED_BY_HOOK源码实例Demo

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

源代码1 项目: knopflerfish.org   文件: Bundles.java
/**
 * Install a new bundle.
 *
 * @param location The location to be installed
 */
BundleImpl install(final String location, final InputStream in, final Bundle caller)
  throws BundleException
{
  checkIllegalState();
  BundleImpl b;
  synchronized (this) {
    b = bundles.get(location);
    if (b != null) {
      if (fwCtx.bundleHooks.filterBundle(b.bundleContext, b) == null &&
          caller != fwCtx.systemBundle) {
        throw new BundleException("Rejected by a bundle hook",
                                  BundleException.REJECTED_BY_HOOK);
      } else {
        return b;
      }
    }
    b = fwCtx.perm.callInstall0(this, location, in, caller);
  }
  return b;
}
 
源代码2 项目: knopflerfish.org   文件: ResolverHooks.java
void filterMatches(BundleRequirement requirement , Collection<? extends BundleCapability> candidates) throws BundleException {
  if (hasHooks()) {
    @SuppressWarnings("unchecked")
    Collection<BundleCapability> c = new RemoveOnlyCollection<BundleCapability>((Collection<BundleCapability>) candidates);
    blockResolveForHooks();
    try {
      for (TrackedResolverHookFactory rhf : active) {
        final ResolverHook rh = checkActiveRemoved(rhf);
        try {
          rh.filterMatches(requirement, c);
        } catch (RuntimeException re) {
          throw new BundleException("Resolver hook throw an exception, bid="
                                    + rhf.bundle.getBundleId(),
                                    BundleException.REJECTED_BY_HOOK, re);
        }
      }
    } finally {
      unblockResolveForHooks();
    }
  }
}
 
源代码3 项目: knopflerfish.org   文件: ResolverHooks.java
void filterSingletonCollisions(BundleCapability singleton , Collection<BundleCapability> candidates) throws BundleException {
  if (hasHooks()) {
    Collection<BundleCapability> c = new RemoveOnlyCollection<BundleCapability>(candidates);
    blockResolveForHooks();
    try {
      for (TrackedResolverHookFactory rhf : active) {
        final ResolverHook rh = checkActiveRemoved(rhf);
        try {
          rh.filterSingletonCollisions(singleton, c);
        } catch (RuntimeException re) {
          throw new BundleException("Resolver hook throw an exception, bid="
                                    + rhf.bundle.getBundleId(),
                                    BundleException.REJECTED_BY_HOOK, re);
        }
      }
    } finally {
      unblockResolveForHooks();
    }
  }
}
 
源代码4 项目: concierge   文件: Concierge.java
/**
 * install a bundle from input stream.
 * 
 * @param location
 *            the bundle location.
 * @param in
 *            the input stream.
 * @return a Bundle object.
 * @throws BundleException
 *             if the installation failed.
 */
synchronized BundleImpl installNewBundle(final BundleContext context,
		final String location, final InputStream in)
				throws BundleException {
	final AbstractBundle cached;
	if ((cached = location_bundles.get(location)) != null) {
		if (!bundleFindHooks.isEmpty()) {
			final Bundle[] test = filterWithBundleHooks(context,
					Arrays.asList((Bundle) cached));
			if (test.length == 0) {
				throw new BundleException(
						"Existing bundle rejected by find hooks",
						BundleException.REJECTED_BY_HOOK);
			}
		}

		return (BundleImpl) cached;
	}

	final BundleImpl bundle = new BundleImpl(this, context, location,
			nextBundleID++, in);

	// notify the listeners
	notifyBundleListeners(BundleEvent.INSTALLED, bundle,
			context.getBundle());

	storeMetadata();
	return bundle;
}
 
源代码5 项目: knopflerfish.org   文件: ResolverHooks.java
synchronized void beginResolve(final BundleImpl [] triggers) throws BundleException {
  if (!isOpen()) {
    return;
  }
  if (currentTriggers == null) {
    Collection<BundleRevision> triggerCollection = new ArrayList<BundleRevision>();
    for (BundleImpl b : triggers) {
      triggerCollection.add(b.current().bundleRevision);
    }
    active = new ArrayList<TrackedResolverHookFactory>();
    for (Entry<ServiceReference<ResolverHookFactory>, TrackedResolverHookFactory> e : resolverHookTracker.getTracked().entrySet()) {
      TrackedResolverHookFactory rhf = resolverHookTracker.getService(e.getKey());
      if (null != rhf) {
        blockResolveForHooks();
        try {
          if (rhf.begin(triggerCollection)) {
            active.add(rhf);
            currentTriggers = triggers;
          }
        } catch (RuntimeException re) {
          throw new BundleException("Resolver hook throw an exception, bid="
                                    + rhf.bundle.getBundleId(),
                                    BundleException.REJECTED_BY_HOOK, re);
        } finally {
          unblockResolveForHooks();
        }
      }
    }
    if (active.isEmpty()) {
      active = null;
    } else {
      resolvableBundles = new HashMap<BundleGeneration, Boolean>();
    }
  }
}
 
源代码6 项目: knopflerfish.org   文件: ResolverHooks.java
boolean filterResolvable(BundleGeneration bg) throws BundleException {
  if (hasHooks()) {
    Boolean res = resolvableBundles.get(bg);
    if (res == null) {
      Collection<BundleRevision> c = new ShrinkableSingletonCollection<BundleRevision>(bg.bundleRevision);
      blockResolveForHooks();
      try {
        for (TrackedResolverHookFactory rhf : active) {
          final ResolverHook rh = checkActiveRemoved(rhf);
          try {
            rh.filterResolvable(c);
          } catch (RuntimeException re) {
            throw new BundleException("Resolver hook throw an exception, bid="
                                    + rhf.bundle.getBundleId(),
                                      BundleException.REJECTED_BY_HOOK, re);
          }
        }
      } finally {
        unblockResolveForHooks();
      }
      res = Boolean.valueOf(!c.isEmpty());
      resolvableBundles.put(bg, res);
    }
    return res.booleanValue();
  }
  return true;
}
 
源代码7 项目: knopflerfish.org   文件: ResolverHooks.java
private ResolverHook checkActiveRemoved(TrackedResolverHookFactory rhf) throws BundleException {
  ResolverHook rh = rhf.getResolverHook();
  if (null == rh) {
    throw new BundleException("Resolver hook service was unregistered",
                              BundleException.REJECTED_BY_HOOK);
  }
  return rh;
}
 
源代码8 项目: knopflerfish.org   文件: BundleImpl.java
/**
 * Get updated bundle state. That means check if an installed bundle has been
 * resolved.
 *
 * @return Bundles state
 */
int getUpdatedState(BundleImpl [] triggers, boolean isResolve) {
  if (state == INSTALLED) {
    try {
      synchronized (fwCtx.resolver) {
        waitOnOperation(fwCtx.resolver, "Bundle.resolve", true);
        final BundleGeneration current = current();
        if (state == INSTALLED && (!fwCtx.isInit || current.isExtension())) {
          if (triggers != null) {
            fwCtx.resolverHooks.beginResolve(triggers);
          }
          if (current.isFragment()) {
            List<BundleGeneration> hosts;
            if (isResolve) {
              hosts = new ArrayList<BundleGeneration>();
              List<BundlePackages> bps = fwCtx.resolver.getFragBundlePackages(current.bpkgs);
              if (bps != null) {
                for (BundlePackages bp : bps) {
                  hosts.add(bp.bg);
                }
              }
            } else {
              hosts = current.fragment.targets();
            }
            if (!hosts.isEmpty()) {
              for (final BundleGeneration host : hosts) {
                if (isResolve || host.bpkgs.isActive()) {
                  if (!current.fragment.isHost(host)) {
                    attachToFragmentHost(host, isResolve);
                  }
                } else {
                  // Try resolve our host
                  // NYI! Detect circular attach
                  host.bundle.getUpdatedState(null, false);
                }
              }
            }
            if (state == INSTALLED && current.fragment.hasHosts()) {
              current.setWired();
              state = RESOLVED;
              operation = RESOLVING;
              if (current.isExtension()) {
                // TODO call on bundle thread!?
                fwCtx.systemBundle.extensionCallStart(this);
              }
              bundleThread().bundleChanged(new BundleEvent(BundleEvent.RESOLVED, this));
              operation = IDLE;
            }
          } else {
            if (current.resolvePackages(triggers, isResolve)) {
              current.setWired();
              state = RESOLVED;
              operation = RESOLVING;
              if (!isResolve) {
                current.updateStateFragments();
              }
              bundleThread().bundleChanged(new BundleEvent(BundleEvent.RESOLVED, this));
              operation = IDLE;
            } else {
              String reason = current.bpkgs.getResolveFailReason();
              throw new BundleException("Bundle#" + id + ", unable to resolve: "
                  + reason,
                  reason == Resolver.RESOLVER_HOOK_VETO ?
                                                         BundleException.REJECTED_BY_HOOK :
                                                           BundleException.RESOLVE_ERROR);
            }
          }
          if (triggers != null && triggers.length == 1) {
            BundleImpl[] t = triggers;
            triggers = null;
            fwCtx.resolverHooks.endResolve(t);
          }
        }
      }
    } catch (final BundleException be) {
      resolveFailException = be;
      fwCtx.frameworkError(this, be);
      if (triggers != null && triggers.length == 1) {
        try {
          fwCtx.resolverHooks.endResolve(triggers);
        } catch (final BundleException be2) {
          resolveFailException = be2;
          fwCtx.frameworkError(this, be2);
        }
      }
    }
  }
  return state;
}