ServiceLoader<PrintContext> consumerLoader = ServiceLoader.load(PrintContext.class);
Iterator<PrintContext> consumerIterator = consumerLoader.iterator();
contextMap = new HashMap<String, PrintContext>();
while (consumerIterator.hasNext()) {
PrintContext p = consumerIterator.next();
if (!contextMap.containsKey(p.getName())) {
contextMap.put(p.getName(), p);
}
else {
if (contextMap.get(p.getName()) != p) {
String msg = "Multiple different PrintContexts with the same context name " +
"('" + p.getName() + "') are present on the classpath. Context names must be unique.";
log.error(msg);
throw new ServiceConfigurationError(msg);
}
}
}