summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-04-08 20:02:31 +0200
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2016-04-25 22:19:34 +0200
commitc794a3f21b9cb050f370350562ee8c0bc7f95766 (patch)
tree05eb01e2546e3f4957f91d06c3b53d2a44f2c589 /src
parentf2f20d5cae37064a329ee451efb6f2f26e2a0f0b (diff)
fixed some bugs in domain serialization and added first integration test for it.
Diffstat (limited to 'src')
-rw-r--r--src/plugins/xml/XmlOutput.cpp34
1 files changed, 23 insertions, 11 deletions
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<Document> 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<Descriptor> referencing,
Handle<StructuredClass> referenced)
{
@@ -249,19 +258,19 @@ static Rooted<Element> transformFieldDescriptor(Handle<Element> parent,
std::map<std::string, std::string> 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<Element> fieldDescriptor{new Element(P.mgr, parent, tagName)};
+ Rooted<Element> fieldDescriptor{new Element(P.mgr, parent, tagName, attrs)};
// translate the syntax.
SyntaxDescriptor stx = fd->getSyntaxDescriptor();
Rooted<Element> syntax = transformSyntaxDescriptor(fieldDescriptor, stx, P);
fieldDescriptor->addChild(syntax);
// translate the child references.
for (auto s : fd->getChildren()) {
- std::string ref = getStructuredClassRef(
- fd->getParent().cast<Descriptor>(), s);
+ std::string ref =
+ getStructuredClassRef(fd->getParent().cast<Descriptor>(), s);
Rooted<Element> childRef{
new Element(P.mgr, fieldDescriptor, "childRef", {{"ref", ref}})};
fieldDescriptor->addChild(childRef);
@@ -293,15 +302,16 @@ static Rooted<Element> transformStructuredClass(Handle<Element> parent,
TransformParams &P)
{
Rooted<Element> 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<Element> transformOntology(Handle<Element> parent, Handle<Ontology> o,
// transform the ontology itself.
// create an XML element for the ontology.
Rooted<Element> ontology{new Element(P.mgr, parent, "ontology")};
+ addNameAttribute(o, ontology->getAttributes());
// transform all StructuredClasses.
for (auto s : o->getStructureClasses()) {
Rooted<Element> structuredClass =
transformStructuredClass(ontology, s, P);
- parent->addChild(structuredClass);
+ ontology->addChild(structuredClass);
}
// transform all AnnotationClasses.
for (auto a : o->getAnnotationClasses()) {
Rooted<Element> annotationClass =
transformAnnotationClass(ontology, a, P);
+ ontology->addChild(annotationClass);
}
// return the transformed Ontology.
return ontology;