/** * Obtains all instances of a particular class from a container by navigating up the container * hierachy. * * @param container The container. * @param clazz The class. * @return A list of all instances of <code>clazz</code>, or the empty list if none found. */ public static List getComponentInstancesOfType(PicoContainer container, Class clazz) { List instances = new ArrayList(); while (container != null) { List l = container.getComponentInstancesOfType(clazz); instances.addAll(l); container = container.getParent(); } return instances; }
/** * Unregisters a component in the container and all parent containers. * * @param container The container. * @param key The key of the component. */ public static void unregisterComponent(PicoContainer container, final Object key) { // go to the top of the hierachy while (container.getParent() != null) { container = container.getParent(); } container.accept( new PicoVisitor() { public Object traverse(Object node) { return null; } public void visitContainer(PicoContainer container) { if (container instanceof MutablePicoContainer) { ((MutablePicoContainer) container).unregisterComponent(key); } } public void visitComponentAdapter(ComponentAdapter adapter) {} public void visitParameter(Parameter parameter) {} }); }
+ 1 // CeDistributedInformation ); assertThat(picoContainer.getParent().getComponentAdapters()).hasSize( CONTAINER_ITSELF + 8 // level 3 ); assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize( CONTAINER_ITSELF + 20 // MigrationConfigurationModule + 17 // level 2 ); assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize( COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION + 26 // level 1 (Class) CeDistributedInformationImpl.class).contains( (Class) StandaloneCeDistributedInformation.class); assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull(); } finally { underTest.stop();
private ObjectHasher getObjectHasher(){ if (objectHasher != null){ return objectHasher; } synchronized (this) { objectHasher = picoContainer.getComponent(ObjectHasher.class); return objectHasher; } }
final PicoContainer parent = container.getParent(); if (parent != null) { adapterMap.putAll(getMatchingComponentAdapters(parent, adapter, keyType, valueType)); final Collection allAdapters = container.getComponentAdapters(); for (final Iterator iter = allAdapters.iterator(); iter.hasNext();) { final ComponentAdapter componentAdapter = (ComponentAdapter) iter.next(); adapterMap.remove(componentAdapter.getComponentKey()); final List adapterList = container.getComponentAdaptersOfType(valueType); for (final Iterator iter = adapterList.iterator(); iter.hasNext();) { final ComponentAdapter componentAdapter = (ComponentAdapter) iter.next();
private ComponentAdapter getTargetAdapter(PicoContainer container, Class expectedType, ComponentAdapter excludeAdapter) { if (componentKey != null) { return container.getComponentAdapter(componentKey); } else if(excludeAdapter == null) { return container.getComponentAdapterOfType(expectedType); } else { Object excludeKey = excludeAdapter.getComponentKey(); ComponentAdapter byKey = container.getComponentAdapter(expectedType); if(byKey != null && !excludeKey.equals(byKey.getComponentKey())) { return byKey; List found = container.getComponentAdaptersOfType(expectedType); ComponentAdapter exclude = null; for(Iterator iterator = found.iterator(); iterator.hasNext();) { if( container.getParent() != null) { return container.getParent().getComponentAdapterOfType(expectedType); } else { return null;
/** * Obtains all component adapters of a particular class from a container by navigating up the * container hierarchy. * * @param container The container. * @param clazz The class. * @return A list of all adapters for components of class <code>clazz</code>, or the empty list * if none found. */ public static List<ComponentAdapter> getComponentAdaptersOfType( PicoContainer container, Class clazz) { List instances = new ArrayList(); while (container != null) { List l = container.getComponentAdaptersOfType(clazz); instances.addAll(l); container = container.getParent(); } return instances; }
public Collection getComponentAdapters() { return delegate.getComponentAdapters(); }
PicoContainer container = new DefaultPicoContainer(); container.addComponent(Earth.class); container.addComponent(Continent.class); container.addComponent(Country.class); container.addComponent(City.class, new ConstantParameter(cityName)); City barcelona = container.getComponent(City.class);
public List<ParserDelegate> getDelegates() { if (this.delegates == null) { this.delegates = container.getComponentInstancesOfType(ParserDelegate.class); } return this.delegates; } }
public Object getComponentInstanceOfType(Class componentType) { return delegate.getComponentInstanceOfType(componentType); }
public void accept(PicoVisitor visitor) { visitor.visitContainer(this); final List componentAdapters = new ArrayList(getComponentAdapters()); for (Iterator iterator = componentAdapters.iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); componentAdapter.accept(visitor); } final List allChildren = new ArrayList(children); for (Iterator iterator = allChildren.iterator(); iterator.hasNext();) { PicoContainer child = (PicoContainer) iterator.next(); child.accept(visitor); } }
/** * @jmx.managed-operation description = "Destroy this Proxy" impact = "ACTION" */ public final void destroy() { checkDestroyStatus(); container_.dispose(); final List list = container_.getComponentInstancesOfType(IContainer.class); for (Iterator i = list.iterator(); i.hasNext();) { IContainer element = (IContainer) i.next(); element.destroy(); } }
public synchronized PicoContainer getParent() { return delegate.getParent(); }
public List getComponentAdaptersOfType(Class componentType) { return delegate.getComponentAdaptersOfType(componentType); }
/** * Dispose the components of this PicoContainer and all its logical child * containers. Any component implementing the lifecycle interface * {@link org.picocontainer.Disposable} will be disposed. * * @see #makeChildContainer() * @see #addChildContainer(PicoContainer) * @see #removeChildContainer(PicoContainer) */ public void dispose() { if (disposed) throw new IllegalStateException("Already disposed"); for (Iterator iterator = children.iterator(); iterator.hasNext();) { PicoContainer child = (PicoContainer) iterator.next(); child.dispose(); } Collection<ComponentAdapter> adapters = getComponentAdapters(); for (ComponentAdapter componentAdapter : adapters) { if (componentAdapter instanceof LifecycleStrategy) { ((LifecycleStrategy) componentAdapter).dispose(getInstance(componentAdapter)); } } disposed = true; }
private ApplicationProperties getProperties() { // Lazy load the application properties return container.getComponent(ApplicationProperties.class); } }
@Override protected List<Class<?>> stepsTypes() { List<Class<?>> types = new ArrayList<>(); for (ComponentAdapter<?> adapter : parent.getComponentAdapters()) { if (hasAnnotatedMethods(adapter.getComponentImplementation())) { types.add(adapter.getComponentImplementation()); } } return types; }
public List getComponentInstancesOfType(Class type) throws PicoException { return delegate.getComponentInstancesOfType(type); }
public GML32Delegate(Encoder encoder) { this.gmlUri = org.geotools.gml3.v3_2.GML.NAMESPACE; this.gmlPrefix = encoder.getNamespaces().getPrefix(gmlUri); this.member = MEMBER.derive(gmlPrefix, gmlUri); this.srsSyntax = (SrsSyntax) encoder.getContext().getComponentInstanceOfType(SrsSyntax.class); this.encodingUtils = new GML32EncodingUtils(); this.numDecimals = getNumDecimals(encoder.getConfiguration()); this.padWithZeros = getPadWithZeros(encoder.getConfiguration()); this.decimalEncoding = getForceDecimalEncoding(encoder.getConfiguration()); this.encodeMeasures = getEncodecoordinatesMeasures(encoder.getConfiguration()); }