Search in sources :

Example 6 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class ExtensionsTestInfrastructureDiscoverer method discoverExtension.

/**
 * It will register the extensions described or annotated and it will generate their resources. If no describers are defined the
 * annotatedClasses would be used to generate the describers.
 *
 * @return a {@link List} of the resources generated for the given describers or annotated classes
 * @throws IllegalStateException if no extensions can be described
 */
public ExtensionModel discoverExtension(Class<?> annotatedClass, ExtensionModelLoader loader) {
    Map<String, Object> params = new HashMap<>();
    params.put(TYPE_PROPERTY_NAME, annotatedClass.getName());
    params.put(VERSION, getProductVersion());
    DslResolvingContext dslResolvingContext = getDefault(singleton(MuleExtensionModelProvider.getExtensionModel()));
    ExtensionModel model = loader.loadExtensionModel(annotatedClass.getClassLoader(), dslResolvingContext, params);
    extensionManager.registerExtension(model);
    return model;
}
Also used : HashMap(java.util.HashMap) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext)

Example 7 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method findTestConnectionGlobalElementFrom.

/**
 * Goes over all {@code globalElementsComponentModel} looking for the configuration and connection elements (parent and child),
 * where if present looks for the {@link ExtensionModel}s validating if the element is in fact a {@link ConnectionProvider}.
 * It heavily relies on the {@link DslSyntaxResolver}, as many elements in the XML do not match to the names of the model.
 *
 * @param globalElementsComponentModel global elements of the smart connector
 * @param extensions set of extensions used to generate the current {@link ExtensionModel}
 * @return a {@link ComponentModel} of the global element to do test connection, empty otherwise.
 */
private Optional<ComponentModel> findTestConnectionGlobalElementFrom(List<ComponentModel> globalElementsComponentModel, Set<ExtensionModel> extensions) {
    Optional<ComponentModel> testConnectionGlobalElement;
    final DslResolvingContext dslResolvingContext = DslResolvingContext.getDefault(extensions);
    final Set<ComponentModel> testConnectionComponentModels = new HashSet<>();
    for (ComponentModel globalElementComponentModel : globalElementsComponentModel) {
        for (ComponentModel connectionProviderChildElement : globalElementComponentModel.getInnerComponents()) {
            final String globalElementConfigurationModelName = globalElementComponentModel.getIdentifier().getName();
            final String childConnectionProviderName = connectionProviderChildElement.getIdentifier().getName();
            for (ExtensionModel extensionModel : extensions) {
                final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, dslResolvingContext);
                for (ConfigurationModel configurationModel : extensionModel.getConfigurationModels()) {
                    if (dslSyntaxResolver.resolve(configurationModel).getElementName().equals(globalElementConfigurationModelName)) {
                        for (ConnectionProviderModel connectionProviderModel : configurationModel.getConnectionProviders()) {
                            if (dslSyntaxResolver.resolve(connectionProviderModel).getElementName().equals(childConnectionProviderName)) {
                                testConnectionComponentModels.add(globalElementComponentModel);
                            }
                        }
                    }
                }
            }
        }
    }
    if (testConnectionComponentModels.size() > 1) {
        throw new MuleRuntimeException(createStaticMessage(format("There are [%d] global elements that can be potentially used for test connection when it should be just one. Mark any of them with the attribute [%s=\"true\"], offended global elements are: [%s]", testConnectionComponentModels.size(), MODULE_CONNECTION_MARKER_ATTRIBUTE, testConnectionComponentModels.stream().map(ComponentModel::getNameAttribute).sorted().collect(Collectors.joining(", ")))));
    }
    testConnectionGlobalElement = testConnectionComponentModels.stream().findFirst();
    return testConnectionGlobalElement;
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) HashSet(java.util.HashSet)

Example 8 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class MuleExtensionUtils method loadExtension.

/**
 * Loads a extension model
 *
 * @param clazz fully qualified name of the class to load.
 * @param params a set of attributes to work with in each concrete implementation of {@link ExtensionModelLoader}, which will be
 *        responsible of extracting the mandatory parameters (while casting, if needed).
 * @return an {@link ExtensionModel} that represents the class being loaded
 * @throws IllegalArgumentException if there are missing entries in {@code attributes} or the type of any of them does not apply
 *         to the expected one.
 */
public static ExtensionModel loadExtension(Class<?> clazz, Map<String, Object> params) {
    params.put(TYPE_PROPERTY_NAME, clazz.getName());
    params.put(VERSION, getProductVersion());
    // TODO MULE-11797: as this utils is consumed from
    // org.mule.runtime.module.extension.internal.capability.xml.schema.AbstractXmlResourceFactory.generateResource(org.mule.runtime.api.meta.model.ExtensionModel),
    // this util should get dropped once the ticket gets implemented.
    final DslResolvingContext dslResolvingContext = getDefault(emptySet());
    return new DefaultJavaExtensionModelLoader().loadExtensionModel(clazz.getClassLoader(), dslResolvingContext, params);
}
Also used : DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) DefaultJavaExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader)

Example 9 with DslResolvingContext

use of org.mule.runtime.api.dsl.DslResolvingContext in project mule by mulesoft.

the class MuleExtensionUtils method loadExtension.

public static ExtensionModel loadExtension(Class<?> clazz, Map<String, Object> params) {
    params.put(TYPE_PROPERTY_NAME, clazz.getName());
    params.put(VERSION, "4.0.0-SNAPSHOT");
    final DslResolvingContext dslResolvingContext = getDefault(emptySet());
    return new DefaultJavaExtensionModelLoader().loadExtensionModel(clazz.getClassLoader(), dslResolvingContext, params);
}
Also used : DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) DefaultJavaExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader)

Aggregations

DslResolvingContext (org.mule.runtime.api.dsl.DslResolvingContext)9 HashMap (java.util.HashMap)5 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)5 NullDslResolvingContext (org.mule.runtime.internal.dsl.NullDslResolvingContext)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 DslResolvingContext.getDefault (org.mule.runtime.api.dsl.DslResolvingContext.getDefault)2 ExtensionManager (org.mule.runtime.core.api.extension.ExtensionManager)2 IOUtils.getResourceAsString (org.mule.runtime.core.api.util.IOUtils.getResourceAsString)2 DslResourceFactory (org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory)2 GeneratedResource (org.mule.runtime.extension.api.resources.GeneratedResource)2 GeneratedResourceFactory (org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory)2 DefaultJavaExtensionModelLoader (org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader)2 ImmutableList.copyOf (com.google.common.collect.ImmutableList.copyOf)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1