From c794a3f21b9cb050f370350562ee8c0bc7f95766 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 8 Apr 2015 20:02:31 +0200 Subject: fixed some bugs in domain serialization and added first integration test for it. --- src/plugins/xml/XmlOutput.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/plugins/xml/XmlOutput.cpp') diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index adf1691..5615bba 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -198,6 +198,15 @@ void XmlTransformer::writeXml(Handle doc, std::ostream &out, * Ontology transformation functions. */ +static std::string getStringForBool(bool val) +{ + if (val) { + return "true"; + } else { + return "false"; + } +} + static std::string getStructuredClassRef(Handle referencing, Handle referenced) { @@ -249,19 +258,19 @@ static Rooted transformFieldDescriptor(Handle parent, std::map attrs; addNameAttribute(fd, attrs); bool isSubtree = fd->getFieldType() == FieldDescriptor::FieldType::SUBTREE; - attrs.emplace("subtree", toString(isSubtree, P)); - attrs.emplace("optional", toString(fd->isOptional(), P)); + attrs.emplace("subtree", getStringForBool(isSubtree)); + attrs.emplace("optional", getStringForBool(fd->isOptional())); // TODO: whitespace mode? // create the XML element itself. - Rooted fieldDescriptor{new Element(P.mgr, parent, tagName)}; + Rooted fieldDescriptor{new Element(P.mgr, parent, tagName, attrs)}; // translate the syntax. SyntaxDescriptor stx = fd->getSyntaxDescriptor(); Rooted syntax = transformSyntaxDescriptor(fieldDescriptor, stx, P); fieldDescriptor->addChild(syntax); // translate the child references. for (auto s : fd->getChildren()) { - std::string ref = getStructuredClassRef( - fd->getParent().cast(), s); + std::string ref = + getStructuredClassRef(fd->getParent().cast(), s); Rooted childRef{ new Element(P.mgr, fieldDescriptor, "childRef", {{"ref", ref}})}; fieldDescriptor->addChild(childRef); @@ -293,15 +302,16 @@ static Rooted transformStructuredClass(Handle parent, TransformParams &P) { Rooted structuredClass{new Element(P.mgr, parent, "struct")}; - structuredClass->getAttributes().emplace("cardinality", - toString(s->getCardinality(), P)); + structuredClass->getAttributes().emplace( + "cardinality", toString(Variant(s->getCardinality()), P)); if (s->getSuperclass() != nullptr) { structuredClass->getAttributes().emplace( "isa", getStructuredClassRef(s, s->getSuperclass())); } - structuredClass->getAttributes().emplace("transparent", - toString(s->isTransparent(), P)); - structuredClass->getAttributes().emplace("root", toString(s->isRoot(), P)); + structuredClass->getAttributes().emplace( + "transparent", getStringForBool(s->isTransparent())); + structuredClass->getAttributes().emplace( + "root", getStringForBool(s->hasRootPermission())); transformDescriptor(structuredClass, s, P); return structuredClass; } @@ -347,16 +357,18 @@ Rooted transformOntology(Handle parent, Handle o, // transform the ontology itself. // create an XML element for the ontology. Rooted ontology{new Element(P.mgr, parent, "ontology")}; + addNameAttribute(o, ontology->getAttributes()); // transform all StructuredClasses. for (auto s : o->getStructureClasses()) { Rooted structuredClass = transformStructuredClass(ontology, s, P); - parent->addChild(structuredClass); + ontology->addChild(structuredClass); } // transform all AnnotationClasses. for (auto a : o->getAnnotationClasses()) { Rooted annotationClass = transformAnnotationClass(ontology, a, P); + ontology->addChild(annotationClass); } // return the transformed Ontology. return ontology; -- cgit v1.2.3