use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createWrappedObject.
private void createWrappedObject(ParameterObjectValue objectValue, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
DslElementModel.Builder<ParameterModel> wrapperElement = DslElementModel.<ParameterModel>builder().withModel(parameterModel).withDsl(paramDsl);
InternalComponentConfiguration.Builder wrapperConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
Reference<DslSyntaxResolver> customDsl = new Reference<>(dsl);
ObjectType nestedElementType;
if (objectValue.getTypeId() == null || objectValue.getTypeId().trim().isEmpty() || getId(parameterModel.getType()).map(id -> id.equals(objectValue.getTypeId())).orElse(false)) {
nestedElementType = (ObjectType) parameterModel.getType();
} else {
nestedElementType = lookupType(objectValue);
context.getTypeCatalog().getDeclaringExtension(objectValue.getTypeId()).ifPresent(owner -> context.getExtension(owner).ifPresent(extensionModel -> customDsl.set(resolvers.get(extensionModel))));
}
customDsl.get().resolve(nestedElementType).ifPresent(typeDsl -> createObject(objectValue, typeDsl, nestedElementType, nestedElementType, wrapperConfig, wrapperElement));
ComponentConfiguration result = wrapperConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(wrapperElement.withConfig(result).build());
}
use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createMapParameter.
private void createMapParameter(ParameterObjectValue objectValue, DslElementSyntax paramDsl, Object model, ObjectType mapType, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
InternalComponentConfiguration.Builder mapConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
DslElementModel.Builder mapElement = DslElementModel.builder().withModel(model).withDsl(paramDsl);
MetadataType valueType = mapType.getOpenRestriction().get();
paramDsl.getGeneric(valueType).ifPresent(entryDsl -> objectValue.getParameters().forEach((key, value) -> {
InternalComponentConfiguration.Builder entryConfigBuilder = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(entryDsl));
DslElementModel.Builder<MetadataType> entryElement = DslElementModel.<MetadataType>builder().withModel(valueType).withDsl(entryDsl);
entryDsl.getAttribute(KEY_ATTRIBUTE_NAME).ifPresent(keyDsl -> {
entryConfigBuilder.withParameter(KEY_ATTRIBUTE_NAME, key);
entryElement.containing(DslElementModel.builder().withModel(typeLoader.load(String.class)).withDsl(keyDsl).withValue(key).build());
});
entryDsl.getAttribute(VALUE_ATTRIBUTE_NAME).ifPresent(valueDsl -> value.accept(new ParameterValueVisitor() {
@Override
public void visitSimpleValue(ParameterSimpleValue text) {
entryConfigBuilder.withParameter(VALUE_ATTRIBUTE_NAME, text.getValue());
entryElement.containing(DslElementModel.builder().withModel(valueType).withDsl(valueDsl).withValue(text.getValue()).build());
}
@Override
public void visitListValue(ParameterListValue list) {
createList(list, valueDsl, valueType, (ArrayType) valueType, entryConfigBuilder, entryElement);
}
@Override
public void visitObjectValue(ParameterObjectValue objectValue) {
if (isMap(valueType)) {
createMapParameter(objectValue, valueDsl, valueType, (ObjectType) valueType, entryConfigBuilder, entryElement);
} else {
createObject(objectValue, valueDsl, valueType, (ObjectType) valueType, entryConfigBuilder, entryElement);
}
}
}));
ComponentConfiguration entryConfig = entryConfigBuilder.build();
mapConfig.withNestedComponent(entryConfig);
mapElement.containing(entryElement.withConfig(entryConfig).build());
}));
ComponentConfiguration result = mapConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(mapElement.withConfig(result).build());
}
use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createObject.
private void createObject(ParameterObjectValue objectValue, DslElementSyntax objectDsl, Object model, ObjectType objectType, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
InternalComponentConfiguration.Builder objectConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(objectDsl));
DslElementModel.Builder objectElement = DslElementModel.builder().withModel(model).withDsl(objectDsl);
populateObjectElementFields(objectType, objectValue, objectDsl, objectConfig, objectElement);
ComponentConfiguration result = objectConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(objectElement.withConfig(result).build());
}
use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method populateEETransform.
private Element populateEETransform(DslElementModel<?> elementModel) {
Element transform = createElement(elementModel.getDsl());
elementModel.getConfiguration().ifPresent(c -> c.getParameters().forEach((name, value) -> elementModel.findElement(name).filter(DslElementModel::isExplicitInDsl).ifPresent(e -> transform.setAttribute(name, value))));
// write set-payload and set-attributes
elementModel.findElement(buildFromStringRepresentation("ee:set-payload")).filter(DslElementModel::isExplicitInDsl).ifPresent(message -> {
Element messageElement = createElement(elementModel.getDsl(), "message");
transform.appendChild(messageElement);
elementModel.findElement(buildFromStringRepresentation("ee:set-payload")).ifPresent(setPayload -> setPayload.getConfiguration().ifPresent(c -> messageElement.appendChild(createTransformTextElement(c))));
elementModel.findElement(buildFromStringRepresentation("ee:set-attributes")).ifPresent(setAttributes -> setAttributes.getConfiguration().ifPresent(c -> messageElement.appendChild(createTransformTextElement(c))));
});
// write set-variable
elementModel.findElement(buildFromStringRepresentation("ee:set-variables")).ifPresent(variables -> {
Element variablesList = createElement(elementModel.getDsl(), "variables");
transform.appendChild(variablesList);
variables.getContainedElements().forEach(variable -> variable.getConfiguration().ifPresent(c -> {
Element var = createTransformTextElement((ComponentConfiguration) c);
var.setAttribute("variableName", ((ComponentConfiguration) c).getParameters().get("variableName"));
variablesList.appendChild(var);
}));
});
return transform;
}
use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method createTransformTextElement.
private Element createTransformTextElement(ComponentConfiguration config) {
String namespaceURI = EE_NAMESPACE;
String eeSchemaLocation = buildSchemaLocation(EE_PREFIX, EE_NAMESPACE);
addNamespaceDeclarationIfNeeded(EE_PREFIX, namespaceURI, eeSchemaLocation);
Element nested = doc.createElementNS(namespaceURI, EE_PREFIX + ":" + config.getIdentifier().getName());
config.getParameters().forEach(nested::setAttribute);
config.getNestedComponents().stream().filter(inner -> inner.getValue().isPresent()).forEach(inner -> nested.appendChild(doc.createCDATASection(inner.getValue().get())));
return nested;
}
Aggregations