use of org.jboss.as.controller.Extension in project wildfly-swarm by wildfly-swarm.
the class StandaloneXMLParserProducer method setupFactory.
private void setupFactory(Fraction fraction) throws Exception {
try (AutoCloseable handle = Performance.time("Setting up XML parser: " + fraction.getClass().getSimpleName())) {
WildFlyExtension anno = fraction.getClass().getAnnotation(WildFlyExtension.class);
if (anno == null) {
return;
}
String extensionModuleName = anno.module();
String extensionClassName = anno.classname();
boolean noClass = anno.noClass();
if (extensionClassName != null && extensionClassName.trim().isEmpty()) {
extensionClassName = null;
}
Module extensionModule = Module.getBootModuleLoader().loadModule(extensionModuleName);
if (noClass) {
// ignore it all
} else if (extensionClassName != null) {
Class<?> extCls = extensionModule.getClassLoader().loadClass(extensionClassName);
try {
Extension ext = (Extension) extCls.newInstance();
add(ext);
} catch (InstantiationException | IllegalAccessException e) {
SwarmConfigMessages.MESSAGES.errorCreatingExtension(extensionClassName, extensionModuleName, e);
}
} else {
ServiceLoader<Extension> extensionLoader = extensionModule.loadService(Extension.class);
Iterator<Extension> extensionIter = extensionLoader.iterator();
List<Extension> extensions = new ArrayList<>();
if (extensionIter.hasNext()) {
Extension ext = extensionIter.next();
extensions.add(ext);
}
if (extensions.size() > 1) {
throw SwarmMessages.MESSAGES.fractionHasMultipleExtensions(fraction.getClass().getName(), extensions.stream().map(Objects::toString).collect(Collectors.toList()));
}
if (!extensions.isEmpty()) {
add(extensions.get(0));
}
}
}
}
Aggregations