/** * @since 3.5 */ public ComponentContainer add(Object... objects) { for (Object object : objects) { if (object instanceof ComponentAdapter) { addPicoAdapter((ComponentAdapter) object); } else if (object instanceof Iterable) { add(Iterables.toArray((Iterable) object, Object.class)); } else { addSingleton(object); } } return this; }
public ComponentContainer createChild() { return new ComponentContainer(this); }
public ComponentContainer addSingleton(Object component) { return addComponent(component, true); }
/** * Create root container */ public ComponentContainer() { this.parent = null; this.child = null; this.pico = createPicoContainer(); this.componentKeys = new ComponentKeys(); propertyDefinitions = new PropertyDefinitions(); addSingleton(propertyDefinitions); addSingleton(this); }
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; }
private void doInstall(ComponentContainer container, ExtensionMatcher matcher, @Nullable PluginMetadata metadata, Object extension) { if (ExtensionUtils.supportsEnvironment(extension, env) && (analysisMode.isDb() || !ExtensionUtils.requiresDB(extension)) && matcher.accept(extension)) { container.addExtension(metadata, extension); } else { container.declareExtension(metadata, extension); } }
/** * This method MUST NOT be renamed start() because the container is registered itself in picocontainer. Starting * a component twice is not authorized. */ public ComponentContainer startComponents() { try { doBeforeStart(); pico.start(); doAfterStart(); return this; } catch (Exception e) { throw PicoUtils.propagate(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 { pico.as(singleton ? Characteristics.CACHE : Characteristics.NO_CACHE).addComponent(key, component); declareExtension(null, component); } return this; }
public ComponentContainer addSingletons(Collection components) { for (Object component : components) { addSingleton(component); } return this; }
/** * Create child container */ protected ComponentContainer(ComponentContainer parent) { this.parent = parent; this.pico = parent.pico.makeChildContainer(); this.parent.child = this; this.propertyDefinitions = parent.propertyDefinitions; this.componentKeys = new ComponentKeys(); addSingleton(this); }