/**
  * Removes the target bundle from the set of those known to provide handler or schema mappings.
  *
  * @param bundle handler bundle
  */
 public void maybeRemoveNameSpaceHandlerFor(Bundle bundle) {
   Assert.notNull(bundle);
   boolean removed = this.namespacePlugins.removePlugin(bundle);
   if (removed && log.isDebugEnabled()) {
     log.debug(
         "Removed namespace handler resolver for "
             + OsgiStringUtils.nullSafeNameAndSymName(bundle));
   }
 }
  private void installAndStartBundle(BundleContext context, Resource resource) throws Exception {
    // install & start
    Bundle bundle =
        context.installBundle(
            "[onTheFly-test-bundle]" + ClassUtils.getShortName(getClass()) + "[" + hashCode() + "]",
            resource.getInputStream());

    String bundleString = OsgiStringUtils.nullSafeNameAndSymName(bundle);
    boolean debug = logger.isDebugEnabled();

    if (debug) logger.debug("Test bundle [" + bundleString + "] succesfully installed");
    bundle.start();
    if (debug) logger.debug("Test bundle [" + bundleString + "] succesfully started");
  }
  /**
   * Registers the namespace plugin handler if this bundle defines handler mapping or schema mapping
   * resources.
   *
   * <p>This method considers only the bundle space and not the class space.
   *
   * @param bundle target bundle
   * @param isLazyBundle indicator if the bundle analyzed is lazily activated
   */
  public void maybeAddNamespaceHandlerFor(Bundle bundle, boolean isLazyBundle) {
    // Ignore system bundle
    if (OsgiBundleUtils.isSystemBundle(bundle)) {
      return;
    }

    // Ignore non-wired Spring DM bundles
    if ("org.springframework.osgi.core".equals(bundle.getSymbolicName())
        && !bundle.equals(BundleUtils.getDMCoreBundle(context))) {
      return;
    }

    boolean debug = log.isDebugEnabled();
    boolean trace = log.isTraceEnabled();
    // FIXME: Blueprint uber bundle temporary hack
    // since embedded libraries are not discovered by findEntries and inlining them doesn't work
    // (due to resource classes such as namespace handler definitions)
    // we use getResource

    boolean hasHandlers = false, hasSchemas = false;

    if (trace) {
      log.trace("Inspecting bundle " + bundle + " for Spring namespaces");
    }
    // extender/RFC 124 bundle
    if (context.getBundle().equals(bundle)) {

      try {
        Enumeration<?> handlers = bundle.getResources(META_INF + SPRING_HANDLERS);
        Enumeration<?> schemas = bundle.getResources(META_INF + SPRING_SCHEMAS);

        hasHandlers = handlers != null;
        hasSchemas = schemas != null;

        if (hasHandlers && debug) {
          log.debug("Found namespace handlers: " + Collections.list(schemas));
        }
      } catch (IOException ioe) {
        log.warn("Cannot discover own namespaces", ioe);
      }
    } else {
      hasHandlers = bundle.findEntries(META_INF, SPRING_HANDLERS, false) != null;
      hasSchemas = bundle.findEntries(META_INF, SPRING_SCHEMAS, false) != null;
    }

    // if the bundle defines handlers
    if (hasHandlers) {

      if (trace) log.trace("Bundle " + bundle + " provides Spring namespace handlers...");

      if (isLazyBundle) {
        this.namespacePlugins.addPlugin(bundle, isLazyBundle, true);
      } else {
        // check type compatibility between the bundle's and spring-extender's spring version
        if (hasCompatibleNamespaceType(bundle)) {
          this.namespacePlugins.addPlugin(bundle, isLazyBundle, false);
        } else {
          if (debug)
            log.debug(
                "Bundle ["
                    + OsgiStringUtils.nullSafeNameAndSymName(bundle)
                    + "] declares namespace handlers but is not compatible with extender ["
                    + extenderInfo
                    + "]; ignoring...");
        }
      }
    } else {
      // bundle declares only schemas, add it though the handlers might not be compatible...
      if (hasSchemas) {
        this.namespacePlugins.addPlugin(bundle, isLazyBundle, false);
        if (trace) log.trace("Bundle " + bundle + " provides Spring schemas...");
      }
    }
  }