Search in sources :

Example 1 with WildFlyExtension

use of org.wildfly.swarm.spi.api.annotations.WildFlyExtension 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));
            }
        }
    }
}
Also used : Extension(org.jboss.as.controller.Extension) WildFlyExtension(org.wildfly.swarm.spi.api.annotations.WildFlyExtension) ServiceLoader(java.util.ServiceLoader) WildFlyExtension(org.wildfly.swarm.spi.api.annotations.WildFlyExtension) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.jboss.modules.Module)

Example 2 with WildFlyExtension

use of org.wildfly.swarm.spi.api.annotations.WildFlyExtension in project wildfly-swarm by wildfly-swarm.

the class ExtensionMarshaller method marshal.

public void marshal(List<ModelNode> list) {
    List<ModelNode> extensions = new ArrayList<>();
    Set<String> seen = new HashSet<>();
    for (Fraction each : this.fractions) {
        WildFlyExtension anno = each.getClass().getAnnotation(WildFlyExtension.class);
        if (anno != null) {
            if (anno.module() != null && !anno.module().equals("")) {
                String module = anno.module();
                if (!seen.contains(module)) {
                    ModelNode node = new ModelNode();
                    node.get(OP_ADDR).set(EXTENSION, anno.module());
                    node.get(OP).set(ADD);
                    extensions.add(node);
                    seen.add(module);
                }
            }
        }
    }
    list.addAll(0, extensions);
}
Also used : WildFlyExtension(org.wildfly.swarm.spi.api.annotations.WildFlyExtension) ArrayList(java.util.ArrayList) Fraction(org.wildfly.swarm.spi.api.Fraction) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 WildFlyExtension (org.wildfly.swarm.spi.api.annotations.WildFlyExtension)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ServiceLoader (java.util.ServiceLoader)1 Extension (org.jboss.as.controller.Extension)1 ModelNode (org.jboss.dmr.ModelNode)1 Module (org.jboss.modules.Module)1 Fraction (org.wildfly.swarm.spi.api.Fraction)1