Java Code Examples for org.osgi.framework.Bundle#ACTIVE

The following examples show how to use org.osgi.framework.Bundle#ACTIVE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: wisdom   File: BundleStates.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the String form of the given OSGi bundle state.
 *
 * @param state the state
 * @return the string form.
 */
public static String from(int state) {
    switch (state) {
        case Bundle.ACTIVE:
            return ACTIVE;
        case Bundle.INSTALLED:
            return INSTALLED;
        case Bundle.RESOLVED:
            return RESOLVED;
        case Bundle.STARTING:
            return STARTING;
        case Bundle.STOPPING:
            return STOPPING;
        case Bundle.UNINSTALLED:
            return UNINSTALLED;
        default:
            return "UNKNOWN (" + Integer.toString(state) + ")";
    }
}
 
Example 2
/**
 * Creates an extension.  If the extension plugin has not
 * been loaded a busy cursor will be activated during the duration of
 * the load.
 *
 * @param element the config element defining the extension
 * @param classAttribute the name of the attribute carrying the class
 * @return the extension object
 * @throws CoreException thrown if the creation failed
 */
public static Object createExtension(final IConfigurationElement element, final String classAttribute) throws CoreException {
	// If plugin has been loaded create extension.
	// Otherwise, show busy cursor then create extension.
	String pluginId = element.getContributor().getName();
	Bundle bundle = Platform.getBundle(pluginId);
	if (bundle != null && bundle.getState() == Bundle.ACTIVE ) {
		return element.createExecutableExtension(classAttribute);
	} else {
		final Object[] ret = new Object[1];
		final CoreException[] exc = new CoreException[1];
		BusyIndicator.showWhile(null, new Runnable() {
			public void run() {
				try {
					ret[0] = element.createExecutableExtension(classAttribute);
				} catch (CoreException e) {
					exc[0] = e;
				}
			}
		});
		if (exc[0] != null)
			throw exc[0];
		else
			return ret[0];
	}
}
 
Example 3
/**
 * Get bundle state as a constant length string. Show state left adjusted as
 * 12 character string.
 *
 * @param bundle
 *          the bundle
 * @return The bundles state
 */
public static String showState(Bundle bundle)
{
  switch (bundle.getState()) {
  case Bundle.INSTALLED:
    return "installed   ";
  case Bundle.RESOLVED:
    return "resolved    ";
  case Bundle.STARTING:
    return "starting    ";
  case Bundle.ACTIVE:
    return "active      ";
  case Bundle.STOPPING:
    return "stopping    ";
  case Bundle.UNINSTALLED:
    return "uninstalled ";
  default:
    return "ILLEGAL <" + bundle.getState() + "> ";
  }
}
 
Example 4
public void close() {
  if(psTracker != null) {
    int state = bundle.getState();
    if(0 != (state & (Bundle.ACTIVE | Bundle.STARTING | Bundle.STOPPING))) {
      try {
        log.debug("close tracker for " + bundle + ", state=" + state);
        psTracker.close();
      } catch (Exception e) {
        log.debug("Failed to close tracker", e);
      }
    } else {
      log.debug("skip tracker close since state=" + state);
    }
  }
  bundle    = null;
  bc        = null;
  psTracker = null;
  ps        = null;
  sysNode   = null;
  usersNode = null;
}
 
Example 5
private boolean doLaunch()
    throws BundleException
{
  boolean bLaunched;
  if (null!=framework && (Bundle.ACTIVE&framework.getState())!=0) {
    throw new IllegalArgumentException
      ("a framework instance is already active.");
  }
  assertFramework();
  framework.start();
  bLaunched = true;
  closeSplash();
  println("Framework launched", 0);
  return bLaunched;
}
 
