if (injectAnnotation != null)
{
++annotatedConstructors;
if (annotatedConstructors > 1)
{
throw new RestLiInternalException("Found multiple constructors annotated with @Inject in "
+ "class '" + beanClazz.getCanonicalName() +
"'. At most one constructor can be annotated "
+"with @Inject.");
}
Class<?>[] parameters = constructor.getParameterTypes();
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
List<DependencyDecl> parameterDecls = new ArrayList<DependencyDecl>(parameters.length);
for (int i = 0; i < parameters.length; ++i)
{
Class<?> parameter = parameters[i];
AnnotationSet annotations = new AnnotationSet(parameterAnnotations[i]);
Named namedAnno = annotations.get(Named.class);
parameterDecls.add(new DependencyDecl(parameter,
namedAnno != null ? namedAnno.value() : null));
}
constructor.setAccessible(true);
_constructorParameterDependencies.put(beanClazz,
new InjectableConstructor(constructor, parameterDecls));
}
}
if (annotatedConstructors == 0)
{
try
{
Constructor<?> defaultConstructor = beanClazz.getConstructor();
defaultConstructor.setAccessible(true);
_constructorParameterDependencies.put(beanClazz,
new InjectableConstructor(defaultConstructor,
Collections.<DependencyDecl>emptyList()));
}
catch (NoSuchMethodException e)
{
throw new RestLiInternalException(
String.format("No injectable constructor defined for class %s. Classes must define"
+" either a default constructor or a constructor annotated "
+ "with @Inject.", beanClazz.getName()), e);
}