use of org.mule.runtime.config.api.dsl.model.DslElementModelFactory in project mule by mulesoft.
the class ApplicationModel method convertArtifactDeclarationToComponentModel.
private void convertArtifactDeclarationToComponentModel(Set<ExtensionModel> extensionModels, ArtifactDeclaration artifactDeclaration) {
if (artifactDeclaration != null && !extensionModels.isEmpty()) {
ExtensionModel muleModel = MuleExtensionModelProvider.getExtensionModel();
if (!extensionModels.contains(muleModel)) {
extensionModels = new HashSet<>(extensionModels);
extensionModels.add(muleModel);
}
DslElementModelFactory elementFactory = DslElementModelFactory.getDefault(DslResolvingContext.getDefault(extensionModels));
ComponentModel rootComponent = new ComponentModel.Builder().setIdentifier(ComponentIdentifier.builder().namespace(CORE_PREFIX).name(CORE_PREFIX).build()).build();
AtomicBoolean atLeastOneComponentAdded = new AtomicBoolean(false);
artifactDeclaration.getGlobalElements().stream().map(e -> elementFactory.create((ElementDeclaration) e)).filter(Optional::isPresent).map(e -> e.get().getConfiguration()).forEach(config -> config.ifPresent(c -> {
atLeastOneComponentAdded.set(true);
ComponentModel componentModel = convertComponentConfiguration(c, true);
componentModel.setParent(rootComponent);
rootComponent.getInnerComponents().add(componentModel);
}));
if (atLeastOneComponentAdded.get()) {
this.muleComponentModels.add(rootComponent);
}
}
}
use of org.mule.runtime.config.api.dsl.model.DslElementModelFactory in project mule by mulesoft.
the class DefaultArtifactDeclarationXmlSerializer method serializeArtifact.
private String serializeArtifact(ArtifactDeclaration artifact) {
checkArgument(artifact != null, "The artifact to serialize cannot be null");
try {
Document doc = createAppDocument(artifact);
XmlDslElementModelConverter toXmlConverter = XmlDslElementModelConverter.getDefault(doc);
DslElementModelFactory modelResolver = DslElementModelFactory.getDefault(context);
artifact.getGlobalElements().forEach(declaration -> appendChildElement(toXmlConverter, doc.getDocumentElement(), modelResolver, (ElementDeclaration) declaration));
List<String> cDataElements = getCDataElements(doc.getDocumentElement());
// write the content into xml file
TransformerFactory transformerFactory = XMLSecureFactories.createDefault().getTransformerFactory();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, join(cDataElements, " "));
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
return writer.getBuffer().toString();
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage("Failed to serialize the declaration for the artifact [" + artifact.getName() + "]: " + e.getMessage()), e);
}
}
Aggregations