@Override public MutablePicoContainer addComponent(final Object key, final Object implOrInstance, final Parameter... parameters) throws PicoCompositionException { return DefaultPicoContainer.this.addComponent(key, implOrInstance, properties, new ConstructorParameters(parameters), null, null); }
@Override public MutablePicoContainer addComponent(final Object key, final Object implOrInstance, final Parameter... parameters) throws PicoCompositionException { return DefaultPicoContainer.this.addComponent(key, implOrInstance, properties, new ConstructorParameters(parameters), null, null); }
/*** * Convenience method that allows creation of a constructor injector with specific, optional parameters. * @param key * @param impl * @param params */ public ConstructorInjector(final Object key, final Class<T> impl, final Parameter... params) { this(key, impl, (params == null || params.length == 0) ? (ConstructorParameters)null : new ConstructorParameters(params)); }
/*** * Convenience method that allows creation of a constructor injector with specific, optional parameters. * @param key * @param impl * @param params */ public ConstructorInjector(final Object key, final Class<T> impl, final Parameter... params) { this(key, impl, (params == null || params.length == 0) ? (ConstructorParameters)null : new ConstructorParameters(params)); }
/** * Constructor injector that uses no monitor and no lifecycle adapter. This is a more * convenient constructor for use when instantiating a constructor injector directly. * * @param key the search key for this implementation * @param impl the concrete implementation * @param parameters the parameters used for initialization * @return */ public static <T> ComponentAdapter<T> constructor(final Object key, final Class<T> impl, final Parameter... parameters) { return new ConstructorInjection.ConstructorInjector<T>(key, impl, new ConstructorParameters(parameters)); }
/** * Constructor injector that uses no monitor and no lifecycle adapter. This is a more * convenient constructor for use when instantiating a constructor injector directly. * * @param key the search key for this implementation * @param impl the concrete implementation * @param parameters the parameters used for initialization * @return */ public static <T> ComponentAdapter<T> constructor(final Object key, final Class<T> impl, final Parameter... parameters) { return new ConstructorInjection.ConstructorInjector<T>(key, impl, new ConstructorParameters(parameters)); }
/** * Creates a ConstructorInjector * * @param key the search key for this implementation * @param impl the concrete implementation * @param monitor the component monitor used by this addAdapter * @param useNames use argument names when looking up dependencies * @param parameters the parameters to use for the initialization * @throws com.picocontainer.injectors.AbstractInjector.NotConcreteRegistrationException * if the implementation is not a concrete class. * @throws NullPointerException if one of the parameters is <code>null</code> * @return */ public static <T> ComponentAdapter<T> constructor(final Object key, final Class<T> impl, final ComponentMonitor monitor, final boolean useNames, final Parameter... parameters) { return new ConstructorInjection.ConstructorInjector<T>(monitor, useNames, key, impl, new ConstructorParameters(parameters)); }
/** * Creates a ConstructorInjector * * @param key the search key for this implementation * @param impl the concrete implementation * @param monitor the component monitor used by this addAdapter * @param useNames use argument names when looking up dependencies * @param parameters the parameters to use for the initialization * @throws com.picocontainer.injectors.AbstractInjector.NotConcreteRegistrationException * if the implementation is not a concrete class. * @throws NullPointerException if one of the parameters is <code>null</code> * @return */ public static <T> ComponentAdapter<T> constructor(final Object key, final Class<T> impl, final ComponentMonitor monitor, final boolean useNames, final Parameter... parameters) { return new ConstructorInjection.ConstructorInjector<T>(monitor, useNames, key, impl, new ConstructorParameters(parameters)); }
/** * Creates a ConstructorInjector * * @param key the search key for this implementation * @param impl the concrete implementation * @param monitor the component monitor used by this addAdapter * @param useNames use argument names when looking up dependencies * @param rememberChosenCtor remember the chosen constructor (to speed up second/subsequent calls) * @param parameters the parameters to use for the initialization * @throws com.picocontainer.injectors.AbstractInjector.NotConcreteRegistrationException * if the implementation is not a concrete class. * @throws NullPointerException if one of the parameters is <code>null</code> * @return */ public static <T> ComponentAdapter<T> constructor(final Object key, final Class<T> impl, final ComponentMonitor monitor, final boolean useNames, final boolean rememberChosenCtor, final Parameter... parameters) { return new ConstructorInjection.ConstructorInjector<T>(monitor, useNames, rememberChosenCtor, key, impl, new ConstructorParameters(parameters) ); }
/** * Creates a ConstructorInjector * * @param key the search key for this implementation * @param impl the concrete implementation * @param monitor the component monitor used by this addAdapter * @param useNames use argument names when looking up dependencies * @param rememberChosenCtor remember the chosen constructor (to speed up second/subsequent calls) * @param parameters the parameters to use for the initialization * @throws com.picocontainer.injectors.AbstractInjector.NotConcreteRegistrationException * if the implementation is not a concrete class. * @throws NullPointerException if one of the parameters is <code>null</code> * @return */ public static <T> ComponentAdapter<T> constructor(final Object key, final Class<T> impl, final ComponentMonitor monitor, final boolean useNames, final boolean rememberChosenCtor, final Parameter... parameters) { return new ConstructorInjection.ConstructorInjector<T>(monitor, useNames, rememberChosenCtor, key, impl, new ConstructorParameters(parameters) ); }
public MutablePicoContainer addComponent(final Object key, final Object implOrInstance, final ConstructorParameters constructorParams, final FieldParameters[] fieldParameters, final MethodParameters[] methodParams) { return this.addComponent(key, implOrInstance, containerProperties, constructorParams, fieldParameters, methodParams); }
public MutablePicoContainer addComponent(final Object key, final Object implOrInstance, final ConstructorParameters constructorParams, final FieldParameters[] fieldParameters, final MethodParameters[] methodParams) { return this.addComponent(key, implOrInstance, containerProperties, constructorParams, fieldParameters, methodParams); }
/** * Constructs an appropriate {@link com.picocontainer.parameters.AccessibleObjectParameterSet} based on the type * of {@link java.lang.reflect.AccessibleObject} sent. If params are null or zero length then default parameter is used. * @param object * @param params * @return */ protected AccessibleObjectParameterSet constructAccessibleObjectParameterSet(final AccessibleObject object, final Parameter... params) { if (object instanceof Constructor) { return new ConstructorParameters(params); } else if (object instanceof Field) { return new FieldParameters( ((Field)object).getDeclaringClass(), ((Field) object).getName(), params); } else if (object instanceof Method) { return new MethodParameters( ((Method)object).getDeclaringClass(), ((Method) object).getName(), params); } else { throwUnknownAccessibleObjectType(object); //Never gets here return null; } }
/** * Constructs an appropriate {@link com.picocontainer.parameters.AccessibleObjectParameterSet} based on the type * of {@link java.lang.reflect.AccessibleObject} sent. If params are null or zero length then default parameter is used. * @param object * @param params * @return */ protected AccessibleObjectParameterSet constructAccessibleObjectParameterSet(final AccessibleObject object, final Parameter... params) { if (object instanceof Constructor) { return new ConstructorParameters(params); } else if (object instanceof Field) { return new FieldParameters( ((Field)object).getDeclaringClass(), ((Field) object).getName(), params); } else if (object instanceof Method) { return new MethodParameters( ((Method)object).getDeclaringClass(), ((Method) object).getName(), params); } else { throwUnknownAccessibleObjectType(object); //Never gets here return null; } }
private ComponentAdapter<?> createComponentAdapter(final String className, final ClassLoader classLoader) { Class<?> implementation = loadClass(classLoader, className); ComponentFactory factory = new AdaptingInjection(); return factory.createComponentAdapter(new NullComponentMonitor(), new NullLifecycleStrategy(), new Properties(), className, implementation, //Adapting injection will now support simultanous constructor //and other types of injection (since 3.0) //Must provide empty parameter array to use the default constructor. // new ConstructorParameters(new Parameter[0]), null, null); }
private void addComponentAdapter(final ClassLoadingPicoContainer container, final Element element, final ClassLoadingPicoContainer metaContainer) throws ClassNotFoundException, PicoCompositionException, MalformedURLException { String className = element.getAttribute(CLASS); if (notSet(className)) { throw new ScriptedPicoContainerMarkupException("'" + CLASS + "' attribute not specified for " + element.getNodeName()); } Class<?> implementationClass = getClassLoader().loadClass(className); Object key = element.getAttribute(KEY); String classKey = element.getAttribute(CLASS_NAME_KEY); if (notSet(key)) { if (!notSet(classKey)) { key = getClassLoader().loadClass(classKey); } else { key = implementationClass; } } Parameter[] parameters = createChildParameters(container, element); ComponentFactory componentFactory = createComponentFactory(element.getAttribute(FACTORY), metaContainer); container.as(Characteristics.NONE).addAdapter(componentFactory.createComponentAdapter(new NullComponentMonitor(), new NullLifecycleStrategy(), new Properties(), key, implementationClass, new ConstructorParameters(parameters), null, null)); }
@Override public Object run(final Object inst) { final Constructor constructor = getGreediestSatisfiableConstructor(guardedContainer).getConstructor(); final Class[] parameterTypes = constructor.getParameterTypes(); final ConstructorParameters constructorParameters = (ConstructorParameters) (parameters != null && parameters.length > 0 ? parameters[0] : new ConstructorParameters()); final Parameter[] currentParameters = constructorParameters.getParams() != null ? constructorParameters.getParams() : createDefaultParameters(parameterTypes.length); for (int i = 0; i < currentParameters.length; i++) { currentParameters[i].verify(container, ConstructorInjector.this, box(parameterTypes[i]), new ParameterNameBinding(getParanamer(), constructor, i), useNames(), getBindings(constructor.getParameterAnnotations())[i]); } return null; } };
@Override public Object run(final Object inst) { final Constructor constructor = getGreediestSatisfiableConstructor(guardedContainer).getConstructor(); final Class[] parameterTypes = constructor.getParameterTypes(); final ConstructorParameters constructorParameters = (ConstructorParameters) (parameters != null && parameters.length > 0 ? parameters[0] : new ConstructorParameters()); final Parameter[] currentParameters = constructorParameters.getParams() != null ? constructorParameters.getParams() : createDefaultParameters(parameterTypes.length); for (int i = 0; i < currentParameters.length; i++) { currentParameters[i].verify(container, ConstructorInjector.this, box(parameterTypes[i]), new ParameterNameBinding(getParanamer(), constructor, i), useNames(), getBindings(constructor.getParameterAnnotations())[i]); } return null; } };
key, (Class<?>) implOrInstance, new ConstructorParameters(tweakedParameters), fieldParameters, methodParameters); removeGenericPropertiesThatWeDontCareAbout(tmpProperties); throwIfPropertiesLeft(tmpProperties);
key, (Class<?>) implOrInstance, new ConstructorParameters(tweakedParameters), fieldParameters, methodParameters); removeGenericPropertiesThatWeDontCareAbout(tmpProperties); throwIfPropertiesLeft(tmpProperties);