Example #1
0
  /**
   * This is a Felix specific extension mechanism that allows extension bundles to have activators
   * and be started via this method.
   *
   * @param felix the framework instance the extension bundle is installed in.
   * @param bundle the extension bundle to start if it has a Felix specific activator.
   */
  void startExtensionBundle(Felix felix, BundleImpl bundle) {
    String activatorClass =
        (String)
            ((BundleRevisionImpl) bundle.adapt(BundleRevision.class))
                .getHeaders()
                .get(FelixConstants.FELIX_EXTENSION_ACTIVATOR);

    if (activatorClass != null) {
      try {
        // TODO: SECURITY - Should this consider security?
        BundleActivator activator =
            (BundleActivator)
                felix.getClass().getClassLoader().loadClass(activatorClass.trim()).newInstance();

        // TODO: EXTENSIONMANAGER - This is kind of hacky, can we improve it?
        felix.m_activatorList.add(activator);

        BundleContext context = felix._getBundleContext();

        bundle.setBundleContext(context);

        if ((felix.getState() == Bundle.ACTIVE) || (felix.getState() == Bundle.STARTING)) {
          Felix.m_secureAction.startActivator(activator, context);
        }
      } catch (Throwable ex) {
        m_logger.log(bundle, Logger.LOG_WARNING, "Unable to start Felix Extension Activator", ex);
      }
    }
  }
  /**
   * This is a Felix specific extension mechanism that allows extension bundles to have activators
   * and be started via this method.
   *
   * @param felix the framework instance the extension bundle is installed in.
   * @param bundle the extension bundle to start if it has a Felix specific activator.
   */
  void startExtensionBundle(Felix felix, BundleImpl bundle) {
    Map<?, ?> headers = bundle.adapt(BundleRevisionImpl.class).getHeaders();
    String activatorClass = (String) headers.get(Constants.EXTENSION_BUNDLE_ACTIVATOR);
    boolean felixExtension = false;
    if (activatorClass == null) {
      felixExtension = true;
      activatorClass = (String) headers.get(FelixConstants.FELIX_EXTENSION_ACTIVATOR);
    }

    if (activatorClass != null) {
      ExtensionTuple tuple = null;
      try {
        // TODO: SECURITY - Should this consider security?
        BundleActivator activator =
            (BundleActivator)
                felix.getClass().getClassLoader().loadClass(activatorClass.trim()).newInstance();

        BundleContext context = felix._getBundleContext();

        bundle.setBundleContext(context);

        // TODO: EXTENSIONMANAGER - This is kind of hacky, can we improve it?
        if (!felixExtension) {
          tuple = new ExtensionTuple(activator, bundle);
          m_extensionTuples.add(tuple);
        } else {
          felix.m_activatorList.add(activator);
        }

        if ((felix.getState() == Bundle.ACTIVE) || (felix.getState() == Bundle.STARTING)) {
          if (tuple != null) {
            tuple.m_started = true;
          }
          Felix.m_secureAction.startActivator(activator, context);
        }
      } catch (Throwable ex) {
        if (tuple != null) {
          tuple.m_failed = true;
        }
        felix.fireFrameworkEvent(
            FrameworkEvent.ERROR, bundle, new BundleException("Unable to start Bundle", ex));

        m_logger.log(bundle, Logger.LOG_WARNING, "Unable to start Extension Activator", ex);
      }
    }
  }