public void start(int options) throws BundleException { if (getState() == UNINSTALLED) throw new IllegalStateException("Bundle.UNINSTALLED"); BundleStartLevel bundleStartLevel = adapt(BundleStartLevel.class); FrameworkStartLevel frameworkStartLevel = getFramework().adapt(FrameworkStartLevel.class); if ((bundleStartLevel != null) && (bundleStartLevel.getStartLevel() > frameworkStartLevel.getStartLevel())) { if ((options & START_TRANSIENT) == START_TRANSIENT) throw new BundleException("startLevel"); else return; } if (getState() == ACTIVE) return; if (getState() == INSTALLED) setState(RESOLVED); setState(STARTING); String location = getLocation(); if (location != null) { BundleActivator bundleActivator = null; Throwable exception = null; try { bundleActivator = (BundleActivator) loadClass(location.replace('/', '.')).newInstance(); bundleActivator.start(getBundleContext()); } catch (Throwable t) { logger.log(Level.SEVERE, "Error starting bundle: " + bundleActivator, t); if (t instanceof ThreadDeath) throw (ThreadDeath) t; else exception = t; } if (exception == null) this.bundleActivator = bundleActivator; else { setState(STOPPING); setState(RESOLVED); getFramework().fireBundleEvent(BundleEvent.STOPPED, this); throw new BundleException("BundleActivator.start", exception); } } if (getState() == UNINSTALLED) throw new IllegalStateException("Bundle.UNINSTALLED"); setState(ACTIVE); }
private String toOsgiBundles(Map<ArtifactKey, File> bundles) throws IOException { StringBuilder result = new StringBuilder(); for (Map.Entry<ArtifactKey, File> entry : bundles.entrySet()) { BundleStartLevel level = startLevel.get(entry.getKey().getId()); if (level != null && level.getLevel() == -1) { continue; // system bundle } if (result.length() > 0) { result.append(","); } result.append(appendAbsolutePath(entry.getValue())); if (level != null) { result.append('@').append(level.getLevel()); if (level.isAutoStart()) { result.append(":start"); } } } return result.toString(); }
public void addBundleStartLevel(BundleStartLevel level) { startLevel.put(level.getId(), level); }