public ComponentContainer addExtension(@Nullable String defaultCategory, Object extension) { Object key = componentKeys.of(extension); try { pico.as(Characteristics.CACHE).addComponent(key, extension); } catch (Throwable t) { throw new IllegalStateException("Unable to register extension " + getName(extension), t); } declareExtension(defaultCategory, extension); return this; }
public ComponentContainer addExtension(@Nullable PluginInfo pluginInfo, Object extension) { Object key = componentKeys.of(extension); try { pico.as(Characteristics.CACHE).addComponent(key, extension); } catch (Throwable t) { throw new IllegalStateException("Unable to register extension " + getName(extension) + (pluginInfo != null ? (" from plugin '" + pluginInfo.getKey() + "'") : ""), t); } declareExtension(pluginInfo, extension); return this; }
/** * @param singleton return always the same instance if true, else a new instance * is returned each time the component is requested */ public ComponentContainer addComponent(Object component, boolean singleton) { Object key = componentKeys.of(component); if (component instanceof ComponentAdapter) { pico.addAdapter((ComponentAdapter) component); } else { try { pico.as(singleton ? Characteristics.CACHE : Characteristics.NO_CACHE).addComponent(key, component); } catch (Throwable t) { throw new IllegalStateException("Unable to register component " + getName(component), t); } declareExtension("", component); } return this; }
private PicoLifecycleException newPicoLifecycleException(boolean initialCheckedException) { MutablePicoContainer container = ComponentContainer.createPicoContainer().as(Characteristics.CACHE); if (initialCheckedException) { container.addComponent(CheckedFailureComponent.class); } else { container.addComponent(UncheckedFailureComponent.class); } try { container.start(); return null; } catch (PicoLifecycleException e) { return e; } }
@Override public MutablePicoContainer as(final Properties... properties) { delegatePicoContainer.as(properties); return this; }
public MutablePicoContainer as(final Properties... properties) { return delegate.as(properties); }
public MutablePicoContainer as(final Properties... properties) { return delegate.as(properties); }
public static <T> T createComponent(java.lang.Class<T> tClass) { return factory.as(Characteristics.NO_CACHE).getComponent(tClass); } }
public ComponentContainer addExtension(@Nullable PluginMetadata plugin, Object extension) { Object key = componentKeys.of(extension); try { pico.as(Characteristics.CACHE).addComponent(key, extension); } catch (Throwable t) { throw new IllegalStateException("Unable to register extension " + getName(extension), t); } declareExtension(plugin, extension); return this; }
public ComponentContainer addExtension(@Nullable String defaultCategory, Object extension) { Object key = componentKeys.of(extension); try { pico.as(Characteristics.CACHE).addComponent(key, extension); } catch (Throwable t) { throw new IllegalStateException("Unable to register extension " + getName(extension), t); } declareExtension(defaultCategory, extension); return this; }
/** * Register a component type. * * @param componentType the component type * @throws ContainerException if registration fails */ @Override public <T> void addComponent(Class<T> componentType) { try { container.as(Characteristics.USE_NAMES).addComponent(componentType); } catch (PicoException exception) { throw new ContainerException(exception); } }
public ComponentContainer addExtension(@Nullable PluginInfo pluginInfo, Object extension) { Object key = componentKeys.of(extension); try { pico.as(Characteristics.CACHE).addComponent(key, extension); } catch (Throwable t) { throw new IllegalStateException("Unable to register extension " + getName(extension) + (pluginInfo != null ? (" from plugin '" + pluginInfo.getKey() + "'") : ""), t); } declareExtension(pluginInfo, extension); return this; }
public void init(FilterConfig filterConfig) throws ServletException { ServletContext context = filterConfig.getServletContext(); ScopedContainers scopedContainers = getScopedContainers(context); setAppContainer(scopedContainers.getApplicationContainer()); isStateless = Boolean.parseBoolean(context.getInitParameter(PicoServletContainerListener.STATELESS_WEBAPP)); printSessionSize = Boolean.parseBoolean(context.getInitParameter(PicoServletContainerListener.PRINT_SESSION_SIZE)); String exposeServletInfrastructureString = filterConfig.getInitParameter("exposeServletInfrastructure"); if (exposeServletInfrastructureString == null || Boolean.parseBoolean(exposeServletInfrastructureString)) { exposeServletInfrastructure = true; } scopedContainers.getRequestContainer().as(Characteristics.NO_CACHE).addAdapter(new HttpSessionInjector()); scopedContainers.getRequestContainer().as(Characteristics.NO_CACHE).addAdapter(new HttpServletRequestInjector()); scopedContainers.getRequestContainer().as(Characteristics.NO_CACHE).addAdapter(new HttpServletResponseInjector()); initAdditionalScopedComponents(scopedContainers.getSessionContainer(), scopedContainers.getRequestContainer()); }
public class Service { private String data; public Service(String data) { this.data = data; } public String getData() { return data; } public static void main(String[] args) { MutablePicoContainer container = new DefaultPicoContainer(); container.as(Characteristics.USE_NAMES).addComponent(Service.class); container.addComponent("Real Data"); // below line added only in test for injecting test data ... container.addComponent("data", "Mock Data"); System.out.println(container.getComponent(Service.class).getData()); } }
/** * @param singleton return always the same instance if true, else a new instance * is returned each time the component is requested */ public ComponentContainer addComponent(Object component, boolean singleton) { Object key = componentKeys.of(component); if (component instanceof ComponentAdapter) { pico.addAdapter((ComponentAdapter) component); } else { pico.as(singleton ? Characteristics.CACHE : Characteristics.NO_CACHE).addComponent(key, component); declareExtension(null, component); } return this; }
/** * @param singleton return always the same instance if true, else a new instance * is returned each time the component is requested */ public ComponentContainer addComponent(Object component, boolean singleton) { Object key = componentKeys.of(component); if (component instanceof ComponentAdapter) { pico.addAdapter((ComponentAdapter) component); } else { try { pico.as(singleton ? Characteristics.CACHE : Characteristics.NO_CACHE).addComponent(key, component); } catch (Throwable t) { throw new IllegalStateException("Unable to register component " + getName(component), t); } declareExtension("", component); } return this; }
PicoBasedContainer provideRequestContainer(final RequestInfo request) { MutablePicoContainer parentContainer; if (sessionScoped.isEmpty()) { logger.debug("There's no @SessionScoped component, so skipping session container creation"); parentContainer = this.appContainer; } else { parentContainer = getSessionContainer(request); } logger.debug("Request components are {}", requestScoped); ComponentMonitor monitor = new AttributeSetterComponentMonitor(new AttributeSetterComponentMonitor.AttributeSetter() { public void setAttribute(String name, Object object) { request.getRequest().setAttribute(name, object); } }); MutablePicoContainer requestContainer = new DefaultPicoContainer(new Caching(), new JavaEE5LifecycleStrategy(monitor), parentContainer, monitor); requestContainer.addComponent(HttpSession.class, request.getRequest().getSession()); for (Map.Entry<Class<?>, Class<?>> entry : requestScoped.entrySet()) { requestContainer.addComponent(entry.getKey(), entry.getValue()); } for (Map.Entry<Class<?>, Class<?>> entry : prototypeScoped.entrySet()) { requestContainer.as(Characteristics.NO_CACHE).addComponent(entry.getKey(), entry.getValue()); } requestContainer.addComponent(request).addComponent(request.getRequest()).addComponent(request.getResponse()); registerComponentFactories(requestContainer, componentFactoryRegistry.getRequestMap()); return new PicoBasedContainer(requestContainer); }
/** * Registers components with the container. * * @param pico the container */ @Override protected void registerComponents(MutablePicoContainer pico) { super.registerComponents(pico); pico .addAdapter(new ProviderAdapter(new GUIInstallDataProvider())) .addAdapter(new ProviderAdapter(new IzPanelsProvider())) .addAdapter(new ProviderAdapter(new IconsProvider())); pico .addComponent(GUIPrompt.class) .addComponent(InstallerController.class) .addComponent(DefaultNavigator.class) .addComponent(InstallerFrame.class) .addComponent(Log.class) .addComponent(GUIPackResources.class) .addComponent(MultiVolumeUnpackerHelper.class) .addComponent(SplashScreen.class) .as(Characteristics.USE_NAMES).addComponent(LanguageDialog.class); }