Example 6
private static boolean isBundleAvailable(BundleContext context, String bsn) {
    for (Bundle bundle : context.getBundles()) {
        if (bundle.getSymbolicName().equals(bsn) && bundle.getState() == Bundle.ACTIVE) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source Project: netbeans   File: NetigsoServicesTest.java    License: Apache License 2.0 5 votes vote down vote up
public static Bundle findBundle(String bsn) throws Exception {
    Bundle[] arr = findFramework().getBundleContext().getBundles();
    Bundle candidate = null;
    for (Bundle b : arr) {
        if (bsn.equals(b.getSymbolicName())) {
            candidate = b;
            if ((b.getState() & Bundle.ACTIVE) != 0) {
                return b;
            }
        }
    }
    return candidate;
}
 
Example 8
public ModelPackageBundleListener(BundleContext bundleContext,
                                  ModelAdapterFactory factory,
                                  AdapterImplementations adapterImplementations,
                                  BindingsValuesProvidersByContext bindingsValuesProvidersByContext,
                                  SlingModelsScriptEngineFactory scriptEngineFactory) {
    this.bundleContext = bundleContext;
    this.factory = factory;
    this.adapterImplementations = adapterImplementations;
    this.bindingsValuesProvidersByContext = bindingsValuesProvidersByContext;
    this.scriptEngineFactory = scriptEngineFactory;
    this.bundleTracker = new BundleTracker<>(bundleContext, Bundle.ACTIVE, this);
    this.bundleTracker.open();
}
 
Example 9
private static boolean isBundleAvailable(BundleContext context, String bsn) {
    for (Bundle bundle : context.getBundles()) {
        final String bsnCurrentBundle = bundle.getSymbolicName();
        if (bsnCurrentBundle != null) {
            if (bsnCurrentBundle.equals(bsn) && bundle.getState() == Bundle.ACTIVE) {
                return true;
            }
        }
    }
    return false;
}
 
Example 10
@SuppressWarnings("unchecked")
public ResourceBundleTracker(BundleContext bundleContext, LocaleProvider localeProvider) {
    super(bundleContext, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null);
    this.localeProvider = localeProvider;
    pkgAdmin = (PackageAdmin) bundleContext
            .getService(bundleContext.getServiceReference(PackageAdmin.class.getName()));
    this.bundleLanguageResourceMap = new LinkedHashMap<>();
}
 
Example 11
@SuppressWarnings("unchecked")
public ResourceBundleTracker(BundleContext bundleContext, LocaleProvider localeProvider) {
    super(bundleContext, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null);
    this.localeProvider = localeProvider;
    pkgAdmin = (PackageAdmin) bundleContext
            .getService(bundleContext.getServiceReference(PackageAdmin.class.getName()));
    this.bundleLanguageResourceMap = new LinkedHashMap<Bundle, LanguageResourceBundleManager>();
}
 
Example 12
Source Project: cxf   File: CXFExtensionBundleListener.java    License: Apache License 2.0 5 votes vote down vote up
public void registerExistingBundles(BundleContext context) throws IOException {
    for (Bundle bundle : context.getBundles()) {
        if ((bundle.getState() == Bundle.RESOLVED
            || bundle.getState() == Bundle.STARTING
            || bundle.getState() == Bundle.ACTIVE
            || bundle.getState() == Bundle.STOPPING)
            && bundle.getBundleId() != context.getBundle().getBundleId()) {
            register(bundle);
        }
    }
}
 
Example 13
/**
 * Creates a new instance of this class with the specified parameters.
 *
 * @param bundleContext the bundle context to be used for tracking bundles (must not
 *            be null)
 * @param xmlDirectory the directory to search for XML files (must neither be null,
 *            nor empty)
 * @param xmlDocumentTypeReader the XML converter to be used (must not be null)
 * @param xmlDocumentProviderFactory the result object processor to be used (must not be null)
 * @param readyMarkerKey the key to use for registering {@link ReadyMarker}s
 * @throws IllegalArgumentException if any of the arguments is null
 */
public XmlDocumentBundleTracker(BundleContext bundleContext, String xmlDirectory,
        XmlDocumentReader<T> xmlDocumentTypeReader, XmlDocumentProviderFactory<T> xmlDocumentProviderFactory,
        String readyMarkerKey, ReadyService readyService) throws IllegalArgumentException {
    super(bundleContext, Bundle.ACTIVE, null);

    if (bundleContext == null) {
        throw new IllegalArgumentException("The BundleContext must not be null!");
    }
    if ((xmlDirectory == null) || (xmlDirectory.isEmpty())) {
        throw new IllegalArgumentException("The XML directory must neither be null, nor empty!");
    }
    if (xmlDocumentTypeReader == null) {
        throw new IllegalArgumentException("The XmlDocumentTypeReader must not be null!");
    }
    if (xmlDocumentProviderFactory == null) {
        throw new IllegalArgumentException("The XmlDocumentProviderFactory must not be null!");
    }
    if (readyService == null) {
        throw new IllegalArgumentException("The ReadyService must not be null!");
    }

    this.readyMarkerKey = readyMarkerKey;
    this.xmlDirectory = xmlDirectory;
    this.xmlDocumentTypeReader = xmlDocumentTypeReader;
    this.xmlDocumentProviderFactory = xmlDocumentProviderFactory;
    this.readyService = readyService;
}
 
Example 14
Source Project: flowable-engine   File: Extender.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * this method checks the initial bundle that are installed/active before bundle tracker is opened.
 *
 * @param b the bundle to check
 */
private void checkInitialBundle(Bundle b) {
    // If the bundle is active, check it
    if (b.getState() == Bundle.RESOLVED || b.getState() == Bundle.STARTING || b.getState() == Bundle.ACTIVE) {
        checkBundle(b);
    }
}
 
Example 15
Source Project: netbeans   File: NetigsoSelfQueryTest.java    License: Apache License 2.0 4 votes vote down vote up
public void start() throws BundleException {
    state = Bundle.ACTIVE;
}
 
Example 16
private static boolean isTeamUIPlugInActivated() {
	return Platform.getBundle("org.eclipse.team.ui").getState() == Bundle.ACTIVE; //$NON-NLS-1$
}
 
Example 17
@Override
public void paintIcon(Component c, Graphics g, int x, int y)
{
  updateIcon();

  super.paintIcon(c, g, x, y);

  Icon overlay = null;

  switch (bundle.getState()) {
  case Bundle.ACTIVE:
    overlay = OVERLAY_ACTIVE;
    break;
  case Bundle.INSTALLED:
    overlay = OVERLAY_INSTALLED;
    break;
  case Bundle.RESOLVED:
    overlay = OVERLAY_RESOLVED;
    break;
  case Bundle.STARTING:
    overlay = OVERLAY_STARTING;
    break;
  case Bundle.STOPPING:
    overlay = OVERLAY_STOPPING;
    break;
  case Bundle.UNINSTALLED:
    overlay = OVERLAY_UNINSTALLED;
    break;
  default:
  }

  if (overlay != null) {
    final int x1 = x + (getIconWidth() - overlay.getIconWidth());
    final int y1 = y + (getIconHeight() - overlay.getIconHeight());

    final int w = overlay.getIconWidth();
    final int h = overlay.getIconHeight();

    g.setColor(Color.white);
    g.fill3DRect(x1 - 1, y1 - 1, w + 2, h + 2, true);
    overlay.paintIcon(c, g, x1, y1);
  }
}
 
Example 18
public String showState(Bundle bundle) {
  final StringBuffer sb = new StringBuffer();

  try {
    final StringBuffer s = new StringBuffer
      (String.valueOf(bundle.adapt(BundleStartLevel.class).getStartLevel()));
    while (s.length() < 2) {
      s.insert(0, " ");
    }
    sb.append(s.toString());
  } catch (final Exception ignored) {
    sb.append("--");
  }

  sb.append("/");

  switch (bundle.getState()) {
  case Bundle.INSTALLED:
    sb.append("installed");
    break;
  case Bundle.RESOLVED:
    sb.append("resolved");
    break;
  case Bundle.STARTING:
    sb.append("starting");
    break;
  case Bundle.ACTIVE:
    sb.append("active");
    break;
  case Bundle.STOPPING:
    sb.append("stopping");
    break;
  case Bundle.UNINSTALLED:
    sb.append("uninstalled");
    break;
  default:
    sb.append("ILLEGAL <" + bundle.getState() + "> ");
    break;
  }
  while (sb.length() < 13) {
    sb.append(" ");
  }

  return sb.toString();
}
 
Example 19
protected boolean isBundleResolved(String bundleId) {
	Bundle[] bundles = Activator.getInstance().getBundle().getBundleContext().getBundles();
	Optional<Bundle> bundle = Arrays.stream(bundles).filter(b -> bundleId.equals(b.getSymbolicName())).findFirst();
	return bundle.isPresent() && (bundle.get().getState() & (Bundle.RESOLVED | Bundle.STARTING) | Bundle.ACTIVE) != 0;
}
 
Example 20
Source Project: vespa   File: ClassLoaderOsgiFramework.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int getState() {
    return Bundle.ACTIVE;
}