/** Look for persistence unit bundles that were already installed when we came along. */
  public void lookForExistingBundles() {

    // Look at the bundles that are already installed
    Bundle[] installedBundles = mgr.getBundleContext().getBundles();
    debug("Extender.lookForExistingBundles: ", installedBundles);

    // Check if any are p-unit bundles
    for (Bundle b : installedBundles) {
      if (isPersistenceUnitBundle(b)) {
        // We found a persistence unit bundle.
        if (GeminiSystemProperties.refreshPersistenceBundles()) {
          // If bundle is active then refresh it and push it through the life cycle again
          // so it will go through resolving and we can assign it a provider, etc.
          //  if ((b.getState() != Bundle.INSTALLED) && (b.getState() != Bundle.UNINSTALLED)) {
          if (b.getState() == Bundle.ACTIVE) {
            if (isAssigned(b)) {
              debug(
                  "Found existing installed bundle " + b.getSymbolicName(),
                  " but it was already assigned");
            } else {
              debug(
                  "Found active bundle ",
                  b,
                  " - refreshing to push it back to resolve for processing");
              refreshBundle(b);
            }
          }
        } else {
          // Refreshing is disabled - go through assigning and registering process w/o events
          if (b.getState() != Bundle.UNINSTALLED) {
            // Assign the p-unit
            // NOTE: With no refresh, assigning may be happening after the bundle has been resolved
            warning(
                "Extender - Refreshing disabled - entities in bundle " + b.getSymbolicName(),
                " may not be woven");
            tryAssigningPersistenceUnitsInBundle(b);
            // Now if bundle is starting or active then register the p-units in it
            if ((b.getState() == Bundle.STARTING) || (b.getState() == Bundle.ACTIVE)) {
              registerPersistenceUnitsInBundle(b);
            } // Otherwise just let future events take their course
          }
        }
      }
    }
  }
  /**
   * Refresh the persistence bundle. If persistence units have already been registered they should
   * have been unregistered before making this refresh call.
   *
   * @param b the bundle the p-units are in
   */
  public void refreshBundle(Bundle b) {
    debug("Extender.refreshBundle: ", b);

    // Add the list of currently refreshing bundles.
    // (It will be removed when the UNRESOLVED event is fired on it)
    addToRefreshingBundles(b);

    // Call refresh on all of the packages
    PackageAdmin admin = getPackageAdmin(mgr.getBundleContext());
    admin.refreshPackages(new Bundle[] {b});

    /* New 4.3 code to use to refresh bundle */
    /*
    Bundle systemBundle = mgr.getBundleContext().getBundle(0);
    FrameworkWiring fw = systemBundle.adapt(FrameworkWiring.class);
    fw.refreshBundles(Arrays.asList(b));
    */
  }
 /** Stop listening to bundle events. */
 public void stopListening() {
   debug("Extender.stopListening");
   mgr.getBundleContext().removeBundleListener(this);
 }
 /** Start listening for bundle events to indicate the presence of persistence unit bundles. */
 public void startListening() {
   debug("Extender.startListening");
   mgr.getBundleContext().addBundleListener(this);
 }