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; }
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; } }
/** * @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; }
public void start() { pico = new PicoBuilder() .withCaching() .withLifecycle() .build(); for (Class<?> clazz : classes) { pico.addComponent(clazz); } pico.start(); }
m_eventSyncCondition = eventSyncCondition; m_container = new DefaultPicoContainer(new Caching()); m_container.addComponent(logger); m_container.addComponent(resources); m_container.addComponent(properties); m_container.addComponent(StatisticsServicesImplementation.getInstance()); m_container.addComponent(new StandardTimeAuthority()); m_container.addComponent(consoleCommunicationSetting); m_container.addComponent(SampleModelImplementationEx.class); m_container.addComponent(SampleModelViewsImplementation.class); m_container.addComponent(ConsoleCommunicationImplementationEx.class); m_container.addComponent(DistributionControlImplementation.class); m_container.addComponent(ProcessControlImplementation.class); m_timer = new Timer(true); m_container.addComponent(m_timer); m_container.addComponent(FileDistributionImplementation.class, FileDistributionImplementation.class, new Parameter[] { new ComponentParameter(DistributionControlImplementation.class), new ComponentParameter(ProcessControlImplementation.class), new ConstantParameter(properties.getDistributionFileFilterPattern()), }); m_container.addComponent(DispatchClientCommands.class); m_container.addComponent(WireFileDistribution.class); m_container.addComponent(WireMessageDispatch.class); m_container.addComponent(WireDistributedBarriers.class); m_container.addComponent(ErrorQueue.class);
@Override public MutablePicoContainer addComponent(final Object componentKey, final Object componentImplementationOrInstance, final Parameter... parameters) { delegatePicoContainer.addComponent(componentKey, componentImplementationOrInstance, parameters); return this; }
public Squid(SquidConfiguration conf) { pico = new TransientPicoContainer(); pico.addComponent(conf); project = new SourceProject("Project"); squidIndex = new SquidIndex(); squidIndex.index(project); pico.addComponent(squidIndex); pico.addComponent(project); pico.addComponent(graph); }
private void addToPicocontainer(Class<?> classToExpose) { if (pico.getComponent(classToExpose) == null) { pico.addComponent(classToExpose); } }
void instance(final Scope scope, final String key, final Object instance) { // cannot provide, String keys not supported scope.get(registry).register(instance.getClass()); container.addComponent(key, instance); }
void instance(final Scope scope, final Object instance) { // cannot provide, non-interface keys not supported scope.get(registry).register(instance.getClass()); container.addComponent(instance); }
<T> void implementationUseDefaultConstructor(final Scope scope, final Class<T> key, final Class<? extends T> implementation) { scope.get(registry).register(key); // we need to parameterise this, otherwise it tries to load the greediest constructor container.addComponent(key, implementation); }
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; }
final MutablePicoContainer container = new PicoBuilder() .withBehaviors(new JobEnabledDecorating()) .build(); container.addComponent(Job.class, MyJob.class); final Job job = container.getComponent(Job.class); job.execute();
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; }
@Test public void shouldBeAbleToInstantiateADependentBean() { this.picoContainer.addComponent(Fruit.class); this.picoContainer.addComponent(Juice.class); Fruit fruit = container.instanceFor(Fruit.class); Juice juice = container.instanceFor(Juice.class); assertThat(juice, is(notNullValue())); assertThat(juice.fruit, is(equalTo(fruit))); } }
public PicoProvider() { this.picoContainer = new DefaultPicoContainer(new Caching(), new JavaEE5LifecycleStrategy(new NullComponentMonitor()), null); ComponentFactoryRegistry componentFactoryRegistry = new DefaultComponentFactoryRegistry(); PicoComponentRegistry componentRegistry = new PicoComponentRegistry(this.picoContainer, componentFactoryRegistry); this.picoContainer.addComponent(componentRegistry); this.picoContainer.addComponent(componentFactoryRegistry); container = new AppScopedContainer(); picoContainer.addComponent(Container.class, container); }
@Test public void shouldBeAbleToInstantiateABean() { this.picoContainer.addComponent(Fruit.class); assertThat(container.instanceFor(Fruit.class), is(notNullValue())); }
@Test public void shouldBeAbleToProvideAFruitButNotAJuice() { this.picoContainer.addComponent(Fruit.class); assertThat(container.canProvide(Fruit.class), is(true)); assertThat(container.canProvide(Juice.class), is(false)); }
public static MutablePicoContainer buildPicoContainer() { ReflectionLifecycleStrategy lifecycleStrategy = new ReflectionLifecycleStrategy(new NullComponentMonitor(), "start", "stop", "dispose"); DefaultPicoContainer result = new DefaultPicoContainer(new OptInCaching(), lifecycleStrategy, null); result.as(Characteristics.CACHE).addComponent(new IocContainer(result)); // for components that directly inject other components (eg Plugins) return result; } }