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;
}
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;
}
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);
}
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);
}
Aggregations