context.debug("Constructor parameter values.");
final List<Value> arguments = bean.getConstructorValues();
final Iterator<Value> argumentsIterator = arguments.iterator();
while (argumentsIterator.hasNext()) {
final Value value = argumentsIterator.next();
body.addArgument(value);
if (context.isDebugEnabled()) {
context.debug(value.toString());
}
}
context.unbranch();
context.branch();
context.debug("Matching constructors.");
final List<Constructor> matchingConstructors = new ArrayList<Constructor>();
final TypeConstructorsVisitor visitor = new TypeConstructorsVisitor() {
protected boolean visit(final Constructor constructor) {
boolean match = false;
// skip non public constructors
if (constructor.getVisibility() == Visibility.PUBLIC) {
final List<ConstructorParameter> constructorParameters = constructor.getParameters();
// skip the given constructor with different numbers of
// parameters.
if (constructorParameters.size() == arguments.size()) {
match = true;
final Iterator<Value> valuesIterator = arguments.iterator();
final Iterator<ConstructorParameter> parametersIterator = constructorParameters.iterator();
while (valuesIterator.hasNext()) {
final ConstructorParameter parameter = parametersIterator.next();
final Value value0 = valuesIterator.next();
if (false == value0.isCompatibleWith(parameter.getType())) {
match = false;
}
}
}
}
if (match) {
matchingConstructors.add(constructor);
context.debug("" + constructor);
}
return false;
}
};
final Type beanType = bean.getType();
visitor.start(beanType);
if (matchingConstructors.size() == 0) {
this.throwUnableToFindConstructor(bean);
}
if (matchingConstructors.size() > 1) {
this.throwTooManyConstructors(bean, matchingConstructors);
}
context.unbranch();
final Constructor constructor = (Constructor) matchingConstructors.get(0);
body.setBean(constructor);
final Iterator<ConstructorParameter> constructorParameters = constructor.getParameters().iterator();
final Iterator<Value> valuesIterator = arguments.iterator();
while (constructorParameters.hasNext()) {
final ConstructorParameter constructorParameter = constructorParameters.next();
final Value value = valuesIterator.next();
value.setPropertyType(constructorParameter.getType());
this.prepareValue(value);
}
if (context.isDebugEnabled()) {