"//AUTOMATICALLY GENERATED FILE\n"
"#include \"%.h\"\n"
"#include <QDomElement>\n"
- "#include <QDomNodeList>\n";
+ "#include <QDomNodeList>\n"
+ "#include <QDomDocument>\n";
//end section of all source files
static const QByteArray SRCEND="\n//END OF FILE\n";
classProperties(cls,hdr,src);
//serializer
- classSerializers(cls,hdr,src);
+ classSerializers(cls,hdr,src,cna);
//deserializer (constructor)
classDeserializer(cls,hdr,src,cna);
src.write(scd.toAscii());
}
-void WocQtClientOut::classSerializers(const WocClass&cls,QFile&hdr,QFile&src)
+void WocQtClientOut::classSerializers(const WocClass&cls,QFile&hdr,QFile&src,QString cn)
{
- //TODO: implement
+ QStringList k=cls.serializers();
+ if(k.size()==0)return;
+ QString hcd=" public:\n";
+ QString scd;
+ for(int i=0;i<k.size();i++){
+ hcd+="\tQString toString"+k[i]+"();\n";
+ scd+="QString "+cn+"::toString"+k[i]+"()\n{\n";
+ scd+="\tQDomDocument doc;\n\tdoc.appendChild(toXml"+k[i]+"(doc));\n";
+ scd+="\treturn doc.toString();\n}\n";
+ hcd+="\tQDomElement toXml"+k[i]+"(QDomDocument&,QString name=\""+cls.name()+"\");\n";
+ scd+="QDomElement "+cn+"::toXml"+k[i]+"(QDomDocument&doc,QString name)\n{\n";
+ scd+="\tQDomElement r=doc.createElement(name);\n";
+ QStringList p=cls.serializerProperties(k[i]);
+ for(int j=0;j<p.size();j++){
+ QStringList pv=p[j].split("/",QString::SkipEmptyParts);
+ if(pv.size()<1){
+ qDebug("Error: encountered empty property while creating serializer %s for class %s.",k[i].toAscii().data(),cls.name().toAscii().data());
+ emit errorFound();
+ return;
+ }
+ QString prop=pv[0];
+ QString var;
+ if(pv.size()>1)var=pv[1];
+ //is it a list
+ if(cls.propertyIsList(prop)){
+ scd+="\tfor(int i=0;i<mp_"+prop+".size();i++){\n";
+ if(cls.propertyIsObject(prop))
+ scd+="\t\tr.appendChild(mp_"+prop+"[i].toXml"+var+"(doc,\""+prop+"\"));\n";
+ else
+ if(cls.propertyIsEnum(prop)){
+ scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n";
+ scd+="\t\tel.appendChild(doc.createTextNode("+cls.propertyPlainType(prop)+"2str(mp_"+prop+"[i])));\n";
+ scd+="\t\tr.appendChild(el);\n";
+ }else
+ if(cls.propertyIsString(prop)){
+ scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n";
+ scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+"[i]));\n";
+ scd+="\t\tr.appendChild(el);\n";
+ }else
+ if(cls.propertyIsInt(prop)){
+ scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n";
+ scd+="\t\tel.appendChild(doc.createTextNode(QString::number(mp_"+prop+"[i])));\n";
+ scd+="\t\tr.appendChild(el);\n";
+ }else{
+ qDebug("Error: cannot generate serializer for class %s property %s.",cls.name().toAscii().data(),prop.toAscii().data());
+ emit errorFound();
+ return;
+ }
+ scd+="\t}\n";
+ }else{
+ //non lists
+ scd+="\tif(!mp_"+prop+".isNull()){\n";
+ if(cls.propertyIsAttribute(prop)){
+ scd+="\t\tr.setAttribute(\""+prop+"\",mp_"+prop+".value());\n";
+ }else{
+ if(cls.propertyIsObject(prop)){
+ scd+="\t\tr.appendChild(mp_"+prop+".toXml"+var+"(doc,\""+prop+"\"));\n";
+ }else
+ if(cls.propertyIsString(prop)){
+ scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n";
+ scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+"));\n";
+ scd+="\t\tr.appendChild(el);\n";
+ }else{
+ qDebug("Error: cannot generate serializer for class %s property %s.",cls.name().toAscii().data(),prop.toAscii().data());
+ emit errorFound();
+ return;
+ }
+ }
+ scd+="\t}\n";
+ }
+ }
+ scd+="\treturn r;\n}\n";
+ }
+ hdr.write(hcd.toAscii());
+ src.write(scd.toAscii());
}
void WocQtClientOut::newTransaction(const WocTransaction&trn)