diff options
| author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-04-08 20:02:31 +0200 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:19:34 +0200 | 
| commit | c794a3f21b9cb050f370350562ee8c0bc7f95766 (patch) | |
| tree | 05eb01e2546e3f4957f91d06c3b53d2a44f2c589 | |
| parent | f2f20d5cae37064a329ee451efb6f2f26e2a0f0b (diff) | |
fixed some bugs in domain serialization and added first integration test for it.
| -rw-r--r-- | src/plugins/xml/XmlOutput.cpp | 34 | ||||
| -rw-r--r-- | testdata/integration/ontology_serialization/simple.in.osml | 11 | ||||
| -rw-r--r-- | testdata/integration/ontology_serialization/simple.out.osml | 22 | 
3 files changed, 56 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; diff --git a/testdata/integration/ontology_serialization/simple.in.osml b/testdata/integration/ontology_serialization/simple.in.osml new file mode 100644 index 0000000..c6549bc --- /dev/null +++ b/testdata/integration/ontology_serialization/simple.in.osml @@ -0,0 +1,11 @@ +\document + +\ontology#test +	\struct#a[root=true] +		\field#afield[subtree=true] +			\childRef[ref=a] +		\field[optional=true] +			\childRef[ref=b] +	\struct#b[transparent=true, cardinality={1, 7-8}] + +\a diff --git a/testdata/integration/ontology_serialization/simple.out.osml b/testdata/integration/ontology_serialization/simple.out.osml new file mode 100644 index 0000000..c40c40f --- /dev/null +++ b/testdata/integration/ontology_serialization/simple.out.osml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<document> +	<ontology name="test"> +		<struct cardinality="{*}" name="a" root="true" transparent="false"> +			<syntax/> +			<field name="afield" optional="false" subtree="true"> +				<syntax/> +				<childRef ref="a"/> +			</field> +			<field optional="true" subtree="false"> +				<syntax/> +				<childRef ref="b"/> +			</field> +		</struct> +		<struct cardinality="{1, 7-8}" name="b" root="false" transparent="true"> +			<syntax/> +		</struct> +	</ontology> +	<test:a> +		<afield/> +	</test:a> +</document> | 
