@Override public boolean isLazy(ComponentAdapter<?> adapter) { return adapter.getComponentImplementation().getAnnotation(EagerStart.class) == null; } };
private Object getTrueInstance(ComponentAdapter ad) { if (compAdapters.contains(ad)) return ad.getComponentInstance(this); return getP(ad); }
public ComponentAdapter registerComponent(ComponentAdapter componentAdapter) { if (componentAdapter instanceof DecoratingComponentAdapter) { componentAdapter = ((DecoratingComponentAdapter) componentAdapter).getDelegate(); } Object key = componentAdapter.getComponentKey(); if (componentAdapter instanceof InstanceComponentAdapter) { Object instance = ((InstanceComponentAdapter) componentAdapter).getComponentInstance(null); put(key, instance); } else { Class implementation = componentAdapter.getComponentImplementation(); put(key, implementation); } return componentAdapter; }
/** * Provide the component itself as {@link DynamicMBean} if it is one and if an {@link ObjectName} can be created. * @see org.picocontainer.gems.jmx.DynamicMBeanProvider#provide(org.picocontainer.PicoContainer, * org.picocontainer.ComponentAdapter) */ public JMXRegistrationInfo provide(final PicoContainer picoContainer, final ComponentAdapter componentAdapter) { if (DynamicMBean.class.isAssignableFrom(componentAdapter.getComponentImplementation())) { final DynamicMBean mBean = (DynamicMBean)componentAdapter.getComponentInstance(picoContainer,null); try { final ObjectName objectName = objectNameFactory.create(componentAdapter.getComponentKey(), mBean); if (objectName != null) { return new JMXRegistrationInfo(objectName, mBean); } } catch (final MalformedObjectNameException e) { throw new JMXRegistrationException("Cannot create ObjectName for component '" + componentAdapter.getComponentKey() + "'", e); } } return null; } }
public Object remove(Object o) { ComponentAdapter adapter = mutablePicoContainer.unregisterComponent(o); if (adapter != null) { // if previously an instance was registered, return it, otherwise return the type return adapter instanceof InstanceComponentAdapter ? adapter .getComponentInstance(mutablePicoContainer) : adapter .getComponentImplementation(); } else { return null; } }
/** * Returns all the components currently inside Pico which are instances of the given class, mapping them to their * component key. * * @param iface The class to search for * @return a map, mapping the component key, to the instances of the clas registered in JIRA's pico container. */ public static <T> Map<String, T> getComponentsOfTypeMap(final Class<T> iface) { final PicoContainer picoContainer = getInstance().getContainer(); final List<ComponentAdapter<T>> componentAdaptersOfType = picoContainer.getComponentAdapters(iface); final Map<String, T> implementations = new HashMap<String, T>(); for (final ComponentAdapter<T> componentAdapter : componentAdaptersOfType) { final T componentInstance = iface.cast(componentAdapter.getComponentInstance(picoContainer)); implementations.put(String.valueOf(componentAdapter.getComponentKey()), componentInstance); } return Collections.unmodifiableMap(implementations); }
private Object getP(ComponentAdapter adapter) { if (parent != null) { return parent.getComponentInstance(adapter.getComponentKey()); } return null; }
@Override public MutablePicoContainer addAdapter(final ComponentAdapter<?> componentAdapter, final Properties properties) { super.addAdapter(componentAdapter, properties); if (componentAdapter.findAdapterOfType(InstanceAdapter.class) != null) { this.instanceRegistrations.add(componentAdapter); } else { this.addStoredReference(componentAdapter.getComponentKey()); } return this; }
public void visitComponentAdapter(ComponentAdapter componentAdapter) { super.visitComponentAdapter(componentAdapter); if (!verifiedComponentAdapters.contains(componentAdapter)) { try { componentAdapter.verify(currentPico); } catch (RuntimeException e) { nestedVerificationExceptions.add(e); } componentAdapter.accept(componentAdapterCollector); } }
public void verify() throws PicoVerificationException { delegate.verify(); } }
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); } }
/** * Precalculates all references to Stored behaviors. * @param key the object key. */ private void addStoredReference(final Object key) { ComponentAdapter<?> ca = this.getComponentAdapter(key); Stored<?> stored = ca.findAdapterOfType(Stored.class); if (stored != null) { storedReferences.put(ca, stored); } }
public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { Object componentKey = getDelegate().getComponentKey(); Class[] classes = null; if (componentKey instanceof Class && ((Class) getDelegate().getComponentKey()).isInterface()) { classes = new Class[]{(Class) getDelegate().getComponentKey()}; } else if (componentKey instanceof Class[]) { classes = (Class[]) componentKey; } else { if(strict) { throw new PicoIntrospectionException("In strict mode, " + getClass().getName() + " only allows components registered with interface keys (java.lang.Class or java.lang.Class[])"); } return getDelegate().getComponentInstance(container); } Class[] interfaces = verifyInterfacesOnly(classes); return createProxy(interfaces, container, getDelegate().getComponentImplementation().getClassLoader()); }
public Object remove(final Object o) { ComponentAdapter adapter = mutablePicoContainer.removeComponent(o); if (adapter != null) { // if previously an instance was registered, return it, otherwise return the type return adapter instanceof InstanceAdapter ? adapter .getComponentInstance(mutablePicoContainer, ComponentAdapter.NOTHING.class) : adapter .getComponentImplementation(); } else { return null; } }
private Object getInstance(ComponentAdapter componentAdapter) { // check wether this is our adapter // we need to check this to ensure up-down dependencies cannot be followed final boolean isLocal = componentAdapters.contains(componentAdapter); if (isLocal) { PicoException firstLevelException = null; Object instance = null; try { instance = componentAdapter.getComponentInstance(this); } catch (PicoInitializationException e) { firstLevelException = e; } catch (PicoIntrospectionException e) { firstLevelException = e; } if (firstLevelException != null) { if (parent != null) { instance = parent.getComponentInstance(componentAdapter.getComponentKey()); if( instance != null ) { return instance; } } throw firstLevelException; } addOrderedComponentAdapter(componentAdapter); return instance; } else if (parent != null) { return parent.getComponentInstance(componentAdapter.getComponentKey()); } return null; }
/** * {@inheritDoc} This method can be used to override the ComponentAdapter * created by the {@link ComponentAdapterFactory} passed to the constructor * of this container. */ public ComponentAdapter registerComponent(ComponentAdapter componentAdapter) throws DuplicateComponentKeyRegistrationException { Object componentKey = componentAdapter.getComponentKey(); if (compKeyAdapters.containsKey(componentKey)) { throw new DuplicateComponentKeyRegistrationException(componentKey); } compAdapters.add(componentAdapter); compKeyAdapters.put(componentKey, componentAdapter); return componentAdapter; }
@Override public MutablePicoContainer addAdapter(final ComponentAdapter<?> componentAdapter) { super.addAdapter(componentAdapter); if (componentAdapter.findAdapterOfType(InstanceAdapter.class) != null) { this.instanceRegistrations.add(componentAdapter); } else { this.addStoredReference(componentAdapter.getComponentKey()); } return this; }
public void verify(PicoContainer container) throws PicoIntrospectionException { delegate.verify(container); }
public void accept(PicoVisitor visitor) { visitor.visitComponentAdapter(this); delegate.accept(visitor); }
@Override public <U extends ComponentAdapter> U findAdapterOfType(final Class<U> adapterType) { if (adapterType.isAssignableFrom(getClass())) { //noinspection unchecked return (U) this; } else if (getDelegate() != null) { return getDelegate().findAdapterOfType(adapterType); } return null; }