ServiceLocator habitat = dom.getHabitat();
boolean result = true;
boolean disableGlobalMessage = true;
for (RemoteKeyInfo remoteKeyInfo : remoteKeys) {
if (remoteKeyInfo.method.getParameterTypes().length > 0) {
throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.getter",
"The RemoteKey annotation must be on a getter method."));
}
try {
Object value = remoteKeyInfo.method.invoke(config);
if (value instanceof String) {
String key = (String) value;
ConfigBeanProxy component = habitat.getService(remoteKeyInfo.annotation.type(), key);
if (component == null) {
result = false;
if (remoteKeyInfo.annotation.message().isEmpty()) {
disableGlobalMessage = false;
} else {
cvc.buildConstraintViolationWithTemplate(remoteKeyInfo.annotation.message())
.addNode(Dom.convertName(remoteKeyInfo.method.getName()))
.addConstraintViolation();
}
}
} else {
throw new UnexpectedTypeException(localStrings.getLocalString("referenceValidator.not.string",
"The RemoteKey annotation must identify a method that returns a String."));
}
} catch (Exception ex) {
return false;
}