From b5cdca0331117ad3834b61eadd94ab3fcb6d2fba Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 1 Mar 2015 21:08:49 +0100 Subject: improved error messages for empty field names. --- src/core/model/Document.cpp | 6 +-- src/core/model/Ontology.hpp | 67 ++++++++++++++++++++----------- src/core/parser/stack/DocumentHandler.cpp | 4 +- 3 files changed, 47 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index fc39348..b29767e 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -180,7 +180,7 @@ bool DocumentEntity::doValidate(Logger &logger) const // check if the parent reference is correct. if (child->getParent() != subInst) { logger.error(std::string("A child of field \"") + - fieldDescs[f]->getName() + + fieldDescs[f]->getNameOrDefaultName() + "\" has the wrong parent reference!", *child); valid = false; @@ -209,7 +209,7 @@ bool DocumentEntity::doValidate(Logger &logger) const c->getDescriptor()->getName() + "\" is not allowed as child of an instance of \"" + descriptor->getName() + "\" in field \"" + - fieldDescs[f]->getName() + "\"", + fieldDescs[f]->getNameOrDefaultName() + "\"", *child); valid = false; continue; @@ -285,7 +285,7 @@ static int enforceGetFieldDescriptorIndex( if (idx == -1) { throw OusiaException(std::string("Descriptor \"") + desc->getName() + "\" does not reference the given field \"" + - fieldDescriptor->getName() + "\""); + fieldDescriptor->getNameOrDefaultName() + "\""); } return idx; } diff --git a/src/core/model/Ontology.hpp b/src/core/model/Ontology.hpp index 948caa5..e1fbe96 100644 --- a/src/core/model/Ontology.hpp +++ b/src/core/model/Ontology.hpp @@ -19,7 +19,8 @@ /** * @file Ontology.hpp * - * This header contains the class hierarchy of descriptor classes for ontologies. + * This header contains the class hierarchy of descriptor classes for + * ontologies. * Properly connected instances of these classes with a Ontology node as root * describe a semantic Ontology in a formal way. It specifies the allowed (tree) * structure of a document by means of StructuredClasses as well as the allowed @@ -95,8 +96,8 @@ * the proper StructuredClass. This can be regulated by the "cardinality" * property of a StructuredClass. * - * It is possible to add further fields, like we would in the "headings" ontology - * to add titles to our structure. + * It is possible to add further fields, like we would in the "headings" + * ontology to add titles to our structure. * * \code{.xml} * @@ -119,10 +120,10 @@ * \endcode * * AnnotationClasses on the other hand do not specify a context free grammar. - * They merely specify what kinds of Annotations are allowed within this ontology - * and which fields or attributes they have. Note that Annotations are allowed - * to define structured children that manifest e.g. meta information of that - * Annotation. An example for that would be the "comment" ontology: + * They merely specify what kinds of Annotations are allowed within this + * ontology and which fields or attributes they have. Note that Annotations are + * allowed to define structured children that manifest e.g. meta information of + * that Annotation. An example for that would be the "comment" ontology: * * \code{.xml} * @@ -437,6 +438,23 @@ public: * children of an instance of this Descriptor. */ NodeVector getDefaultFields() const; + + /** + * Returns the name of this FieldDescriptor or the default field name + * if the name is empty. + * + * @return the name of this FieldDescriptor or the default field name + * if the name is empty. + */ + std::string getNameOrDefaultName() + { + std::string name = getName(); + if (name.empty()) { + return DEFAULT_FIELD_NAME; + } else { + return std::move(name); + } + } }; /** @@ -824,7 +842,7 @@ public: * * @param mgr is the current Manager. * @param name is the name of the StructuredClass. - * @param ontology is the Ontology this StructuredClass belongs + * @param ontology is the Ontology this StructuredClass belongs * to. * @param cardinality specifies how often an element of this type * may occur at a specific point in the @@ -983,7 +1001,7 @@ public: * @param name is a name for this AnnotationClass that will * be used for later references to this * AnnotationClass. - * @param ontology is the Ontology this AnnotationClass belongs + * @param ontology is the Ontology this AnnotationClass belongs * to. */ AnnotationClass(Manager &mgr, std::string name, Handle ontology); @@ -991,7 +1009,8 @@ public: /** * A Ontology node specifies which StructuredClasses and which AnnotationClasses - * are part of this ontology. TODO: Do we want to be able to restrict Annotations + * are part of this ontology. TODO: Do we want to be able to restrict + * Annotations * to certain Structures? */ class Ontology : public RootNode { @@ -1012,8 +1031,8 @@ protected: public: /** - * The constructor for a new ontology. Note that this is an empty Ontology and - * still has to be filled with StructuredClasses and AnnotationClasses. + * The constructor for a new ontology. Note that this is an empty Ontology + * and still has to be filled with StructuredClasses and AnnotationClasses. * * @param mgr is the Manager instance. * @param name is a name for this ontology which will be used for later @@ -1029,8 +1048,8 @@ public: } /** - * The constructor for a new ontology. Note that this is an empty Ontology and - * still has to be filled with StructuredClasses and AnnotationClasses. + * The constructor for a new ontology. Note that this is an empty Ontology + * and still has to be filled with StructuredClasses and AnnotationClasses. * * @param mgr is the Manager instance. * @param sys is the SystemTypesystem instance. @@ -1068,16 +1087,16 @@ public: } /** * Adds a StructuredClass to this ontology. This also sets the parent of the - * given StructuredClass if it is not set to this Ontology already and removes - * it from the old Ontology. + * given StructuredClass if it is not set to this Ontology already and + * removes it from the old Ontology. * * @param s is some StructuredClass. */ void addStructuredClass(Handle s); /** - * Removes a StructuredClass from this ontology. This also sets the parent of - * the given StructuredClass to null. + * Removes a StructuredClass from this ontology. This also sets the parent + * of the given StructuredClass to null. * * @param s is some StructuredClass. * @return true if the given StructuredClass was removed and false if this @@ -1127,17 +1146,17 @@ public: return annotationClasses; } /** - * Adds an AnnotationClass to this ontology. This also sets the parent of the - * given AnnotationClass if it is not set to this Ontology already and removes - * it from the old Ontology. + * Adds an AnnotationClass to this ontology. This also sets the parent of + * the given AnnotationClass if it is not set to this Ontology already and + * removes it from the old Ontology. * * @param a is some AnnotationClass. */ void addAnnotationClass(Handle a); /** - * Removes a AnnotationClass from this ontology. This also sets the parent of - * the given AnnotationClass to null. + * Removes a AnnotationClass from this ontology. This also sets the parent + * of the given AnnotationClass to null. * * @param a is some AnnotationClass. * @return true if the given AnnotationClass was removed and false if this @@ -1200,4 +1219,4 @@ extern const Rtti Ontology; } } -#endif /* _OUSIA_MODEL_DOMAIN_HPP_ */ +#endif /* _OUSIA_MODEL_DOMAIN_HPP_ */ \ No newline at end of file diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index 2144c34..a307f71 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -235,7 +235,7 @@ bool DocumentChildHandler::start(Variant::mapType &args) throw LoggableException( std::string("An instance of \"") + strct->getName() + "\" is not allowed as child of field \"" + - field->getName() + "\" of descriptor \"" + + field->getNameOrDefaultName() + "\" of descriptor \"" + parent->getDescriptor()->getName() + "\"", location()); } @@ -245,8 +245,6 @@ bool DocumentChildHandler::start(Variant::mapType &args) parent->getDescriptor()->getFieldDescriptorIndex(); } // create the entity for the new element at last. - // TODO: REMOVE - strct_name = strct->getName(); entity = parent->createChildStructuredEntity(strct, lastFieldIdx, args, nameAttr); } -- cgit v1.2.3