PropertyRefParser.cpp
Go to the documentation of this file.00001 #include "PropertyRefParser.h"
00002 #include "PropertyParser.h"
00003 #include "ReferenceDefinition.h"
00004 #include "exception/XmlParseException.h"
00005
00006 #include <QtXml/QDomDocument>
00007 #include <QtXml/QDomNode>
00008 #include <QString>
00009 #include <QHash>
00010 #include <QtPlugin>
00011
00012 using namespace qic;
00013
00014 const char * PropertyRefParser::PROPERTY_REF_OBJECT_ATTR = "object";
00015 const char * PropertyRefParser::PROPERTY_REF_TAG = "ref";
00016 const char * PropertyRefParser::PROPERTY_REF_WEAK_ATTR = "weak";
00017
00018 QVariant
00019 PropertyRefParser::parseProperty (const QDomNode & prop, QHash <QString, QObject *> & )
00020 {
00021 QDomElement e = prop.toElement();
00022 if(e.tagName() == PROPERTY_REF_TAG)
00023 {
00024 QString refObject = e.attribute(PROPERTY_REF_OBJECT_ATTR);
00025 if (refObject.isEmpty())
00026 {
00027 throw XmlParseException (QString("%1 must have %2 attribute.").arg(PROPERTY_REF_TAG).arg(PROPERTY_REF_OBJECT_ATTR));
00028 }
00029 else
00030 {
00031
00032 ReferenceDefinition refDef;
00033 refDef.refId = refObject;
00034 QString refWeak = e.attribute(PROPERTY_REF_WEAK_ATTR);
00035 if (refWeak == "yes")
00036 {
00037 refDef.isWeak = true;
00038 }
00039 else
00040 {
00041
00042 refDef.isWeak = false;
00043 }
00044 return QVariant::fromValue(refDef);
00045 }
00046 }
00047 else
00048 {
00049 throw XmlParseException (QString("Expecting ref, %1 encountered.").arg(e.tagName()));
00050 }
00051 }
00052
00053 Q_EXPORT_PLUGIN2(ref_parser, PropertyRefParser)