/** * Returns a set of integers that point to where in the Parameter array unmatched parameters exist. * @param container * @param matchingParameterList * @param assignedParameters {@link com.picocontainer.Parameter} for the current object being instantiated. * @return set of integers pointing to the index in the parameter array things went awry. */ private Set<AccessibleObjectParameterSet> matchParameters(final PicoContainer container, final List<Object> matchingParameterList, final AccessibleObjectParameterSet... assignedParameters) { Set<AccessibleObjectParameterSet> unmatchedParameters = new HashSet<AccessibleObjectParameterSet>(); for (AccessibleObject eachObject : injectionMembers) { AccessibleObjectParameterSet currentParameter = getParameterToUseForObject(eachObject, assignedParameters); if (currentParameter == null) { currentParameter = this.constructAccessibleObjectParameterSet(eachObject,new Parameter[] {constructDefaultComponentParameter()}); } if (!matchParameter(container, matchingParameterList, currentParameter)) { unmatchedParameters.add(currentParameter); } } return unmatchedParameters; }
@Override public T run(final Object instance) { final ParameterToAccessibleObjectPair[] matchingParameters = getMatchingParameterListForMembers(guardedContainer); Object componentInstance = makeInstance(container, constructor, currentMonitor()); return decorateComponentInstance(matchingParameters, currentMonitor(), componentInstance, container, guardedContainer, into, null); } };
protected void initializeInjectionMembersAndTypeLists() { injectionMembers = new ArrayList<AccessibleObject>(); Set<String> injectionMemberNames = new HashSet<String>(); List<Annotation> bingingIds = new ArrayList<Annotation>(); final List<String> nameList = new ArrayList<String>(); final List<Type> typeList = new ArrayList<Type>(); final Method[] methods = getMethods(); for (final Method method : methods) { final Type[] parameterTypes = method.getGenericParameterTypes(); fixGenericParameterTypes(method, parameterTypes); String methodSignature = crudeMethodSignature(method); // We're only interested if there is only one parameter and the method name is bean-style. if (parameterTypes.length == 1) { boolean isInjector = isInjectorMethod(method); // ... and the method name is bean-style. // We're also not interested in dupes from parent classes (not all JDK impls) if (isInjector && !injectionMemberNames.contains(methodSignature)) { injectionMembers.add(method); injectionMemberNames.add(methodSignature); nameList.add(getName(method)); typeList.add(box(parameterTypes[0])); bingingIds.add(getBindings(method, 0)); } } } injectionTypes = typeList.toArray(new Type[0]); bindings = bingingIds.toArray(new Annotation[0]); initialized = true; }
private boolean matchParameter(final PicoContainer container, final List<Object> matchingParameterList, final AccessibleObjectParameterSet parameter) { for (int j = 0; j < injectionTypes.length; j++) { Object o = matchingParameterList.get(j); AccessibleObject targetInjectionMember = getTargetInjectionMember(injectionMembers, j, parameter.getParams()[0]); if (targetInjectionMember == null) { return false; } AccessibleObjectParameterSet paramToUse = getParameterToUseForObject(targetInjectionMember, parameter); if (paramToUse == null) { paramToUse = constructAccessibleObjectParameterSet(targetInjectionMember); } try { if (o == null && paramToUse.getParams()[0].resolve(container, this, null, injectionTypes[j], makeParameterNameImpl(targetInjectionMember), useNames(), bindings[j]).isResolved()) { matchingParameterList.set(j, new ParameterToAccessibleObjectPair(targetInjectionMember, paramToUse)); return true; } } catch (AmbiguousComponentResolutionException e) { e.setComponent(getComponentImplementation()); e.setMember(injectionMembers.get(j)); throw e; } } return false; }
makeParameterNameImpl(injectionMembers.get(i)), useNames(), bindings[i]).resolveInstance(into); Object rv = monitor.invoking(container, this, (Member) member, componentInstance, new Object[] {toInject}); if (rv == ComponentMonitor.KEEP) { long str = System.currentTimeMillis(); lastReturn = injectIntoMember(member, componentInstance, toInject); monitor.invoked(container, this, (Member) member, componentInstance, System.currentTimeMillis() - str, lastReturn, new Object[] {toInject}); } else { return (T) memberInvocationReturn(lastReturn, member, componentInstance); } catch (InvocationTargetException e) { return caughtInvocationTargetException(monitor, (Member) member, componentInstance, e); } catch (IllegalAccessException e) { return caughtIllegalAccessException(monitor, (Member) member, componentInstance, e);
private Object makeInstance(final PicoContainer container, final Constructor constructor, final ComponentMonitor monitor) { long startTime = System.currentTimeMillis(); Constructor constructorToUse = monitor.instantiating(container, IterativeInjector.this, constructor); Object componentInstance; try { componentInstance = newInstance(constructorToUse, null); } catch (InvocationTargetException e) { monitor.instantiationFailed(container, IterativeInjector.this, constructorToUse, e); if (e.getTargetException() instanceof RuntimeException) { throw (RuntimeException)e.getTargetException(); } else if (e.getTargetException() instanceof Error) { throw (Error)e.getTargetException(); } throw new PicoCompositionException(e.getTargetException()); } catch (InstantiationException e) { return caughtInstantiationException(monitor, constructor, e, container); } catch (IllegalAccessException e) { return caughtIllegalAccessException(monitor, constructor, e, container); } monitor.instantiated(container, IterativeInjector.this, constructorToUse, componentInstance, NONE, System.currentTimeMillis() - startTime); return componentInstance; }
protected void initializeInjectionMembersAndTypeLists() { injectionMembers = new ArrayList<AccessibleObject>(); Set<String> injectionMemberNames = new HashSet<String>(); List<Annotation> bingingIds = new ArrayList<Annotation>(); final List<String> nameList = new ArrayList<String>(); final List<Type> typeList = new ArrayList<Type>(); final Method[] methods = getMethods(); for (final Method method : methods) { final Type[] parameterTypes = method.getGenericParameterTypes(); fixGenericParameterTypes(method, parameterTypes); String methodSignature = crudeMethodSignature(method); // We're only interested if there is only one parameter and the method name is bean-style. if (parameterTypes.length == 1) { boolean isInjector = isInjectorMethod(method); // ... and the method name is bean-style. // We're also not interested in dupes from parent classes (not all JDK impls) if (isInjector && !injectionMemberNames.contains(methodSignature)) { injectionMembers.add(method); injectionMemberNames.add(methodSignature); nameList.add(getName(method)); typeList.add(box(parameterTypes[0])); bingingIds.add(getBindings(method, 0)); } } } injectionTypes = typeList.toArray(new Type[0]); bindings = bingingIds.toArray(new Annotation[0]); initialized = true; }
private boolean matchParameter(final PicoContainer container, final List<Object> matchingParameterList, final AccessibleObjectParameterSet parameter) { for (int j = 0; j < injectionTypes.length; j++) { Object o = matchingParameterList.get(j); AccessibleObject targetInjectionMember = getTargetInjectionMember(injectionMembers, j, parameter.getParams()[0]); if (targetInjectionMember == null) { return false; } AccessibleObjectParameterSet paramToUse = getParameterToUseForObject(targetInjectionMember, parameter); if (paramToUse == null) { paramToUse = constructAccessibleObjectParameterSet(targetInjectionMember); } try { if (o == null && paramToUse.getParams()[0].resolve(container, this, null, injectionTypes[j], makeParameterNameImpl(targetInjectionMember), useNames(), bindings[j]).isResolved()) { matchingParameterList.set(j, new ParameterToAccessibleObjectPair(targetInjectionMember, paramToUse)); return true; } } catch (AmbiguousComponentResolutionException e) { e.setComponent(getComponentImplementation()); e.setMember(injectionMembers.get(j)); throw e; } } return false; }
makeParameterNameImpl(injectionMembers.get(i)), useNames(), bindings[i]).resolveInstance(into); Object rv = monitor.invoking(container, this, (Member) member, componentInstance, new Object[] {toInject}); if (rv == ComponentMonitor.KEEP) { long str = System.currentTimeMillis(); lastReturn = injectIntoMember(member, componentInstance, toInject); monitor.invoked(container, this, (Member) member, componentInstance, System.currentTimeMillis() - str, lastReturn, new Object[] {toInject}); } else { return (T) memberInvocationReturn(lastReturn, member, componentInstance); } catch (InvocationTargetException e) { return caughtInvocationTargetException(monitor, (Member) member, componentInstance, e); } catch (IllegalAccessException e) { return caughtIllegalAccessException(monitor, (Member) member, componentInstance, e);
private Object makeInstance(final PicoContainer container, final Constructor constructor, final ComponentMonitor monitor) { long startTime = System.currentTimeMillis(); Constructor constructorToUse = monitor.instantiating(container, IterativeInjector.this, constructor); Object componentInstance; try { componentInstance = newInstance(constructorToUse, null); } catch (InvocationTargetException e) { monitor.instantiationFailed(container, IterativeInjector.this, constructorToUse, e); if (e.getTargetException() instanceof RuntimeException) { throw (RuntimeException)e.getTargetException(); } else if (e.getTargetException() instanceof Error) { throw (Error)e.getTargetException(); } throw new PicoCompositionException(e.getTargetException()); } catch (InstantiationException e) { return caughtInstantiationException(monitor, constructor, e, container); } catch (IllegalAccessException e) { return caughtIllegalAccessException(monitor, constructor, e, container); } monitor.instantiated(container, IterativeInjector.this, constructorToUse, componentInstance, NONE, System.currentTimeMillis() - startTime); return componentInstance; }
@Override public T run(final Object inst) { final ParameterToAccessibleObjectPair[] matchingParameters = getMatchingParameterListForMembers(guardedContainer); return decorateComponentInstance(matchingParameters, currentMonitor(), inst, container, guardedContainer, into, superclassPortion); } };
/** * Returns a set of integers that point to where in the Parameter array unmatched parameters exist. * @param container * @param matchingParameterList * @param assignedParameters {@link com.picocontainer.Parameter} for the current object being instantiated. * @return set of integers pointing to the index in the parameter array things went awry. */ private Set<AccessibleObjectParameterSet> matchParameters(final PicoContainer container, final List<Object> matchingParameterList, final AccessibleObjectParameterSet... assignedParameters) { Set<AccessibleObjectParameterSet> unmatchedParameters = new HashSet<AccessibleObjectParameterSet>(); for (AccessibleObject eachObject : injectionMembers) { AccessibleObjectParameterSet currentParameter = getParameterToUseForObject(eachObject, assignedParameters); if (currentParameter == null) { currentParameter = this.constructAccessibleObjectParameterSet(eachObject,new Parameter[] {constructDefaultComponentParameter()}); } if (!matchParameter(container, matchingParameterList, currentParameter)) { unmatchedParameters.add(currentParameter); } } return unmatchedParameters; }
@Override public T run(final Object instance) { final ParameterToAccessibleObjectPair[] matchingParameters = getMatchingParameterListForMembers(guardedContainer); Object componentInstance = makeInstance(container, constructor, currentMonitor()); return decorateComponentInstance(matchingParameters, currentMonitor(), componentInstance, container, guardedContainer, into, null); } };
@Override public T run(final Object inst) { final ParameterToAccessibleObjectPair[] matchingParameters = getMatchingParameterListForMembers(guardedContainer); return decorateComponentInstance(matchingParameters, currentMonitor(), inst, container, guardedContainer, into, superclassPortion); } };