Qt IOC Container 3.5


PropertyListParser.cpp

Go to the documentation of this file.
00001 #include "PropertyListParser.h"
00002 #include "PropertyParser.h"
00003 #include "exception/XmlParseException.h"
00004 
00005 #include <QtXml/QDomDocument>
00006 #include <QtXml/QDomNode>
00007 #include <QString>
00008 #include <QHash>
00009 #include <QtPlugin>
00010 
00011 using namespace qic;
00012 
00013 QVariant
00014 PropertyListParser::parseProperty (const QDomNode & prop, QHash <QString, QObject *> & parser_map)
00015 {
00016   QDomElement e = prop.toElement();
00017   if (e.tagName() == "list")
00018   {
00019     QList<QVariant> list;
00020     for(QDomNode ln = e.firstChild(); !ln.isNull(); ln= ln.nextSibling())
00021     {
00022       QDomElement ve = ln.toElement();
00023       QString tag = ve.tagName();
00024       if (parser_map.contains(tag))
00025       {
00026         QObject * parser_obj = parser_map[tag];
00027         PropertyParser * parser = qobject_cast<PropertyParser *>(parser_obj);
00028         list.append(parser->parseProperty(ln, parser_map));
00029       }
00030       else
00031       {
00032         throw XmlParseException (QString("Parser not available for tag %1.").arg(e.tagName()));
00033       }
00034     }
00035     return QVariant(list);
00036   }
00037   else
00038   {
00039     throw XmlParseException (QString("Expecting list, %1 encountered.").arg(e.tagName()));
00040   }
00041 }
00042 
00043 Q_EXPORT_PLUGIN2(list_parser, PropertyListParser)