Search in sources :

Example 1 with PrivateOperationsModelProperty

use of org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method loadModuleExtension.

private void loadModuleExtension(ExtensionDeclarer declarer, URL resource, Document moduleDocument, Set<ExtensionModel> extensions, boolean comesFromTNS) {
    final ComponentModel moduleModel = getModuleComponentModel(resource, moduleDocument);
    if (!moduleModel.getIdentifier().equals(MODULE_IDENTIFIER)) {
        throw new MuleRuntimeException(createStaticMessage(format("The root element of a module must be '%s', but found '%s'", MODULE_IDENTIFIER.toString(), moduleModel.getIdentifier().toString())));
    }
    final String name = moduleModel.getParameters().get(MODULE_NAME);
    // TODO(fernandezlautaro): MULE-11010 remove version from ExtensionModel
    final String version = "4.0.0";
    final String category = moduleModel.getParameters().get(CATEGORY);
    final String vendor = moduleModel.getParameters().get(VENDOR);
    final XmlDslModel xmlDslModel = getXmlDslModel(moduleModel, name, version);
    final String description = getDescription(moduleModel);
    final String xmlnsTnsValue = moduleModel.getParameters().get(XMLNS_TNS);
    if (xmlnsTnsValue != null && !xmlDslModel.getNamespace().equals(xmlnsTnsValue)) {
        throw new MuleRuntimeException(createStaticMessage(format("The %s attribute value of the module must be '%s', but found '%s'", XMLNS_TNS, xmlDslModel.getNamespace(), xmlnsTnsValue)));
    }
    fillDeclarer(declarer, name, version, category, vendor, xmlDslModel, description);
    declarer.withModelProperty(getXmlExtensionModelProperty(moduleModel, xmlDslModel));
    DirectedGraph<String, DefaultEdge> directedGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
    // loading public operations
    final Optional<ConfigurationDeclarer> configurationDeclarer = loadPropertiesFrom(declarer, moduleModel, extensions);
    final HasOperationDeclarer hasOperationDeclarer = configurationDeclarer.isPresent() ? configurationDeclarer.get() : declarer;
    loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PUBLIC);
    // loading private operations
    if (comesFromTNS) {
        // when parsing for the TNS, we need the <operation/>s to be part of the extension model to validate the XML properly
        loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
    } else {
        // when parsing for the macro expansion, the <operation/>s will be left in the PrivateOperationsModelProperty model property
        final ExtensionDeclarer temporalDeclarer = new ExtensionDeclarer();
        fillDeclarer(temporalDeclarer, name, version, category, vendor, xmlDslModel, description);
        loadOperationsFrom(temporalDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
        final ExtensionModel result = createExtensionModel(temporalDeclarer);
        declarer.withModelProperty(new PrivateOperationsModelProperty(result.getOperationModels()));
    }
    final CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(directedGraph);
    final Set<String> cycles = cycleDetector.findCycles();
    if (!cycles.isEmpty()) {
        throw new MuleRuntimeException(createStaticMessage(format(CYCLIC_OPERATIONS_ERROR, new TreeSet(cycles))));
    }
}
Also used : DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DefaultEdge(org.jgrapht.graph.DefaultEdge) CycleDetector(org.jgrapht.alg.CycleDetector) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) TreeSet(java.util.TreeSet) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel)

Aggregations

TreeSet (java.util.TreeSet)1 CycleDetector (org.jgrapht.alg.CycleDetector)1 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)1 DefaultEdge (org.jgrapht.graph.DefaultEdge)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 XmlDslModel (org.mule.runtime.api.meta.model.XmlDslModel)1 ConfigurationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer)1 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)1 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)1 PrivateOperationsModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty)1 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)1