use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addInlineGroup.
private void addInlineGroup(DslElementSyntax elementDsl, Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementModel.Builder parent, ParameterGroupModel group) {
elementDsl.getChild(group.getName()).ifPresent(groupDsl -> {
Optional<ComponentIdentifier> identifier = getIdentifier(groupDsl);
if (!identifier.isPresent()) {
return;
}
ComponentConfiguration groupComponent = getSingleComponentConfiguration(innerComponents, identifier);
if (groupComponent != null) {
DslElementModel.Builder<ParameterGroupModel> groupElementBuilder = DslElementModel.<ParameterGroupModel>builder().withModel(group).withDsl(groupDsl).withConfig(groupComponent);
Multimap<ComponentIdentifier, ComponentConfiguration> groupInnerComponents = getNestedComponents(groupComponent);
group.getParameterModels().forEach(p -> addElementParameter(groupInnerComponents, parameters, groupDsl, groupElementBuilder, p));
parent.containing(groupElementBuilder.build());
} else if (shoulBuildDefaultGroup(group)) {
builDefaultInlineGroupElement(parent, group, groupDsl, identifier.get());
}
});
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method getComponentChildVisitor.
private MetadataTypeVisitor getComponentChildVisitor(final DslElementModel.Builder typeBuilder, final ComponentConfiguration configuration, final MetadataType model, final String name, final DslElementSyntax modelDsl, final Optional<String> defaultValue, Deque<String> typeResolvingStack) {
final Map<String, String> parameters = configuration.getParameters();
return new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
DslElementModel.Builder<MetadataType> elementBuilder = DslElementModel.<MetadataType>builder().withModel(model).withDsl(modelDsl);
Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
String value = parameters.get(name);
if (isBlank(value)) {
if (identifier.isPresent()) {
ComponentConfiguration nested = getSingleComponentConfiguration(getNestedComponents(configuration), identifier);
if (nested != null && nested.getValue().isPresent() && !isBlank(nested.getValue().get())) {
value = nested.getValue().get().trim();
}
} else if (defaultValue.isPresent()) {
value = defaultValue.get();
elementBuilder.isExplicitInDsl(false);
}
}
if (!isBlank(value)) {
typeBuilder.containing(elementBuilder.withValue(value).build());
}
}
@Override
public void visitArrayType(ArrayType arrayType) {
Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
if (identifier.isPresent()) {
ComponentConfiguration fieldComponent = getSingleComponentConfiguration(getNestedComponents(configuration), identifier);
if (fieldComponent != null) {
DslElementModel.Builder<Object> list = DslElementModel.builder().withModel(model).withDsl(modelDsl).withConfig(fieldComponent);
modelDsl.getGeneric(arrayType.getType()).ifPresent(itemdsl -> {
ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
fieldComponent.getNestedComponents().forEach(c -> {
if (c.getIdentifier().equals(itemIdentifier)) {
getComponentChildVisitor(list, c, arrayType.getType(), VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, typeResolvingStack);
}
});
});
typeBuilder.containing(list.build());
return;
}
}
defaultValue.ifPresent(s -> typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(defaultValue.get()).isExplicitInDsl(false).build()));
}
@Override
public void visitObject(ObjectType objectType) {
Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
if (identifier.isPresent()) {
if (isMap(objectType)) {
typeBuilder.containing(createMapElement(objectType, modelDsl, configuration));
return;
}
Multimap<ComponentIdentifier, ComponentConfiguration> nestedComponents = getNestedComponents(configuration);
ComponentConfiguration fieldComponent = nestedComponents.containsKey(identifier.get()) ? nestedComponents.get(identifier.get()).iterator().next() : null;
fieldComponent = fieldComponent == null ? configuration : fieldComponent;
String value = fieldComponent.getParameters().get(modelDsl.getAttributeName());
if (!isBlank(value)) {
typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(value).build());
} else {
resolveBasedOnType(objectType, fieldComponent, typeResolvingStack).ifPresent(typeBuilder::containing);
}
return;
}
defaultValue.ifPresent(s -> typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(defaultValue.get()).isExplicitInDsl(false).build()));
}
};
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method createIdentifiedElement.
private DslElementModel createIdentifiedElement(ComponentConfiguration configuration) {
final ComponentIdentifier identifier = configuration.getIdentifier();
Optional<Map.Entry<ExtensionModel, DslSyntaxResolver>> entry = resolvers.entrySet().stream().filter(e -> e.getKey().getXmlDslModel().getPrefix().equals(identifier.getNamespace())).findFirst();
if (!entry.isPresent()) {
return null;
}
currentExtension = entry.get().getKey();
dsl = entry.get().getValue();
Reference<DslElementModel> elementModel = new Reference<>();
new ExtensionWalker() {
@Override
protected void onConfiguration(ConfigurationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
DslElementModel.Builder<ConfigurationModel> element = createElementModel(model, elementDsl, configuration);
addConnectionProvider(model, dsl, element, configuration);
elementModel.set(element.build());
stop();
}
});
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
}.walk(currentExtension);
if (elementModel.get() == null) {
resolveBasedOnTypes(configuration).ifPresent(elementModel::set);
}
return elementModel.get();
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method resolveWrappedElement.
private void resolveWrappedElement(DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel p, DslElementSyntax pDsl, ComponentConfiguration paramComponent) {
if (paramComponent != null) {
DslElementModel.Builder<ParameterModel> paramElement = DslElementModel.<ParameterModel>builder().withModel(p).withDsl(pDsl).withConfig(paramComponent);
if (paramComponent.getNestedComponents().size() > 0) {
ComponentConfiguration wrappedComponent = paramComponent.getNestedComponents().get(0);
this.create(wrappedComponent).ifPresent(paramElement::containing);
}
groupElementBuilder.containing(paramElement.build());
}
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createTopLevelElement.
private DslElementModel createTopLevelElement(ObjectType model, TopLevelParameterDeclaration declaration) {
DslElementSyntax objectDsl = dsl.resolve(model).orElseThrow(() -> new IllegalArgumentException("Failed to resolve the DSL syntax for type '" + getId(model) + "'"));
DslElementModel.Builder<MetadataType> parentElement = DslElementModel.<MetadataType>builder().withModel(model).withDsl(objectDsl);
InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(objectDsl)).withParameter(NAME_ATTRIBUTE_NAME, declaration.getRefName());
populateObjectElementFields(model, declaration.getValue(), objectDsl, configuration, parentElement);
return parentElement.withConfig(configuration.build()).build();
}
Aggregations