{
final List<Message> messages = Lists.newArrayList();
for (String error : configurationFactory.getInitialErrors()) {
final Message message = new Message(error);
messages.add(message);
configurationFactory.getMonitor().onError(message);
}
ElementsIterator elementsIterator = new ElementsIterator(modules);
for (final Element element : elementsIterator) {
element.acceptVisitor(new DefaultElementVisitor<Void>()
{
@Override
public <T> Void visit(Binding<T> binding)
{
// look for ConfigurationProviders...
if (binding instanceof ProviderInstanceBinding) {
ProviderInstanceBinding<?> providerInstanceBinding = (ProviderInstanceBinding<?>) binding;
Provider<?> provider = providerInstanceBinding.getProviderInstance();
if (provider instanceof ConfigurationAwareProvider) {
ConfigurationAwareProvider<?> configurationProvider = (ConfigurationAwareProvider<?>) provider;
// give the provider the configuration factory
configurationProvider.setConfigurationFactory(configurationFactory);
configurationProvider.setWarningsMonitor(warningsMonitor);
try {
// call the getter which will cause object creation
configurationProvider.get();
} catch (ConfigurationException e) {
// if we got errors, add them to the errors list
for (Message message : e.getErrorMessages()) {
messages.add(new Message(singletonList(binding.getSource()), message.getMessage(), message.getCause()));
}
}
}
}
return null;
}
@Override
public Void visit(PrivateElements privateElements)
{
for (Element element : privateElements.getElements()) {
element.acceptVisitor(this);
}
return null;
}
});
}
for (String unusedProperty : configurationFactory.getUnusedProperties()) {
final Message message = new Message(format("Configuration property '%s' was not used", unusedProperty));
messages.add(message);
configurationFactory.getMonitor().onError(message);
}
return messages;