/** * @deprecated since 1.1 - Use new VerifyingVisitor().traverse(this) */ public void verify() throws PicoVerificationException { new VerifyingVisitor().traverse(this); }
protected JdonInstantiatingComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses) { this(componentKey, componentImplementation, parameters, allowNonPublicClasses, new DelegatingComponentMonitor()); }
public void start(Object component) { lifecycleStrategy.start(component); }
public MutablePicoContainer makeChildContainer() { DefaultPicoContainer pc = new DefaultPicoContainer(componentAdapterFactory, this); addChildContainer(pc); return pc; }
/** * Returns the component adapter for a binding with the specified name. * * @param type The qualified name of the type of the binding. * @return The binding class, or null if no such class exists. */ protected ComponentAdapter getBinding(QName type) { Object o = bindings.get(type); if (o == null) { return null; } if (o instanceof ComponentAdapter) { return (ComponentAdapter) o; } if (o instanceof Class) { return new ConstructorInjectionComponentAdapter(null, (Class) o); } return new InstanceComponentAdapter(null, o); } }
/** * Loads a binding with a specifc class into a context. * * @param bindingClass The class of the binding. * @param context The context which is to contain the binding. * @return The binding object of the associated type, otherwise null if no such binding could be * created. */ public Binding loadBinding(QName qName, Class bindingClass, PicoContainer context) { // instantiate within the given context ComponentAdapter adapter = new ConstructorInjectionComponentAdapter(qName, bindingClass); return (Binding) adapter.getComponentInstance(context); }
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; }
public boolean hasLifecycle(Class type) { return lifecycleStrategy.hasLifecycle(type); }
/** * {@inheritDoc} The returned ComponentAdapter will be instantiated by the * {@link ComponentAdapterFactory} passed to the container's constructor. */ public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoRegistrationException { ComponentAdapter componentAdapter = componentAdapterFactory.createComponentAdapter(componentKey, componentImplementation, parameters); registerComponent(componentAdapter); return componentAdapter; }
public void stop(Object component) { lifecycleStrategy.stop(component); }
public void dispose(Object component) { lifecycleStrategy.dispose(component); }
/** * Constructs a new ComponentAdapter for the given key and implementation. * * @param componentKey * the search key for this implementation * @param componentImplementation * the concrete implementation * @param parameters * the parameters to use for the initialization * @param allowNonPublicClasses * flag to allow instantiation of non-public classes * @param monitor * the component monitor used by this ComponentAdapter * @throws AssignabilityRegistrationException * if the key is a type and the implementation cannot be * assigned to * @throws NotConcreteRegistrationException * if the implementation is not a concrete class * @throws NullPointerException * if one of the parameters is <code>null</code> */ protected JdonInstantiatingComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses, ComponentMonitor monitor) { this(componentKey, componentImplementation, parameters, allowNonPublicClasses, monitor, new DefaultLifecycleStrategy(monitor)); }
/** * Creates a new container with a custom ComponentAdapterFactory and a * parent container. * <p/> * <em> * Important note about caching: If you intend the components to be cached, you should pass * in a factory that creates {@link CachingComponentAdapter} instances, such as for example * {@link CachingComponentAdapterFactory}. CachingComponentAdapterFactory can delegate to * other ComponentAdapterFactories. * </em> * * @param componentAdapterFactory * the factory to use for creation of ComponentAdapters. * @param parent * the parent container (used for component dependency lookups). */ public JdonPicoContainer(ComponentAdapterFactory componentAdapterFactory, PicoContainer parent) { if (componentAdapterFactory == null) throw new NullPointerException("componentAdapterFactory"); this.componentAdapterFactory = componentAdapterFactory; this.parent = parent == null ? null : ImmutablePicoContainerProxyFactory.newProxyInstance(parent); }
public void accept(PicoVisitor visitor) { super.accept(visitor); if (parameters != null) { for (int i = 0; i < parameters.length; i++) { parameters[i].accept(visitor); } } }
/** * Changes monitor in the ComponentAdapterFactory, the component adapters * and the child containers, if these support a ComponentMonitorStrategy. * {@inheritDoc} */ public void changeMonitor(ComponentMonitor monitor) { // will also change monitor in lifecycleStrategyForInstanceRegistrations if (componentAdapterFactory instanceof ComponentMonitorStrategy) { ((ComponentMonitorStrategy) componentAdapterFactory).changeMonitor(monitor); } for (Iterator i = compAdapters.iterator(); i.hasNext();) { Object adapter = i.next(); if (adapter instanceof ComponentMonitorStrategy) { ((ComponentMonitorStrategy) adapter).changeMonitor(monitor); } } for (Iterator i = children.iterator(); i.hasNext();) { Object child = i.next(); if (child instanceof ComponentMonitorStrategy) { ((ComponentMonitorStrategy) child).changeMonitor(monitor); } } }
/** * {@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; }
private void checkConcrete() throws NotConcreteRegistrationException { // Assert that the component class is concrete. boolean isAbstract = (getComponentImplementation().getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT; if (getComponentImplementation().isInterface() || isAbstract) { throw new NotConcreteRegistrationException(getComponentImplementation()); } }
public Binding stratagy(QName qname) throws Exception { return factory.loadBinding(qname, new DefaultPicoContainer()); }
public ComponentAdapter getComponentAdapter(Object componentKey) { if (componentKey == null) { return null; } Object o = get(componentKey); if (o == null) { return null; } if (o instanceof Class) { // TODO: determine which form of injection to use return new ConstructorInjectionComponentAdapter(componentKey, (Class) o); } return new InstanceComponentAdapter(componentKey, o); }
public Binding stratagy(String name) throws Exception { return factory.loadBinding(xs(name), new DefaultPicoContainer()); }