return;
}
tf.write(PHPSTART);
+
+ ////
//generate code
- QString code="class "+cna+" extends "+cls.baseClass()+"{\n";
+ QString code="class "+cna+" extends "+cls.baseClass()+"{\n\n";
+
//implement enums
+ QStringList k=cls.enumTypes();
+ for(int i=0;i<k.size();i++){
+ QList<QPair<QString,int> >ev=cls.enumValues(k[i]);
+ for(int j=0;j<ev.size();j++)
+ code+="const "+ev[j].first+"="+QString::number(ev[j].second)+";\n";
+ }
+
//implement properties
//implement mappings
//implement serializers
+ k=cls.serializers();
+ for(int i=0;i<k.size();i++){
+ code+="\nfunction toString"+k[i]+"(){\n\t$xml=new DomDocument;\n";
+ code+="\t$xml->appendChild($this->toXml"+k[i]+"($xml));\n\treturn $xml->saveXml();\n}\n";
+ code+="function toXml"+k[i]+"($xml){\n\t$root=$xml->createElement(\""+cls.name()+k[i]+"\");\n";
+ //TODO: add properties
+ code+="\treturn $root;\n}\n";
+ }
//implement de-serializer
+ code+="\nstatic function fromString($txt){\n\t$xml=new DomDocument;\n";
+ code+="\t$xml->loadXml(trim($txt));\n\treturn self::fromXml($xml,$xml->documentElement);\n}\n";
+ code+="static function fromXml($xml,$elem){\n\t$data=array();\n";
+ k=cls.propertyNames();
+ for(int i=0;i<k.size();i++){
+ //TODO: scan properties
+ code+="\t??\n";
+ }
+ code+="\treturn $ret;\n}\n";
+
+ //end of class
+ code+="\n//end of class\n};\n";
+
- code+="};\n";
//write & close
tf.write(code.toAscii());
tf.write(PHPEND);
QDomElement el=nl.at(i).toElement();
if(el.isNull())continue;
QString nm=el.attribute("name");
+ if(!symok.exactMatch(nm)){
+ qDebug("Error: Illegal enum type %s in class %s.",nm.toAscii().data(),m_name.toAscii().data());
+ m_valid=false;
+ return;
+ }
+ if(hasEnumType(nm)){
+ qDebug("Error: Double definition of enum type %s in class %s.",nm.toAscii().data(),m_name.toAscii().data());
+ m_valid=false;
+ return;
+ }
QList<QPair<QString,int> >ev;
//check whether there is a reference
if(el.hasAttribute("refColumn")){
nxval=el2.attribute("value",QString::number(nxval)).toInt(0,0);
ev.append(QPair<QString,int>(n,nxval));
nxval++;
+ //TODO: check that value name does not exist yet
}
m_enumvals.insert(nm,ev);
}
for(int i=0;i<nl.size();i++){
QDomElement el=nl.at(i).toElement();
if(el.isNull())continue;
- QString name=el.attribute("name");
+ QString name=el.attribute("table");
+ if(!symok.exactMatch(name)){
+ qDebug("Error: Illegal mapping %s in class %s.",name.toAscii().data(),m_name.toAscii().data());
+ m_valid=false;
+ return;
+ }
+ if(hasMapping(name)){
+ qDebug("Error: Double definition of mapping %s in class %s.",name.toAscii().data(),m_name.toAscii().data());
+ m_valid=false;
+ return;
+ }
QList<QPair<QString,QString> >map;
QDomNodeList nl2=el.elementsByTagName("Map");
for(int j=0;j<nl2.size();j++){
}
m_maps.insert(name,map);
}
+ //scan serializers
+ nl=cls.elementsByTagName("ToXml");
+ for(int i=0;i<nl.size();i++){
+ QDomElement el=nl.at(i).toElement();
+ if(el.isNull())continue;
+ QString name=el.attribute("name");
+ if(!symok.exactMatch(name)){
+ qDebug("Error: Illegal serializer %s in class %s.",name.toAscii().data(),m_name.toAscii().data());
+ m_valid=false;
+ return;
+ }
+ if(hasSerializer(name)){
+ qDebug("Error: Double definition of serializer %s in class %s.",name.toAscii().data(),m_name.toAscii().data());
+ m_valid=false;
+ return;
+ }
+ QStringList prop=el.text().split(" ",QString::SkipEmptyParts);
+ //TODO: check that properties exist
+ m_serial.insert(name,prop);
+ }
//check abstraction
if(!m_abstract && isAbstract()){
qDebug("Warning: class %s should be declared abstract.",m_name.toAscii().data());
return m_abstract;
}
+QStringList WocClass::propertyNames()const
+{
+ QStringList r;
+ for(int i=0;i<m_props.size();i++)
+ r<<m_props[i].name;
+ return r;
+}
+
+QString WocClass::propertyType(QString p)const
+{
+ for(int i=0;i<m_props.size();i++)
+ if(p==m_props[i].name)
+ return m_props[i].type;
+ return "";
+}
+
+bool WocClass::propertyIsId(QString p)const
+{
+ for(int i=0;i<m_props.size();i++)
+ if(p==m_props[i].name)
+ return m_props[i].isid;
+ return false;
+}
+
+bool WocClass::propertyIsAbstract(QString p)const
+{
+ for(int i=0;i<m_props.size();i++)
+ if(p==m_props[i].name)
+ return m_props[i].isabstract;
+ return false;
+}
+
/******************************************************************************
* WocTable
#include <QMap>
#include <QObject>
#include <QPair>
+#include <QStringList>
class QDomElement;
QString baseClass()const{return m_base;}
bool hasProperty(QString)const;
+ QStringList propertyNames()const;
+ QString propertyType(QString)const;
+ bool propertyIsId(QString)const;
+ bool propertyIsAbstract(QString)const;
bool isAbstract()const;
+ QStringList enumTypes()const{return m_enumvals.keys();}
+ bool hasEnumType(QString t)const{return m_enumvals.contains(t);}
+ QList<QPair<QString,int> > enumValues(QString t)const{return m_enumvals[t];}
+
+ QStringList serializers()const{return m_serial.keys();}
+ bool hasSerializer(QString s)const{return m_serial.contains(s);}
+ QStringList serializerProperties(QString s)const{return m_serial[s];}
+
+ bool hasMapping(QString m)const{return m_maps.contains(m);}
+
private:
bool m_valid,m_abstract;
QString m_name,m_base;
QList<s_prop> m_props;
QMap<QString,QList<QPair<QString,QString> > >m_maps;
QMap<QString,QList<QPair<QString,int> > >m_enumvals;
+ QMap<QString,QStringList>m_serial;
};
class WocTable