if (bestMatchingCtor == null) {
if (possibleCtor == null) {
for (int j = usedDependencies.length(); j-- > 0;) {
usedDependencies.clear(j); // JDK 1.3, BitSet.clear() is JDK 1.4
}
throw new ObjectAccessException("Cannot construct "
+ type.getName()
+ ", none of the dependencies match any constructor's parameters");
} else {
bestMatchingCtor = possibleCtor;
}
}
}
try {
final Object instance;
if (bestMatchingCtor == null) {
instance = type.newInstance();
} else {
instance = bestMatchingCtor.newInstance(matchingDependencies.toArray());
}
return instance;
} catch (final InstantiationException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
} catch (final IllegalAccessException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
} catch (final InvocationTargetException e) {
throw new ObjectAccessException("Cannot construct " + type.getName(), e);
}
}