/** * Launders the given throwable * * <ul> * <li>Rethrows a given {@link RuntimeException} * <li>Rethrows a given {@link Error} * <li>Returns a given {@link ModuleException} * <li>Otherwise wrapps the given {@link Throwable} in a {@link ModuleException} * </ul> */ public static ModuleException launderThrowable(Throwable cause) { if (cause instanceof RuntimeException) throw (RuntimeException) cause; if (cause instanceof Error) throw (Error) cause; if (cause instanceof ModuleException) return (ModuleException) cause; return new ModuleException(cause); } }
@Override public Module installPluginModule(Runtime runtime, ClassLoader classLoader) throws ModuleException { String resourceName = getBundleActivator().replace('.', '/') + ".class"; URL resurl = classLoader.getResource(resourceName); if (resurl == null) { RuntimeLogger.LOGGER.debug("Cannot load BundleActivator resource '{}'", resourceName); return null; } String urlpath = resurl.toExternalForm(); urlpath = urlpath.substring(0, urlpath.indexOf(resourceName)); urlpath = urlpath + JarFile.MANIFEST_NAME; Manifest manifest; try { manifest = new Manifest(new URL(urlpath).openStream()); } catch (Exception ex) { throw new ModuleException("Cannot load plugin manifest: " + urlpath, ex); } Dictionary<String, String> headers = new ManifestHeadersProvider(manifest).getHeaders(); headers.put(Constants.MODULE_ACTIVATOR, getClass().getName()); return runtime.installModule(classLoader, headers); }
throw new ModuleException("Cannot aquire stop lock for: " + this); throw new ModuleException("Cannot stop module: " + this, stopException);
@Override public final Module installModule(ClassLoader classLoader, Resource resource, Dictionary<String, String> headers, Attachable context) throws ModuleException { assertNoShutdown(); context = context != null ? context : new AttachableSupport(); AbstractModule module = createModule(classLoader, resource, headers, context); // Attach the {@link ModuleEntriesProvider} ModuleEntriesProvider entriesProvider = context.getAttachment(AbstractModule.MODULE_ENTRIES_PROVIDER_KEY); entriesProvider = entriesProvider != null ? entriesProvider : getDefaultEntriesProvider(module, context); if (entriesProvider != null) { module.putAttachment(AbstractModule.MODULE_ENTRIES_PROVIDER_KEY, entriesProvider); } if (getModule(module.getIdentity()) != null) throw new ModuleException("Module already installed: " + module); modules.put(module.getModuleId(), module); // #1 The module's state is set to {@code INSTALLED}. module.setState(State.INSTALLED); // #2 A module event of type {@link ModuleEvent#INSTALLED} is fired. runtimeEvents.fireModuleEvent(module, ModuleEvent.INSTALLED); LOGGER.info("Installed: {}", module); return module; }
throw new ModuleException("Cannot aquire start lock for: " + this); throw new ModuleException("Cannot start module: " + this, th);