Class<?> param,
PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
List<String> injectionNames) throws InvalidAutowireException, InvalidConstructorException {
// the param is marked as an autowire
Autowire autowireAnnot = (Autowire) annot;
JavaMappedReference reference = new JavaMappedReference();
reference.setAutowire(true);
String name = autowireAnnot.name();
if (name == null || name.length() == 0) {
if (constructorNames.length > 1 && (constructorNames.length < pos + 1 || constructorNames[pos] == null)) {
throw new InvalidAutowireException("Names in @Constructor and autowire parameter do not match at "
+ (pos + 1));
} else if (constructorNames.length == 1 && constructorNames[0].length() == 0) {
// special case when @Constructor present with all autowire params not specifying any name
name = param.getName() + String.valueOf(pos);
} else if (constructorNames.length == 1
&& (constructorNames.length < pos + 1 || constructorNames[pos] == null)) {
throw new InvalidAutowireException("Names in @Constructor and autowire parameter do not match at "
+ (pos + 1));
} else if (constructorNames.length == 1 && constructorNames[0].length() > 0) {
name = constructorNames[pos];
} else if (constructorNames.length == 0 || constructorNames[pos].length() == 0) {
name = param.getName() + String.valueOf(pos);
} else {
name = constructorNames[pos];
}
} else if (pos < constructorNames.length && constructorNames[pos] != null
&& constructorNames[pos].length() != 0 && !name.equals(constructorNames[pos])) {
throw new InvalidConstructorException("Name specified by @Constructor does not match autowire name at "
+ (pos + 1));
}
reference.setName(name);
reference.setRequired(autowireAnnot.required());
ServiceContract<?> contract = new JavaServiceContract();
contract.setInterfaceClass(param);
reference.setServiceContract(contract);
type.getReferences().put(name, reference);
addName(injectionNames, pos, name);
}