summaryrefslogtreecommitdiff
path: root/src/core/model/Document.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-18 13:48:45 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-18 13:48:45 +0100
commit372c67e0844654362fc7d440b0b4a31500a6d02a (patch)
treed677aa19bdc77486be02171de77e5675ce5f0f80 /src/core/model/Document.cpp
parentdb51a874964b038c69f1336a8a659ae40471e26b (diff)
parent3e63d6539b9738018a4aca68d07a119e4402e9aa (diff)
Merge branch 'master' of somweyr.de:ousia
Conflicts: application/src/core/model/Domain.hpp
Diffstat (limited to 'src/core/model/Document.cpp')
-rw-r--r--src/core/model/Document.cpp53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index ee15e31..5f0ad4c 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -92,7 +92,7 @@ int DocumentEntity::getFieldDescriptorIndex(
}
}
-bool DocumentEntity::validate(Logger &logger) const
+bool DocumentEntity::doValidate(Logger &logger) const
{
// TODO: check the validated form of Attributes
// iterate over every field
@@ -246,7 +246,7 @@ bool StructuredEntity::doValidate(Logger &logger) const
return false;
}
// check the validity as a DocumentEntity.
- return DocumentEntity::validate(logger);
+ return DocumentEntity::doValidate(logger);
}
/* Class AnnotationEntity */
@@ -281,12 +281,17 @@ bool AnnotationEntity::doValidate(Logger &logger) const
logger.error("This annotation was not registered at the document.");
return false;
}
-
+ // check if the Anchors are part of the right document.
+ if (!doc->hasChild(start)) {
+ return false;
+ }
+ if (!doc->hasChild(end)) {
+ return false;
+ }
// check the validity as a DocumentEntity.
- if (!DocumentEntity::validate(logger)) {
+ if (!DocumentEntity::doValidate(logger)) {
return false;
}
- // TODO: then check if the anchors are in the correct document.
return true;
}
@@ -300,6 +305,44 @@ void Document::doResolve(ResolutionState &state)
}
continueResolveReferences(domains, state);
}
+
+bool Document::doValidate(Logger &logger) const
+{
+ if (root != nullptr) {
+ // check if the root is allowed to be a root.
+ if (!root->getDescriptor().cast<StructuredClass>()->root) {
+ logger.error(std::string("A node of type ") +
+ root->getDescriptor()->getName() +
+ " is not allowed to be the Document root!");
+ return false;
+ }
+ // then call validate on the root
+ if (!root->validate(logger)) {
+ return false;
+ }
+ }
+ // call validate on the AnnotationEntities
+ for (auto &a : annotations) {
+ if (!a->validate(logger)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool Document::hasChild(Handle<StructureNode> s) const
+{
+ Rooted<Managed> parent = s->getParent();
+ if (parent->isa(RttiTypes::StructureNode)) {
+ return hasChild(parent.cast<StructureNode>());
+ } else if (parent->isa(RttiTypes::AnnotationEntity)) {
+ Handle<AnnotationEntity> a = parent.cast<AnnotationEntity>();
+ return this == a->getParent();
+ } else if (parent->isa(RttiTypes::Document)) {
+ return this == parent;
+ }
+ return false;
+}
}
/* Type registrations */