diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-09 17:30:06 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-09 17:30:06 +0100 |
commit | eb864f65356468a023abe9462a1aa5805d3ee5ef (patch) | |
tree | 6ddd44cd0e6b3621aa0b1d4fdf7d4bc4c53991c1 /src/plugins | |
parent | 85a4bb306a648964ddbf166e88e3263ace293768 (diff) | |
parent | fbaad57be8ddf3f90eb13551cc7eb18674b3efa2 (diff) |
Merge branch 'master' of somweyr.de:ousia
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/xml/XmlParser.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index 6d77138..c46d9de 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -132,6 +132,7 @@ public: // try to find a FieldDescriptor for the given tag if we are not in a // field already. + // TODO: Consider fields of transparent classes if (!inField && parent != nullptr && parent->getDescriptor()->hasField(name())) { Rooted<DocumentField> field{new DocumentField( @@ -151,17 +152,37 @@ public: std::string("\"") + name() + "\" could not be resolved.", location()); } + std::string name; auto it = args.find("name"); if (it != args.end()) { name = it->second.asString(); args.erase(it); } + Rooted<StructuredEntity> entity; if (parentNode->isa(&RttiTypes::Document)) { entity = parentNode.cast<Document>()->createRootStructuredEntity( strct, args, name); } else { + // calculate a path if transparent entities are needed in between. + auto path = parent->getDescriptor()->pathTo(strct); + if (path.empty()) { + throw LoggableException( + std::string("An instance of \"") + strct->getName() + + "\" is not allowed as child of an instance of \"" + + parent->getDescriptor()->getName() + "\"", + location()); + } + + // create all transparent entities until the last field. + for (size_t p = 1; p < path.size() - 1; p = p + 2) { + parent = static_cast<DocumentEntity *>( + parent->createChildStructuredEntity( + path[p].cast<StructuredClass>(), + Variant::mapType{}, path[p - 1]->getName(), + "").get()); + } entity = parent->createChildStructuredEntity(strct, args, fieldName, name); } @@ -184,15 +205,9 @@ public: preamble(parentNode, fieldName, parent, inField); // retrieve the correct FieldDescriptor. + // TODO: Consider fields of transparent classes Rooted<Descriptor> desc = parent->getDescriptor(); - Rooted<FieldDescriptor> field = nullptr; - // TODO: Use more convenient mechanism once possible. - for (auto &fd : desc->getFieldDescriptors()) { - if (fd->getName() == fieldName) { - field = fd; - break; - } - } + Rooted<FieldDescriptor> field = desc->getFieldDescriptor(fieldName); if (field == nullptr) { logger().error( std::string("Can't handle data because no field with name \"") + |