From 234799c9b89f9debdba7936d765679c0449dd4a2 Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 28 Jul 2010 06:37:23 +0000 Subject: [PATCH] move targets and processor into separate dirs git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@576 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- woc/php/php.pri | 16 ++ woc/php/phpclass.cpp | 531 ++++++++++++++++++++++++++++++++++++++++++++++++ woc/php/phpclass.h | 67 ++++++ woc/php/phpconst.h | 34 +++ woc/php/phpctrans.cpp | 171 ++++++++++++++++ woc/php/phpctrans.h | 34 +++ woc/php/phpdb.cpp | 221 ++++++++++++++++++++ woc/php/phpdb.h | 35 ++++ woc/php/phpout.cpp | 106 ++++++++++ woc/php/phpout.h | 85 ++++++++ woc/php/phpstrans.cpp | 207 +++++++++++++++++++ woc/php/phpstrans.h | 36 ++++ woc/php/phptrans.cpp | 251 +++++++++++++++++++++++ woc/php/phptrans.h | 51 +++++ woc/phpclass.cpp | 531 ------------------------------------------------ woc/phpclass.h | 67 ------ woc/phpconst.h | 34 --- woc/phpctrans.cpp | 171 ---------------- woc/phpctrans.h | 34 --- woc/phpdb.cpp | 221 -------------------- woc/phpdb.h | 35 ---- woc/phpout.cpp | 106 ---------- woc/phpout.h | 85 -------- woc/phpstrans.cpp | 207 ------------------- woc/phpstrans.h | 36 ---- woc/phptrans.cpp | 251 ----------------------- woc/phptrans.h | 51 ----- woc/proc/proc.pri | 12 + woc/proc/procclass.cpp | 332 ++++++++++++++++++++++++++++++ woc/proc/procclass.h | 141 +++++++++++++ woc/proc/processor.cpp | 354 ++++++++++++++++++++++++++++++++ woc/proc/processor.h | 152 ++++++++++++++ woc/proc/proctable.cpp | 448 ++++++++++++++++++++++++++++++++++++++++ woc/proc/proctable.h | 124 +++++++++++ woc/proc/proctrans.cpp | 191 +++++++++++++++++ woc/proc/proctrans.h | 123 +++++++++++ woc/procclass.cpp | 332 ------------------------------ woc/procclass.h | 141 ------------- woc/processor.cpp | 354 -------------------------------- woc/processor.h | 152 -------------- woc/proctable.cpp | 448 ---------------------------------------- woc/proctable.h | 124 ----------- woc/proctrans.cpp | 191 ----------------- woc/proctrans.h | 123 ----------- woc/qt/qt.pri | 15 ++ woc/qt/qtclass.cpp | 374 ++++++++++++++++++++++++++++++++++ woc/qt/qtclass.h | 46 ++++ woc/qt/qtconst.h | 51 +++++ woc/qt/qtctrans.cpp | 330 ++++++++++++++++++++++++++++++ woc/qt/qtctrans.h | 38 ++++ woc/qt/qtdb.cpp | 21 ++ woc/qt/qtdb.h | 34 +++ woc/qt/qtout.cpp | 211 +++++++++++++++++++ woc/qt/qtout.h | 88 ++++++++ woc/qt/qtstrans.cpp | 24 +++ woc/qt/qtstrans.h | 29 +++ woc/qtclass.cpp | 374 ---------------------------------- woc/qtclass.h | 46 ---- woc/qtconst.h | 51 ----- woc/qtctrans.cpp | 330 ------------------------------ woc/qtctrans.h | 38 ---- woc/qtdb.cpp | 21 -- woc/qtdb.h | 34 --- woc/qtout.cpp | 211 ------------------- woc/qtout.h | 88 -------- woc/qtstrans.cpp | 24 --- woc/qtstrans.h | 29 --- woc/woc.pro | 37 +--- 68 files changed, 4990 insertions(+), 4970 deletions(-) create mode 100644 woc/php/php.pri create mode 100644 woc/php/phpclass.cpp create mode 100644 woc/php/phpclass.h create mode 100644 woc/php/phpconst.h create mode 100644 woc/php/phpctrans.cpp create mode 100644 woc/php/phpctrans.h create mode 100644 woc/php/phpdb.cpp create mode 100644 woc/php/phpdb.h create mode 100644 woc/php/phpout.cpp create mode 100644 woc/php/phpout.h create mode 100644 woc/php/phpstrans.cpp create mode 100644 woc/php/phpstrans.h create mode 100644 woc/php/phptrans.cpp create mode 100644 woc/php/phptrans.h delete mode 100644 woc/phpclass.cpp delete mode 100644 woc/phpclass.h delete mode 100644 woc/phpconst.h delete mode 100644 woc/phpctrans.cpp delete mode 100644 woc/phpctrans.h delete mode 100644 woc/phpdb.cpp delete mode 100644 woc/phpdb.h delete mode 100644 woc/phpout.cpp delete mode 100644 woc/phpout.h delete mode 100644 woc/phpstrans.cpp delete mode 100644 woc/phpstrans.h delete mode 100644 woc/phptrans.cpp delete mode 100644 woc/phptrans.h create mode 100644 woc/proc/proc.pri create mode 100644 woc/proc/procclass.cpp create mode 100644 woc/proc/procclass.h create mode 100644 woc/proc/processor.cpp create mode 100644 woc/proc/processor.h create mode 100644 woc/proc/proctable.cpp create mode 100644 woc/proc/proctable.h create mode 100644 woc/proc/proctrans.cpp create mode 100644 woc/proc/proctrans.h delete mode 100644 woc/procclass.cpp delete mode 100644 woc/procclass.h delete mode 100644 woc/processor.cpp delete mode 100644 woc/processor.h delete mode 100644 woc/proctable.cpp delete mode 100644 woc/proctable.h delete mode 100644 woc/proctrans.cpp delete mode 100644 woc/proctrans.h create mode 100644 woc/qt/qt.pri create mode 100644 woc/qt/qtclass.cpp create mode 100644 woc/qt/qtclass.h create mode 100644 woc/qt/qtconst.h create mode 100644 woc/qt/qtctrans.cpp create mode 100644 woc/qt/qtctrans.h create mode 100644 woc/qt/qtdb.cpp create mode 100644 woc/qt/qtdb.h create mode 100644 woc/qt/qtout.cpp create mode 100644 woc/qt/qtout.h create mode 100644 woc/qt/qtstrans.cpp create mode 100644 woc/qt/qtstrans.h delete mode 100644 woc/qtclass.cpp delete mode 100644 woc/qtclass.h delete mode 100644 woc/qtconst.h delete mode 100644 woc/qtctrans.cpp delete mode 100644 woc/qtctrans.h delete mode 100644 woc/qtdb.cpp delete mode 100644 woc/qtdb.h delete mode 100644 woc/qtout.cpp delete mode 100644 woc/qtout.h delete mode 100644 woc/qtstrans.cpp delete mode 100644 woc/qtstrans.h diff --git a/woc/php/php.pri b/woc/php/php.pri new file mode 100644 index 0000000..93f22a7 --- /dev/null +++ b/woc/php/php.pri @@ -0,0 +1,16 @@ +SOURCES+= \ + php/phpout.cpp \ + php/phpclass.cpp \ + php/phptrans.cpp \ + php/phpctrans.cpp \ + php/phpstrans.cpp \ + php/phpdb.cpp +HEADERS+= \ + php/phpout.h \ + php/phpdb.h \ + php/phpclass.h \ + php/phptrans.h \ + php/phpctrans.h \ + php/phpstrans.h + +INCLUDEPATH += php diff --git a/woc/php/phpclass.cpp b/woc/php/phpclass.cpp new file mode 100644 index 0000000..d7bb590 --- /dev/null +++ b/woc/php/phpclass.cpp @@ -0,0 +1,531 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "phpout.h" +#include "phpclass.h" + +#include +#include + +#include "phpconst.h" + +WocPHPClass::WocPHPClass(WocPHPOut* p) +{ + m_parent=p; + connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); +} + +void WocPHPClass::finalize() +{ +} + +void WocPHPClass::newClass(const WocClass&cls) +{ + //cover basics + QString cn=className(cls); + QString cna=abstractClassName(cls); + QString fn="wo_"+cls.name(); + addLoad(cna,fn); + fn=m_subdir+"/"+fn+m_fileext; + QFile tf(m_basedir+"/"+fn); + if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){ + qDebug("Error: cannot create PHP object file %s.",fn.toAscii().data()); + emit errorFound(); + return; + } + tf.write(PHPSTART); + + //// + //generate code + QString code="/* TRANSLATOR "+cna+" */\nclass "+cna+" extends "+cls.serverBaseClass()+"{\n\n"; + tf.write(code.toAscii()); + + //property declaration and constructor + tf.write(classConstruct(cls).toAscii()); + + //enums + tf.write(classEnums(cls).toAscii()); + + //properties + tf.write(classProperties(cls).toAscii()); + + //mappings + tf.write(classMappings(cls).toAscii()); + + //serializers + tf.write(classSerializers(cls).toAscii()); + + //de-serializer + tf.write(classDeserializers(cls).toAscii()); + + //prop to array conversion + tf.write(classPropertiesList(cls).toAscii()); + + //end of class + code="\n//end of class\n};\n"; + tf.write(code.toAscii()); + + tf.write(PHPEND); + tf.close(); +} + +QString WocPHPClass::classConstruct(const WocClass&cls) +{ + QString code; + QStringList k=cls.propertyNames(); + for(int i=0;iev=cls.enumValues(k[i]); + for(int j=0;jprop_"+k[i]+";}\n"; + //is it a list? + if(cls.propertyIsList(k[i])){ + //lists... + //getters + code+=classPropertyListGetters(cls,k[i]); + //setters + code+=classPropertyListSetters(cls,k[i]); + }else{ + //non-lists... + //getters + code+=classPropertyScalarGetters(cls,k[i]); + //setter + code+=classPropertyScalarSetters(cls,k[i]); + } + } + + return code; +} + +QString WocPHPClass::classPropertiesList(const WocClass&cls) +{ + QString code; + QStringList k=cls.propertyNames(); + code+="public function propertyArray(){\n\treturn array("; + for(int i=0;i"; + //is it a list? + if(cls.propertyIsList(k[i])){ + //lists... + //object? + if(cls.propertyIsObject(k[i])) + code+="array_map(\"WObject::objectToArray\",$this->prop_"+k[i]+")"; + else + code+="$this->prop_"+k[i]; + }else{ + //non-lists... + //object? + if(cls.propertyIsObject(k[i])) + code+="WObject::objectToArray($this->prop_"+k[i]+")"; + else + code+="$this->prop_"+k[i]; + } + } + code+=");\n}\n"; + + return code; +} + +QString WocPHPClass::classPropertyValidator(const WocClass&cls,QString prop) +{ + QString code; + code+="static public function validate"+prop+"($value){\n"; + if(cls.propertyIsEnum(prop)){ + QListev=cls.enumValues(cls.propertyPlainType(prop)); + code+="\tif(is_numeric($value)){\n\t\t$value=$value+0;\n"; + for(int j=0;jprop_"+prop+";}\n"; + else + if(cls.propertyIsBlob(prop)){ + code+="public function getstrlist_"+prop+"(){\n\t$ret=array();\n"; + code+="\tforeach($this->prop_"+prop+" as $p)$ret[]=base64_encode($this->prop_"+prop+");"; + code+="\treturn $ret;\n}\n"; + }else + if(cls.propertyIsInt(prop)){ + code+="public function getstrlist_"+prop+"(){\n"; + code+="\t$ret=array();\n\tforeach($this->prop_"+prop+" as $p)$ret[]=\"\".$p;\n"; + code+="\treturn $ret;\n}\n"; + }else + if(cls.propertyIsBool(prop)){ + code+="public function getstrlist_"+prop+"(){\n"; + code+="\t$ret=array();\n\tforeach($this->prop_"+prop+" as $p)$ret[]=$p?\"yes\":\"no\";\n"; + code+="\treturn $ret;\n}\n"; + }else + if(cls.propertyIsEnum(prop)){ + code+="public function getstrlist_"+prop+"(){\n"; + code+="\t$ret=array();\n"; + code+="\tforeach($this->prop_"+prop+" as $p)switch($p){\n"; + QList ev=cls.enumValues(cls.propertyPlainType(prop)); + for(int j=0;jprop_"+prop+"=array();}\n"; + QString acode;//body of add_ function, see below + code+="public function set"+prop+"(array $values){\n"; + if(cls.propertyIsEnum(prop)){ + QListev=cls.enumValues(cls.propertyPlainType(prop)); + code+="\t$prop=array();\n"; + code+="\tforeach($values as $value){\n"; + code+="\t\tif(is_numeric($value)){\n\t\t\t$value=$value+0;\n"; + acode+="\tif(is_numeric($value)){\n\t\t$value=$value+0;\n"; + for(int j=0;jprop_"+prop+";}\n"; + else + if(cls.propertyIsBlob(prop)) + code+="public function getstr_"+prop+"(){return base64_encode($this->prop_"+prop+");}\n"; + else + if(cls.propertyIsInt(prop)) + code+="public function getstr_"+prop+"(){return \"\".$this->prop_"+prop+";}\n"; + else + if(cls.propertyIsBool(prop)) + code+="public function getstr_"+prop+"(){return $this->prop_"+prop+"?\"yes\":\"no\";}\n"; + else + if(cls.propertyIsEnum(prop)){ + code+="public function getstr_"+prop+"(){\n\tswitch($this->prop_"+prop+"){\n"; + QList ev=cls.enumValues(cls.propertyPlainType(prop)); + for(int j=0;jev=cls.enumValues(cls.propertyPlainType(prop)); + code+="\tif(is_numeric($value)){\n\t\t$value=$value+0;\n"; + for(int j=0;jprop_"+prop+"=true;else\n"; + code+="\tif($value==\"no\")$this->prop_"+prop+"=false;\n\telse return false;\n"; + code+="\treturn true;\n"; + }else + if(cls.propertyIsString(prop)||cls.propertyIsBlob(prop)) + code+="\t$this->prop_"+prop+"=\"\".$value;\n\treturn true;\n"; + //TODO: special handling for astring + //TODO: do something about Blob + else + if(cls.propertyIsObject(prop)){ + code+="\tif(is_a($value,\"WO"+cls.propertyPlainType(prop)+"\")){\n"; + code+="\t\t$this->prop_"+prop+"=$value;\n"; + code+="\t\treturn true;\n\t}\n"; + }else{ + qDebug("Warning: unable to generate setter for class %s property %s: unknown type.",cls.name().toAscii().data(),prop.toAscii().data()); + code+="\treturn false;\n"; + } + code+="}\n"; + + return code; +} + +QString WocPHPClass::classSerializers(const WocClass&cls) +{ + QString code; + //toString function (wraps toXml) + code+="\npublic function toString(){\n\t$xml=new DomDocument;\n"; + code+="\t$xml->appendChild($this->toXml($xml));\n\treturn $xml->saveXml();\n}\n"; + //toXml function: + code+="public function toXml($xml,$elementname=\""+cls.name()+"\"){\n"; + code+="\t$root=$xml->createElement($elementname);\n"; + //add properties + QStringList p=cls.propertyNames(); + for(int j=0;jtextContent));\n"; + }else{ + code+="\t\t$data->add_"+k[i]+"($el->textContent);\n"; + } + code+="\t}\n"; + }else{ + if(cls.propertyIsObject(k[i])){ + code+="\tforeach(WObject::elementsByTagName($elem,\""+k[i]+"\") as $el){\n"; + code+="\t\t$data->set"+k[i]+"(WO"+cls.propertyPlainType(k[i])+"::fromXml($xml,$el));\n"; + code+="\t}\n"; + }else + if(cls.propertyIsAttribute(k[i])){ + code+="\tif($elem->hasAttribute(\""+k[i]+"\"))\n"; + code+="\t\t$data->set"+k[i]+"($elem->getAttribute(\""+k[i]+"\"));\n"; + }else{ + code+="\tforeach(WObject::elementsByTagName($elem,\""+k[i]+"\") as $el){\n"; + if(cls.propertyIsBlob(k[i])) + code+="\t\t$data->set"+k[i]+"(base64_decode($el->textContent));\n"; + else + code+="\t\t$data->set"+k[i]+"($el->textContent);\n"; + code+="\t}\n"; + } + } + } + code+="\treturn $data;\n}\n"; + return code; +} + +QString WocPHPClass::classMappings(const WocClass&cls) +{ + //don't do it for client mode (clients do not have a DB) + if(m_parent->ptable==0)return QString(); + //implement mappings + QString code; + QStringList k=cls.mappingTables(); + for(int i=0;itable(k[i]); + //single object mapping + code+="\nstatic public function fromTable"+k[i]+"($table){\n"; + code+="\tif($table === false)return false;\n"; + code+="\t$data=new WO"+cls.name()+"();\n"; + QMapmap=cls.mapping(k[i]); + QStringList mapk=cls.mappingProperties(k[i]); + for(int j=0;j"+map[mapk[j]]+";\n"; + } + code+="\treturn $data;\n}\n"; + //wrapper for multi-object mapping + code+="static public function fromTableArray"+k[i]+"(array $table){\n\t$ret=array();\n"; + code+="\tfor($i=0;$i"+map[mapk[j]]+"!=$this->prop_"+mapk[j]+")\n"; + code+="\t\t$table->"+map[mapk[j]]+"=$this->prop_"+mapk[j]+";\n"; + } + } + code+="\treturn $table;\n}\n"; + } + + return code; +} + +QString WocPHPClass::propertyToXml(const WocClass&cls,QString sl) +{ + QString prop=sl.trimmed(); + //is it a list? + if(cls.propertyIsList(prop)){ + //is it a class? + if(cls.propertyIsObject(prop)){ + QString code="\tforeach($this->get"+prop+"() as $o)\n\t\t"; + code+="$root->appendChild($o->toXml($xml,\""+prop+"\"));\n"; + return code; + }else{ + //there is no way to create lists of attributes, hence we always create elements + QString code="\tforeach($this->getstrlist_"+prop+"() as $e)\n\t\t"; + code+="$root->appendChild($xml->createElement(\""+prop+"\",xq($e)));\n"; + return code; + } + } + //non lists: + QString code="\t$p=$this->get"+prop+"();\n"; + //is it an attribute? + if(cls.propertyIsAttribute(prop)) + return code+"\tif($p!==null)$root->setAttribute(\""+prop+"\",$this->getstr_"+prop+"());\n"; + //is it an element? + if(cls.propertyIsElement(prop)) + return code+"\tif($p!==null)$root->appendChild($xml->createElement(\""+prop+"\",xq($this->getstr_"+prop+"())));\n"; + //is it a class? + if(cls.propertyIsObject(prop)) + return code+"\tif(is_a($p,\"WO"+cls.propertyPlainType(prop)+"\"))$root->appendChild($p->toXml($xml,\""+prop+"\"));\n"; + //anything else? + qDebug("Warning: end of WocPHPClass::propertyToXml - this code should not be reachable."); + return "//internal generator error!\n"; +} diff --git a/woc/php/phpclass.h b/woc/php/phpclass.h new file mode 100644 index 0000000..fc67a26 --- /dev/null +++ b/woc/php/phpclass.h @@ -0,0 +1,67 @@ +// +// C++ Interface: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHPOUT_CLASS_H +#define WOC_PHPOUT_CLASS_H + + +class WocPHPOut; +class WocClass; + +#include + +/**generates output for a PHP server side*/ +class WocPHPClass:public QObject +{ + Q_OBJECT + public: + /**initializes the output object*/ + WocPHPClass(WocPHPOut*); + /**writes any last words after parsing finished*/ + virtual void finalize(); + /**creates a class*/ + virtual void newClass(const WocClass&); + + protected: + WocPHPOut*m_parent; + + /**helper: generates PHP code to transform a class property to XML*/ + QString propertyToXml(const WocClass&,QString); + /**helper: generate class constructor*/ + QString classConstruct(const WocClass&); + /**helper: generate class internal enums*/ + QString classEnums(const WocClass&); + /**helper: generate class internal props*/ + QString classProperties(const WocClass&); + /**helper: generate class internal serializers*/ + QString classSerializers(const WocClass&); + /**helper: generate class internal deserializers*/ + QString classDeserializers(const WocClass&); + /**helper: generate class internal mappers*/ + QString classMappings(const WocClass&); + /**helper: generate property validator*/ + QString classPropertyValidator(const WocClass&,QString); + /**helper: generate getters for list properties*/ + QString classPropertyListGetters(const WocClass&,QString); + /**helper: generate setters for list properties*/ + QString classPropertyListSetters(const WocClass&,QString); + /**helper: generate getters for scalar properties*/ + QString classPropertyScalarGetters(const WocClass&,QString); + /**helper: generate setters for sclar properties*/ + QString classPropertyScalarSetters(const WocClass&,QString); + /**helper: generate the property to array converter, eg. for renderers like for Twig*/ + QString classPropertiesList(const WocClass&); + signals: + void errorFound(); +}; + +#endif diff --git a/woc/php/phpconst.h b/woc/php/phpconst.h new file mode 100644 index 0000000..d7b3036 --- /dev/null +++ b/woc/php/phpconst.h @@ -0,0 +1,34 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHP_CONST_H +#define WOC_PHP_CONST_H + +static const QByteArray PHPSTART(""); + +#ifndef WOC_PHP_NO_WRAP +#define m_basedir m_parent->m_basedir +#define m_subdir m_parent->m_subdir +#define m_fileext m_parent->m_fileext +#define m_transbase m_parent->m_transbase +#define m_loader m_parent->m_loader +#define m_schema m_parent->m_schema +#define m_transact m_parent->m_transact +#define className m_parent->className +#define abstractClassName m_parent->abstractClassName +#define trnClassName m_parent->trnClassName +#define addLoad m_parent->addLoad +#define m_lang m_parent->m_lang +#endif + +#endif diff --git a/woc/php/phpctrans.cpp b/woc/php/phpctrans.cpp new file mode 100644 index 0000000..53fc835 --- /dev/null +++ b/woc/php/phpctrans.cpp @@ -0,0 +1,171 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "phpout.h" +#include "phpctrans.h" + +#include +#include + +#include "phpconst.h" + +WocPHPClientTransaction::WocPHPClientTransaction(WocPHPOut*p ) + :WocPHPTransaction(p) +{ +} + +QString WocPHPClientTransaction::trnHandlers(const WocTransaction&trn) +{ + //create file + QString cn=trnClassName(trn); + QString fn="wtr_"+trn.name(); + + //// + //generate code + QString code; + + //request handler: + code="public function handleRequest(){\n"; + code+="\t$this->startTransaction("+QString(trn.isDbUpdating()?"true":"false")+");\n"; + + //security handling + switch(trn.authMode()){ + case WocTransaction::Checked: + code+="\t/*security check: authenticated and authorized*/\n"; + code+="\tif(!$this->isAuthorized(\""+trn.name()+"\""+"))$this->notAuthenticated();\n"; + break; + case WocTransaction::Auth: + code+="\t/*security check: authenticated*/\n"; + code+="\tif(!$this->isAuthenticated())$this->notAuthenticated();\n"; + break; + default: + code+="\t/*no security check, open function*/\n"; + break;//none + } + + //parse low level XML + code+="\t/*low level XML parsing*/\n"; + code+="\tglobal $HTTP_RAW_POST_DATA;\n\tif(isset($HTTP_RAW_POST_DATA))$txt=$HTTP_RAW_POST_DATA;else $txt=\"\";\n"; + code+="\t$xml=new DOMDocument;\n\tif(!$xml->loadXML($txt))$this->xmlParserError();\n"; + code+="\t$root=$xml->documentElement;\n"; + + //parse inputs + code+=trnInput(trn); + + //call + if(trn.hasCall(m_lang)){ + code+="\t/*call actual functionality:*/\n"; + code+="\ttry{"+trn.callFunction(m_lang)+"}catch(Exception $e){$this->handleException($e);}\n"; + }else{ + code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n"; + code+="\t$this->abortNotImplemented();\nreturn;\n"; + qDebug("Warning: transaction %s does not have a PHP call!",trn.name().toAscii().data()); + } + + //encode outputs/handle errors + code+=trnOutput(trn); + + code+="\t$this->commitTransaction();\n}\n"; + + return code; +} + +QString WocPHPClientTransaction::trnInput(const WocTransaction&trn) +{ + QString code="\t/*start of input parsing*/\n"; + code+="\ttry{\n"; + QStringList sl=trn.inputNames(); + for(int i=0;igetAttribute(\""+sl[i]+"\")"; + if(trn.isIntType(t))code+="+0"; + if(trn.isBoolType(t))code+="==\"yes\""; + code+=";\n"; + }else{ + if(trn.isListType(t)){ + QString pt=trn.plainType(t); + code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; + if(trn.isObjectType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=WO"+pt+"::fromXml($xml,$el);\n"; + }else if(trn.isBlobType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=base64_decode($el->textContent);\n"; + }else{ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=$el->textContent"; + if(trn.isIntType(t))code+="+0"; + if(trn.isBoolType(t))code+="==\"yes\""; + code+=";\n"; + } + code+="\t\t}\n"; + }else{ + code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; + if(trn.isObjectType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=WO"+t+"::fromXml($xml,$el);\n"; + }else if(trn.isBlobType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=base64_decode($el->textContent);\n"; + }else{ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=$el->textContent"; + if(trn.isIntType(t))code+="+0"; + code+=";\n"; + } + code+="\t\t}\n"; + } + } + } + code+="\t}catch(Exception $e){$this->handleException($e);}\n"; + code+="\t/*end of input parsing*/\n"; + return code; +} + +QString WocPHPClientTransaction::trnOutput(const WocTransaction&trn) +{ + QStringList sl=trn.outputNames(); + QString code="\t/*start of output encoding*/\n"; + code+="\ttry{\n\t\t$xml=new DOMDocument;\n"; + code+="\t\t$root=$xml->createElement(\"WobResponse-"+trn.name()+"\");\n"; + for(int i=0;iaoutput[\""+sl[i]+"\"]);\n"; + }else{ + if(trn.isListType(t)){ + if(trn.isObjectType(t)){ + code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $o)\n"; + code+="\t\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; + code+="\t\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; + }else if(trn.isBlobType(t)){ + code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; + code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($v)));\n"; + }else{ + code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; + code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($v)));\n"; + } + }else{ + if(trn.isObjectType(t)){ + code+="\t\t$o=$this->aoutput[\""+sl[i]+"\"];\n"; + code+="\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; + code+="\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; + }else if(trn.isBlobType(t)){ + code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($this->aoutput[\""+sl[i]+"\"])));\n"; + }else{ + code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($this->aoutput[\""+sl[i]+"\"])));\n"; + } + } + } + } + code+="\t\t$xml->appendChild($root);\n"; + code+="\t\theader(\"X-WobResponse-Status: Ok\");\n"; + code+="\t\tprint($xml->saveXml());\n"; + code+="\t}catch(Exception $e){$this->handleException($e);}\n"; + code+="\t/*end of output*/\n"; + return code; +} diff --git a/woc/php/phpctrans.h b/woc/php/phpctrans.h new file mode 100644 index 0000000..0e1a700 --- /dev/null +++ b/woc/php/phpctrans.h @@ -0,0 +1,34 @@ +// +// C++ Interface: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHPOUT_CTRANS_H +#define WOC_PHPOUT_CTRANS_H + +#include "phptrans.h" + + +/**generates output for a PHP server side*/ +class WocPHPClientTransaction:public WocPHPTransaction +{ + public: + /**initializes the output object*/ + WocPHPClientTransaction(WocPHPOut*); + private: + /**helper: create transaction constructor*/ + QString trnHandlers(const WocTransaction&); + /**helper: create transaction input parser*/ + QString trnInput(const WocTransaction&); + /**helper: create transaction output serializer*/ + QString trnOutput(const WocTransaction&); +}; + +#endif diff --git a/woc/php/phpdb.cpp b/woc/php/phpdb.cpp new file mode 100644 index 0000000..c60f489 --- /dev/null +++ b/woc/php/phpdb.cpp @@ -0,0 +1,221 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "phpout.h" +#include "phpdb.h" + +#include + +#include "phpconst.h" + +static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nfunction __construct(){\n\tparent::__construct();\n"); +static const QByteArray SCHEMAEND("}};\n"); + +WocPHPTable::WocPHPTable(WocPHPOut* p) + :m_parent(p) +{ + connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); + + //create schema file + m_schema.setFileName(m_basedir+"/"+m_subdir+"/schema"+m_fileext); + if(!m_schema.open(QIODevice::ReadWrite|QIODevice::Truncate)){ + qDebug("Error: PHP Server Generator - cannot create DB schema file."); + emit errorFound(); + return; + } + m_schema.write(PHPSTART); + m_schema.write(SCHEMASTART); + m_schema.write(("\tself::$sversion=\""+WocProcessor::instance()->dbVersion()+"\";\n").toAscii()); + addLoad("WobSchema","schema"); +} + +void WocPHPTable::finalize() +{ + if(m_schema.isOpen()){ + m_schema.write(SCHEMAEND); + m_schema.write(PHPEND); + m_schema.close(); + } +} + +void WocPHPTable::newTable(const WocTable&tbl) +{ + if(!m_loader.isOpen())return; + WocProcessor *woc=WocProcessor::instance(); + //create table file + QString fn=m_subdir+"/wt_"+tbl.name()+m_fileext; + QFile tf(m_basedir+"/"+fn); + if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){ + qDebug("Error: cannot create PHP table file %s.",fn.toAscii().data()); + emit errorFound(); + return; + } + tf.write(PHPSTART); + QString code="/* TRANSLATOR WT"+tbl.name()+" */\nclass WT"+tbl.name()+" extends "+tbl.baseClass()+"\n{\n"; + //initializer + code+="protected function __construct(array $data,$isfromdb){parent::__construct($data,$isfromdb,\""+tbl.name()+"\");}\n\n"; + + //static new instance for insert only + code+="public static function newRow(array $data=array()){return new WT"+tbl.name()+"($data,false);}\n\n"; + + //static get instance + QStringList cols=tbl.columns(); + QStringList pcols=tbl.primaryColumns(); + //header + code+="public static function getFromDB("; + for(int i=0;idbInst(); + //DB query + code+="){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",\""; + for(int i=0;iescapeColumn(\""+tbl.name()+"\",\""+pcols[i]+"\",$"+pcols[i]+").\""; + } + code+="\");\n"; + //check result + code+="\tif($res===false)return false;\n\tif(count($res)<1)return false;\n\telse return new WT"+tbl.name()+"($res[0],true);\n}\n\n"; + + //static get selection + code+="public static function selectFromDB($where=\"\",$orderby=\"\"){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",$where,$orderby);\n\tif($res===false || count($res)<1)return array();\n\t"; + code+="$r=array();\n\tforeach($res as $row)\n\t\t$r[]=new WT"+tbl.name()+"($row,true);\n\treturn $r;\n}\n\n"; + + //go through columns, generate specific code + for(int i=0;iescapeColumn(\""+foreign[0]+"\",\""+foreign[1]+"\",$this->"+cols[i]+"));\n}\n\n"; + } + //implement enum check for set method of enum columns + if(tbl.columnType(cols[i]).startsWith("enum")){ + code+="protected function verifyValue"+cols[i]+"($v){if(false"; + QListens=tbl.columnEnums(cols[i]); + QListenvs; + for(int j=0;jescapeColumn(\""; + code+=foreign[0]+"\",\""+foreign[1]+"\",$this->"+local+"));\n}\n\n"; + } + + //create enum constants + QListens=tbl.getEnums(); + for(int i=0;idata);\n"; + code+="\treturn $ad->insert();\n}\n"; + } + + //create newKey function + code+="public function newKey(){\n\tparent::newKey();\n"; + for(int i=0;iarray(\""; + code+=tbl.columnType(cols[i])+"\""; + if(!tbl.columnIsNull(cols[i]))code+=",\"notnull\""; + if(tbl.columnIsForeign(cols[i]))code+=",\"foreignkey:"+tbl.columnForeign(cols[i])+"\""; + if(pcols.size()<2 && tbl.columnIsPrimary(cols[i]))code+=",\"primarykey\""; + if(tbl.columnHasDefault(cols[i]))code+=",\"default:"+tbl.columnDefault(cols[i])+"\""; + if(tbl.columnIsIndexed(cols[i]))code+=",\"index\""; + if(tbl.columnIsUnique(cols[i]))code+=",\"unique\""; + code+=")"; + } + if(pcols.size()>=2){ + code+=",\n\t\t\":primarykey\"=>array("; + for(int i=0;i >presets=tbl.presets(); + if(presets.size()>0){ + code+="\tself::$preset[\""+tbl.name()+"\"]=array("; + for(int i=0;i"+presets[i][k[j]]; + } + code+=")"; + } + code+="\n\t);\n"; + } + + //write + m_schema.write(code.toAscii()); + + //create autoloading + addLoad("WT"+tbl.name(),"wt_"+tbl.name()); +} diff --git a/woc/php/phpdb.h b/woc/php/phpdb.h new file mode 100644 index 0000000..5c9193d --- /dev/null +++ b/woc/php/phpdb.h @@ -0,0 +1,35 @@ +// +// C++ Interface: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHPOUT_DB_H +#define WOC_PHPOUT_DB_H + +#include "phpout.h" + +/**generates output for a PHP server side*/ +class WocPHPTable:public QObject +{ + Q_OBJECT + public: + /**initializes the output object*/ + WocPHPTable(WocPHPOut*); + /**writes any last words after parsing finished*/ + virtual void finalize(); + /**creates a class*/ + virtual void newTable(const WocTable&); + private: + WocPHPOut*m_parent; + signals: + void errorFound(); +}; + +#endif diff --git a/woc/php/phpout.cpp b/woc/php/phpout.cpp new file mode 100644 index 0000000..eb2c54b --- /dev/null +++ b/woc/php/phpout.cpp @@ -0,0 +1,106 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "phpout.h" +#include "phpdb.h" +#include "phpctrans.h" +#include "phpstrans.h" +#include "phpclass.h" + +#include +#include + +#define WOC_PHP_NO_WRAP +#include "phpconst.h" + +static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nfunction __construct(){\n\tparent::__construct();\n"); +static const QByteArray SCHEMAEND("}};\n"); + +WocPHPServerOut::WocPHPServerOut(const QDomElement&el) + :WocPHPOut(el) +{ + m_lang="php/server"; + pclass=new WocPHPClass(this); + ptable=new WocPHPTable(this); + ptrans=new WocPHPServerTransaction(this); +} + +WocPHPClientOut::WocPHPClientOut(const QDomElement& el) + :WocPHPOut(el) +{ + m_lang="php/client"; + pclass=new WocPHPClass(this); + ptrans=new WocPHPClientTransaction(this); +} + + +WocPHPOut::WocPHPOut(const QDomElement&el) +{ + pclass=0;ptable=0;ptrans=0; + qDebug("Info: creating PHP Server Output Generator."); + m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir","."); + m_subdir=el.attribute("subDir","phpwob"); + m_fileext=el.attribute("extension",".inc"); + m_transbase=el.attribute("transactionBase","WobTransaction"); + //cleanup directory (remove normal files, assume remainder is harmless) + QDir d(m_basedir+"/"+m_subdir); + if(d.exists() && str2bool(el.attribute("clean","0"))){ + QStringList ent=d.entryList(QDir::Files); + for(int i=0;ifinalize(); + if(ptable)ptable->finalize(); + if(ptrans)ptrans->finalize(); + if(m_loader.isOpen()){ + m_loader.write(PHPEND); + m_loader.close(); + } +} + + +void WocPHPOut::addLoad(QString cn,QString fn) +{ + QString ld="wob_autoclass(\""+cn+"\",$d.\"/"+fn+m_fileext+"\");\n"; + m_loader.write(ld.toAscii()); +} + +void WocPHPOut::newTransaction(const WocTransaction&trn) +{ + if(ptrans)ptrans->newTransaction(trn); +} + +void WocPHPOut::newClass(const WocClass& cls) +{ + if(pclass)pclass->newClass(cls); +} + +void WocPHPOut::newTable(const WocTable& tbl) +{ + if(ptable)ptable->newTable(tbl); +} diff --git a/woc/php/phpout.h b/woc/php/phpout.h new file mode 100644 index 0000000..e9275d3 --- /dev/null +++ b/woc/php/phpout.h @@ -0,0 +1,85 @@ +// +// C++ Interface: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHPOUT_H +#define WOC_PHPOUT_H + +#include + +#include "processor.h" + +class QDomElement; + +class WocPHPOut; +class WocPHPClass; +class WocPHPTable; +class WocPHPTransaction; +class WocPHPClientTransaction; +class WocPHPServerTransaction; + +/**generates output for a PHP server side*/ +class WocPHPOut:public WocOutput +{ + public: + /**initializes the output object*/ + WocPHPOut(const QDomElement&); + protected: + /**writes any last words after parsing finished*/ + virtual void finalize(); + /**creates a class*/ + virtual void newClass(const WocClass&); + /**creates a table*/ + virtual void newTable(const WocTable&); + /**creates a transaction*/ + virtual void newTransaction(const WocTransaction&); + + friend class WocPHPClass; + friend class WocPHPTable; + friend class WocPHPTransaction; + friend class WocPHPClientTransaction; + friend class WocPHPServerTransaction; + + QString m_basedir,m_subdir,m_fileext; + QString m_transbase,m_lang; + QFile m_loader,m_schema,m_transact; + + /**helper: adds a loader line for a class to autoload.php*/ + void addLoad(QString classname,QString filename); + + WocPHPClass*pclass; + WocPHPTable*ptable; + WocPHPTransaction*ptrans; + + /**helper: return the PHP-class-name of a WocClass*/ + QString className(const WocClass&c){return "WO"+c.name();} + /**helper: return the PHP-class-name of a WocClass plus Abstract if it is abstract*/ + QString abstractClassName(const WocClass&c){return "WO"+c.name()+QString(c.isAbstract("php")?"Abstract":"");} + + /**helper: returns the PHP-class-name for a WocTransaction*/ + QString trnClassName(const WocTransaction&t){return "WTr"+t.name();} +}; + +class WocPHPServerOut:public WocPHPOut +{ + public: + /**initializes the output object*/ + WocPHPServerOut(const QDomElement&); +}; + +class WocPHPClientOut:public WocPHPOut +{ + public: + /**initializes the output object*/ + WocPHPClientOut(const QDomElement&); +}; + +#endif diff --git a/woc/php/phpstrans.cpp b/woc/php/phpstrans.cpp new file mode 100644 index 0000000..0043a96 --- /dev/null +++ b/woc/php/phpstrans.cpp @@ -0,0 +1,207 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "phpout.h" +#include "phpstrans.h" + +#include +#include + +#include "phpconst.h" + +WocPHPServerTransaction::WocPHPServerTransaction(WocPHPOut*p ) + :WocPHPTransaction(p) +{ +} + +QString WocPHPServerTransaction::trnHandlers(const WocTransaction&trn) +{ + //create file + QString cn=trnClassName(trn); + QString fn="wtr_"+trn.name(); + //// + //generate code + QString code; + //request handler: + code="public function handleRequest(){\n"; + code+="\t$this->startTransaction("+QString(trn.isDbUpdating()?"true":"false")+");\n"; + + //security handling + switch(trn.authMode()){ + case WocTransaction::Checked: + code+="\t/*security check: authenticated and authorized*/\n"; + code+="\tif(!$this->isAuthorized(\""+trn.name()+"\""+"))$this->notAuthenticated();\n"; + break; + case WocTransaction::Auth: + code+="\t/*security check: authenticated*/\n"; + code+="\tif(!$this->isAuthenticated())$this->notAuthenticated();\n"; + break; + default: + code+="\t/*no security check, open function*/\n"; + break;//none + } + + //parse low level XML + code+="\t/*low level XML parsing*/\n"; + code+="\tglobal $HTTP_RAW_POST_DATA;\n\tif(isset($HTTP_RAW_POST_DATA))$txt=$HTTP_RAW_POST_DATA;else $txt=\"\";\n"; + code+="\t$xml=new DOMDocument;\n\tif(!$xml->loadXML($txt))$this->xmlParserError();\n"; + code+="\t$root=$xml->documentElement;\n"; + + //parse inputs + code+=trnInput(trn); + + //call + if(trn.hasCall(m_lang)){ + code+="\t/*call actual functionality:*/\n"; + code+="\ttry{"+trn.callFunction(m_lang)+"}catch(Exception $e){$this->handleException($e);}\n"; + }else{ + code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n"; + code+="\t$this->abortNotImplemented();\nreturn;\n"; + qDebug("Warning: transaction %s does not have a PHP call!",trn.name().toAscii().data()); + } + + //encode outputs/handle errors + code+=trnOutput(trn); + + code+="\t$this->commitTransaction();\n}\n"; + + //direct execution + code+=trnExecute(trn).toAscii(); + + return code; +} + +QString WocPHPServerTransaction::trnInput(const WocTransaction&trn) +{ + QString code="\t/*start of input parsing*/\n"; + code+="\ttry{\n"; + QStringList sl=trn.inputNames(); + for(int i=0;igetAttribute(\""+sl[i]+"\")"; + if(trn.isIntType(t))code+="+0"; + if(trn.isBoolType(t))code+="==\"yes\""; + code+=";\n"; + }else{ + if(trn.isListType(t)){ + QString pt=trn.plainType(t); + code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; + if(trn.isObjectType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=WO"+pt+"::fromXml($xml,$el);\n"; + }else if(trn.isBlobType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=base64_decode($el->textContent);\n"; + }else{ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=$el->textContent"; + if(trn.isIntType(t))code+="+0"; + if(trn.isBoolType(t))code+="==\"yes\""; + code+=";\n"; + } + code+="\t\t}\n"; + }else{ + code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; + if(trn.isObjectType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=WO"+t+"::fromXml($xml,$el);\n"; + }else if(trn.isBlobType(t)){ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=base64_decode($el->textContent);\n"; + }else{ + code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=$el->textContent"; + if(trn.isIntType(t))code+="+0"; + code+=";\n"; + } + code+="\t\t}\n"; + } + } + } + code+="\t}catch(Exception $e){$this->handleException($e);}\n"; + code+="\t/*end of input parsing*/\n"; + return code; +} + +QString WocPHPServerTransaction::trnOutput(const WocTransaction&trn) +{ + QStringList sl=trn.outputNames(); + QString code="\t/*start of output encoding*/\n"; + code+="\ttry{\n\t\t$xml=new DOMDocument;\n"; + code+="\t\t$root=$xml->createElement(\"WobResponse-"+trn.name()+"\");\n"; + for(int i=0;iaoutput[\""+sl[i]+"\"]);\n"; + }else{ + if(trn.isListType(t)){ + if(trn.isObjectType(t)){ + code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $o)\n"; + code+="\t\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; + code+="\t\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; + }else if(trn.isBlobType(t)){ + code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; + code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($v)));\n"; + }else{ + code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; + code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($v)));\n"; + } + }else{ + if(trn.isObjectType(t)){ + code+="\t\t$o=$this->aoutput[\""+sl[i]+"\"];\n"; + code+="\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; + code+="\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; + }else if(trn.isBlobType(t)){ + code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($this->aoutput[\""+sl[i]+"\"])));\n"; + }else{ + code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($this->aoutput[\""+sl[i]+"\"])));\n"; + } + } + } + } + code+="\t\t$xml->appendChild($root);\n"; + code+="\t\theader(\"X-WobResponse-Status: Ok\");\n"; + code+="\t\tprint($xml->saveXml());\n"; + code+="\t}catch(Exception $e){$this->handleException($e);}\n"; + code+="\t/*end of output*/\n"; + return code; +} + +QString WocPHPServerTransaction::trnExecute(const WocTransaction&trn) +{ + //the execute function is split into a static and non-static part, + //since the code from the wolf file assumes to be inside the instance + QStringList in=trn.inputNames(); + //static wrapper for execution + QString code="static public function execute("; + for(int i=0;ihandleException($ex);\n\t}\n"; + code+="\tself::$running=\"\";\n}\n"; + return code; +} diff --git a/woc/php/phpstrans.h b/woc/php/phpstrans.h new file mode 100644 index 0000000..05a1399 --- /dev/null +++ b/woc/php/phpstrans.h @@ -0,0 +1,36 @@ +// +// C++ Interface: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHPOUT_STRANS_H +#define WOC_PHPOUT_STRANS_H + +#include "phptrans.h" + + +/**generates output for a PHP server side*/ +class WocPHPServerTransaction:public WocPHPTransaction +{ + public: + /**initializes the output object*/ + WocPHPServerTransaction(WocPHPOut*); + private: + /**helper: create handlers*/ + virtual QString trnHandlers(const WocTransaction&); + /**helper: create transaction input parser*/ + QString trnInput(const WocTransaction&); + /**helper: create transaction output serializer*/ + QString trnOutput(const WocTransaction&); + /**helper: create direct execution code for web interface*/ + QString trnExecute(const WocTransaction&); +}; + +#endif diff --git a/woc/php/phptrans.cpp b/woc/php/phptrans.cpp new file mode 100644 index 0000000..a0976db --- /dev/null +++ b/woc/php/phptrans.cpp @@ -0,0 +1,251 @@ +// +// C++ Implementation: phpout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "phpout.h" +#include "phpctrans.h" + +#include +#include + +#include "phpconst.h" + +static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n"); +static const QByteArray TRANSACTSTART(" static public function handle(){\n try{switch(WobTransactionBase::getTransactionName()){\n"); +static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n }}catch(WobTransactionError $er){$er->printXml();}\n }\n"); + +WocPHPTransaction::WocPHPTransaction(WocPHPOut*p ): QObject(p) +{ + m_parent=p; + connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); + //create Transaction file + m_transact.setFileName(m_basedir+"/"+m_subdir+"/transaction"+m_fileext); + if(!m_transact.open(QIODevice::ReadWrite|QIODevice::Truncate)){ + qDebug("Error: PHP Server Generator - cannot create transaction processor file."); + emit errorFound(); + return; + } + m_transact.write(PHPSTART); + m_transact.write(TRANSACTCLASS); + transInfo(); + m_transact.write(TRANSACTSTART); + addLoad("WobTransaction","transaction"); +} + +void WocPHPTransaction::transInfo() +{ + WocProcessor*woc=WocProcessor::instance(); + m_transact.write(QString(" static public function commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); + m_transact.write(QString(" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); + m_transact.write(QString(" static public function version(){return \""+woc->verHR()+"\";}\n").toAscii()); + m_transact.write(QString(" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); + m_transact.write(QString(" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); + m_transact.write(QString(" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); +} + +void WocPHPTransaction::transInfo2() +{ + WocProcessor*woc=WocProcessor::instance(); + //transaction names + QString code=" static public function transactionNames(){\n\treturn array("; + QStringList tns=woc->transactionNames(); + for(int i=0;iprivilegeNames(); + for(int i=0;ihandleRequest();break;\n"; + m_transact.write(code.toAscii()); +} + +QString WocPHPTransaction::trnConstruct(const WocTransaction&trn) +{ + QString code="public function __construct(){\n\tparent::__construct();\n"; + code+="\t$this->ainput=array("; + QStringList sl=trn.inputNames(); + for(int i=0;i"; + if(trn.isListType(trn.inputType(sl[i])))code+="array()"; + else code+="false"; + } + code+=");\n"; + code+="\t$this->tinput=array("; + for(int i=0;i\""; + code+=trn.inputType(sl[i]); + code+="\""; + } + code+=");\n"; + + + code+="\t$this->aoutput=array("; + sl=trn.outputNames(); + for(int i=0;i"; + if(trn.isListType(trn.outputType(sl[i])))code+="array()"; + else code+="false"; + } + code+=");\n"; + code+="\t$this->toutput=array("; + for(int i=0;i\""; + code+=trn.outputType(sl[i]); + code+="\""; + } + code+=");\n}\n"; + return code; +} + +QString WocPHPTransaction::trnGetSet(const WocTransaction&trn) +{ + QString code; + //getters + QStringList sl=trn.inputNames(); + for(int i=0;iainput[\""+sl[i]+"\"];}\n"; + } + //setters + sl=trn.outputNames(); + for(int i=0;iaoutput[\""+sl[i]+"\"];}\n"; + QString add; + QString t=trn.outputType(sl[i]); + code+="public function set"+sl[i]+"($v){\n"; + if(trn.isListType(t)){ + add="public function add"+sl[i]+"($vv){\n"; + code+="\t$this->aoutput[\""+sl[i]+"\"]=array();\n"; + code+="\tforeach($v as $vv){\n"; + if(trn.isIntType(t)){ + code+="\t\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n"; + add+="\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n"; + }else + if(trn.isBoolType(t)){ + code+="\t\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n"; + add+="\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n"; + }else + if(trn.isObjectType(t)){ + code+="\t\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n"; + add+="\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n"; + }else{ + code+="\t\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n"; + add+="\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n"; + } + code+="\t}\n"; + add+="}\n"; + }else{ + if(trn.isIntType(t)){ + code+="\tif(is_numeric($v))$this->aoutput[\""+sl[i]+"\"]=$v+0;\n"; + }else + if(trn.isBoolType(t)){ + code+="\tif(is_bool($v))$this->aoutput[\""+sl[i]+"\"]=$v!=false;\n"; + }else + if(trn.isObjectType(t)){ + code+="\tif(is_a($v,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"]=$v;\n"; + }else{ + code+="\t$this->aoutput[\""+sl[i]+"\"]=\"\".$v;\n"; + } + } + code+="}\n"+add; + } + + + return code; +} + +QString WocPHPTransaction::trnPrivileges(const WocTransaction&trn) +{ + //privilege inventory + QString code; + code+="static public function privileges(){\n\treturn array("; + QString cn=trnClassName(trn); + QStringList priv=trn.privileges(); + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PHPOUT_TRANS_H +#define WOC_PHPOUT_TRANS_H + +#include "phpout.h" + + +/**generates output for a PHP server side*/ +class WocPHPTransaction:public QObject +{ + Q_OBJECT + public: + /**initializes the output object*/ + WocPHPTransaction(WocPHPOut*); + /**writes any last words after parsing finished*/ + virtual void finalize(); + /**creates a transaction*/ + virtual void newTransaction(const WocTransaction&); + private: + + /**helper: create info functions (mainly version info) at the start*/ + virtual void transInfo(); + /**helper: create info functions (mainly version info) at the end*/ + virtual void transInfo2(); + + /**helper: create transaction constructor*/ + virtual QString trnConstruct(const WocTransaction&); + /**helper: create handlers*/ + virtual QString trnHandlers(const WocTransaction&)=0; + /**helper: create getters and setters*/ + virtual QString trnGetSet(const WocTransaction&); + /**helper: create privilege check code for web interface*/ + virtual QString trnPrivileges(const WocTransaction&); + protected: + WocPHPOut*m_parent; + signals: + void errorFound(); +}; + +#endif diff --git a/woc/phpclass.cpp b/woc/phpclass.cpp deleted file mode 100644 index d7bb590..0000000 --- a/woc/phpclass.cpp +++ /dev/null @@ -1,531 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "phpout.h" -#include "phpclass.h" - -#include -#include - -#include "phpconst.h" - -WocPHPClass::WocPHPClass(WocPHPOut* p) -{ - m_parent=p; - connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); -} - -void WocPHPClass::finalize() -{ -} - -void WocPHPClass::newClass(const WocClass&cls) -{ - //cover basics - QString cn=className(cls); - QString cna=abstractClassName(cls); - QString fn="wo_"+cls.name(); - addLoad(cna,fn); - fn=m_subdir+"/"+fn+m_fileext; - QFile tf(m_basedir+"/"+fn); - if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){ - qDebug("Error: cannot create PHP object file %s.",fn.toAscii().data()); - emit errorFound(); - return; - } - tf.write(PHPSTART); - - //// - //generate code - QString code="/* TRANSLATOR "+cna+" */\nclass "+cna+" extends "+cls.serverBaseClass()+"{\n\n"; - tf.write(code.toAscii()); - - //property declaration and constructor - tf.write(classConstruct(cls).toAscii()); - - //enums - tf.write(classEnums(cls).toAscii()); - - //properties - tf.write(classProperties(cls).toAscii()); - - //mappings - tf.write(classMappings(cls).toAscii()); - - //serializers - tf.write(classSerializers(cls).toAscii()); - - //de-serializer - tf.write(classDeserializers(cls).toAscii()); - - //prop to array conversion - tf.write(classPropertiesList(cls).toAscii()); - - //end of class - code="\n//end of class\n};\n"; - tf.write(code.toAscii()); - - tf.write(PHPEND); - tf.close(); -} - -QString WocPHPClass::classConstruct(const WocClass&cls) -{ - QString code; - QStringList k=cls.propertyNames(); - for(int i=0;iev=cls.enumValues(k[i]); - for(int j=0;jprop_"+k[i]+";}\n"; - //is it a list? - if(cls.propertyIsList(k[i])){ - //lists... - //getters - code+=classPropertyListGetters(cls,k[i]); - //setters - code+=classPropertyListSetters(cls,k[i]); - }else{ - //non-lists... - //getters - code+=classPropertyScalarGetters(cls,k[i]); - //setter - code+=classPropertyScalarSetters(cls,k[i]); - } - } - - return code; -} - -QString WocPHPClass::classPropertiesList(const WocClass&cls) -{ - QString code; - QStringList k=cls.propertyNames(); - code+="public function propertyArray(){\n\treturn array("; - for(int i=0;i"; - //is it a list? - if(cls.propertyIsList(k[i])){ - //lists... - //object? - if(cls.propertyIsObject(k[i])) - code+="array_map(\"WObject::objectToArray\",$this->prop_"+k[i]+")"; - else - code+="$this->prop_"+k[i]; - }else{ - //non-lists... - //object? - if(cls.propertyIsObject(k[i])) - code+="WObject::objectToArray($this->prop_"+k[i]+")"; - else - code+="$this->prop_"+k[i]; - } - } - code+=");\n}\n"; - - return code; -} - -QString WocPHPClass::classPropertyValidator(const WocClass&cls,QString prop) -{ - QString code; - code+="static public function validate"+prop+"($value){\n"; - if(cls.propertyIsEnum(prop)){ - QListev=cls.enumValues(cls.propertyPlainType(prop)); - code+="\tif(is_numeric($value)){\n\t\t$value=$value+0;\n"; - for(int j=0;jprop_"+prop+";}\n"; - else - if(cls.propertyIsBlob(prop)){ - code+="public function getstrlist_"+prop+"(){\n\t$ret=array();\n"; - code+="\tforeach($this->prop_"+prop+" as $p)$ret[]=base64_encode($this->prop_"+prop+");"; - code+="\treturn $ret;\n}\n"; - }else - if(cls.propertyIsInt(prop)){ - code+="public function getstrlist_"+prop+"(){\n"; - code+="\t$ret=array();\n\tforeach($this->prop_"+prop+" as $p)$ret[]=\"\".$p;\n"; - code+="\treturn $ret;\n}\n"; - }else - if(cls.propertyIsBool(prop)){ - code+="public function getstrlist_"+prop+"(){\n"; - code+="\t$ret=array();\n\tforeach($this->prop_"+prop+" as $p)$ret[]=$p?\"yes\":\"no\";\n"; - code+="\treturn $ret;\n}\n"; - }else - if(cls.propertyIsEnum(prop)){ - code+="public function getstrlist_"+prop+"(){\n"; - code+="\t$ret=array();\n"; - code+="\tforeach($this->prop_"+prop+" as $p)switch($p){\n"; - QList ev=cls.enumValues(cls.propertyPlainType(prop)); - for(int j=0;jprop_"+prop+"=array();}\n"; - QString acode;//body of add_ function, see below - code+="public function set"+prop+"(array $values){\n"; - if(cls.propertyIsEnum(prop)){ - QListev=cls.enumValues(cls.propertyPlainType(prop)); - code+="\t$prop=array();\n"; - code+="\tforeach($values as $value){\n"; - code+="\t\tif(is_numeric($value)){\n\t\t\t$value=$value+0;\n"; - acode+="\tif(is_numeric($value)){\n\t\t$value=$value+0;\n"; - for(int j=0;jprop_"+prop+";}\n"; - else - if(cls.propertyIsBlob(prop)) - code+="public function getstr_"+prop+"(){return base64_encode($this->prop_"+prop+");}\n"; - else - if(cls.propertyIsInt(prop)) - code+="public function getstr_"+prop+"(){return \"\".$this->prop_"+prop+";}\n"; - else - if(cls.propertyIsBool(prop)) - code+="public function getstr_"+prop+"(){return $this->prop_"+prop+"?\"yes\":\"no\";}\n"; - else - if(cls.propertyIsEnum(prop)){ - code+="public function getstr_"+prop+"(){\n\tswitch($this->prop_"+prop+"){\n"; - QList ev=cls.enumValues(cls.propertyPlainType(prop)); - for(int j=0;jev=cls.enumValues(cls.propertyPlainType(prop)); - code+="\tif(is_numeric($value)){\n\t\t$value=$value+0;\n"; - for(int j=0;jprop_"+prop+"=true;else\n"; - code+="\tif($value==\"no\")$this->prop_"+prop+"=false;\n\telse return false;\n"; - code+="\treturn true;\n"; - }else - if(cls.propertyIsString(prop)||cls.propertyIsBlob(prop)) - code+="\t$this->prop_"+prop+"=\"\".$value;\n\treturn true;\n"; - //TODO: special handling for astring - //TODO: do something about Blob - else - if(cls.propertyIsObject(prop)){ - code+="\tif(is_a($value,\"WO"+cls.propertyPlainType(prop)+"\")){\n"; - code+="\t\t$this->prop_"+prop+"=$value;\n"; - code+="\t\treturn true;\n\t}\n"; - }else{ - qDebug("Warning: unable to generate setter for class %s property %s: unknown type.",cls.name().toAscii().data(),prop.toAscii().data()); - code+="\treturn false;\n"; - } - code+="}\n"; - - return code; -} - -QString WocPHPClass::classSerializers(const WocClass&cls) -{ - QString code; - //toString function (wraps toXml) - code+="\npublic function toString(){\n\t$xml=new DomDocument;\n"; - code+="\t$xml->appendChild($this->toXml($xml));\n\treturn $xml->saveXml();\n}\n"; - //toXml function: - code+="public function toXml($xml,$elementname=\""+cls.name()+"\"){\n"; - code+="\t$root=$xml->createElement($elementname);\n"; - //add properties - QStringList p=cls.propertyNames(); - for(int j=0;jtextContent));\n"; - }else{ - code+="\t\t$data->add_"+k[i]+"($el->textContent);\n"; - } - code+="\t}\n"; - }else{ - if(cls.propertyIsObject(k[i])){ - code+="\tforeach(WObject::elementsByTagName($elem,\""+k[i]+"\") as $el){\n"; - code+="\t\t$data->set"+k[i]+"(WO"+cls.propertyPlainType(k[i])+"::fromXml($xml,$el));\n"; - code+="\t}\n"; - }else - if(cls.propertyIsAttribute(k[i])){ - code+="\tif($elem->hasAttribute(\""+k[i]+"\"))\n"; - code+="\t\t$data->set"+k[i]+"($elem->getAttribute(\""+k[i]+"\"));\n"; - }else{ - code+="\tforeach(WObject::elementsByTagName($elem,\""+k[i]+"\") as $el){\n"; - if(cls.propertyIsBlob(k[i])) - code+="\t\t$data->set"+k[i]+"(base64_decode($el->textContent));\n"; - else - code+="\t\t$data->set"+k[i]+"($el->textContent);\n"; - code+="\t}\n"; - } - } - } - code+="\treturn $data;\n}\n"; - return code; -} - -QString WocPHPClass::classMappings(const WocClass&cls) -{ - //don't do it for client mode (clients do not have a DB) - if(m_parent->ptable==0)return QString(); - //implement mappings - QString code; - QStringList k=cls.mappingTables(); - for(int i=0;itable(k[i]); - //single object mapping - code+="\nstatic public function fromTable"+k[i]+"($table){\n"; - code+="\tif($table === false)return false;\n"; - code+="\t$data=new WO"+cls.name()+"();\n"; - QMapmap=cls.mapping(k[i]); - QStringList mapk=cls.mappingProperties(k[i]); - for(int j=0;j"+map[mapk[j]]+";\n"; - } - code+="\treturn $data;\n}\n"; - //wrapper for multi-object mapping - code+="static public function fromTableArray"+k[i]+"(array $table){\n\t$ret=array();\n"; - code+="\tfor($i=0;$i"+map[mapk[j]]+"!=$this->prop_"+mapk[j]+")\n"; - code+="\t\t$table->"+map[mapk[j]]+"=$this->prop_"+mapk[j]+";\n"; - } - } - code+="\treturn $table;\n}\n"; - } - - return code; -} - -QString WocPHPClass::propertyToXml(const WocClass&cls,QString sl) -{ - QString prop=sl.trimmed(); - //is it a list? - if(cls.propertyIsList(prop)){ - //is it a class? - if(cls.propertyIsObject(prop)){ - QString code="\tforeach($this->get"+prop+"() as $o)\n\t\t"; - code+="$root->appendChild($o->toXml($xml,\""+prop+"\"));\n"; - return code; - }else{ - //there is no way to create lists of attributes, hence we always create elements - QString code="\tforeach($this->getstrlist_"+prop+"() as $e)\n\t\t"; - code+="$root->appendChild($xml->createElement(\""+prop+"\",xq($e)));\n"; - return code; - } - } - //non lists: - QString code="\t$p=$this->get"+prop+"();\n"; - //is it an attribute? - if(cls.propertyIsAttribute(prop)) - return code+"\tif($p!==null)$root->setAttribute(\""+prop+"\",$this->getstr_"+prop+"());\n"; - //is it an element? - if(cls.propertyIsElement(prop)) - return code+"\tif($p!==null)$root->appendChild($xml->createElement(\""+prop+"\",xq($this->getstr_"+prop+"())));\n"; - //is it a class? - if(cls.propertyIsObject(prop)) - return code+"\tif(is_a($p,\"WO"+cls.propertyPlainType(prop)+"\"))$root->appendChild($p->toXml($xml,\""+prop+"\"));\n"; - //anything else? - qDebug("Warning: end of WocPHPClass::propertyToXml - this code should not be reachable."); - return "//internal generator error!\n"; -} diff --git a/woc/phpclass.h b/woc/phpclass.h deleted file mode 100644 index fc67a26..0000000 --- a/woc/phpclass.h +++ /dev/null @@ -1,67 +0,0 @@ -// -// C++ Interface: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHPOUT_CLASS_H -#define WOC_PHPOUT_CLASS_H - - -class WocPHPOut; -class WocClass; - -#include - -/**generates output for a PHP server side*/ -class WocPHPClass:public QObject -{ - Q_OBJECT - public: - /**initializes the output object*/ - WocPHPClass(WocPHPOut*); - /**writes any last words after parsing finished*/ - virtual void finalize(); - /**creates a class*/ - virtual void newClass(const WocClass&); - - protected: - WocPHPOut*m_parent; - - /**helper: generates PHP code to transform a class property to XML*/ - QString propertyToXml(const WocClass&,QString); - /**helper: generate class constructor*/ - QString classConstruct(const WocClass&); - /**helper: generate class internal enums*/ - QString classEnums(const WocClass&); - /**helper: generate class internal props*/ - QString classProperties(const WocClass&); - /**helper: generate class internal serializers*/ - QString classSerializers(const WocClass&); - /**helper: generate class internal deserializers*/ - QString classDeserializers(const WocClass&); - /**helper: generate class internal mappers*/ - QString classMappings(const WocClass&); - /**helper: generate property validator*/ - QString classPropertyValidator(const WocClass&,QString); - /**helper: generate getters for list properties*/ - QString classPropertyListGetters(const WocClass&,QString); - /**helper: generate setters for list properties*/ - QString classPropertyListSetters(const WocClass&,QString); - /**helper: generate getters for scalar properties*/ - QString classPropertyScalarGetters(const WocClass&,QString); - /**helper: generate setters for sclar properties*/ - QString classPropertyScalarSetters(const WocClass&,QString); - /**helper: generate the property to array converter, eg. for renderers like for Twig*/ - QString classPropertiesList(const WocClass&); - signals: - void errorFound(); -}; - -#endif diff --git a/woc/phpconst.h b/woc/phpconst.h deleted file mode 100644 index d7b3036..0000000 --- a/woc/phpconst.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHP_CONST_H -#define WOC_PHP_CONST_H - -static const QByteArray PHPSTART(""); - -#ifndef WOC_PHP_NO_WRAP -#define m_basedir m_parent->m_basedir -#define m_subdir m_parent->m_subdir -#define m_fileext m_parent->m_fileext -#define m_transbase m_parent->m_transbase -#define m_loader m_parent->m_loader -#define m_schema m_parent->m_schema -#define m_transact m_parent->m_transact -#define className m_parent->className -#define abstractClassName m_parent->abstractClassName -#define trnClassName m_parent->trnClassName -#define addLoad m_parent->addLoad -#define m_lang m_parent->m_lang -#endif - -#endif diff --git a/woc/phpctrans.cpp b/woc/phpctrans.cpp deleted file mode 100644 index 53fc835..0000000 --- a/woc/phpctrans.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "phpout.h" -#include "phpctrans.h" - -#include -#include - -#include "phpconst.h" - -WocPHPClientTransaction::WocPHPClientTransaction(WocPHPOut*p ) - :WocPHPTransaction(p) -{ -} - -QString WocPHPClientTransaction::trnHandlers(const WocTransaction&trn) -{ - //create file - QString cn=trnClassName(trn); - QString fn="wtr_"+trn.name(); - - //// - //generate code - QString code; - - //request handler: - code="public function handleRequest(){\n"; - code+="\t$this->startTransaction("+QString(trn.isDbUpdating()?"true":"false")+");\n"; - - //security handling - switch(trn.authMode()){ - case WocTransaction::Checked: - code+="\t/*security check: authenticated and authorized*/\n"; - code+="\tif(!$this->isAuthorized(\""+trn.name()+"\""+"))$this->notAuthenticated();\n"; - break; - case WocTransaction::Auth: - code+="\t/*security check: authenticated*/\n"; - code+="\tif(!$this->isAuthenticated())$this->notAuthenticated();\n"; - break; - default: - code+="\t/*no security check, open function*/\n"; - break;//none - } - - //parse low level XML - code+="\t/*low level XML parsing*/\n"; - code+="\tglobal $HTTP_RAW_POST_DATA;\n\tif(isset($HTTP_RAW_POST_DATA))$txt=$HTTP_RAW_POST_DATA;else $txt=\"\";\n"; - code+="\t$xml=new DOMDocument;\n\tif(!$xml->loadXML($txt))$this->xmlParserError();\n"; - code+="\t$root=$xml->documentElement;\n"; - - //parse inputs - code+=trnInput(trn); - - //call - if(trn.hasCall(m_lang)){ - code+="\t/*call actual functionality:*/\n"; - code+="\ttry{"+trn.callFunction(m_lang)+"}catch(Exception $e){$this->handleException($e);}\n"; - }else{ - code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n"; - code+="\t$this->abortNotImplemented();\nreturn;\n"; - qDebug("Warning: transaction %s does not have a PHP call!",trn.name().toAscii().data()); - } - - //encode outputs/handle errors - code+=trnOutput(trn); - - code+="\t$this->commitTransaction();\n}\n"; - - return code; -} - -QString WocPHPClientTransaction::trnInput(const WocTransaction&trn) -{ - QString code="\t/*start of input parsing*/\n"; - code+="\ttry{\n"; - QStringList sl=trn.inputNames(); - for(int i=0;igetAttribute(\""+sl[i]+"\")"; - if(trn.isIntType(t))code+="+0"; - if(trn.isBoolType(t))code+="==\"yes\""; - code+=";\n"; - }else{ - if(trn.isListType(t)){ - QString pt=trn.plainType(t); - code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; - if(trn.isObjectType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=WO"+pt+"::fromXml($xml,$el);\n"; - }else if(trn.isBlobType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=base64_decode($el->textContent);\n"; - }else{ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=$el->textContent"; - if(trn.isIntType(t))code+="+0"; - if(trn.isBoolType(t))code+="==\"yes\""; - code+=";\n"; - } - code+="\t\t}\n"; - }else{ - code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; - if(trn.isObjectType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=WO"+t+"::fromXml($xml,$el);\n"; - }else if(trn.isBlobType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=base64_decode($el->textContent);\n"; - }else{ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=$el->textContent"; - if(trn.isIntType(t))code+="+0"; - code+=";\n"; - } - code+="\t\t}\n"; - } - } - } - code+="\t}catch(Exception $e){$this->handleException($e);}\n"; - code+="\t/*end of input parsing*/\n"; - return code; -} - -QString WocPHPClientTransaction::trnOutput(const WocTransaction&trn) -{ - QStringList sl=trn.outputNames(); - QString code="\t/*start of output encoding*/\n"; - code+="\ttry{\n\t\t$xml=new DOMDocument;\n"; - code+="\t\t$root=$xml->createElement(\"WobResponse-"+trn.name()+"\");\n"; - for(int i=0;iaoutput[\""+sl[i]+"\"]);\n"; - }else{ - if(trn.isListType(t)){ - if(trn.isObjectType(t)){ - code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $o)\n"; - code+="\t\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; - code+="\t\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; - }else if(trn.isBlobType(t)){ - code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; - code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($v)));\n"; - }else{ - code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; - code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($v)));\n"; - } - }else{ - if(trn.isObjectType(t)){ - code+="\t\t$o=$this->aoutput[\""+sl[i]+"\"];\n"; - code+="\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; - code+="\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; - }else if(trn.isBlobType(t)){ - code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($this->aoutput[\""+sl[i]+"\"])));\n"; - }else{ - code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($this->aoutput[\""+sl[i]+"\"])));\n"; - } - } - } - } - code+="\t\t$xml->appendChild($root);\n"; - code+="\t\theader(\"X-WobResponse-Status: Ok\");\n"; - code+="\t\tprint($xml->saveXml());\n"; - code+="\t}catch(Exception $e){$this->handleException($e);}\n"; - code+="\t/*end of output*/\n"; - return code; -} diff --git a/woc/phpctrans.h b/woc/phpctrans.h deleted file mode 100644 index 0e1a700..0000000 --- a/woc/phpctrans.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// C++ Interface: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHPOUT_CTRANS_H -#define WOC_PHPOUT_CTRANS_H - -#include "phptrans.h" - - -/**generates output for a PHP server side*/ -class WocPHPClientTransaction:public WocPHPTransaction -{ - public: - /**initializes the output object*/ - WocPHPClientTransaction(WocPHPOut*); - private: - /**helper: create transaction constructor*/ - QString trnHandlers(const WocTransaction&); - /**helper: create transaction input parser*/ - QString trnInput(const WocTransaction&); - /**helper: create transaction output serializer*/ - QString trnOutput(const WocTransaction&); -}; - -#endif diff --git a/woc/phpdb.cpp b/woc/phpdb.cpp deleted file mode 100644 index c60f489..0000000 --- a/woc/phpdb.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "phpout.h" -#include "phpdb.h" - -#include - -#include "phpconst.h" - -static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nfunction __construct(){\n\tparent::__construct();\n"); -static const QByteArray SCHEMAEND("}};\n"); - -WocPHPTable::WocPHPTable(WocPHPOut* p) - :m_parent(p) -{ - connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); - - //create schema file - m_schema.setFileName(m_basedir+"/"+m_subdir+"/schema"+m_fileext); - if(!m_schema.open(QIODevice::ReadWrite|QIODevice::Truncate)){ - qDebug("Error: PHP Server Generator - cannot create DB schema file."); - emit errorFound(); - return; - } - m_schema.write(PHPSTART); - m_schema.write(SCHEMASTART); - m_schema.write(("\tself::$sversion=\""+WocProcessor::instance()->dbVersion()+"\";\n").toAscii()); - addLoad("WobSchema","schema"); -} - -void WocPHPTable::finalize() -{ - if(m_schema.isOpen()){ - m_schema.write(SCHEMAEND); - m_schema.write(PHPEND); - m_schema.close(); - } -} - -void WocPHPTable::newTable(const WocTable&tbl) -{ - if(!m_loader.isOpen())return; - WocProcessor *woc=WocProcessor::instance(); - //create table file - QString fn=m_subdir+"/wt_"+tbl.name()+m_fileext; - QFile tf(m_basedir+"/"+fn); - if(!tf.open(QIODevice::ReadWrite|QIODevice::Truncate)){ - qDebug("Error: cannot create PHP table file %s.",fn.toAscii().data()); - emit errorFound(); - return; - } - tf.write(PHPSTART); - QString code="/* TRANSLATOR WT"+tbl.name()+" */\nclass WT"+tbl.name()+" extends "+tbl.baseClass()+"\n{\n"; - //initializer - code+="protected function __construct(array $data,$isfromdb){parent::__construct($data,$isfromdb,\""+tbl.name()+"\");}\n\n"; - - //static new instance for insert only - code+="public static function newRow(array $data=array()){return new WT"+tbl.name()+"($data,false);}\n\n"; - - //static get instance - QStringList cols=tbl.columns(); - QStringList pcols=tbl.primaryColumns(); - //header - code+="public static function getFromDB("; - for(int i=0;idbInst(); - //DB query - code+="){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",\""; - for(int i=0;iescapeColumn(\""+tbl.name()+"\",\""+pcols[i]+"\",$"+pcols[i]+").\""; - } - code+="\");\n"; - //check result - code+="\tif($res===false)return false;\n\tif(count($res)<1)return false;\n\telse return new WT"+tbl.name()+"($res[0],true);\n}\n\n"; - - //static get selection - code+="public static function selectFromDB($where=\"\",$orderby=\"\"){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",$where,$orderby);\n\tif($res===false || count($res)<1)return array();\n\t"; - code+="$r=array();\n\tforeach($res as $row)\n\t\t$r[]=new WT"+tbl.name()+"($row,true);\n\treturn $r;\n}\n\n"; - - //go through columns, generate specific code - for(int i=0;iescapeColumn(\""+foreign[0]+"\",\""+foreign[1]+"\",$this->"+cols[i]+"));\n}\n\n"; - } - //implement enum check for set method of enum columns - if(tbl.columnType(cols[i]).startsWith("enum")){ - code+="protected function verifyValue"+cols[i]+"($v){if(false"; - QListens=tbl.columnEnums(cols[i]); - QListenvs; - for(int j=0;jescapeColumn(\""; - code+=foreign[0]+"\",\""+foreign[1]+"\",$this->"+local+"));\n}\n\n"; - } - - //create enum constants - QListens=tbl.getEnums(); - for(int i=0;idata);\n"; - code+="\treturn $ad->insert();\n}\n"; - } - - //create newKey function - code+="public function newKey(){\n\tparent::newKey();\n"; - for(int i=0;iarray(\""; - code+=tbl.columnType(cols[i])+"\""; - if(!tbl.columnIsNull(cols[i]))code+=",\"notnull\""; - if(tbl.columnIsForeign(cols[i]))code+=",\"foreignkey:"+tbl.columnForeign(cols[i])+"\""; - if(pcols.size()<2 && tbl.columnIsPrimary(cols[i]))code+=",\"primarykey\""; - if(tbl.columnHasDefault(cols[i]))code+=",\"default:"+tbl.columnDefault(cols[i])+"\""; - if(tbl.columnIsIndexed(cols[i]))code+=",\"index\""; - if(tbl.columnIsUnique(cols[i]))code+=",\"unique\""; - code+=")"; - } - if(pcols.size()>=2){ - code+=",\n\t\t\":primarykey\"=>array("; - for(int i=0;i >presets=tbl.presets(); - if(presets.size()>0){ - code+="\tself::$preset[\""+tbl.name()+"\"]=array("; - for(int i=0;i"+presets[i][k[j]]; - } - code+=")"; - } - code+="\n\t);\n"; - } - - //write - m_schema.write(code.toAscii()); - - //create autoloading - addLoad("WT"+tbl.name(),"wt_"+tbl.name()); -} diff --git a/woc/phpdb.h b/woc/phpdb.h deleted file mode 100644 index 5c9193d..0000000 --- a/woc/phpdb.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// C++ Interface: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHPOUT_DB_H -#define WOC_PHPOUT_DB_H - -#include "phpout.h" - -/**generates output for a PHP server side*/ -class WocPHPTable:public QObject -{ - Q_OBJECT - public: - /**initializes the output object*/ - WocPHPTable(WocPHPOut*); - /**writes any last words after parsing finished*/ - virtual void finalize(); - /**creates a class*/ - virtual void newTable(const WocTable&); - private: - WocPHPOut*m_parent; - signals: - void errorFound(); -}; - -#endif diff --git a/woc/phpout.cpp b/woc/phpout.cpp deleted file mode 100644 index eb2c54b..0000000 --- a/woc/phpout.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "phpout.h" -#include "phpdb.h" -#include "phpctrans.h" -#include "phpstrans.h" -#include "phpclass.h" - -#include -#include - -#define WOC_PHP_NO_WRAP -#include "phpconst.h" - -static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nfunction __construct(){\n\tparent::__construct();\n"); -static const QByteArray SCHEMAEND("}};\n"); - -WocPHPServerOut::WocPHPServerOut(const QDomElement&el) - :WocPHPOut(el) -{ - m_lang="php/server"; - pclass=new WocPHPClass(this); - ptable=new WocPHPTable(this); - ptrans=new WocPHPServerTransaction(this); -} - -WocPHPClientOut::WocPHPClientOut(const QDomElement& el) - :WocPHPOut(el) -{ - m_lang="php/client"; - pclass=new WocPHPClass(this); - ptrans=new WocPHPClientTransaction(this); -} - - -WocPHPOut::WocPHPOut(const QDomElement&el) -{ - pclass=0;ptable=0;ptrans=0; - qDebug("Info: creating PHP Server Output Generator."); - m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir","."); - m_subdir=el.attribute("subDir","phpwob"); - m_fileext=el.attribute("extension",".inc"); - m_transbase=el.attribute("transactionBase","WobTransaction"); - //cleanup directory (remove normal files, assume remainder is harmless) - QDir d(m_basedir+"/"+m_subdir); - if(d.exists() && str2bool(el.attribute("clean","0"))){ - QStringList ent=d.entryList(QDir::Files); - for(int i=0;ifinalize(); - if(ptable)ptable->finalize(); - if(ptrans)ptrans->finalize(); - if(m_loader.isOpen()){ - m_loader.write(PHPEND); - m_loader.close(); - } -} - - -void WocPHPOut::addLoad(QString cn,QString fn) -{ - QString ld="wob_autoclass(\""+cn+"\",$d.\"/"+fn+m_fileext+"\");\n"; - m_loader.write(ld.toAscii()); -} - -void WocPHPOut::newTransaction(const WocTransaction&trn) -{ - if(ptrans)ptrans->newTransaction(trn); -} - -void WocPHPOut::newClass(const WocClass& cls) -{ - if(pclass)pclass->newClass(cls); -} - -void WocPHPOut::newTable(const WocTable& tbl) -{ - if(ptable)ptable->newTable(tbl); -} diff --git a/woc/phpout.h b/woc/phpout.h deleted file mode 100644 index e9275d3..0000000 --- a/woc/phpout.h +++ /dev/null @@ -1,85 +0,0 @@ -// -// C++ Interface: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHPOUT_H -#define WOC_PHPOUT_H - -#include - -#include "processor.h" - -class QDomElement; - -class WocPHPOut; -class WocPHPClass; -class WocPHPTable; -class WocPHPTransaction; -class WocPHPClientTransaction; -class WocPHPServerTransaction; - -/**generates output for a PHP server side*/ -class WocPHPOut:public WocOutput -{ - public: - /**initializes the output object*/ - WocPHPOut(const QDomElement&); - protected: - /**writes any last words after parsing finished*/ - virtual void finalize(); - /**creates a class*/ - virtual void newClass(const WocClass&); - /**creates a table*/ - virtual void newTable(const WocTable&); - /**creates a transaction*/ - virtual void newTransaction(const WocTransaction&); - - friend class WocPHPClass; - friend class WocPHPTable; - friend class WocPHPTransaction; - friend class WocPHPClientTransaction; - friend class WocPHPServerTransaction; - - QString m_basedir,m_subdir,m_fileext; - QString m_transbase,m_lang; - QFile m_loader,m_schema,m_transact; - - /**helper: adds a loader line for a class to autoload.php*/ - void addLoad(QString classname,QString filename); - - WocPHPClass*pclass; - WocPHPTable*ptable; - WocPHPTransaction*ptrans; - - /**helper: return the PHP-class-name of a WocClass*/ - QString className(const WocClass&c){return "WO"+c.name();} - /**helper: return the PHP-class-name of a WocClass plus Abstract if it is abstract*/ - QString abstractClassName(const WocClass&c){return "WO"+c.name()+QString(c.isAbstract("php")?"Abstract":"");} - - /**helper: returns the PHP-class-name for a WocTransaction*/ - QString trnClassName(const WocTransaction&t){return "WTr"+t.name();} -}; - -class WocPHPServerOut:public WocPHPOut -{ - public: - /**initializes the output object*/ - WocPHPServerOut(const QDomElement&); -}; - -class WocPHPClientOut:public WocPHPOut -{ - public: - /**initializes the output object*/ - WocPHPClientOut(const QDomElement&); -}; - -#endif diff --git a/woc/phpstrans.cpp b/woc/phpstrans.cpp deleted file mode 100644 index 0043a96..0000000 --- a/woc/phpstrans.cpp +++ /dev/null @@ -1,207 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "phpout.h" -#include "phpstrans.h" - -#include -#include - -#include "phpconst.h" - -WocPHPServerTransaction::WocPHPServerTransaction(WocPHPOut*p ) - :WocPHPTransaction(p) -{ -} - -QString WocPHPServerTransaction::trnHandlers(const WocTransaction&trn) -{ - //create file - QString cn=trnClassName(trn); - QString fn="wtr_"+trn.name(); - //// - //generate code - QString code; - //request handler: - code="public function handleRequest(){\n"; - code+="\t$this->startTransaction("+QString(trn.isDbUpdating()?"true":"false")+");\n"; - - //security handling - switch(trn.authMode()){ - case WocTransaction::Checked: - code+="\t/*security check: authenticated and authorized*/\n"; - code+="\tif(!$this->isAuthorized(\""+trn.name()+"\""+"))$this->notAuthenticated();\n"; - break; - case WocTransaction::Auth: - code+="\t/*security check: authenticated*/\n"; - code+="\tif(!$this->isAuthenticated())$this->notAuthenticated();\n"; - break; - default: - code+="\t/*no security check, open function*/\n"; - break;//none - } - - //parse low level XML - code+="\t/*low level XML parsing*/\n"; - code+="\tglobal $HTTP_RAW_POST_DATA;\n\tif(isset($HTTP_RAW_POST_DATA))$txt=$HTTP_RAW_POST_DATA;else $txt=\"\";\n"; - code+="\t$xml=new DOMDocument;\n\tif(!$xml->loadXML($txt))$this->xmlParserError();\n"; - code+="\t$root=$xml->documentElement;\n"; - - //parse inputs - code+=trnInput(trn); - - //call - if(trn.hasCall(m_lang)){ - code+="\t/*call actual functionality:*/\n"; - code+="\ttry{"+trn.callFunction(m_lang)+"}catch(Exception $e){$this->handleException($e);}\n"; - }else{ - code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n"; - code+="\t$this->abortNotImplemented();\nreturn;\n"; - qDebug("Warning: transaction %s does not have a PHP call!",trn.name().toAscii().data()); - } - - //encode outputs/handle errors - code+=trnOutput(trn); - - code+="\t$this->commitTransaction();\n}\n"; - - //direct execution - code+=trnExecute(trn).toAscii(); - - return code; -} - -QString WocPHPServerTransaction::trnInput(const WocTransaction&trn) -{ - QString code="\t/*start of input parsing*/\n"; - code+="\ttry{\n"; - QStringList sl=trn.inputNames(); - for(int i=0;igetAttribute(\""+sl[i]+"\")"; - if(trn.isIntType(t))code+="+0"; - if(trn.isBoolType(t))code+="==\"yes\""; - code+=";\n"; - }else{ - if(trn.isListType(t)){ - QString pt=trn.plainType(t); - code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; - if(trn.isObjectType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=WO"+pt+"::fromXml($xml,$el);\n"; - }else if(trn.isBlobType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=base64_decode($el->textContent);\n"; - }else{ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=$el->textContent"; - if(trn.isIntType(t))code+="+0"; - if(trn.isBoolType(t))code+="==\"yes\""; - code+=";\n"; - } - code+="\t\t}\n"; - }else{ - code+="\t\tforeach(WObject::elementsByTagName($root,\""+sl[i]+"\") as $el){\n"; - if(trn.isObjectType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=WO"+t+"::fromXml($xml,$el);\n"; - }else if(trn.isBlobType(t)){ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=base64_decode($el->textContent);\n"; - }else{ - code+="\t\t\t$this->ainput[\""+sl[i]+"\"]=$el->textContent"; - if(trn.isIntType(t))code+="+0"; - code+=";\n"; - } - code+="\t\t}\n"; - } - } - } - code+="\t}catch(Exception $e){$this->handleException($e);}\n"; - code+="\t/*end of input parsing*/\n"; - return code; -} - -QString WocPHPServerTransaction::trnOutput(const WocTransaction&trn) -{ - QStringList sl=trn.outputNames(); - QString code="\t/*start of output encoding*/\n"; - code+="\ttry{\n\t\t$xml=new DOMDocument;\n"; - code+="\t\t$root=$xml->createElement(\"WobResponse-"+trn.name()+"\");\n"; - for(int i=0;iaoutput[\""+sl[i]+"\"]);\n"; - }else{ - if(trn.isListType(t)){ - if(trn.isObjectType(t)){ - code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $o)\n"; - code+="\t\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; - code+="\t\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; - }else if(trn.isBlobType(t)){ - code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; - code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($v)));\n"; - }else{ - code+="\t\tforeach($this->aoutput[\""+sl[i]+"\"] as $v)\n"; - code+="\t\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($v)));\n"; - } - }else{ - if(trn.isObjectType(t)){ - code+="\t\t$o=$this->aoutput[\""+sl[i]+"\"];\n"; - code+="\t\tif(is_a($o,\"WO"+trn.plainType(t)+"\"))\n"; - code+="\t\t\t$root->appendChild($o->toXml"+trn.typeSerializer(t)+"($xml,\""+sl[i]+"\"));\n"; - }else if(trn.isBlobType(t)){ - code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",base64_encode($this->aoutput[\""+sl[i]+"\"])));\n"; - }else{ - code+="\t\t$root->appendChild($xml->createElement(\""+sl[i]+"\",xq($this->aoutput[\""+sl[i]+"\"])));\n"; - } - } - } - } - code+="\t\t$xml->appendChild($root);\n"; - code+="\t\theader(\"X-WobResponse-Status: Ok\");\n"; - code+="\t\tprint($xml->saveXml());\n"; - code+="\t}catch(Exception $e){$this->handleException($e);}\n"; - code+="\t/*end of output*/\n"; - return code; -} - -QString WocPHPServerTransaction::trnExecute(const WocTransaction&trn) -{ - //the execute function is split into a static and non-static part, - //since the code from the wolf file assumes to be inside the instance - QStringList in=trn.inputNames(); - //static wrapper for execution - QString code="static public function execute("; - for(int i=0;ihandleException($ex);\n\t}\n"; - code+="\tself::$running=\"\";\n}\n"; - return code; -} diff --git a/woc/phpstrans.h b/woc/phpstrans.h deleted file mode 100644 index 05a1399..0000000 --- a/woc/phpstrans.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// C++ Interface: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHPOUT_STRANS_H -#define WOC_PHPOUT_STRANS_H - -#include "phptrans.h" - - -/**generates output for a PHP server side*/ -class WocPHPServerTransaction:public WocPHPTransaction -{ - public: - /**initializes the output object*/ - WocPHPServerTransaction(WocPHPOut*); - private: - /**helper: create handlers*/ - virtual QString trnHandlers(const WocTransaction&); - /**helper: create transaction input parser*/ - QString trnInput(const WocTransaction&); - /**helper: create transaction output serializer*/ - QString trnOutput(const WocTransaction&); - /**helper: create direct execution code for web interface*/ - QString trnExecute(const WocTransaction&); -}; - -#endif diff --git a/woc/phptrans.cpp b/woc/phptrans.cpp deleted file mode 100644 index a0976db..0000000 --- a/woc/phptrans.cpp +++ /dev/null @@ -1,251 +0,0 @@ -// -// C++ Implementation: phpout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "phpout.h" -#include "phpctrans.h" - -#include -#include - -#include "phpconst.h" - -static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n"); -static const QByteArray TRANSACTSTART(" static public function handle(){\n try{switch(WobTransactionBase::getTransactionName()){\n"); -static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n }}catch(WobTransactionError $er){$er->printXml();}\n }\n"); - -WocPHPTransaction::WocPHPTransaction(WocPHPOut*p ): QObject(p) -{ - m_parent=p; - connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); - //create Transaction file - m_transact.setFileName(m_basedir+"/"+m_subdir+"/transaction"+m_fileext); - if(!m_transact.open(QIODevice::ReadWrite|QIODevice::Truncate)){ - qDebug("Error: PHP Server Generator - cannot create transaction processor file."); - emit errorFound(); - return; - } - m_transact.write(PHPSTART); - m_transact.write(TRANSACTCLASS); - transInfo(); - m_transact.write(TRANSACTSTART); - addLoad("WobTransaction","transaction"); -} - -void WocPHPTransaction::transInfo() -{ - WocProcessor*woc=WocProcessor::instance(); - m_transact.write(QString(" static public function commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); - m_transact.write(QString(" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); - m_transact.write(QString(" static public function version(){return \""+woc->verHR()+"\";}\n").toAscii()); - m_transact.write(QString(" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); - m_transact.write(QString(" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); - m_transact.write(QString(" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); -} - -void WocPHPTransaction::transInfo2() -{ - WocProcessor*woc=WocProcessor::instance(); - //transaction names - QString code=" static public function transactionNames(){\n\treturn array("; - QStringList tns=woc->transactionNames(); - for(int i=0;iprivilegeNames(); - for(int i=0;ihandleRequest();break;\n"; - m_transact.write(code.toAscii()); -} - -QString WocPHPTransaction::trnConstruct(const WocTransaction&trn) -{ - QString code="public function __construct(){\n\tparent::__construct();\n"; - code+="\t$this->ainput=array("; - QStringList sl=trn.inputNames(); - for(int i=0;i"; - if(trn.isListType(trn.inputType(sl[i])))code+="array()"; - else code+="false"; - } - code+=");\n"; - code+="\t$this->tinput=array("; - for(int i=0;i\""; - code+=trn.inputType(sl[i]); - code+="\""; - } - code+=");\n"; - - - code+="\t$this->aoutput=array("; - sl=trn.outputNames(); - for(int i=0;i"; - if(trn.isListType(trn.outputType(sl[i])))code+="array()"; - else code+="false"; - } - code+=");\n"; - code+="\t$this->toutput=array("; - for(int i=0;i\""; - code+=trn.outputType(sl[i]); - code+="\""; - } - code+=");\n}\n"; - return code; -} - -QString WocPHPTransaction::trnGetSet(const WocTransaction&trn) -{ - QString code; - //getters - QStringList sl=trn.inputNames(); - for(int i=0;iainput[\""+sl[i]+"\"];}\n"; - } - //setters - sl=trn.outputNames(); - for(int i=0;iaoutput[\""+sl[i]+"\"];}\n"; - QString add; - QString t=trn.outputType(sl[i]); - code+="public function set"+sl[i]+"($v){\n"; - if(trn.isListType(t)){ - add="public function add"+sl[i]+"($vv){\n"; - code+="\t$this->aoutput[\""+sl[i]+"\"]=array();\n"; - code+="\tforeach($v as $vv){\n"; - if(trn.isIntType(t)){ - code+="\t\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n"; - add+="\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n"; - }else - if(trn.isBoolType(t)){ - code+="\t\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n"; - add+="\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n"; - }else - if(trn.isObjectType(t)){ - code+="\t\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n"; - add+="\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n"; - }else{ - code+="\t\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n"; - add+="\t$this->aoutput[\""+sl[i]+"\"][]=\"\".$vv;\n"; - } - code+="\t}\n"; - add+="}\n"; - }else{ - if(trn.isIntType(t)){ - code+="\tif(is_numeric($v))$this->aoutput[\""+sl[i]+"\"]=$v+0;\n"; - }else - if(trn.isBoolType(t)){ - code+="\tif(is_bool($v))$this->aoutput[\""+sl[i]+"\"]=$v!=false;\n"; - }else - if(trn.isObjectType(t)){ - code+="\tif(is_a($v,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"]=$v;\n"; - }else{ - code+="\t$this->aoutput[\""+sl[i]+"\"]=\"\".$v;\n"; - } - } - code+="}\n"+add; - } - - - return code; -} - -QString WocPHPTransaction::trnPrivileges(const WocTransaction&trn) -{ - //privilege inventory - QString code; - code+="static public function privileges(){\n\treturn array("; - QString cn=trnClassName(trn); - QStringList priv=trn.privileges(); - for(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PHPOUT_TRANS_H -#define WOC_PHPOUT_TRANS_H - -#include "phpout.h" - - -/**generates output for a PHP server side*/ -class WocPHPTransaction:public QObject -{ - Q_OBJECT - public: - /**initializes the output object*/ - WocPHPTransaction(WocPHPOut*); - /**writes any last words after parsing finished*/ - virtual void finalize(); - /**creates a transaction*/ - virtual void newTransaction(const WocTransaction&); - private: - - /**helper: create info functions (mainly version info) at the start*/ - virtual void transInfo(); - /**helper: create info functions (mainly version info) at the end*/ - virtual void transInfo2(); - - /**helper: create transaction constructor*/ - virtual QString trnConstruct(const WocTransaction&); - /**helper: create handlers*/ - virtual QString trnHandlers(const WocTransaction&)=0; - /**helper: create getters and setters*/ - virtual QString trnGetSet(const WocTransaction&); - /**helper: create privilege check code for web interface*/ - virtual QString trnPrivileges(const WocTransaction&); - protected: - WocPHPOut*m_parent; - signals: - void errorFound(); -}; - -#endif diff --git a/woc/proc/proc.pri b/woc/proc/proc.pri new file mode 100644 index 0000000..58acc4d --- /dev/null +++ b/woc/proc/proc.pri @@ -0,0 +1,12 @@ +SOURCES+= \ + processor.cpp \ + procclass.cpp \ + proctrans.cpp \ + proctable.cpp +HEADERS+= \ + processor.h \ + procclass.h \ + proctrans.h \ + proctable.h + +INCLUDEPATH += proc \ No newline at end of file diff --git a/woc/proc/procclass.cpp b/woc/proc/procclass.cpp new file mode 100644 index 0000000..f656fef --- /dev/null +++ b/woc/proc/procclass.cpp @@ -0,0 +1,332 @@ +// +// C++ Implementation: processor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "processor.h" + +#include "phpout.h" +#include "qtout.h" +#include "htmlout.h" + +#include "domquery.h" + +#include +#include +#include +#include + +/****************************************************************************** + * WocClass + ******************************************************************************/ + +WocClass::WocClass(const QDomElement&cls) +{ + //scan basics + m_valid=true; + m_abstract=str2bool(cls.attribute("abstract","0")); + WocProcessor *woc=WocProcessor::instance(); + QRegExp symok("[a-z_][a-z0-9_]*",Qt::CaseInsensitive); + m_name=cls.attribute("name"); + if(m_name==""){ + qDebug("Error: unnamed class at line %i column %i.",cls.lineNumber(),cls.columnNumber()); + m_valid=false; + return; + } + if(woc->hasClass(m_name)){ + qDebug("Error: double definition of class %s at line %i column %i.",m_name.toAscii().data(),cls.lineNumber(),cls.columnNumber()); + m_valid=false; + return; + } + if(!symok.exactMatch(m_name)){ + qDebug("Error: Illegal class name %s.",m_name.toAscii().data()); + m_valid=false; + return; + } + qDebug("Info: parsing class %s",m_name.toAscii().data()); + m_sbase=cls.attribute("serverbase","WObject"); + m_cbase=cls.attribute("clientbase","WObject"); + //scan properties + QList nl=elementsByTagName(cls,"Property"); + for(int i=0;iev; + //check whether there is a reference + if(el.hasAttribute("refColumn")){ + QStringList ref=el.attribute("refColumn").split(":"); + if(ref.size()!=2){ + qDebug("Error: illegal enum reference in class %s enum %s.",m_name.toAscii().data(),nm.toAscii().data()); + m_valid=false; + return; + } + if(!woc->hasTable(ref[0])){ + qDebug("Error: enum reference in class %s enum %s points to non-existant table.",m_name.toAscii().data(),nm.toAscii().data()); + m_valid=false; + return; + } + WocTable tab=woc->table(ref[0]); + if(!tab.hasColumn(ref[1])){ + qDebug("Error: enum reference in class %s enum %s points to non-existant column.",m_name.toAscii().data(),nm.toAscii().data()); + m_valid=false; + return; + } + ev=tab.columnEnums(ref[1]); + } + //scan values + QList nl2=elementsByTagName(el,"Value"); + int nxval=0; + for(int j=0;jmap; + QList nl2=elementsByTagName(el,"Map"); + for(int j=0;j nl3=elementsByTagName(el2,"Call"); + for(int k=0;khasClass(t); +} + +bool WocClass::propertyIsEnum(QString p)const +{ + QString t=propertyPlainType(p); + //default types take precedence over enums + if(attrtypes.contains(t))return false; + if(elemtypes.contains(t))return false; + //enums + return hasEnumType(t); +} + +bool WocClass::propertyIsList(QString p)const +{ + if(propertyType(p).startsWith("List:"))return true; + else return false; +} + +QMap WocClass::mapping(QString m)const +{ + if(!m_maps.contains(m))return QMap(); + QList sml=m_maps[m]; + QMapret; + for(int i=0;i sml=m_maps[m]; + QStringList ret; + for(int i=0;i sml=m_maps[table]; + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PROCESSOR_CLASS_H +#define WOC_PROCESSOR_CLASS_H + +#include +#include +#include +#include +#include + +/**helper structure to store enums in classes and tables*/ +struct WocEnum { + QString name,doc; + int val; + WocEnum(){val=0;} + WocEnum(QString n,int v,QString d=""){name=n;val=v;doc=d;} +}; + +/**stores a communication class including serialization and deserialization information*/ +class WocClass +{ + public: + /**parses XML to create itself*/ + WocClass(const QDomElement&); + + /**returns whether parsing was successful and this instance represents a valid communication class*/ + bool isValid()const{return m_valid;} + + /**returns the class name*/ + QString name()const{return m_name;} + /**returns the name of the class it is derived from (on the server side) - default: WObject*/ + QString serverBaseClass()const{return m_sbase;} + /**returns the parent class of the class on client side- default: WObject*/ + QString clientBaseClass()const{return m_cbase;} + + /**returns true of it has a property with this name*/ + bool hasProperty(QString)const; + /**returns a list of all property names*/ + QStringList propertyNames()const; + /**returns the type string of the property, including "List:" if applicable*/ + QString propertyType(QString)const; + /**returns the plain type string of the property without "List:"*/ + QString propertyPlainType(QString)const; + /**returns whether this property identifies the object instance*/ + bool propertyIsIdentity(QString)const; + /**returns whether this property is abstract*/ + bool propertyIsAbstract(QString)const; + /**returns whether this property is serialized as XML attribute*/ + bool propertyIsAttribute(QString)const; + /**returns whether this property is serialized as XML element*/ + bool propertyIsElement(QString)const; + /**returns whether this property has an enum type*/ + bool propertyIsEnum(QString)const; + /**returns whether the property is an object*/ + bool propertyIsObject(QString)const; + /**returns whether the property is a list of values (false for scalars)*/ + bool propertyIsList(QString)const; + /**returns whether the property type is integer*/ + bool propertyIsInt(QString p)const{QString pt=propertyPlainType(p);return pt=="int" || pt=="int32" || pt=="int64";} + /**returns whether the property type is boolean*/ + bool propertyIsBool(QString p)const{return propertyPlainType(p)=="bool";} + /**returns whether the property type is string*/ + bool propertyIsString(QString p)const{QString pt=propertyPlainType(p);return pt=="string"||pt=="astring";} + /**returns whether the property type is blob*/ + bool propertyIsBlob(QString p)const{QString pt=propertyPlainType(p);return pt=="blob";} + + /**returns whether the class is abstract in the requested language (needs to be customized); it is automatically abstract if any property is abstract*/ + bool isAbstract(QString)const; + /**returns the languages in which the class is conditionally abstract*/ + QStringList abstractLangs()const{return m_cabstract;} + + /**returns the names of all enum types of this class*/ + QStringList enumTypes()const{return m_enumvals.keys();} + /**returns true if the given enum type exists in this class*/ + bool hasEnumType(QString t)const{return m_enumvals.contains(t);} + /**returns a list of enum values as name-value pairs*/ + QList enumValues(QString t)const{return m_enumvals[t];} + + /**returns true if the given mapping exists*/ + bool hasMapping(QString m)const{return m_maps.contains(m);} + /**returns the names of all tables for which a mapping exists*/ + QStringList mappingTables()const{return m_maps.keys();} + /**returns the (correctly ordered) properties for a mapping*/ + QStringList mappingProperties(QString)const; + /**returns the specific mapping; map key=property, map value=column*/ + QMap mapping(QString m)const; + /**returns the method for a specific mapping or an empty string if it does not exist in the specified language*/ + QString mapMethod(QString table,QString property,QString lang)const; + + /**returns documentation for this class*/ + QStringList docStrings()const{return m_docstrings;} + /**returns documentation for a property*/ + QString propDoc(QString p)const + {if(m_propdoc.contains(p))return m_propdoc[p];else return "";} + + private: + //valid: parsing the WOLF succeeded + //abstract: the class is declared abstract (isAbstract may return true even if this is false) + //cabstract: conditional abstract - just for one or two languages; abstract overrides cabstract! + bool m_valid,m_abstract; + QStringList m_cabstract; + //name: class name + //base: name of parent class (s=server, c=client) + QString m_name,m_sbase,m_cbase; + //property info + struct s_prop{ + QString name,type; + bool isid,isabstract; + }; + QList m_props; + //mappings: "table-name" => List of ("column-name","property-name") + struct s_map{ + QString column,property; + QMapmethod;//lang->method + }; + QMap >m_maps; + //enum types: "type-name" => List of ("constant-name",int-constant-value) + QMap >m_enumvals; + //serializers: "name" => List of properties (syntax Objects: "propertyname/Serializer" +// QMap m_serial; + + //docu + QStringList m_docstrings; + QMapm_propdoc; + + //helper: contains predefined types sorted by serialization type + static const QStringList attrtypes,elemtypes; +}; + +#endif diff --git a/woc/proc/processor.cpp b/woc/proc/processor.cpp new file mode 100644 index 0000000..11cea42 --- /dev/null +++ b/woc/proc/processor.cpp @@ -0,0 +1,354 @@ +// +// C++ Implementation: processor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "processor.h" + +#include "phpout.h" +#include "qtout.h" +#include "htmlout.h" + +#include "domquery.h" + +#include +#include +#include +#include + +QListelementsByTagName(const QDomElement&root,QString tag) +{ + QDomNodeList cn=root.childNodes(); + QListret; + for(int i=0;i nl=elementsByTagName(el,"AuditTables"); + for(int i=0;imaxv)maxv=cv; + } + if(minv==maxv) + m_svnRev=QString::number(maxv); + else + m_svnRev=QString::number(minv)+"-"+QString::number(maxv); + } + //parse for repository path + MDomNodeList nl=MDomQuery(doc,"/*/entry"); + for(int i=0;i0)m_svnUrl=rl[0]; + rl=MDomQuery(el,"repository/root"); + if(rl.size()>0)m_svnRoot=rl[0]; + break;//we can stop now + } + } + } + //svn status + svn.start(m_svnExe,QStringList()<<"status"<<"--xml"<<"--non-interactive"<<"."); + svn.waitForFinished(); + if(svn.exitCode()!=0){ + qDebug("Warning: error while calling svn status."); + m_svnRev+=" uncertain"; + return; + }else{ + QDomDocument doc; + if(!doc.setContent(svn.readAllStandardOutput())){ + qDebug("Warning: unable to parse output of svn status."); + m_svnRev+=" uncertain"; + return; + } + QStringList rl=MDomQuery(doc,"/status/target/entry/wc-status/@item"); + bool ismod=false; + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PROCESSOR_H +#define WOC_PROCESSOR_H + +#include +#include +#include +#include +#include + +class QDomElement; + +QListelementsByTagName(const QDomElement&,QString); + +inline bool str2bool(QString s) +{ + bool b; + int i=s.toInt(&b,0); + if(b)return i?true:false; + s=s.toLower(); + if(s=="yes"||s=="y"||s=="on"||s=="true"||s=="t")return true; + return false; +} + +#include "procclass.h" +#include "proctable.h" +#include "proctrans.h" + + +/**base class of all output generators*/ +class WocOutput:public QObject +{ + Q_OBJECT + public: + /**the constructor should set up and initialize the environment of the generator*/ + WocOutput(); + /**currently there is no guarantee that the destructor is ever called.*/ + virtual ~WocOutput(); + + protected slots: + /**called whenever the parser finds a new class in the XML input; some references might not exist yet*/ + virtual void newClass(const WocClass&)=0; + /**called whenever the parser finds a new table in the XML input; the parser guarantees that tables it depends on already exist (it will throw an error otherwise)*/ + virtual void newTable(const WocTable&)=0; + /**called whenever the parser finds a new transaction; the parser guarantees that all referenced types exist (it will throw an error otherwise)*/ + virtual void newTransaction(const WocTransaction&)=0; + /**called when the parsing is complete: it should clean up the generators environment; it may not be called if woc stops with an error*/ + virtual void finalize()=0; + signals: + void errorFound(); +}; + +/**central processing singleton*/ +class WocProcessor:public QObject +{ + Q_OBJECT + public: + WocProcessor(); + + /**called from main loop to parse a file*/ + bool processFile(QString); + /**called from main loop to finalize its work*/ + void finalize(); + + /**returns the instance of the processor (if it exists yet)*/ + static WocProcessor* instance(){return inst;} + + /**returns the base directory of the project (all other pathes are relative to it)*/ + QString baseDir()const{return m_baseDir;} + /**returns the directory where WOLFs are found, should normally not be used outside this class*/ + QString wobDir()const{return m_wobDir;} + /**returns the project name (default="WobProject")*/ + QString projectName()const{return m_projname;} + /**returns the current communication protocol version*/ + QString verComm()const{return m_verComm;} + /**returns the communication protocol version that is at least needed to be compatible*/ + QString verNeedComm()const{return m_verNeedComm;} + /**returns a human readable version string*/ + QString verHR()const{return m_verHR;} + /**returns the SVN revision of the project: it contains two tokens, the first one is the current revision or min-max if the working copy contains mixed revisions; the second token contains the word "vanilla" if there are no local modifications, or "modified" if there are local modifications*/ + QString svnRevision()const{return m_svnRev;} + /**returns the SVN Repository Root*/ + QString svnRepositoryRoot()const{return m_svnRoot;} + /**returns the complete SVN Repository URL*/ + QString svnRepositoryUrl()const{return m_svnUrl;} + /**returns the variable name that will contain the database driver instance*/ + QString dbInst()const{return m_dbInst;} + /**returns the variable name that will contain the database schema object*/ + QString dbSchema()const{return m_dbSchema;} + /**returns the database schema version*/ + QString dbVersion()const{return m_dbVer;} + + /**returns whether a table exists*/ + bool hasTable(QString)const; + /**returns the requested table*/ + WocTable table(QString)const; + + /**returns whether a class exists*/ + bool hasClass(QString)const; + + /**returns a list of transaction names*/ + QStringList transactionNames()const; + /**returns a list of class names*/ + QStringList classNames()const; + /**returns a list of table names*/ + QStringList tableNames()const; + + /**returns global docu*/ + QStringList docStrings()const{return m_docstrings;} + + /**returns the qualified names of all privileges*/ + QStringList privilegeNames()const; + + /**returns the default for the database "updating" attribute*/ + bool dbUpdatingDefault()const{return m_dbUpd;} + signals: + void sfinalize(); + void newClass(const WocClass&); + void newTable(const WocTable&); + void newTransaction(const WocTransaction&); + public slots: + void errorFound(); + private: + QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR,m_projname; + QString m_svnTarget,m_svnRev,m_svnExe,m_svnRoot,m_svnUrl; + QString m_dbInst,m_dbSchema,m_dbVer; + QStringList m_docstrings; + bool m_error,m_dbUpd; + + QList m_tables; + QList m_classes; + QList m_transactions; + + static WocProcessor*inst; + + /**helper: calls SVN and parses its output*/ + void callSvn(); +}; + + +#endif diff --git a/woc/proc/proctable.cpp b/woc/proc/proctable.cpp new file mode 100644 index 0000000..c521ee8 --- /dev/null +++ b/woc/proc/proctable.cpp @@ -0,0 +1,448 @@ +// +// C++ Implementation: processor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "processor.h" + +#include "phpout.h" +#include "qtout.h" +#include "htmlout.h" + +#include "domquery.h" + +#include +#include +#include +#include + + +/****************************************************************************** + * WocTable + ******************************************************************************/ + +WocTable::WocTable() +{ + m_backup=m_valid=m_audit=false; +} + +WocTable::WocTable(const QDomElement&tbl) +{ + m_valid=true; + //parse XML + m_name=tbl.attribute("name"); + WocProcessor*woc=WocProcessor::instance(); + QRegExp good("[a-z][a-z0-9_]*",Qt::CaseInsensitive); + //check name syntax, check it does not exist yet + if(woc->hasTable(m_name)){ + qDebug("Error: double definition of table %s.",m_name.toAscii().data()); + m_valid=false; + return; + } + if(!good.exactMatch(m_name)){ + qDebug("Error: table %s does not have a regular name.",m_name.toAscii().data()); + m_valid=false; + return; + } + m_backup=str2bool(tbl.attribute("backup","0")); + m_base=tbl.attribute("base","WobTable"); + m_audit=str2bool(tbl.attribute("audit","0")); + qDebug("Info: parsing table %s",m_name.toAscii().data()); + //Columns + QList nl=elementsByTagName(tbl,"Column"); + for(int i=0;i cl=parseColumn(el,m_name); + if(!cl.first)return; + if(hasColumn(cl.second.name)){ + qDebug("Error: double definition of column %s in table %s.",cl.second.name.toAscii().data(),m_name.toAscii().data()); + m_valid=false; + return; + } + m_columns.append(cl.second); + } + //Audit Columns + nl=elementsByTagName(tbl,"AuditColumn"); + for(int i=0;i cl=parseColumn(el,m_name); + if(!cl.first)return; + m_auditcolumns.append(cl.second); + } + + //Foreign getter methods + nl=elementsByTagName(tbl,"Foreign"); + for(int i=0;i(el.attribute("method"),el.attribute("via"))); + //TODO: validate foreign getter + //docu + QString s=el.text().trimmed(); + if(s!="")m_fordocs.insert(el.attribute("method"),s); + } + + //Presets + nl=elementsByTagName(tbl,"Preset"); + for(int i=0;ips; + QList nl2=elementsByTagName(el,"V"); + for(int j=0;j0)m_presets.append(ps); + } + + //Docu + nl=elementsByTagName(tbl,"Doc"); + for(int i=0;i WocTable::parseColumn(const QDomElement&el,QString m_name) +{ + s_col cl; + QRegExp good("[a-z][a-z0-9_]*",Qt::CaseInsensitive); + cl.name=el.attribute("name"); + //check name syntax, check it is not doubled + if(!good.exactMatch(cl.name)){ + qDebug("Error: table %s column %s does not have a regular name.",m_name.toAscii().data(),cl.name.toAscii().data()); + return QPair(false,s_col()); + } + cl.isprime=str2bool(el.attribute("primarykey","0")); + cl.isunique=str2bool(el.attribute("unique","0")); + cl.isindex=str2bool(el.attribute("index","0")); + if(cl.isprime)cl.isnull=false; + else cl.isnull=true; + if(el.hasAttribute("null")) + cl.isnull=str2bool(el.attribute("null")); + else if(el.hasAttribute("notnull")) + cl.isnull=!str2bool(el.attribute("notnull","0")); + cl.type=el.attribute("type"); + //TODO: validate type + cl.foreign=el.attribute("foreignkey"); + WocProcessor*woc=WocProcessor::instance(); + //check foreign key exists + if(cl.foreign!=""){ + QStringList fgn=cl.foreign.split(":"); + if(fgn.size()!=2){ + qDebug("Error: table %s column %s: foreign key definition must use syntax 'table:column'",m_name.toAscii().data(),cl.name.toAscii().data()); + return QPair(false,s_col()); + } + if(!woc->hasTable(fgn[0])){ + qDebug("Error: table %s column %s: foreign key target table %s does not exist",m_name.toAscii().data(),cl.name.toAscii().data(),fgn[0].toAscii().data()); + return QPair(false,s_col()); + } + if(!woc->table(fgn[0]).hasColumn(fgn[1])){ + qDebug("Error: table %s column %s: foreign key target table/column %s does not exist",m_name.toAscii().data(),cl.name.toAscii().data(),cl.foreign.toAscii().data()); + return QPair(false,s_col()); + } + } + cl.defaultval=el.attribute("default"); + //TODO: validate default against type + QList nl2=elementsByTagName(el,"Value"); + int nxval=0; + //enum values + for(int j=0;j(true,cl); +} + +QStringList WocTable::columns()const +{ + QStringList r; + for(int i=0;i WocTable::columnEnums(QString c)const +{ + for(int i=0;i(); +} + +QList WocTable::getEnums()const +{ + QList r; + for(int i=0;iWocTable::m_staticauditcolumns; +void WocTable::parseAuditStatic(const QDomElement&el) +{ + QList nl=elementsByTagName(el,"Column"); + for(int i=0;icl=parseColumn(el2,"(global audit settings)"); + if(!cl.first){ + WocProcessor::instance()->errorFound(); + return; + } + m_staticauditcolumns.append(cl.second); + } +} + +WocTable WocTable::auditTable()const +{ + WocTable adt; + adt.m_valid=m_valid; + adt.m_backup=m_backup; + adt.m_audit=false; + adt.m_name=m_name+"_audit";//enhance the name + adt.m_base="WobTable";//revert to default + adt.m_foreign=m_foreign; + adt.m_fordocs=m_fordocs; + adt.m_docstrings=m_docstrings; + //these stay empty: m_presets, m_auditcolumns + + //now for the complicated stuff + //create primary key + s_col cl; + cl.name="auditid";cl.type="seq64";cl.doc="additional primary key for auditing"; + cl.isindex=cl.isunique=cl.isnull=false;cl.isprime=true; + adt.m_columns.append(cl); + //copy common columns + adt.m_columns.append(m_staticauditcolumns); + //copy normal columns + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PROCESSOR_TABLE_H +#define WOC_PROCESSOR_TABLE_H + +#include +#include +#include +#include +#include + + +/**stores the internal representation of a database table and its abstraction class*/ +class WocTable +{ + public: + /**initializes an invalid table*/ + WocTable(); + /**initializes a table from XML*/ + WocTable(const QDomElement&); + + /**returns whether this instance is valid, ie. whether parsing was successful*/ + bool isValid()const{return m_valid;} + + /**returns the table name*/ + QString name()const{return m_name;} + /**returns whether the table is marked for backup*/ + bool inBackup()const{return m_backup;} + /**returns the parent class of the table class - default: WobTable*/ + QString baseClass()const{return m_base;} + + /**returns whether the table has a column with this name*/ + bool hasColumn(QString)const; + /**returns a list of all defined column names*/ + QStringList columns()const; + /**returns the list of all primary key columns*/ + QStringList primaryColumns()const; + /**returns the data type of the column*/ + QString columnType(QString)const; + /**returns whether the column allows NULLs*/ + bool columnIsNull(QString)const; + /**returns whether the column is part of the primary key*/ + bool columnIsPrimary(QString)const; + /**returns whether the column has a default*/ + bool columnHasDefault(QString)const; + /**returns the default value of the column (empty string if there is none)*/ + QString columnDefault(QString)const; + /**returns whether the column is a foreign key*/ + bool columnIsForeign(QString)const; + /**returns the foreign key reference of the column in the format table:column*/ + QString columnForeign(QString)const; + /**returns whether the column has an index*/ + bool columnIsIndexed(QString)const; + /**returns whether the column has a unique constraint*/ + bool columnIsUnique(QString)const; + /**returns enum definitions of the column - each pair contains the symbolic name in first and the assigned integer value in second*/ + QList columnEnums(QString)const; + /**returns the insert call of a column for a specific language; empty string if there is none*/ + QString columnCall(QString col,QString lang)const; + + /**returns all enum definitions of the table; see also columnEnums */ + QList getEnums()const; + + /**returns a list of all foreign definitions - methods that return data from other tables*/ + QStringList foreigns()const; + /**returns the definition of a specific foreign table query method*/ + QString foreignQuery(QString)const; + /**returns whether a foreign table query method exists*/ + bool haveForeign(QString)const; + + /**returns a list of all preset values (to be generated when the DB is created); + each entry in the list is a dictionary with the column name as key and the intended preset value as value - each entry of the list is one DB row, each key-value-pair in the map is one preset value in that row*/ + QList > presets()const{return m_presets;} + + /**parses the static part of auditing*/ + static void parseAuditStatic(const QDomElement&); + /**returns whether the table is auditable*/ + bool isAuditable()const{return m_audit;} + /**creates and returns the table instance that represents the audit table*/ + WocTable auditTable()const; + /**returns the names of audit columns (except auditid)*/ + QStringList auditColumns()const; + + /**returns table documentation*/ + QStringList docStrings()const{return m_docstrings;} + /**returns column documentation*/ + QString columnDoc(QString c)const; + /**returns foreign getter documentation*/ + QString foreignDoc(QString c)const + {if(m_fordocs.contains(c))return m_fordocs[c];else return "";} + + private: + bool m_valid,m_backup,m_audit; + QString m_name,m_base; + struct s_col { + QString name,type,foreign,defaultval,doc; + bool isnull,isprime,isindex,isunique; + QListenumvals; + QMapmethodcalls; + }; + QListm_columns,m_auditcolumns; + static QListm_staticauditcolumns; + QList >m_foreign; + QList >m_presets; + + QStringList m_docstrings; + QMapm_fordocs; + + //helper method: parses a single column element + static QPair parseColumn(const QDomElement&,QString); +}; + + +#endif diff --git a/woc/proc/proctrans.cpp b/woc/proc/proctrans.cpp new file mode 100644 index 0000000..6486a34 --- /dev/null +++ b/woc/proc/proctrans.cpp @@ -0,0 +1,191 @@ +// +// C++ Implementation: processor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "processor.h" + +#include "phpout.h" +#include "qtout.h" +#include "htmlout.h" + +#include "domquery.h" + +#include +#include +#include +#include + +/****************************************************************************** + * WocTransaction + ******************************************************************************/ + +WocTransaction::WocTransaction(const QDomElement&root) +{ + m_valid=true; + m_mode=Checked; + QRegExp rval("[a-z][a-z0-9_]*",Qt::CaseInsensitive); + //get basics + m_name=root.attribute("name"); + if(!rval.exactMatch(m_name)){ + qDebug("Error: invalid transaction name %s.",m_name.toAscii().data()); + m_valid=false; + return; + } + qDebug("Info: parsing transaction %s",m_name.toAscii().data()); + if(root.hasAttribute("mode")){ + QString m=root.attribute("mode").toLower(); + if(m=="checked")m_mode=Checked;else + if(m=="auth")m_mode=Auth;else + if(m=="open")m_mode=Open; + else{ + qDebug("Error: invalid transaction mode %s in transaction %s, must be checked, auth, or open.",m.toAscii().data(),m_name.toAscii().data()); + m_valid=false; + return; + } + } + if(root.hasAttribute("updating")) + m_update=str2bool(root.attribute("updating")); + else + m_update=WocProcessor::instance()->dbUpdatingDefault(); + //input tag + QList nl=elementsByTagName(root,"Input"); + for(int i=0;i nl2=elementsByTagName(el,"Var"); + for(int j=0;j(nm,tp)); + //docu + QString s=el2.text().trimmed(); + if(s!="")m_indoc.insert(nm,s); + } + } + //call tag + nl=elementsByTagName(root,"Call"); + for(int j=0;j nl2=elementsByTagName(el,"Var"); + for(int j=0;j(nm,tp)); + //docu + QString s=el2.text().trimmed(); + if(s!="")m_outdoc.insert(nm,s); + } + } + //docu + nl=elementsByTagName(root,"Doc"); + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_PROCESSOR_TRANS_H +#define WOC_PROCESSOR_TRANS_H + +#include +#include +#include +#include +#include + +/**internal representation of a transaction*/ +class WocTransaction +{ + public: + /**initializes a transaction from XML*/ + WocTransaction(const QDomElement&); + /**returns whether parsing it was successful*/ + bool isValid()const{return m_valid;} + + /**returns the name of the transaction*/ + QString name()const{return m_name;} + + /**returns whether an input variable exists*/ + bool hasInput(QString v)const; + /**returns the names of all inputs in the order of definition*/ + QStringList inputNames()const; + /**returns the type of an input variable*/ + QString inputType(QString)const; + + /**returns whether an output variable exists*/ + bool hasOutput(QString v)const; + /**returns the names of all outputs in the order of definition*/ + QStringList outputNames()const; + /**returns the type of an output variable*/ + QString outputType(QString)const; + + /**returns whether a specific language binding exists for a call*/ + bool hasCall(QString c)const{return m_call.contains(c);} + /**returns the called function*/ + QString callFunction(QString c)const{return m_call[c];} + + /**authentication mode*/ + enum AuthMode { + /**default: need a valid session and the privilege*/ + Checked, + /**only need to be authenticated, every valid user can do it*/ + Auth, + /**available even to anonymous/unauthenticated users*/ + Open + }; + AuthMode authMode()const{return m_mode;} + + /**returns true if the type given is a list*/ + bool isListType(QString t)const{return t.startsWith("List:");} + /**returns the type without list or xml qualifiers*/ + QString plainType(QString t)const{ + if(t.startsWith("List:"))t=t.mid(5); + QStringList l=t.split("/",QString::SkipEmptyParts); + if(l.size()>0)t=l[0];else t="unknown"; + return t; + } + /**returns the XML serializer for Object types*/ + QString typeSerializer(QString t)const{ + QStringList l=t.split("/",QString::SkipEmptyParts); + if(l.size()>1)return l[1]; + else return ""; + } + /**returns true if the type is integer*/ + bool isIntType(QString t)const{QString pt=plainType(t);return pt=="int" || pt=="int32" || pt=="int64";} + /**returns true if the type is boolean*/ + bool isBoolType(QString t)const{return plainType(t)=="bool";} + /**returns true if the type is a string*/ + bool isStringType(QString t)const{QString p=plainType(t);return p=="astring"||p=="string";} + /**returns true if the type is a blob*/ + bool isBlobType(QString t)const{QString p=plainType(t);return p=="blob";} + /**returns true if the type is to be encoded as attribute*/ + bool isAttributeType(QString t)const{return t=="astring"||t=="int"||t=="int32"||t=="int64"||t=="bool";} + /**returns true if the type is to be encoded as element*/ + bool isElementType(QString t)const{return !isAttributeType(t);} + /**return true if the type is an object type*/ + bool isObjectType(QString t)const{QString p=plainType(t);return p!="astring"&&p!="string"&&p!="int"&&p!="int32"&&p!="int64"&&p!="bool"&&p!="blob";} + + /**return the documentation of the transaction*/ + QStringList docStrings()const{return m_docstrings;} + /**return docu of input element*/ + QString inputDoc(QString v)const + {if(m_indoc.contains(v))return m_indoc[v];else return "";} + /**return docu of output element*/ + QString outputDoc(QString v)const + {if(m_outdoc.contains(v))return m_outdoc[v];else return "";} + /**return docu of a privilege*/ + QString privilegeDoc(QString p)const + {if(m_privdoc.contains(p))return m_privdoc[p];else return "";} + + /**return privileges that exist inside this transaction*/ + QStringList privileges()const{return m_privileges;} + + /**returns whether this transaction is considered to update the database*/ + bool isDbUpdating()const{return m_update;} + private: + QString m_name; + bool m_valid,m_update; + AuthMode m_mode; + QMap m_call; + QList >m_input,m_output; + QStringList m_privileges; + //docu + QStringList m_docstrings; + QMapm_indoc,m_outdoc,m_privdoc; +}; + +#endif diff --git a/woc/procclass.cpp b/woc/procclass.cpp deleted file mode 100644 index f656fef..0000000 --- a/woc/procclass.cpp +++ /dev/null @@ -1,332 +0,0 @@ -// -// C++ Implementation: processor -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "processor.h" - -#include "phpout.h" -#include "qtout.h" -#include "htmlout.h" - -#include "domquery.h" - -#include -#include -#include -#include - -/****************************************************************************** - * WocClass - ******************************************************************************/ - -WocClass::WocClass(const QDomElement&cls) -{ - //scan basics - m_valid=true; - m_abstract=str2bool(cls.attribute("abstract","0")); - WocProcessor *woc=WocProcessor::instance(); - QRegExp symok("[a-z_][a-z0-9_]*",Qt::CaseInsensitive); - m_name=cls.attribute("name"); - if(m_name==""){ - qDebug("Error: unnamed class at line %i column %i.",cls.lineNumber(),cls.columnNumber()); - m_valid=false; - return; - } - if(woc->hasClass(m_name)){ - qDebug("Error: double definition of class %s at line %i column %i.",m_name.toAscii().data(),cls.lineNumber(),cls.columnNumber()); - m_valid=false; - return; - } - if(!symok.exactMatch(m_name)){ - qDebug("Error: Illegal class name %s.",m_name.toAscii().data()); - m_valid=false; - return; - } - qDebug("Info: parsing class %s",m_name.toAscii().data()); - m_sbase=cls.attribute("serverbase","WObject"); - m_cbase=cls.attribute("clientbase","WObject"); - //scan properties - QList nl=elementsByTagName(cls,"Property"); - for(int i=0;iev; - //check whether there is a reference - if(el.hasAttribute("refColumn")){ - QStringList ref=el.attribute("refColumn").split(":"); - if(ref.size()!=2){ - qDebug("Error: illegal enum reference in class %s enum %s.",m_name.toAscii().data(),nm.toAscii().data()); - m_valid=false; - return; - } - if(!woc->hasTable(ref[0])){ - qDebug("Error: enum reference in class %s enum %s points to non-existant table.",m_name.toAscii().data(),nm.toAscii().data()); - m_valid=false; - return; - } - WocTable tab=woc->table(ref[0]); - if(!tab.hasColumn(ref[1])){ - qDebug("Error: enum reference in class %s enum %s points to non-existant column.",m_name.toAscii().data(),nm.toAscii().data()); - m_valid=false; - return; - } - ev=tab.columnEnums(ref[1]); - } - //scan values - QList nl2=elementsByTagName(el,"Value"); - int nxval=0; - for(int j=0;jmap; - QList nl2=elementsByTagName(el,"Map"); - for(int j=0;j nl3=elementsByTagName(el2,"Call"); - for(int k=0;khasClass(t); -} - -bool WocClass::propertyIsEnum(QString p)const -{ - QString t=propertyPlainType(p); - //default types take precedence over enums - if(attrtypes.contains(t))return false; - if(elemtypes.contains(t))return false; - //enums - return hasEnumType(t); -} - -bool WocClass::propertyIsList(QString p)const -{ - if(propertyType(p).startsWith("List:"))return true; - else return false; -} - -QMap WocClass::mapping(QString m)const -{ - if(!m_maps.contains(m))return QMap(); - QList sml=m_maps[m]; - QMapret; - for(int i=0;i sml=m_maps[m]; - QStringList ret; - for(int i=0;i sml=m_maps[table]; - for(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PROCESSOR_CLASS_H -#define WOC_PROCESSOR_CLASS_H - -#include -#include -#include -#include -#include - -/**helper structure to store enums in classes and tables*/ -struct WocEnum { - QString name,doc; - int val; - WocEnum(){val=0;} - WocEnum(QString n,int v,QString d=""){name=n;val=v;doc=d;} -}; - -/**stores a communication class including serialization and deserialization information*/ -class WocClass -{ - public: - /**parses XML to create itself*/ - WocClass(const QDomElement&); - - /**returns whether parsing was successful and this instance represents a valid communication class*/ - bool isValid()const{return m_valid;} - - /**returns the class name*/ - QString name()const{return m_name;} - /**returns the name of the class it is derived from (on the server side) - default: WObject*/ - QString serverBaseClass()const{return m_sbase;} - /**returns the parent class of the class on client side- default: WObject*/ - QString clientBaseClass()const{return m_cbase;} - - /**returns true of it has a property with this name*/ - bool hasProperty(QString)const; - /**returns a list of all property names*/ - QStringList propertyNames()const; - /**returns the type string of the property, including "List:" if applicable*/ - QString propertyType(QString)const; - /**returns the plain type string of the property without "List:"*/ - QString propertyPlainType(QString)const; - /**returns whether this property identifies the object instance*/ - bool propertyIsIdentity(QString)const; - /**returns whether this property is abstract*/ - bool propertyIsAbstract(QString)const; - /**returns whether this property is serialized as XML attribute*/ - bool propertyIsAttribute(QString)const; - /**returns whether this property is serialized as XML element*/ - bool propertyIsElement(QString)const; - /**returns whether this property has an enum type*/ - bool propertyIsEnum(QString)const; - /**returns whether the property is an object*/ - bool propertyIsObject(QString)const; - /**returns whether the property is a list of values (false for scalars)*/ - bool propertyIsList(QString)const; - /**returns whether the property type is integer*/ - bool propertyIsInt(QString p)const{QString pt=propertyPlainType(p);return pt=="int" || pt=="int32" || pt=="int64";} - /**returns whether the property type is boolean*/ - bool propertyIsBool(QString p)const{return propertyPlainType(p)=="bool";} - /**returns whether the property type is string*/ - bool propertyIsString(QString p)const{QString pt=propertyPlainType(p);return pt=="string"||pt=="astring";} - /**returns whether the property type is blob*/ - bool propertyIsBlob(QString p)const{QString pt=propertyPlainType(p);return pt=="blob";} - - /**returns whether the class is abstract in the requested language (needs to be customized); it is automatically abstract if any property is abstract*/ - bool isAbstract(QString)const; - /**returns the languages in which the class is conditionally abstract*/ - QStringList abstractLangs()const{return m_cabstract;} - - /**returns the names of all enum types of this class*/ - QStringList enumTypes()const{return m_enumvals.keys();} - /**returns true if the given enum type exists in this class*/ - bool hasEnumType(QString t)const{return m_enumvals.contains(t);} - /**returns a list of enum values as name-value pairs*/ - QList enumValues(QString t)const{return m_enumvals[t];} - - /**returns true if the given mapping exists*/ - bool hasMapping(QString m)const{return m_maps.contains(m);} - /**returns the names of all tables for which a mapping exists*/ - QStringList mappingTables()const{return m_maps.keys();} - /**returns the (correctly ordered) properties for a mapping*/ - QStringList mappingProperties(QString)const; - /**returns the specific mapping; map key=property, map value=column*/ - QMap mapping(QString m)const; - /**returns the method for a specific mapping or an empty string if it does not exist in the specified language*/ - QString mapMethod(QString table,QString property,QString lang)const; - - /**returns documentation for this class*/ - QStringList docStrings()const{return m_docstrings;} - /**returns documentation for a property*/ - QString propDoc(QString p)const - {if(m_propdoc.contains(p))return m_propdoc[p];else return "";} - - private: - //valid: parsing the WOLF succeeded - //abstract: the class is declared abstract (isAbstract may return true even if this is false) - //cabstract: conditional abstract - just for one or two languages; abstract overrides cabstract! - bool m_valid,m_abstract; - QStringList m_cabstract; - //name: class name - //base: name of parent class (s=server, c=client) - QString m_name,m_sbase,m_cbase; - //property info - struct s_prop{ - QString name,type; - bool isid,isabstract; - }; - QList m_props; - //mappings: "table-name" => List of ("column-name","property-name") - struct s_map{ - QString column,property; - QMapmethod;//lang->method - }; - QMap >m_maps; - //enum types: "type-name" => List of ("constant-name",int-constant-value) - QMap >m_enumvals; - //serializers: "name" => List of properties (syntax Objects: "propertyname/Serializer" -// QMap m_serial; - - //docu - QStringList m_docstrings; - QMapm_propdoc; - - //helper: contains predefined types sorted by serialization type - static const QStringList attrtypes,elemtypes; -}; - -#endif diff --git a/woc/processor.cpp b/woc/processor.cpp deleted file mode 100644 index 11cea42..0000000 --- a/woc/processor.cpp +++ /dev/null @@ -1,354 +0,0 @@ -// -// C++ Implementation: processor -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "processor.h" - -#include "phpout.h" -#include "qtout.h" -#include "htmlout.h" - -#include "domquery.h" - -#include -#include -#include -#include - -QListelementsByTagName(const QDomElement&root,QString tag) -{ - QDomNodeList cn=root.childNodes(); - QListret; - for(int i=0;i nl=elementsByTagName(el,"AuditTables"); - for(int i=0;imaxv)maxv=cv; - } - if(minv==maxv) - m_svnRev=QString::number(maxv); - else - m_svnRev=QString::number(minv)+"-"+QString::number(maxv); - } - //parse for repository path - MDomNodeList nl=MDomQuery(doc,"/*/entry"); - for(int i=0;i0)m_svnUrl=rl[0]; - rl=MDomQuery(el,"repository/root"); - if(rl.size()>0)m_svnRoot=rl[0]; - break;//we can stop now - } - } - } - //svn status - svn.start(m_svnExe,QStringList()<<"status"<<"--xml"<<"--non-interactive"<<"."); - svn.waitForFinished(); - if(svn.exitCode()!=0){ - qDebug("Warning: error while calling svn status."); - m_svnRev+=" uncertain"; - return; - }else{ - QDomDocument doc; - if(!doc.setContent(svn.readAllStandardOutput())){ - qDebug("Warning: unable to parse output of svn status."); - m_svnRev+=" uncertain"; - return; - } - QStringList rl=MDomQuery(doc,"/status/target/entry/wc-status/@item"); - bool ismod=false; - for(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PROCESSOR_H -#define WOC_PROCESSOR_H - -#include -#include -#include -#include -#include - -class QDomElement; - -QListelementsByTagName(const QDomElement&,QString); - -inline bool str2bool(QString s) -{ - bool b; - int i=s.toInt(&b,0); - if(b)return i?true:false; - s=s.toLower(); - if(s=="yes"||s=="y"||s=="on"||s=="true"||s=="t")return true; - return false; -} - -#include "procclass.h" -#include "proctable.h" -#include "proctrans.h" - - -/**base class of all output generators*/ -class WocOutput:public QObject -{ - Q_OBJECT - public: - /**the constructor should set up and initialize the environment of the generator*/ - WocOutput(); - /**currently there is no guarantee that the destructor is ever called.*/ - virtual ~WocOutput(); - - protected slots: - /**called whenever the parser finds a new class in the XML input; some references might not exist yet*/ - virtual void newClass(const WocClass&)=0; - /**called whenever the parser finds a new table in the XML input; the parser guarantees that tables it depends on already exist (it will throw an error otherwise)*/ - virtual void newTable(const WocTable&)=0; - /**called whenever the parser finds a new transaction; the parser guarantees that all referenced types exist (it will throw an error otherwise)*/ - virtual void newTransaction(const WocTransaction&)=0; - /**called when the parsing is complete: it should clean up the generators environment; it may not be called if woc stops with an error*/ - virtual void finalize()=0; - signals: - void errorFound(); -}; - -/**central processing singleton*/ -class WocProcessor:public QObject -{ - Q_OBJECT - public: - WocProcessor(); - - /**called from main loop to parse a file*/ - bool processFile(QString); - /**called from main loop to finalize its work*/ - void finalize(); - - /**returns the instance of the processor (if it exists yet)*/ - static WocProcessor* instance(){return inst;} - - /**returns the base directory of the project (all other pathes are relative to it)*/ - QString baseDir()const{return m_baseDir;} - /**returns the directory where WOLFs are found, should normally not be used outside this class*/ - QString wobDir()const{return m_wobDir;} - /**returns the project name (default="WobProject")*/ - QString projectName()const{return m_projname;} - /**returns the current communication protocol version*/ - QString verComm()const{return m_verComm;} - /**returns the communication protocol version that is at least needed to be compatible*/ - QString verNeedComm()const{return m_verNeedComm;} - /**returns a human readable version string*/ - QString verHR()const{return m_verHR;} - /**returns the SVN revision of the project: it contains two tokens, the first one is the current revision or min-max if the working copy contains mixed revisions; the second token contains the word "vanilla" if there are no local modifications, or "modified" if there are local modifications*/ - QString svnRevision()const{return m_svnRev;} - /**returns the SVN Repository Root*/ - QString svnRepositoryRoot()const{return m_svnRoot;} - /**returns the complete SVN Repository URL*/ - QString svnRepositoryUrl()const{return m_svnUrl;} - /**returns the variable name that will contain the database driver instance*/ - QString dbInst()const{return m_dbInst;} - /**returns the variable name that will contain the database schema object*/ - QString dbSchema()const{return m_dbSchema;} - /**returns the database schema version*/ - QString dbVersion()const{return m_dbVer;} - - /**returns whether a table exists*/ - bool hasTable(QString)const; - /**returns the requested table*/ - WocTable table(QString)const; - - /**returns whether a class exists*/ - bool hasClass(QString)const; - - /**returns a list of transaction names*/ - QStringList transactionNames()const; - /**returns a list of class names*/ - QStringList classNames()const; - /**returns a list of table names*/ - QStringList tableNames()const; - - /**returns global docu*/ - QStringList docStrings()const{return m_docstrings;} - - /**returns the qualified names of all privileges*/ - QStringList privilegeNames()const; - - /**returns the default for the database "updating" attribute*/ - bool dbUpdatingDefault()const{return m_dbUpd;} - signals: - void sfinalize(); - void newClass(const WocClass&); - void newTable(const WocTable&); - void newTransaction(const WocTransaction&); - public slots: - void errorFound(); - private: - QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR,m_projname; - QString m_svnTarget,m_svnRev,m_svnExe,m_svnRoot,m_svnUrl; - QString m_dbInst,m_dbSchema,m_dbVer; - QStringList m_docstrings; - bool m_error,m_dbUpd; - - QList m_tables; - QList m_classes; - QList m_transactions; - - static WocProcessor*inst; - - /**helper: calls SVN and parses its output*/ - void callSvn(); -}; - - -#endif diff --git a/woc/proctable.cpp b/woc/proctable.cpp deleted file mode 100644 index c521ee8..0000000 --- a/woc/proctable.cpp +++ /dev/null @@ -1,448 +0,0 @@ -// -// C++ Implementation: processor -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "processor.h" - -#include "phpout.h" -#include "qtout.h" -#include "htmlout.h" - -#include "domquery.h" - -#include -#include -#include -#include - - -/****************************************************************************** - * WocTable - ******************************************************************************/ - -WocTable::WocTable() -{ - m_backup=m_valid=m_audit=false; -} - -WocTable::WocTable(const QDomElement&tbl) -{ - m_valid=true; - //parse XML - m_name=tbl.attribute("name"); - WocProcessor*woc=WocProcessor::instance(); - QRegExp good("[a-z][a-z0-9_]*",Qt::CaseInsensitive); - //check name syntax, check it does not exist yet - if(woc->hasTable(m_name)){ - qDebug("Error: double definition of table %s.",m_name.toAscii().data()); - m_valid=false; - return; - } - if(!good.exactMatch(m_name)){ - qDebug("Error: table %s does not have a regular name.",m_name.toAscii().data()); - m_valid=false; - return; - } - m_backup=str2bool(tbl.attribute("backup","0")); - m_base=tbl.attribute("base","WobTable"); - m_audit=str2bool(tbl.attribute("audit","0")); - qDebug("Info: parsing table %s",m_name.toAscii().data()); - //Columns - QList nl=elementsByTagName(tbl,"Column"); - for(int i=0;i cl=parseColumn(el,m_name); - if(!cl.first)return; - if(hasColumn(cl.second.name)){ - qDebug("Error: double definition of column %s in table %s.",cl.second.name.toAscii().data(),m_name.toAscii().data()); - m_valid=false; - return; - } - m_columns.append(cl.second); - } - //Audit Columns - nl=elementsByTagName(tbl,"AuditColumn"); - for(int i=0;i cl=parseColumn(el,m_name); - if(!cl.first)return; - m_auditcolumns.append(cl.second); - } - - //Foreign getter methods - nl=elementsByTagName(tbl,"Foreign"); - for(int i=0;i(el.attribute("method"),el.attribute("via"))); - //TODO: validate foreign getter - //docu - QString s=el.text().trimmed(); - if(s!="")m_fordocs.insert(el.attribute("method"),s); - } - - //Presets - nl=elementsByTagName(tbl,"Preset"); - for(int i=0;ips; - QList nl2=elementsByTagName(el,"V"); - for(int j=0;j0)m_presets.append(ps); - } - - //Docu - nl=elementsByTagName(tbl,"Doc"); - for(int i=0;i WocTable::parseColumn(const QDomElement&el,QString m_name) -{ - s_col cl; - QRegExp good("[a-z][a-z0-9_]*",Qt::CaseInsensitive); - cl.name=el.attribute("name"); - //check name syntax, check it is not doubled - if(!good.exactMatch(cl.name)){ - qDebug("Error: table %s column %s does not have a regular name.",m_name.toAscii().data(),cl.name.toAscii().data()); - return QPair(false,s_col()); - } - cl.isprime=str2bool(el.attribute("primarykey","0")); - cl.isunique=str2bool(el.attribute("unique","0")); - cl.isindex=str2bool(el.attribute("index","0")); - if(cl.isprime)cl.isnull=false; - else cl.isnull=true; - if(el.hasAttribute("null")) - cl.isnull=str2bool(el.attribute("null")); - else if(el.hasAttribute("notnull")) - cl.isnull=!str2bool(el.attribute("notnull","0")); - cl.type=el.attribute("type"); - //TODO: validate type - cl.foreign=el.attribute("foreignkey"); - WocProcessor*woc=WocProcessor::instance(); - //check foreign key exists - if(cl.foreign!=""){ - QStringList fgn=cl.foreign.split(":"); - if(fgn.size()!=2){ - qDebug("Error: table %s column %s: foreign key definition must use syntax 'table:column'",m_name.toAscii().data(),cl.name.toAscii().data()); - return QPair(false,s_col()); - } - if(!woc->hasTable(fgn[0])){ - qDebug("Error: table %s column %s: foreign key target table %s does not exist",m_name.toAscii().data(),cl.name.toAscii().data(),fgn[0].toAscii().data()); - return QPair(false,s_col()); - } - if(!woc->table(fgn[0]).hasColumn(fgn[1])){ - qDebug("Error: table %s column %s: foreign key target table/column %s does not exist",m_name.toAscii().data(),cl.name.toAscii().data(),cl.foreign.toAscii().data()); - return QPair(false,s_col()); - } - } - cl.defaultval=el.attribute("default"); - //TODO: validate default against type - QList nl2=elementsByTagName(el,"Value"); - int nxval=0; - //enum values - for(int j=0;j(true,cl); -} - -QStringList WocTable::columns()const -{ - QStringList r; - for(int i=0;i WocTable::columnEnums(QString c)const -{ - for(int i=0;i(); -} - -QList WocTable::getEnums()const -{ - QList r; - for(int i=0;iWocTable::m_staticauditcolumns; -void WocTable::parseAuditStatic(const QDomElement&el) -{ - QList nl=elementsByTagName(el,"Column"); - for(int i=0;icl=parseColumn(el2,"(global audit settings)"); - if(!cl.first){ - WocProcessor::instance()->errorFound(); - return; - } - m_staticauditcolumns.append(cl.second); - } -} - -WocTable WocTable::auditTable()const -{ - WocTable adt; - adt.m_valid=m_valid; - adt.m_backup=m_backup; - adt.m_audit=false; - adt.m_name=m_name+"_audit";//enhance the name - adt.m_base="WobTable";//revert to default - adt.m_foreign=m_foreign; - adt.m_fordocs=m_fordocs; - adt.m_docstrings=m_docstrings; - //these stay empty: m_presets, m_auditcolumns - - //now for the complicated stuff - //create primary key - s_col cl; - cl.name="auditid";cl.type="seq64";cl.doc="additional primary key for auditing"; - cl.isindex=cl.isunique=cl.isnull=false;cl.isprime=true; - adt.m_columns.append(cl); - //copy common columns - adt.m_columns.append(m_staticauditcolumns); - //copy normal columns - for(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PROCESSOR_TABLE_H -#define WOC_PROCESSOR_TABLE_H - -#include -#include -#include -#include -#include - - -/**stores the internal representation of a database table and its abstraction class*/ -class WocTable -{ - public: - /**initializes an invalid table*/ - WocTable(); - /**initializes a table from XML*/ - WocTable(const QDomElement&); - - /**returns whether this instance is valid, ie. whether parsing was successful*/ - bool isValid()const{return m_valid;} - - /**returns the table name*/ - QString name()const{return m_name;} - /**returns whether the table is marked for backup*/ - bool inBackup()const{return m_backup;} - /**returns the parent class of the table class - default: WobTable*/ - QString baseClass()const{return m_base;} - - /**returns whether the table has a column with this name*/ - bool hasColumn(QString)const; - /**returns a list of all defined column names*/ - QStringList columns()const; - /**returns the list of all primary key columns*/ - QStringList primaryColumns()const; - /**returns the data type of the column*/ - QString columnType(QString)const; - /**returns whether the column allows NULLs*/ - bool columnIsNull(QString)const; - /**returns whether the column is part of the primary key*/ - bool columnIsPrimary(QString)const; - /**returns whether the column has a default*/ - bool columnHasDefault(QString)const; - /**returns the default value of the column (empty string if there is none)*/ - QString columnDefault(QString)const; - /**returns whether the column is a foreign key*/ - bool columnIsForeign(QString)const; - /**returns the foreign key reference of the column in the format table:column*/ - QString columnForeign(QString)const; - /**returns whether the column has an index*/ - bool columnIsIndexed(QString)const; - /**returns whether the column has a unique constraint*/ - bool columnIsUnique(QString)const; - /**returns enum definitions of the column - each pair contains the symbolic name in first and the assigned integer value in second*/ - QList columnEnums(QString)const; - /**returns the insert call of a column for a specific language; empty string if there is none*/ - QString columnCall(QString col,QString lang)const; - - /**returns all enum definitions of the table; see also columnEnums */ - QList getEnums()const; - - /**returns a list of all foreign definitions - methods that return data from other tables*/ - QStringList foreigns()const; - /**returns the definition of a specific foreign table query method*/ - QString foreignQuery(QString)const; - /**returns whether a foreign table query method exists*/ - bool haveForeign(QString)const; - - /**returns a list of all preset values (to be generated when the DB is created); - each entry in the list is a dictionary with the column name as key and the intended preset value as value - each entry of the list is one DB row, each key-value-pair in the map is one preset value in that row*/ - QList > presets()const{return m_presets;} - - /**parses the static part of auditing*/ - static void parseAuditStatic(const QDomElement&); - /**returns whether the table is auditable*/ - bool isAuditable()const{return m_audit;} - /**creates and returns the table instance that represents the audit table*/ - WocTable auditTable()const; - /**returns the names of audit columns (except auditid)*/ - QStringList auditColumns()const; - - /**returns table documentation*/ - QStringList docStrings()const{return m_docstrings;} - /**returns column documentation*/ - QString columnDoc(QString c)const; - /**returns foreign getter documentation*/ - QString foreignDoc(QString c)const - {if(m_fordocs.contains(c))return m_fordocs[c];else return "";} - - private: - bool m_valid,m_backup,m_audit; - QString m_name,m_base; - struct s_col { - QString name,type,foreign,defaultval,doc; - bool isnull,isprime,isindex,isunique; - QListenumvals; - QMapmethodcalls; - }; - QListm_columns,m_auditcolumns; - static QListm_staticauditcolumns; - QList >m_foreign; - QList >m_presets; - - QStringList m_docstrings; - QMapm_fordocs; - - //helper method: parses a single column element - static QPair parseColumn(const QDomElement&,QString); -}; - - -#endif diff --git a/woc/proctrans.cpp b/woc/proctrans.cpp deleted file mode 100644 index 6486a34..0000000 --- a/woc/proctrans.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// -// C++ Implementation: processor -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "processor.h" - -#include "phpout.h" -#include "qtout.h" -#include "htmlout.h" - -#include "domquery.h" - -#include -#include -#include -#include - -/****************************************************************************** - * WocTransaction - ******************************************************************************/ - -WocTransaction::WocTransaction(const QDomElement&root) -{ - m_valid=true; - m_mode=Checked; - QRegExp rval("[a-z][a-z0-9_]*",Qt::CaseInsensitive); - //get basics - m_name=root.attribute("name"); - if(!rval.exactMatch(m_name)){ - qDebug("Error: invalid transaction name %s.",m_name.toAscii().data()); - m_valid=false; - return; - } - qDebug("Info: parsing transaction %s",m_name.toAscii().data()); - if(root.hasAttribute("mode")){ - QString m=root.attribute("mode").toLower(); - if(m=="checked")m_mode=Checked;else - if(m=="auth")m_mode=Auth;else - if(m=="open")m_mode=Open; - else{ - qDebug("Error: invalid transaction mode %s in transaction %s, must be checked, auth, or open.",m.toAscii().data(),m_name.toAscii().data()); - m_valid=false; - return; - } - } - if(root.hasAttribute("updating")) - m_update=str2bool(root.attribute("updating")); - else - m_update=WocProcessor::instance()->dbUpdatingDefault(); - //input tag - QList nl=elementsByTagName(root,"Input"); - for(int i=0;i nl2=elementsByTagName(el,"Var"); - for(int j=0;j(nm,tp)); - //docu - QString s=el2.text().trimmed(); - if(s!="")m_indoc.insert(nm,s); - } - } - //call tag - nl=elementsByTagName(root,"Call"); - for(int j=0;j nl2=elementsByTagName(el,"Var"); - for(int j=0;j(nm,tp)); - //docu - QString s=el2.text().trimmed(); - if(s!="")m_outdoc.insert(nm,s); - } - } - //docu - nl=elementsByTagName(root,"Doc"); - for(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_PROCESSOR_TRANS_H -#define WOC_PROCESSOR_TRANS_H - -#include -#include -#include -#include -#include - -/**internal representation of a transaction*/ -class WocTransaction -{ - public: - /**initializes a transaction from XML*/ - WocTransaction(const QDomElement&); - /**returns whether parsing it was successful*/ - bool isValid()const{return m_valid;} - - /**returns the name of the transaction*/ - QString name()const{return m_name;} - - /**returns whether an input variable exists*/ - bool hasInput(QString v)const; - /**returns the names of all inputs in the order of definition*/ - QStringList inputNames()const; - /**returns the type of an input variable*/ - QString inputType(QString)const; - - /**returns whether an output variable exists*/ - bool hasOutput(QString v)const; - /**returns the names of all outputs in the order of definition*/ - QStringList outputNames()const; - /**returns the type of an output variable*/ - QString outputType(QString)const; - - /**returns whether a specific language binding exists for a call*/ - bool hasCall(QString c)const{return m_call.contains(c);} - /**returns the called function*/ - QString callFunction(QString c)const{return m_call[c];} - - /**authentication mode*/ - enum AuthMode { - /**default: need a valid session and the privilege*/ - Checked, - /**only need to be authenticated, every valid user can do it*/ - Auth, - /**available even to anonymous/unauthenticated users*/ - Open - }; - AuthMode authMode()const{return m_mode;} - - /**returns true if the type given is a list*/ - bool isListType(QString t)const{return t.startsWith("List:");} - /**returns the type without list or xml qualifiers*/ - QString plainType(QString t)const{ - if(t.startsWith("List:"))t=t.mid(5); - QStringList l=t.split("/",QString::SkipEmptyParts); - if(l.size()>0)t=l[0];else t="unknown"; - return t; - } - /**returns the XML serializer for Object types*/ - QString typeSerializer(QString t)const{ - QStringList l=t.split("/",QString::SkipEmptyParts); - if(l.size()>1)return l[1]; - else return ""; - } - /**returns true if the type is integer*/ - bool isIntType(QString t)const{QString pt=plainType(t);return pt=="int" || pt=="int32" || pt=="int64";} - /**returns true if the type is boolean*/ - bool isBoolType(QString t)const{return plainType(t)=="bool";} - /**returns true if the type is a string*/ - bool isStringType(QString t)const{QString p=plainType(t);return p=="astring"||p=="string";} - /**returns true if the type is a blob*/ - bool isBlobType(QString t)const{QString p=plainType(t);return p=="blob";} - /**returns true if the type is to be encoded as attribute*/ - bool isAttributeType(QString t)const{return t=="astring"||t=="int"||t=="int32"||t=="int64"||t=="bool";} - /**returns true if the type is to be encoded as element*/ - bool isElementType(QString t)const{return !isAttributeType(t);} - /**return true if the type is an object type*/ - bool isObjectType(QString t)const{QString p=plainType(t);return p!="astring"&&p!="string"&&p!="int"&&p!="int32"&&p!="int64"&&p!="bool"&&p!="blob";} - - /**return the documentation of the transaction*/ - QStringList docStrings()const{return m_docstrings;} - /**return docu of input element*/ - QString inputDoc(QString v)const - {if(m_indoc.contains(v))return m_indoc[v];else return "";} - /**return docu of output element*/ - QString outputDoc(QString v)const - {if(m_outdoc.contains(v))return m_outdoc[v];else return "";} - /**return docu of a privilege*/ - QString privilegeDoc(QString p)const - {if(m_privdoc.contains(p))return m_privdoc[p];else return "";} - - /**return privileges that exist inside this transaction*/ - QStringList privileges()const{return m_privileges;} - - /**returns whether this transaction is considered to update the database*/ - bool isDbUpdating()const{return m_update;} - private: - QString m_name; - bool m_valid,m_update; - AuthMode m_mode; - QMap m_call; - QList >m_input,m_output; - QStringList m_privileges; - //docu - QStringList m_docstrings; - QMapm_indoc,m_outdoc,m_privdoc; -}; - -#endif diff --git a/woc/qt/qt.pri b/woc/qt/qt.pri new file mode 100644 index 0000000..912dcdb --- /dev/null +++ b/woc/qt/qt.pri @@ -0,0 +1,15 @@ +SOURCES+= \ + qt/qtout.cpp \ + qt/qtclass.cpp \ + qt/qtdb.cpp \ + qt/qtctrans.cpp \ + qt/qtstrans.cpp + +HEADERS+= \ + qt/qtout.h \ + qt/qtclass.h \ + qt/qtdb.h \ + qt/qtctrans.h \ + qt/qtstrans.cpp + +INCLUDEPATH += qt \ No newline at end of file diff --git a/woc/qt/qtclass.cpp b/woc/qt/qtclass.cpp new file mode 100644 index 0000000..0ff8f0c --- /dev/null +++ b/woc/qt/qtclass.cpp @@ -0,0 +1,374 @@ +// +// C++ Implementation: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "qtout.h" +#include "qtclass.h" + +#include +#include + +#include "qtconst.h" + +WocQtClass::WocQtClass(WocQtOut* p) +{ + m_parent=p; + connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); +} + +WocQtClass::~WocQtClass() +{ +} + +void WocQtClass::finalize() +{ +} + + +void WocQtClass::newClass(const WocClass&cls) +{ + QString cn=m_prefix+"O"+cls.name(); + QString cna=cn; + if(cls.isAbstract(m_lang))cna+="Abstract"; + addFile(cna); + MFile hdr(m_basedir+"/"+m_subdir+"/"+cna+".h"); + MFile src(m_basedir+"/"+m_subdir+"/"+cna+".cpp"); + if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) || + !src.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create class files for class %s.",cn.toAscii().data()); + emit errorFound(); + return; + } + //lead in + hdr.write(QByteArray(HDRSTART).replace("%",cna.toAscii())); + src.write(QByteArray(SRCSTART).replace("%",cna.toAscii())); + + QString hcd; + QString scd; + //includes + hcd="#include \""+cls.clientBaseClass()+".h\"\n#include \n\n"; + QStringList k=cls.propertyNames(); + for(int i=0;iev=cls.enumValues(k[i]); + if(ev.size()<1){ + qDebug("Error: enums must have at least one member - class %s enum %s",cls.name().toAscii().data(),k[i].toAscii().data()); + emit errorFound(); + return; + } + for(int j=0;j1)var=pv[1]; + //is it a list + if(cls.propertyIsList(prop)){ + scd+="\tfor(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_QTOUT_CLASS_H +#define WOC_QTOUT_CLASS_H + +#include "mfile.h" +#include + +class QDomElement; +class WocClass; +class WocQtOut; + +class WocQtClass:public QObject +{ + Q_OBJECT + public: + WocQtClass(WocQtOut*); + ~WocQtClass(); + virtual void finalize(); + virtual void newClass(const WocClass&); + private: + WocQtOut*m_parent; + + /**helper: generate enums for classes*/ + void classEnums(const WocClass&,MFile&,MFile&,QString); + /**helper: generate properties*/ + void classProperties(const WocClass&,MFile&,MFile&); + /**helper: generate constructors/deserializer/copiers*/ + void classDeserializer(const WocClass&,MFile&,MFile&,QString); + /**helper: generate serializers*/ + void classSerializers(const WocClass&,MFile&,MFile&,QString); + signals: + void errorFound(); +}; + +#endif diff --git a/woc/qt/qtconst.h b/woc/qt/qtconst.h new file mode 100644 index 0000000..f252ddd --- /dev/null +++ b/woc/qt/qtconst.h @@ -0,0 +1,51 @@ +// +// C++ Implementation: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_QT_CONST_H +#define WOC_QT_CONST_H + +//start section of all header files +static const QByteArray HDRSTART= + "//AUTOMATICALLY GENERATED FILE\n" + "//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE!\n" + "#ifndef WOBGEN_%\n" + "#define WOBGEN_%\n\n"; +//end section of all header files +static const QByteArray HDREND="\n//END OF AUTOMATICALLY GENERATED FILE\n#endif\n"; + +//start section of all source files +static const QByteArray SRCSTART= + "//AUTOMATICALLY GENERATED FILE\n" + "//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE!\n" + "#include \"%.h\"\n" + "#include \n" + "#include \n"; +//end section of all source files +static const QByteArray SRCEND="\n//END OF AUTOMATICALLY GENERATED FILE\n"; + +#ifndef QT_OUT_NO_WRAP +#define m_basedir m_parent->m_basedir +#define m_subdir m_parent->m_subdir +#define m_prefix m_parent->m_prefix +#define m_transbase m_parent->m_transbase +#define m_pri m_parent->m_pri +#define m_iface m_parent->m_iface +#define m_ifacecpp m_parent->m_ifacecpp +#define m_hdr m_parent->m_hdr +#define m_clean m_parent->m_clean +#define qttype m_parent->qttype +#define qtobjtype m_parent->qtobjtype +#define addFile m_parent->addFile +#define m_lang m_parent->m_lang +#endif + +#endif diff --git a/woc/qt/qtctrans.cpp b/woc/qt/qtctrans.cpp new file mode 100644 index 0000000..e38b36e --- /dev/null +++ b/woc/qt/qtctrans.cpp @@ -0,0 +1,330 @@ +// +// C++ Implementation: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "qtout.h" +#include "qtctrans.h" + +#include +#include + +#include "qtconst.h" + +WocQtClientTransaction::WocQtClientTransaction(WocQtOut*p) + :WocQtTransaction(p) +{} +WocQtClientTransaction::~WocQtClientTransaction(){} + +void WocQtClientTransaction::finalize() +{ + trnList(); +} + +void WocQtClientTransaction::newTransaction(const WocTransaction&trn) +{ + QString cn=m_prefix+"T"+trn.name(); + addFile(cn); + MFile hdr(m_basedir+"/"+m_subdir+"/"+cn+".h"); + MFile src(m_basedir+"/"+m_subdir+"/"+cn+".cpp"); + if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) || + !src.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create class files for transaction %s.",cn.toAscii().data()); + emit errorFound(); + return; + } + //basics + QStringList in=trn.inputNames(); + QStringList out=trn.outputNames(); + //lead in + hdr.write(QByteArray(HDRSTART).replace("%",cn.toAscii())); + src.write(QByteArray(SRCSTART).replace("%",cn.toAscii())); + QString hcd; + QString scd; + hcd="#include \""+m_transbase+".h\"\n"; + scd+="#include \"WInterface.h\"\n#include \n"; + for(int i=0;i\n"; + } + for(int i=0;i\n"; + } + hcd+="\nclass "+cn+":public "+m_transbase+"\n{\n"; + hdr.write(hcd.toAscii()); + + //create properties + QString inlist,clist; + hcd=" private:\n"; + for(int i=0;iprojectName()+"\""; + //define parametric constructor + hcd=" public:\n"; + hcd+="\t"+cn+"("+inlist+defparm+");\n"; + //parametric constructor implementation + scd+=cn+"::"+cn+"("+inlist+")\n\t:"+m_transbase+"(iface)\n{\n"; + for(int i=0;itransactionNames(); + QStringList p=WocProcessor::instance()->privilegeNames(); + QStringList pp=p; + for(int i=0;i "+m_prefix+"Interface::allKnownRights()\n{\n"; + code+="\tQList ret;ret"; + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_QTOUT_CTRANS_H +#define WOC_QTOUT_CTRANS_H + +#include "qtout.h" + +class WocQtOut; +class WocTransaction; +class WocClass; + +class WocQtClientTransaction:public WocQtTransaction +{ + public: + WocQtClientTransaction(WocQtOut*); + ~WocQtClientTransaction(); + virtual void finalize(); + virtual void newTransaction(const WocTransaction&); + private: + /**helper generates the transaction input encoding*/ + QString trnInput(const WocTransaction&); + /**helper generates the transaction output decoding*/ + QString trnOutput(const WocTransaction&); + /**helper generates enums and strings for all transactions*/ + void trnList(); +}; + +#endif diff --git a/woc/qt/qtdb.cpp b/woc/qt/qtdb.cpp new file mode 100644 index 0000000..6d93269 --- /dev/null +++ b/woc/qt/qtdb.cpp @@ -0,0 +1,21 @@ +// +// C++ Implementation: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "qtout.h" +#include "qtdb.h" + +#include "qtconst.h" + +WocQtTable::WocQtTable(WocQtOut*){} +WocQtTable::~WocQtTable(){} +void WocQtTable::finalize(){} +void WocQtTable::newTable(const WocTable&){} diff --git a/woc/qt/qtdb.h b/woc/qt/qtdb.h new file mode 100644 index 0000000..15c1768 --- /dev/null +++ b/woc/qt/qtdb.h @@ -0,0 +1,34 @@ +// +// C++ Interface: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_QTOUT_DB_H +#define WOC_QTOUT_DB_H + +#include "processor.h" + +#include "mfile.h" + +class QDomElement; +class WocQtOut; + +class WocQtTable +{ + public: + WocQtTable(WocQtOut*); + ~WocQtTable(); + virtual void finalize(); + virtual void newTable(const WocTable&); + private: + WocQtOut*m_parent; +}; + +#endif diff --git a/woc/qt/qtout.cpp b/woc/qt/qtout.cpp new file mode 100644 index 0000000..0c7de04 --- /dev/null +++ b/woc/qt/qtout.cpp @@ -0,0 +1,211 @@ +// +// C++ Implementation: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "qtout.h" +#include "qtctrans.h" +#include "qtstrans.h" +#include "qtclass.h" +#include "qtdb.h" + +#include +#include + +#define QT_OUT_NO_WRAP +#include "qtconst.h" + +WocQtOut::WocQtOut(QDomElement&el) +{ + qclass=0;qtable=0;qtrans=0; + + qDebug("Info: creating Qt Client Output Generator."); + m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir","."); + m_subdir=el.attribute("subDir","qtwob"); + m_clean=str2bool(el.attribute("clean","0")); + m_prefix=el.attribute("classPrefix","Wob"); + m_transbase=el.attribute("transactionBase","WTransaction"); + //get/create directory + QDir d(m_basedir+"/"+m_subdir); + if(!d.exists())QDir(".").mkpath(m_basedir+"/"+m_subdir); + + //create project file + m_pri.setFileName(m_basedir+"/"+m_subdir+"/"+el.attribute("priInclude","qtwob.pri")); + if(!m_pri.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create Qt project file %s.",m_pri.fileName().toAscii().data()); + emit errorFound(); + return; + } + m_pri.write(QByteArray("#AUTOMATICALLY GENERATED FILE - DONT CHANGE!\n")); + m_pri.write(QByteArray("INCLUDEPATH += ")+m_subdir.toAscii()+QByteArray("\n")); + + //create interface class + WocProcessor*woc=WocProcessor::instance(); + QString pn=woc->projectName(); + m_ifacecpp.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Interface.cpp"); + if(!m_ifacecpp.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create Qt interface file %s.",m_ifacecpp.fileName().toAscii().data()); + emit errorFound(); + return; + } + m_ifacecpp.write(QByteArray(SRCSTART).replace('%',m_prefix+"Interface")); + m_iface.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Interface.h"); + if(!m_iface.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create Qt interface file %s.",m_iface.fileName().toAscii().data()); + emit errorFound(); + return; + } + m_iface.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"INTERFACE_H")); + m_iface.write(QByteArray("#include \""+m_prefix.toAscii()+"Include.h\"\n#include \"WInterface.h\"\n")); + m_iface.write(QByteArray("#include \n")); + m_iface.write(QString("class "+m_prefix+"Interface:public WInterface\n{\n Q_OBJECT\n").toAscii()); + m_iface.write(QString(" public:\n "+m_prefix+"Interface(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii()); + m_iface.write(QString(" static "+m_prefix+"Interface*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+m_prefix+"Interface*>(WInterface::instance(name));}\n\n").toAscii()); + m_iface.write(QString(" static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); + m_iface.write(QString(" static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); + m_iface.write(QString(" static QString version(){return \""+woc->verHR()+"\";}\n").toAscii()); + m_iface.write(QString(" static QString svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); + m_iface.write(QString(" static QString svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); + m_iface.write(QString(" static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); + + //create all includer + m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Include.h"); + if(!m_hdr.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create Qt header file %s.",m_hdr.fileName().toAscii().data()); + emit errorFound(); + return; + } + m_hdr.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"INCLUDE_H")); + addFile(m_prefix.toAscii()+"Interface"); +} + +WocQtOut::~WocQtOut(){} + +void WocQtOut::finalize() +{ + if(qclass)qclass->finalize(); + if(qtable)qtable->finalize(); + if(qtrans)qtrans->finalize(); + //finish sources + m_ifacecpp.write(SRCEND); + m_ifacecpp.close(); + m_iface.write(QByteArray("};\n")+HDREND); + m_iface.close(); + m_pri.write(QByteArray("\n#END OF AUTOGENERATED PRI FILE\n")); + m_pri.close(); + m_hdr.write(HDREND); + m_hdr.close(); + //cleanup directory (remove untouched normal files, assume remainder is harmless) + QDir d(m_basedir+"/"+m_subdir); + if(m_clean){ + QStringList ent=d.entryList(QDir::Files); + for(int i=0;inewTable(tbl); +} + +void WocQtOut::newClass(const WocClass&cls) +{ + if(qclass)qclass->newClass(cls); +} + +void WocQtOut::newTransaction(const WocTransaction&trn) +{ + if(qtrans)qtrans->newTransaction(trn); +} + +void WocQtOut::addFile(QString bn) +{ + QString code="HEADERS+="+m_subdir+"/"+bn+".h\nSOURCES+="+m_subdir+"/"+bn+".cpp\n"; + m_pri.write(code.toAscii()); + m_hdr.write(QByteArray("#include \"%.h\"\n").replace('%',bn.toAscii())); +} + +QString WocQtOut::qttype(const WocClass&cls,QString p,bool dolist) +{ + QString r; + if(cls.propertyIsList(p)&&dolist)r="QList<"; + else r="Nullable<"; + if(cls.propertyIsString(p))r+="QString";else + if(cls.propertyIsInt(p))r+="qint64";else + if(cls.propertyIsBool(p))r+="bool";else + if(cls.propertyIsBlob(p))r+="QByteArray";else + if(cls.propertyIsObject(p))r+=m_prefix+"O"+cls.propertyPlainType(p); + else r+=cls.propertyPlainType(p); + r+=">"; + return r; +} + +QString WocQtOut::qttype(const WocTransaction&trn,QString v,InOut io) +{ + QString tp=io==In?trn.inputType(v):trn.outputType(v); + QString r,e; + if(tp.startsWith("List:")){ + r="QList<";e=">"; + tp=tp.mid(5); + }else + if(io==Out){ + r="Nullable<"; + e=">"; + } + if(tp=="astring" || tp=="string")r+="QString";else + if(tp=="int"||tp=="int32"||tp=="int64")r+="qint64";else + if(tp=="blob")r+="QByteArray";else + if(tp=="bool")r+="bool";else + if(tp==""){ + qDebug("Warning: the final type of property %s is empty!",v.toAscii().data()); + r+="void"; + }else r+=m_prefix+"O"+tp.split("/",QString::SkipEmptyParts).at(0); + r+=e;r+=" "; + return r; +} + +QString WocQtOut::qtobjtype(const WocTransaction&trn,QString v,InOut io) +{ + QString tp=io==In?trn.inputType(v):trn.outputType(v); + if(tp.startsWith("List:")) + tp=tp.mid(5); + if(tp=="astring" || tp=="string" || tp=="int" || tp=="int32" || tp=="int64" || tp=="bool" || tp=="blob") + return ""; + else + return m_prefix+"O"+tp; +} + +WocQtClientOut::WocQtClientOut(QDomElement&el) + :WocQtOut(el) +{ + m_lang="qt/client"; + qclass=new WocQtClass(this); + qtrans=new WocQtClientTransaction(this); +} + +WocQtServerOut::WocQtServerOut(QDomElement& el) + :WocQtOut(el) +{ + m_lang="qt/server"; + qclass=new WocQtClass(this); + qtrans=new WocQtServerTransaction(this); + qtable=new WocQtTable(this); +} + + +WocQtTransaction::WocQtTransaction(WocQtOut*p) + :m_parent(p) +{ + connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); +} diff --git a/woc/qt/qtout.h b/woc/qt/qtout.h new file mode 100644 index 0000000..77781c2 --- /dev/null +++ b/woc/qt/qtout.h @@ -0,0 +1,88 @@ +// +// C++ Interface: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_QTOUT_H +#define WOC_QTOUT_H + +#include "processor.h" + +#include "mfile.h" + +class QDomElement; + +class WocQtOut; + +class WocQtTransaction:public QObject +{ + Q_OBJECT + public: + WocQtTransaction(WocQtOut*); + virtual void newTransaction(const WocTransaction&)=0; + virtual void finalize()=0; + signals: + void errorFound(); + protected: + WocQtOut*m_parent; +}; + +class WocQtClass; +class WocQtTable; + +class WocQtOut:public WocOutput +{ + public: + WocQtOut(QDomElement&); + ~WocQtOut(); + protected: + virtual void finalize(); + virtual void newClass(const WocClass&); + virtual void newTable(const WocTable&); + virtual void newTransaction(const WocTransaction&); + + friend class WocQtClass; + friend class WocQtClientTransaction; + friend class WocQtServerTransaction; + friend class WocQtTransaction; + friend class WocQtTable; + + QString m_basedir,m_subdir,m_prefix,m_transbase,m_lang; + MFile m_pri,m_iface,m_ifacecpp,m_hdr; + bool m_clean; + + /**helper: generate a proper Qt type for a property*/ + QString qttype(const WocClass&,QString,bool dolist=true); + enum InOut{In,Out}; + /**helper: generate a proper QT type for a transaction variable*/ + QString qttype(const WocTransaction&,QString,InOut); + /**helper: generate a proper QT type for a transaction variable, WO* only */ + QString qtobjtype(const WocTransaction&,QString,InOut); + /**helper: adds a file to the project file*/ + void addFile(QString basename); + + WocQtClass*qclass; + WocQtTable*qtable; + WocQtTransaction*qtrans; +}; + +class WocQtClientOut:public WocQtOut +{ + public: + WocQtClientOut(QDomElement&); +}; + +class WocQtServerOut:public WocQtOut +{ + public: + WocQtServerOut(QDomElement&); +}; + +#endif diff --git a/woc/qt/qtstrans.cpp b/woc/qt/qtstrans.cpp new file mode 100644 index 0000000..3051cb2 --- /dev/null +++ b/woc/qt/qtstrans.cpp @@ -0,0 +1,24 @@ +// +// C++ Implementation: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "qtout.h" +#include "qtstrans.h" + +#include "qtconst.h" + +WocQtServerTransaction::WocQtServerTransaction(WocQtOut*p) + :WocQtTransaction(p) +{ +} +WocQtServerTransaction::~WocQtServerTransaction(){} +void WocQtServerTransaction::finalize(){} +void WocQtServerTransaction::newTransaction(const WocTransaction&){} diff --git a/woc/qt/qtstrans.h b/woc/qt/qtstrans.h new file mode 100644 index 0000000..5bfd58d --- /dev/null +++ b/woc/qt/qtstrans.h @@ -0,0 +1,29 @@ +// +// C++ Interface: qtout +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_QTOUT_STRANS_H +#define WOC_QTOUT_STRANS_H + +#include "qtout.h" + +class WocQtServerTransaction:public WocQtTransaction +{ + public: + WocQtServerTransaction(WocQtOut*); + ~WocQtServerTransaction(); + virtual void finalize(); + virtual void newTransaction(const WocTransaction&); + private: + WocQtOut*m_parent; +}; + +#endif diff --git a/woc/qtclass.cpp b/woc/qtclass.cpp deleted file mode 100644 index 0ff8f0c..0000000 --- a/woc/qtclass.cpp +++ /dev/null @@ -1,374 +0,0 @@ -// -// C++ Implementation: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "qtout.h" -#include "qtclass.h" - -#include -#include - -#include "qtconst.h" - -WocQtClass::WocQtClass(WocQtOut* p) -{ - m_parent=p; - connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); -} - -WocQtClass::~WocQtClass() -{ -} - -void WocQtClass::finalize() -{ -} - - -void WocQtClass::newClass(const WocClass&cls) -{ - QString cn=m_prefix+"O"+cls.name(); - QString cna=cn; - if(cls.isAbstract(m_lang))cna+="Abstract"; - addFile(cna); - MFile hdr(m_basedir+"/"+m_subdir+"/"+cna+".h"); - MFile src(m_basedir+"/"+m_subdir+"/"+cna+".cpp"); - if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) || - !src.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - qDebug("Error: cannot create class files for class %s.",cn.toAscii().data()); - emit errorFound(); - return; - } - //lead in - hdr.write(QByteArray(HDRSTART).replace("%",cna.toAscii())); - src.write(QByteArray(SRCSTART).replace("%",cna.toAscii())); - - QString hcd; - QString scd; - //includes - hcd="#include \""+cls.clientBaseClass()+".h\"\n#include \n\n"; - QStringList k=cls.propertyNames(); - for(int i=0;iev=cls.enumValues(k[i]); - if(ev.size()<1){ - qDebug("Error: enums must have at least one member - class %s enum %s",cls.name().toAscii().data(),k[i].toAscii().data()); - emit errorFound(); - return; - } - for(int j=0;j1)var=pv[1]; - //is it a list - if(cls.propertyIsList(prop)){ - scd+="\tfor(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_QTOUT_CLASS_H -#define WOC_QTOUT_CLASS_H - -#include "mfile.h" -#include - -class QDomElement; -class WocClass; -class WocQtOut; - -class WocQtClass:public QObject -{ - Q_OBJECT - public: - WocQtClass(WocQtOut*); - ~WocQtClass(); - virtual void finalize(); - virtual void newClass(const WocClass&); - private: - WocQtOut*m_parent; - - /**helper: generate enums for classes*/ - void classEnums(const WocClass&,MFile&,MFile&,QString); - /**helper: generate properties*/ - void classProperties(const WocClass&,MFile&,MFile&); - /**helper: generate constructors/deserializer/copiers*/ - void classDeserializer(const WocClass&,MFile&,MFile&,QString); - /**helper: generate serializers*/ - void classSerializers(const WocClass&,MFile&,MFile&,QString); - signals: - void errorFound(); -}; - -#endif diff --git a/woc/qtconst.h b/woc/qtconst.h deleted file mode 100644 index f252ddd..0000000 --- a/woc/qtconst.h +++ /dev/null @@ -1,51 +0,0 @@ -// -// C++ Implementation: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_QT_CONST_H -#define WOC_QT_CONST_H - -//start section of all header files -static const QByteArray HDRSTART= - "//AUTOMATICALLY GENERATED FILE\n" - "//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE!\n" - "#ifndef WOBGEN_%\n" - "#define WOBGEN_%\n\n"; -//end section of all header files -static const QByteArray HDREND="\n//END OF AUTOMATICALLY GENERATED FILE\n#endif\n"; - -//start section of all source files -static const QByteArray SRCSTART= - "//AUTOMATICALLY GENERATED FILE\n" - "//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE!\n" - "#include \"%.h\"\n" - "#include \n" - "#include \n"; -//end section of all source files -static const QByteArray SRCEND="\n//END OF AUTOMATICALLY GENERATED FILE\n"; - -#ifndef QT_OUT_NO_WRAP -#define m_basedir m_parent->m_basedir -#define m_subdir m_parent->m_subdir -#define m_prefix m_parent->m_prefix -#define m_transbase m_parent->m_transbase -#define m_pri m_parent->m_pri -#define m_iface m_parent->m_iface -#define m_ifacecpp m_parent->m_ifacecpp -#define m_hdr m_parent->m_hdr -#define m_clean m_parent->m_clean -#define qttype m_parent->qttype -#define qtobjtype m_parent->qtobjtype -#define addFile m_parent->addFile -#define m_lang m_parent->m_lang -#endif - -#endif diff --git a/woc/qtctrans.cpp b/woc/qtctrans.cpp deleted file mode 100644 index e38b36e..0000000 --- a/woc/qtctrans.cpp +++ /dev/null @@ -1,330 +0,0 @@ -// -// C++ Implementation: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "qtout.h" -#include "qtctrans.h" - -#include -#include - -#include "qtconst.h" - -WocQtClientTransaction::WocQtClientTransaction(WocQtOut*p) - :WocQtTransaction(p) -{} -WocQtClientTransaction::~WocQtClientTransaction(){} - -void WocQtClientTransaction::finalize() -{ - trnList(); -} - -void WocQtClientTransaction::newTransaction(const WocTransaction&trn) -{ - QString cn=m_prefix+"T"+trn.name(); - addFile(cn); - MFile hdr(m_basedir+"/"+m_subdir+"/"+cn+".h"); - MFile src(m_basedir+"/"+m_subdir+"/"+cn+".cpp"); - if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) || - !src.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - qDebug("Error: cannot create class files for transaction %s.",cn.toAscii().data()); - emit errorFound(); - return; - } - //basics - QStringList in=trn.inputNames(); - QStringList out=trn.outputNames(); - //lead in - hdr.write(QByteArray(HDRSTART).replace("%",cn.toAscii())); - src.write(QByteArray(SRCSTART).replace("%",cn.toAscii())); - QString hcd; - QString scd; - hcd="#include \""+m_transbase+".h\"\n"; - scd+="#include \"WInterface.h\"\n#include \n"; - for(int i=0;i\n"; - } - for(int i=0;i\n"; - } - hcd+="\nclass "+cn+":public "+m_transbase+"\n{\n"; - hdr.write(hcd.toAscii()); - - //create properties - QString inlist,clist; - hcd=" private:\n"; - for(int i=0;iprojectName()+"\""; - //define parametric constructor - hcd=" public:\n"; - hcd+="\t"+cn+"("+inlist+defparm+");\n"; - //parametric constructor implementation - scd+=cn+"::"+cn+"("+inlist+")\n\t:"+m_transbase+"(iface)\n{\n"; - for(int i=0;itransactionNames(); - QStringList p=WocProcessor::instance()->privilegeNames(); - QStringList pp=p; - for(int i=0;i "+m_prefix+"Interface::allKnownRights()\n{\n"; - code+="\tQList ret;ret"; - for(int i=0;i, (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_QTOUT_CTRANS_H -#define WOC_QTOUT_CTRANS_H - -#include "qtout.h" - -class WocQtOut; -class WocTransaction; -class WocClass; - -class WocQtClientTransaction:public WocQtTransaction -{ - public: - WocQtClientTransaction(WocQtOut*); - ~WocQtClientTransaction(); - virtual void finalize(); - virtual void newTransaction(const WocTransaction&); - private: - /**helper generates the transaction input encoding*/ - QString trnInput(const WocTransaction&); - /**helper generates the transaction output decoding*/ - QString trnOutput(const WocTransaction&); - /**helper generates enums and strings for all transactions*/ - void trnList(); -}; - -#endif diff --git a/woc/qtdb.cpp b/woc/qtdb.cpp deleted file mode 100644 index 6d93269..0000000 --- a/woc/qtdb.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// -// C++ Implementation: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "qtout.h" -#include "qtdb.h" - -#include "qtconst.h" - -WocQtTable::WocQtTable(WocQtOut*){} -WocQtTable::~WocQtTable(){} -void WocQtTable::finalize(){} -void WocQtTable::newTable(const WocTable&){} diff --git a/woc/qtdb.h b/woc/qtdb.h deleted file mode 100644 index 15c1768..0000000 --- a/woc/qtdb.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// C++ Interface: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_QTOUT_DB_H -#define WOC_QTOUT_DB_H - -#include "processor.h" - -#include "mfile.h" - -class QDomElement; -class WocQtOut; - -class WocQtTable -{ - public: - WocQtTable(WocQtOut*); - ~WocQtTable(); - virtual void finalize(); - virtual void newTable(const WocTable&); - private: - WocQtOut*m_parent; -}; - -#endif diff --git a/woc/qtout.cpp b/woc/qtout.cpp deleted file mode 100644 index 0c7de04..0000000 --- a/woc/qtout.cpp +++ /dev/null @@ -1,211 +0,0 @@ -// -// C++ Implementation: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "qtout.h" -#include "qtctrans.h" -#include "qtstrans.h" -#include "qtclass.h" -#include "qtdb.h" - -#include -#include - -#define QT_OUT_NO_WRAP -#include "qtconst.h" - -WocQtOut::WocQtOut(QDomElement&el) -{ - qclass=0;qtable=0;qtrans=0; - - qDebug("Info: creating Qt Client Output Generator."); - m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir","."); - m_subdir=el.attribute("subDir","qtwob"); - m_clean=str2bool(el.attribute("clean","0")); - m_prefix=el.attribute("classPrefix","Wob"); - m_transbase=el.attribute("transactionBase","WTransaction"); - //get/create directory - QDir d(m_basedir+"/"+m_subdir); - if(!d.exists())QDir(".").mkpath(m_basedir+"/"+m_subdir); - - //create project file - m_pri.setFileName(m_basedir+"/"+m_subdir+"/"+el.attribute("priInclude","qtwob.pri")); - if(!m_pri.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - qDebug("Error: cannot create Qt project file %s.",m_pri.fileName().toAscii().data()); - emit errorFound(); - return; - } - m_pri.write(QByteArray("#AUTOMATICALLY GENERATED FILE - DONT CHANGE!\n")); - m_pri.write(QByteArray("INCLUDEPATH += ")+m_subdir.toAscii()+QByteArray("\n")); - - //create interface class - WocProcessor*woc=WocProcessor::instance(); - QString pn=woc->projectName(); - m_ifacecpp.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Interface.cpp"); - if(!m_ifacecpp.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - qDebug("Error: cannot create Qt interface file %s.",m_ifacecpp.fileName().toAscii().data()); - emit errorFound(); - return; - } - m_ifacecpp.write(QByteArray(SRCSTART).replace('%',m_prefix+"Interface")); - m_iface.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Interface.h"); - if(!m_iface.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - qDebug("Error: cannot create Qt interface file %s.",m_iface.fileName().toAscii().data()); - emit errorFound(); - return; - } - m_iface.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"INTERFACE_H")); - m_iface.write(QByteArray("#include \""+m_prefix.toAscii()+"Include.h\"\n#include \"WInterface.h\"\n")); - m_iface.write(QByteArray("#include \n")); - m_iface.write(QString("class "+m_prefix+"Interface:public WInterface\n{\n Q_OBJECT\n").toAscii()); - m_iface.write(QString(" public:\n "+m_prefix+"Interface(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii()); - m_iface.write(QString(" static "+m_prefix+"Interface*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+m_prefix+"Interface*>(WInterface::instance(name));}\n\n").toAscii()); - m_iface.write(QString(" static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); - m_iface.write(QString(" static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); - m_iface.write(QString(" static QString version(){return \""+woc->verHR()+"\";}\n").toAscii()); - m_iface.write(QString(" static QString svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); - m_iface.write(QString(" static QString svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); - m_iface.write(QString(" static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); - - //create all includer - m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Include.h"); - if(!m_hdr.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - qDebug("Error: cannot create Qt header file %s.",m_hdr.fileName().toAscii().data()); - emit errorFound(); - return; - } - m_hdr.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"INCLUDE_H")); - addFile(m_prefix.toAscii()+"Interface"); -} - -WocQtOut::~WocQtOut(){} - -void WocQtOut::finalize() -{ - if(qclass)qclass->finalize(); - if(qtable)qtable->finalize(); - if(qtrans)qtrans->finalize(); - //finish sources - m_ifacecpp.write(SRCEND); - m_ifacecpp.close(); - m_iface.write(QByteArray("};\n")+HDREND); - m_iface.close(); - m_pri.write(QByteArray("\n#END OF AUTOGENERATED PRI FILE\n")); - m_pri.close(); - m_hdr.write(HDREND); - m_hdr.close(); - //cleanup directory (remove untouched normal files, assume remainder is harmless) - QDir d(m_basedir+"/"+m_subdir); - if(m_clean){ - QStringList ent=d.entryList(QDir::Files); - for(int i=0;inewTable(tbl); -} - -void WocQtOut::newClass(const WocClass&cls) -{ - if(qclass)qclass->newClass(cls); -} - -void WocQtOut::newTransaction(const WocTransaction&trn) -{ - if(qtrans)qtrans->newTransaction(trn); -} - -void WocQtOut::addFile(QString bn) -{ - QString code="HEADERS+="+m_subdir+"/"+bn+".h\nSOURCES+="+m_subdir+"/"+bn+".cpp\n"; - m_pri.write(code.toAscii()); - m_hdr.write(QByteArray("#include \"%.h\"\n").replace('%',bn.toAscii())); -} - -QString WocQtOut::qttype(const WocClass&cls,QString p,bool dolist) -{ - QString r; - if(cls.propertyIsList(p)&&dolist)r="QList<"; - else r="Nullable<"; - if(cls.propertyIsString(p))r+="QString";else - if(cls.propertyIsInt(p))r+="qint64";else - if(cls.propertyIsBool(p))r+="bool";else - if(cls.propertyIsBlob(p))r+="QByteArray";else - if(cls.propertyIsObject(p))r+=m_prefix+"O"+cls.propertyPlainType(p); - else r+=cls.propertyPlainType(p); - r+=">"; - return r; -} - -QString WocQtOut::qttype(const WocTransaction&trn,QString v,InOut io) -{ - QString tp=io==In?trn.inputType(v):trn.outputType(v); - QString r,e; - if(tp.startsWith("List:")){ - r="QList<";e=">"; - tp=tp.mid(5); - }else - if(io==Out){ - r="Nullable<"; - e=">"; - } - if(tp=="astring" || tp=="string")r+="QString";else - if(tp=="int"||tp=="int32"||tp=="int64")r+="qint64";else - if(tp=="blob")r+="QByteArray";else - if(tp=="bool")r+="bool";else - if(tp==""){ - qDebug("Warning: the final type of property %s is empty!",v.toAscii().data()); - r+="void"; - }else r+=m_prefix+"O"+tp.split("/",QString::SkipEmptyParts).at(0); - r+=e;r+=" "; - return r; -} - -QString WocQtOut::qtobjtype(const WocTransaction&trn,QString v,InOut io) -{ - QString tp=io==In?trn.inputType(v):trn.outputType(v); - if(tp.startsWith("List:")) - tp=tp.mid(5); - if(tp=="astring" || tp=="string" || tp=="int" || tp=="int32" || tp=="int64" || tp=="bool" || tp=="blob") - return ""; - else - return m_prefix+"O"+tp; -} - -WocQtClientOut::WocQtClientOut(QDomElement&el) - :WocQtOut(el) -{ - m_lang="qt/client"; - qclass=new WocQtClass(this); - qtrans=new WocQtClientTransaction(this); -} - -WocQtServerOut::WocQtServerOut(QDomElement& el) - :WocQtOut(el) -{ - m_lang="qt/server"; - qclass=new WocQtClass(this); - qtrans=new WocQtServerTransaction(this); - qtable=new WocQtTable(this); -} - - -WocQtTransaction::WocQtTransaction(WocQtOut*p) - :m_parent(p) -{ - connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); -} diff --git a/woc/qtout.h b/woc/qtout.h deleted file mode 100644 index 77781c2..0000000 --- a/woc/qtout.h +++ /dev/null @@ -1,88 +0,0 @@ -// -// C++ Interface: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_QTOUT_H -#define WOC_QTOUT_H - -#include "processor.h" - -#include "mfile.h" - -class QDomElement; - -class WocQtOut; - -class WocQtTransaction:public QObject -{ - Q_OBJECT - public: - WocQtTransaction(WocQtOut*); - virtual void newTransaction(const WocTransaction&)=0; - virtual void finalize()=0; - signals: - void errorFound(); - protected: - WocQtOut*m_parent; -}; - -class WocQtClass; -class WocQtTable; - -class WocQtOut:public WocOutput -{ - public: - WocQtOut(QDomElement&); - ~WocQtOut(); - protected: - virtual void finalize(); - virtual void newClass(const WocClass&); - virtual void newTable(const WocTable&); - virtual void newTransaction(const WocTransaction&); - - friend class WocQtClass; - friend class WocQtClientTransaction; - friend class WocQtServerTransaction; - friend class WocQtTransaction; - friend class WocQtTable; - - QString m_basedir,m_subdir,m_prefix,m_transbase,m_lang; - MFile m_pri,m_iface,m_ifacecpp,m_hdr; - bool m_clean; - - /**helper: generate a proper Qt type for a property*/ - QString qttype(const WocClass&,QString,bool dolist=true); - enum InOut{In,Out}; - /**helper: generate a proper QT type for a transaction variable*/ - QString qttype(const WocTransaction&,QString,InOut); - /**helper: generate a proper QT type for a transaction variable, WO* only */ - QString qtobjtype(const WocTransaction&,QString,InOut); - /**helper: adds a file to the project file*/ - void addFile(QString basename); - - WocQtClass*qclass; - WocQtTable*qtable; - WocQtTransaction*qtrans; -}; - -class WocQtClientOut:public WocQtOut -{ - public: - WocQtClientOut(QDomElement&); -}; - -class WocQtServerOut:public WocQtOut -{ - public: - WocQtServerOut(QDomElement&); -}; - -#endif diff --git a/woc/qtstrans.cpp b/woc/qtstrans.cpp deleted file mode 100644 index 3051cb2..0000000 --- a/woc/qtstrans.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// -// C++ Implementation: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "qtout.h" -#include "qtstrans.h" - -#include "qtconst.h" - -WocQtServerTransaction::WocQtServerTransaction(WocQtOut*p) - :WocQtTransaction(p) -{ -} -WocQtServerTransaction::~WocQtServerTransaction(){} -void WocQtServerTransaction::finalize(){} -void WocQtServerTransaction::newTransaction(const WocTransaction&){} diff --git a/woc/qtstrans.h b/woc/qtstrans.h deleted file mode 100644 index 5bfd58d..0000000 --- a/woc/qtstrans.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// C++ Interface: qtout -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef WOC_QTOUT_STRANS_H -#define WOC_QTOUT_STRANS_H - -#include "qtout.h" - -class WocQtServerTransaction:public WocQtTransaction -{ - public: - WocQtServerTransaction(WocQtOut*); - ~WocQtServerTransaction(); - virtual void finalize(); - virtual void newTransaction(const WocTransaction&); - private: - WocQtOut*m_parent; -}; - -#endif diff --git a/woc/woc.pro b/woc/woc.pro index 839d05c..ff1a5f9 100644 --- a/woc/woc.pro +++ b/woc/woc.pro @@ -12,41 +12,18 @@ RCC_DIR = .ctmp SOURCES+= \ - processor.cpp \ - procclass.cpp \ - proctrans.cpp \ - proctable.cpp \ woc.cpp \ - qtout.cpp \ - qtclass.cpp \ - qtdb.cpp \ - qtctrans.cpp \ - qtstrans.cpp \ - phpout.cpp \ - phpclass.cpp \ - phptrans.cpp \ - phpctrans.cpp \ - phpstrans.cpp \ - phpdb.cpp \ htmlout.cpp \ mfile.cpp \ domquery.cpp HEADERS+= \ - processor.h \ - procclass.h \ - proctrans.h \ - proctable.h \ - phpout.h \ - phpdb.h \ - phpclass.h \ - phptrans.h \ - phpctrans.h \ - phpstrans.h \ - qtout.h \ - qtclass.h \ - qtdb.h \ - qtctrans.h \ - qtstrans.cpp \ htmlout.h \ mfile.h \ domquery.h + +include(proc/proc.pri) +include(php/php.pri) +include(qt/qt.pri) + +#make sure dependencies are found +DEPENDPATH += $$INCLUDEPATH -- 1.7.2.5