From: konrad Date: Sat, 31 Jul 2010 17:34:28 +0000 (+0000) Subject: start of schema file generator X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d82479e0904e01cdd87ce6f60f58282b9d792282;p=web%2Fkonrad%2Fpack.git start of schema file generator git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@581 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/woc/mfile.h b/woc/mfile.h index 44a3d38..07b298d 100644 --- a/woc/mfile.h +++ b/woc/mfile.h @@ -18,20 +18,28 @@ #include /**overwrites QFile to only generate a file if its new version differs from an existing one, it creates a temporary file with ",new" added to the file name; additionally it records all file names that it touches; -this is not a complete implementation - just enough for woc*/ +this is not a complete implementation - just enough for woc; it assumes that files are opened to be (re)created*/ class MFile:public QFile { public: + /**creates a new file (tentatively) with the given name (temporarily with ",new" appended)*/ MFile(QString name,QObject*parent=0); + /**creates a file object*/ MFile(QObject *parent=0); + /**implicitly closes the file*/ ~MFile(); + /**compares the old (if it exists) and new version of the file and overwrites the old one if there are differences*/ virtual void close(); + /**opens the file, WriteOnly is assumed as mode*/ virtual bool open(QIODevice::OpenMode m); + /**returns the name of the file (without ",new")*/ QString fileName()const{return name;} + /**sets the file name for the file to be written; must be called before it is opened*/ void setFileName(QString n); + /**returns true if that file name has been touched yet*/ static bool touchedFile(QString); private: //flag to show whether file is open diff --git a/woc/php/phpstrans.cpp b/woc/php/phpstrans.cpp index 721ad75..4c4bd05 100644 --- a/woc/php/phpstrans.cpp +++ b/woc/php/phpstrans.cpp @@ -131,8 +131,8 @@ QString WocPHPServerTransaction::trnOutput(const WocTransaction&trn) { QStringList sl=trn.outputNames(); QString code="\t/*start of output encoding*/\n"; - code+="\ttry{\n\t\t$xml=$this->xmlCreate(\"WobResponse-"+trn.name()+"\");\n"; - code+="\t\t$root=$xml['root'];\n"; + code+="\ttry{\n\t\t$xmla=$this->xmlCreate(\"WobResponse-"+trn.name()+"\");\n"; + code+="\t\t$xml=$xmla['doc'];\n\t\t$root=$xmla['root'];\n"; for(int i=0;i0)t=l[0];else t="unknown"; @@ -77,19 +77,19 @@ class WocTransaction 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";} + static bool isIntType(QString t){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";} + static bool isBoolType(QString t){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";} + static bool isStringType(QString t){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";} + static bool isBlobType(QString t){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";} + static bool isAttributeType(QString t){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);} + static bool isElementType(QString t){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";} + static bool isObjectType(QString t){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;} diff --git a/woc/soap/schemaout.cpp b/woc/soap/schemaout.cpp new file mode 100644 index 0000000..8273cff --- /dev/null +++ b/woc/soap/schemaout.cpp @@ -0,0 +1,131 @@ +// +// C++ Interface: schemaout +// +// Description: XML Schema file generator +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "schemaout.h" + +#include "mfile.h" + +#include + +WocSchemaOut::WocSchemaOut(QString fname): WocOutput() +{ + m_name=fname; + WocProcessor*woc=WocProcessor::instance(); + m_doc.appendChild(m_doc.createComment("Automatically generated Schema file for project "+woc->projectName())); + m_root=m_doc.createElementNS(woc->xmlSchemaNamespace(),"xs:schema"); + m_root.setAttribute("targetNamespace",woc->xmlProjectNamespace()); + m_root.setAttribute("xmlns",woc->xmlProjectNamespace()); +} + +void WocSchemaOut::finalize() +{ + //finish off + m_doc.appendChild(m_root); + //write + MFile fd(WocProcessor::instance()->baseDir()+"/"+m_name); + fd.open(QIODevice::WriteOnly); + fd.write(m_doc.toByteArray()); +} + +void WocSchemaOut::newClass(const WocClass& cls) +{ + m_root.appendChild(m_doc.createComment("Class "+cls.name())); + //create type + QDomElement cel=m_doc.createElement("xs:complexType"); + cel.setAttribute("name","class-"+cls.name()); + //get properties + //create elements + //create attributes + //add to root + m_root.appendChild(cel); +} + +void WocSchemaOut::newTransaction(const WocTransaction& trn) +{ + m_root.appendChild(m_doc.createComment("Transaction "+trn.name())); + //create elements + QDomElement tel=m_doc.createElement("xs:element"); + tel.setAttribute("name",trn.name()+"-Request"); + tel.setAttribute("type",trn.name()+"-Request"); + m_root.appendChild(tel); + tel=m_doc.createElement("xs:element"); + tel.setAttribute("name",trn.name()+"-Response"); + tel.setAttribute("type",trn.name()+"-Response"); + m_root.appendChild(tel); + + //create type: req + tel=m_doc.createElement("xs:complexType"); + tel.setAttribute("name",trn.name()+"-Request"); + QDomElement wel=m_doc.createElement("xs:sequence"); + QStringList vars=trn.inputNames(); + for(int i=0;i, (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_SCHEMAOUT_H +#define WOC_SCHEMAOUT_H + +#include "processor.h" + +#include +#include + +/**generates output for a schema file*/ +class WocSchemaOut:public WocOutput +{ + public: + /**initializes the output object with the given file name that will receive the schema for this project*/ + WocSchemaOut(QString); + 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&); + private: + QString m_name; + QDomDocument m_doc; + QDomElement m_root; + + /**helper: returns the corresponding schema type for a WOB type*/ + QString schemaType(QString); +}; + +#endif diff --git a/woc/soap/soap.pri b/woc/soap/soap.pri index 09ec496..379ddb6 100644 --- a/woc/soap/soap.pri +++ b/woc/soap/soap.pri @@ -1 +1,9 @@ -RESOURCES += soap/schemafiles.qrc \ No newline at end of file +RESOURCES += soap/schemafiles.qrc + +SOURCES += \ + soap/schemaout.cpp + +HEADERS += \ + soap/schemaout.h + +INCLUDEPATH += soap \ No newline at end of file diff --git a/woc/soap/soap12.xsd b/woc/soap/soap12.xsd index 85a6d8e..c8e82f9 100644 --- a/woc/soap/soap12.xsd +++ b/woc/soap/soap12.xsd @@ -21,7 +21,8 @@ elementFormDefault="qualified" > + schemaLocation="xml.xsd"/> +