use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax 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.extension.api.dsl.syntax.DslElementSyntax 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.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method writeApplicationElement.
private void writeApplicationElement(Element element, DslElementModel<?> elementModel, Element parentNode) {
populateInfrastructureConfiguration(element, elementModel);
if (elementModel.getContainedElements().isEmpty() && elementModel.getValue().isPresent()) {
setTextContentElement(element, elementModel, parentNode);
return;
}
elementModel.getContainedElements().stream().filter(c -> !isInfrastructure(c)).forEach(inner -> {
DslElementSyntax innerDsl = inner.getDsl();
Reference<Boolean> configured = new Reference<>(false);
if (innerDsl.supportsAttributeDeclaration() && inner.getValue().isPresent()) {
getCustomizedValue(inner).ifPresent(value -> {
configured.set(true);
element.setAttribute(innerDsl.getAttributeName(), value);
});
}
if (!configured.get() && innerDsl.supportsChildDeclaration() && inner.isExplicitInDsl()) {
Element childElement = createElement(innerDsl, inner.getConfiguration());
if (isEETransform(childElement)) {
element.appendChild(populateEETransform(inner));
} else {
writeApplicationElement(childElement, inner, element);
}
}
});
if (parentNode != element) {
parentNode.appendChild(element);
}
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addConnectionProvider.
private DslElementModel.Builder<ConfigurationModel> addConnectionProvider(ConfigurationModel model, DslSyntaxResolver dsl, DslElementModel.Builder<ConfigurationModel> element, ComponentConfiguration configuration) {
concat(model.getConnectionProviders().stream(), currentExtension.getConnectionProviders().stream()).map(provider -> {
DslElementSyntax providerDsl = dsl.resolve(provider);
ComponentIdentifier identifier = getIdentifier(providerDsl).orElse(null);
return configuration.getNestedComponents().stream().filter(c -> c.getIdentifier().equals(identifier)).findFirst().map(providerConfig -> element.containing(createElementModel(provider, providerDsl, providerConfig).build())).orElse(null);
}).filter(Objects::nonNull).findFirst();
return element;
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addElementParameter.
private void addElementParameter(Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementSyntax groupDsl, DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel paramModel) {
groupDsl.getContainedElement(paramModel.getName()).ifPresent(paramDsl -> {
if (isInfrastructure(paramModel)) {
handleInfrastructure(paramModel, paramDsl, innerComponents, parameters, groupElementBuilder);
return;
}
ComponentConfiguration paramComponent = getSingleComponentConfiguration(innerComponents, getIdentifier(paramDsl));
if (paramDsl.isWrapped()) {
resolveWrappedElement(groupElementBuilder, paramModel, paramDsl, paramComponent);
return;
}
String value = paramDsl.supportsAttributeDeclaration() ? parameters.get(paramDsl.getAttributeName()) : null;
Optional<String> defaultValue = getDefaultValue(paramModel);
if (paramComponent != null || !isBlank(value) || defaultValue.isPresent()) {
DslElementModel.Builder<ParameterModel> paramElementBuilder = DslElementModel.<ParameterModel>builder().withModel(paramModel).withDsl(paramDsl);
if (paramComponent != null && !isContent(paramModel)) {
paramElementBuilder.withConfig(paramComponent);
paramModel.getType().accept(new MetadataTypeVisitor() {
@Override
public void visitArrayType(ArrayType arrayType) {
MetadataType itemType = arrayType.getType();
paramDsl.getGeneric(itemType).ifPresent(itemdsl -> {
ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
paramComponent.getNestedComponents().forEach(c -> {
if (c.getIdentifier().equals(itemIdentifier)) {
itemType.accept(getComponentChildVisitor(paramElementBuilder, c, itemType, VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, new ArrayDeque<>()));
}
});
});
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
populateMapEntries(objectType, paramDsl, paramElementBuilder, paramComponent);
return;
}
populateObjectFields(objectType, paramComponent, paramDsl, paramElementBuilder, new ArrayDeque<>());
}
});
} else {
if (isBlank(value)) {
if (paramComponent != null && paramComponent.getValue().isPresent() && !isBlank(paramComponent.getValue().get())) {
value = paramComponent.getValue().get().trim();
} else if (defaultValue.isPresent()) {
value = defaultValue.get();
paramElementBuilder.isExplicitInDsl(false);
}
}
paramElementBuilder.withValue(value);
}
groupElementBuilder.containing(paramElementBuilder.build());
}
});
}
Aggregations