From 9d9b65691347ce84d124fcafad7a562f91884c15 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 15 Apr 2015 20:42:26 +0200 Subject: Implement resolution of referenced object --- src/core/model/Typesystem.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index 86ee811..97cb043 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -16,8 +16,9 @@ along with this program. If not, see . */ -#include "Typesystem.hpp" +#include "Document.hpp" #include "Ontology.hpp" +#include "Typesystem.hpp" #include #include @@ -663,16 +664,34 @@ ReferenceType::ReferenceType(Manager &mgr, const std::string &name, bool ReferenceType::doBuild(Variant &data, Logger &logger, const ResolveCallback &resolveCallback) const { - // Null references are valid references + // Null references are valid references (these are mostly generated as a + // result of errors) if (data.isNull()) { return true; } if (data.isObject()) { - // TODO: Check: object is an instance of the entity descriptor + // Fetch the descriptor of the given object + Rooted obj = data.asObject(); + Rooted objectDescriptor; + if (obj->isa(&RttiTypes::AnnotationEntity)) { + objectDescriptor = obj.cast()->getDescriptor(); + } else if (obj->isa(&RttiTypes::StructuredEntity)) { + objectDescriptor = obj.cast()->getDescriptor(); + } else { + throw LoggableException("Reference targets wrong internal type \"" + + obj->type()->name + "\"!"); + } + + // Make sure the referenced object has the correct type + if (!objectDescriptor->inheritsFrom(descriptor)) { + throw LoggableException( + "Referenced entity of type \"" + objectDescriptor->getName() + + "\" is not compatible to reference type \"" + + descriptor->getName() + "\""); + } return true; } else if (data.isString()) { - // TODO: Lookup referenced object if (!Utils::isNamespacedIdentifier(data.asString())) { throw LoggableException("Reference must be a valid identifier", data); -- cgit v1.2.3