/** * 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 Object run() { final Constructor constructor; try { constructor = getGreediestSatisfiableConstructor(guardedContainer); } catch (AmbiguousComponentResolutionException e) { e.setComponent(getComponentImplementation()); throw e; ComponentMonitor componentMonitor = currentMonitor(); try { Object[] parameters = getConstructorArguments(guardedContainer, constructor); componentMonitor.instantiating(constructor); long startTime = System.currentTimeMillis(); Object inst = newInstance(constructor, parameters); componentMonitor.instantiated(constructor, System.currentTimeMillis() - startTime); return inst;
final Set unsatisfiableDependencyTypes = new HashSet(); if (sortedMatchingConstructors == null) { sortedMatchingConstructors = getSortedMatchingConstructors(); Constructor constructor = (Constructor) sortedMatchingConstructors.get(i); Class[] parameterTypes = constructor.getParameterTypes(); Parameter[] currentParameters = parameters != null ? parameters : createDefaultParameters(parameterTypes); throw new TooManySatisfiableConstructorsException(getComponentImplementation(), conflicts); } else if (greediestConstructor == null && !unsatisfiableDependencyTypes.isEmpty()) { throw new UnsatisfiableDependenciesException(this, unsatisfiedDependencyType, unsatisfiableDependencyTypes, container); final Constructor[] constructors = getConstructors(); for (int i = 0; i < constructors.length; i++) { nonMatching.add(constructors[i]); throw new PicoInitializationException("Either do the specified parameters not match any of the following constructors: " + nonMatching.toString() + " or the constructors were not accessible for '" + getComponentImplementation() + "'");
public Object run() { return getComponentImplementation().getDeclaredConstructors(); } });
protected Object[] getConstructorArguments(PicoContainer container, Constructor ctor) { Class[] parameterTypes = ctor.getParameterTypes(); Object[] result = new Object[parameterTypes.length]; Parameter[] currentParameters = parameters != null ? parameters : createDefaultParameters(parameterTypes); for (int i = 0; i < currentParameters.length; i++) { result[i] = currentParameters[i].resolveInstance(container, this, parameterTypes[i]); } return result; }
private List getSortedMatchingConstructors() { List matchingConstructors = new ArrayList(); Constructor[] allConstructors = getConstructors(); // filter out all constructors that will definately not match for (int i = 0; i < allConstructors.length; i++) { Constructor constructor = allConstructors[i]; if ((parameters == null || constructor.getParameterTypes().length == parameters.length) && (allowNonPublicClasses || (constructor.getModifiers() & Modifier.PUBLIC) != 0)) { matchingConstructors.add(constructor); } } // optimize list of constructors moving the longest at the beginning if (parameters == null) { Collections.sort(matchingConstructors, new Comparator() { public int compare(Object arg0, Object arg1) { return ((Constructor) arg1).getParameterTypes().length - ((Constructor) arg0).getParameterTypes().length; } }); } return matchingConstructors; }
return instantiationGuard.observe(getComponentImplementation());
/** * 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); } }
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 CurrentTimeUtilComponentAdapter() { super(new ConstructorInjectionComponentAdapter(CurrentTimeUtil.class, CurrentTimeUtil.class)); }
public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { return new ConstructorInjectionComponentAdapter(componentKey, componentImplementation, parameters, allowNonPublicClasses, currentMonitor(), lifecycleStrategy); } }
public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { return new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(componentKey, componentImplementation, parameters, false, currentMonitor(), lifecycleStrategy)); }
/** * 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, MutablePicoContainer context) { //instantiate within the given context ComponentAdapter adapter = new ConstructorInjectionComponentAdapter( qName, bindingClass ); return (Binding) adapter.getComponentInstance( context ); }
/** * 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 Class ) { return new ConstructorInjectionComponentAdapter( null, (Class) o ); } return new InstanceComponentAdapter( null, o ); } }
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 ); }
private static void registerEvaluationContextFactory(final MutablePicoContainer container) { // PoolingEvaluationContextFactory depends on DefaultEvaluationContextFactory. // however both implement the same interface users depend on which causes an ambiguity. // therefore DefaultEvaluationContextFactory should be only visible to PoolingEvaluationContextFactory. final ConstructorInjectionComponentAdapter _serviceCA = new ConstructorInjectionComponentAdapter(DefaultEvaluationContextFactory.class, DefaultEvaluationContextFactory.class); final ConstructorInjectionComponentAdapter _poolingServiceCA = new ConstructorInjectionComponentAdapter(EvaluationContextFactory.class, PoolingEvaluationContextFactory.class, new Parameter[] {BasicComponentParameter.BASIC_DEFAULT, new BasicComponentParameter(DefaultEvaluationContextFactory.class)}); final LocalParameterComponentAdapter _localParamCA = new LocalParameterComponentAdapter(_poolingServiceCA, new ComponentAdapter[] {_serviceCA}); final ComponentAdapter _cachingCA = new CachingComponentAdapter(_localParamCA); container.registerComponent(_cachingCA); }
private static void registerCoreServices(final MutablePicoContainer container) { container.registerComponent(new CachingComponentAdapter( new PushTaskExecutorFactoryComponentAdapter( new ConstructorInjectionComponentAdapter(PushTaskExecutorFactory.class, ConfigurablePushTaskExecutorFactory.class)))); // etcl evaluator container.registerComponentImplementation(DefaultETCLEvaluator.class); // message factory container.registerComponentImplementation(DefaultMessageFactory.class); // taskprocessor container.registerComponentImplementation(DefaultTaskFactory.class); container.registerComponentImplementation(DefaultTaskProcessor.class); registerEvaluationContextFactory(container); }