use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareElement.
private void declareElement(final ConfigLine configLine, final ArtifactDeclarer artifactDeclarer) {
final ExtensionModel ownerExtension = getExtensionModel(configLine);
final ElementDeclarer extensionElementsDeclarer = forExtension(ownerExtension.getName());
final DslSyntaxResolver dsl = resolvers.get(getNamespace(configLine));
Reference<Boolean> alreadyDeclared = new Reference<>(false);
new ExtensionWalker() {
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
declareComponentModel(configLine, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
getDeclaredName(configLine).ifPresent(((ConstructElementDeclarer) declarer)::withRefName);
artifactDeclarer.withGlobalElement((GlobalElementDeclaration) declarer.getDeclaration());
alreadyDeclared.set(true);
stop();
});
}
@Override
protected void onConfiguration(ConfigurationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
if (elementDsl.getElementName().equals(configLine.getIdentifier())) {
ConfigurationElementDeclarer configurationDeclarer = extensionElementsDeclarer.newConfiguration(model.getName());
getDeclaredName(configLine).ifPresent(configurationDeclarer::withRefName);
Map<String, SimpleConfigAttribute> attributes = configLine.getConfigAttributes().values().stream().filter(a -> !a.getName().equals(NAME_ATTRIBUTE_NAME)).collect(toMap(SimpleConfigAttribute::getName, a -> a));
List<ConfigLine> configComplexParameters = configLine.getChildren().stream().filter(config -> declareAsConnectionProvider(ownerExtension, model, configurationDeclarer, config, extensionElementsDeclarer)).collect(toList());
declareParameterizedComponent(model, elementDsl, configurationDeclarer, attributes, configComplexParameters);
artifactDeclarer.withGlobalElement(configurationDeclarer.getDeclaration());
alreadyDeclared.set(true);
stop();
}
}
}.walk(ownerExtension);
if (!alreadyDeclared.get()) {
ownerExtension.getTypes().stream().filter(type -> dsl.resolve(type).map(typeDsl -> typeDsl.getElementName().equals(configLine.getIdentifier())).orElse(false)).findFirst().ifPresent(type -> {
TopLevelParameterDeclarer topLevelParameter = extensionElementsDeclarer.newGlobalParameter(configLine.getIdentifier());
getDeclaredName(configLine).ifPresent(topLevelParameter::withRefName);
type.accept(getParameterDeclarerVisitor(configLine, dsl.resolve(type).get(), value -> topLevelParameter.withValue((ParameterObjectValue) value)));
artifactDeclarer.withGlobalElement(topLevelParameter.getDeclaration());
});
}
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareComposableModel.
private void declareComposableModel(ComposableModel model, DslElementSyntax elementDsl, ConfigLine containerConfig, HasNestedComponentDeclarer declarer) {
containerConfig.getChildren().forEach((ConfigLine child) -> {
ExtensionModel extensionModel = getExtensionModel(child);
ElementDeclarer extensionElementsDeclarer = forExtension(extensionModel.getName());
Reference<Boolean> componentFound = new Reference<>(false);
getComponentDeclaringWalker(declaration -> {
declarer.withComponent(declaration);
componentFound.set(true);
}, child, extensionElementsDeclarer).walk(extensionModel);
if (!componentFound.get()) {
declareRoute(model, elementDsl, child, extensionElementsDeclarer).ifPresent(declarer::withComponent);
}
});
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class MacroExpansionModulesModel method fillDependencyGraph.
private void fillDependencyGraph(DirectedGraph<String, DefaultEdge> g, String sourceVertex, Map<String, ExtensionModel> allExtensionsByNamespace) {
final ExtensionModel extensionModel = allExtensionsByNamespace.get(sourceVertex);
g.addVertex(sourceVertex);
for (String dependencyNamespace : getDependenciesOrFail(extensionModel)) {
if (allExtensionsByNamespace.containsKey(dependencyNamespace)) {
g.addVertex(dependencyNamespace);
g.addEdge(sourceVertex, dependencyNamespace);
fillDependencyGraph(g, dependencyNamespace, allExtensionsByNamespace);
}
}
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class PrivilegedExtensionContributionTestCase method loadPrivilegedExtension.
@Test
public void loadPrivilegedExtension() {
ExtensionModel extension = loadExtension(PrivilegedExtension.class);
assertThat(extension.getName(), is(NEW_NAME));
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DefaultExtensionManager method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
public Optional<ConfigurationInstance> getConfiguration(ExtensionModel extensionModel, ComponentModel componentModel, CoreEvent muleEvent) {
ConfigurationInstance instance = getConfigurationProvider(extensionModel, componentModel).map(p -> p.get(muleEvent)).orElse(null);
if (instance != null) {
return of(instance);
}
Optional<ConfigurationModel> configurationModel = getConfigurationModelForExtension(extensionModel, getConfigurationForComponent(extensionModel, componentModel));
if (configurationModel.isPresent()) {
createImplicitConfiguration(extensionModel, configurationModel.get(), muleEvent);
return of(getConfiguration(getImplicitConfigurationProviderName(extensionModel, configurationModel.get()), muleEvent));
}
return empty();
}
Aggregations