From c2fb0693208c2e980fdb161e63ef82096c49d59a Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 21 Jan 2015 22:21:24 +0100 Subject: added variant content validation for Documents. --- src/core/model/Document.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/core/model/Document.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 7552bd3..f29af1c 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -147,10 +147,14 @@ bool DocumentEntity::doValidate(Logger &logger) const // a constructor we can not check anything else. return false; } - // TODO: check the validated form of Attributes - // TODO: Check if descriptor is registered at the Document? - - bool valid = true; + // check the attribute primitive content. + bool valid; + if (descriptor->getAttributesDescriptor() == nullptr) { + valid = getAttributes() == nullptr; + } else { + valid = descriptor->getAttributesDescriptor()->isValid(getAttributes(), + logger); + } /* * generate the set of effective fields. This is trivial for * AnnotationEntities, but in the case of StructuredEntities we have to @@ -188,7 +192,18 @@ bool DocumentEntity::doValidate(Logger &logger) const continue; } // if we are here we know that exactly one child exists. - // TODO: Check the primitive type of the child. + if (!fields[f][0]->isa(RttiTypes::DocumentPrimitive)) { + logger.error(std::string("Primitive Field \"") + + fieldDescs[f]->getName() + + "\" has non primitive content!"); + valid = false; + } else { + Handle primitive = + fields[f][0].cast(); + valid = valid & + fieldDescs[f]->getPrimitiveType()->isValid( + primitive->getContent(), logger); + } continue; } -- cgit v1.2.3