summaryrefslogtreecommitdiffstats
path: root/kode
diff options
context:
space:
mode:
Diffstat (limited to 'kode')
-rw-r--r--kode/Makefile.am21
-rw-r--r--kode/README6
-rw-r--r--kode/automakefile.cpp115
-rw-r--r--kode/automakefile.h94
-rw-r--r--kode/class.cpp176
-rw-r--r--kode/class.h98
-rw-r--r--kode/code.cpp167
-rw-r--r--kode/code.h71
-rw-r--r--kode/enum.cpp58
-rw-r--r--kode/enum.h47
-rw-r--r--kode/file.cpp158
-rw-r--r--kode/file.h99
-rw-r--r--kode/function.cpp123
-rw-r--r--kode/function.h91
-rw-r--r--kode/kodemain.cpp633
-rw-r--r--kode/kwsdl/Makefile.am19
-rw-r--r--kode/kwsdl/TODO6
-rw-r--r--kode/kwsdl/binding.cpp63
-rw-r--r--kode/kwsdl/binding.h108
-rw-r--r--kode/kwsdl/compiler.cpp113
-rw-r--r--kode/kwsdl/compiler.h62
-rw-r--r--kode/kwsdl/converter.cpp998
-rw-r--r--kode/kwsdl/converter.h78
-rw-r--r--kode/kwsdl/creator.cpp71
-rw-r--r--kode/kwsdl/creator.h49
-rw-r--r--kode/kwsdl/kung/Makefile.am12
-rw-r--r--kode/kwsdl/kung/binaryinputfield.cpp186
-rw-r--r--kode/kwsdl/kung/binaryinputfield.h83
-rw-r--r--kode/kwsdl/kung/boolinputfield.cpp81
-rw-r--r--kode/kwsdl/kung/boolinputfield.h54
-rw-r--r--kode/kwsdl/kung/complexbaseinputfield.cpp155
-rw-r--r--kode/kwsdl/kung/complexbaseinputfield.h41
-rw-r--r--kode/kwsdl/kung/conversationmanager.h37
-rw-r--r--kode/kwsdl/kung/dateinputfield.cpp81
-rw-r--r--kode/kwsdl/kung/dateinputfield.h55
-rw-r--r--kode/kwsdl/kung/dispatcher.cpp153
-rw-r--r--kode/kwsdl/kung/dispatcher.h58
-rw-r--r--kode/kwsdl/kung/doubleinputfield.cpp94
-rw-r--r--kode/kwsdl/kung/doubleinputfield.h55
-rw-r--r--kode/kwsdl/kung/enuminputfield.cpp86
-rw-r--r--kode/kwsdl/kung/enuminputfield.h55
-rw-r--r--kode/kwsdl/kung/generalconversationmanager.cpp51
-rw-r--r--kode/kwsdl/kung/generalconversationmanager.h43
-rw-r--r--kode/kwsdl/kung/inputdialog.cpp32
-rw-r--r--kode/kwsdl/kung/inputdialog.h33
-rw-r--r--kode/kwsdl/kung/inputfield.cpp102
-rw-r--r--kode/kwsdl/kung/inputfield.h146
-rw-r--r--kode/kwsdl/kung/inputfieldfactory.cpp123
-rw-r--r--kode/kwsdl/kung/inputfieldfactory.h69
-rw-r--r--kode/kwsdl/kung/integerinputfield.cpp132
-rw-r--r--kode/kwsdl/kung/integerinputfield.h55
-rw-r--r--kode/kwsdl/kung/listinputfield.cpp189
-rw-r--r--kode/kwsdl/kung/listinputfield.h80
-rw-r--r--kode/kwsdl/kung/loader.cpp89
-rw-r--r--kode/kwsdl/kung/loader.h55
-rw-r--r--kode/kwsdl/kung/main.cpp64
-rw-r--r--kode/kwsdl/kung/outputdialog.cpp30
-rw-r--r--kode/kwsdl/kung/outputdialog.h33
-rw-r--r--kode/kwsdl/kung/pageinputfield.cpp107
-rw-r--r--kode/kwsdl/kung/pageinputfield.h51
-rw-r--r--kode/kwsdl/kung/simplebaseinputfield.cpp120
-rw-r--r--kode/kwsdl/kung/simplebaseinputfield.h41
-rw-r--r--kode/kwsdl/kung/stringinputfield.cpp100
-rw-r--r--kode/kwsdl/kung/stringinputfield.h55
-rw-r--r--kode/kwsdl/kung/timeinputfield.cpp81
-rw-r--r--kode/kwsdl/kung/timeinputfield.h55
-rw-r--r--kode/kwsdl/kung/transport.cpp69
-rw-r--r--kode/kwsdl/kung/transport.h47
-rw-r--r--kode/kwsdl/kung/wsclconversationmanager.cpp50
-rw-r--r--kode/kwsdl/kung/wsclconversationmanager.h43
-rw-r--r--kode/kwsdl/main.cpp77
-rw-r--r--kode/kwsdl/message.cpp72
-rw-r--r--kode/kwsdl/message.h71
-rw-r--r--kode/kwsdl/namemapper.cpp45
-rw-r--r--kode/kwsdl/namemapper.h43
-rw-r--r--kode/kwsdl/parser.cpp240
-rw-r--r--kode/kwsdl/parser.h64
-rw-r--r--kode/kwsdl/port.cpp62
-rw-r--r--kode/kwsdl/port.h75
-rw-r--r--kode/kwsdl/schema/Makefile.am15
-rw-r--r--kode/kwsdl/schema/attribute.cpp80
-rw-r--r--kode/kwsdl/schema/attribute.h68
-rw-r--r--kode/kwsdl/schema/complextype.cpp403
-rw-r--r--kode/kwsdl/schema/complextype.h181
-rw-r--r--kode/kwsdl/schema/element.cpp130
-rw-r--r--kode/kwsdl/schema/element.h89
-rw-r--r--kode/kwsdl/schema/fileprovider.cpp105
-rw-r--r--kode/kwsdl/schema/fileprovider.h55
-rw-r--r--kode/kwsdl/schema/parser.cpp1095
-rw-r--r--kode/kwsdl/schema/parser.h139
-rw-r--r--kode/kwsdl/schema/qualifiedname.cpp78
-rw-r--r--kode/kwsdl/schema/qualifiedname.h59
-rw-r--r--kode/kwsdl/schema/simpletype.cpp301
-rw-r--r--kode/kwsdl/schema/simpletype.h163
-rw-r--r--kode/kwsdl/schema/types.cpp54
-rw-r--r--kode/kwsdl/schema/types.h51
-rw-r--r--kode/kwsdl/schema/typestable.cpp251
-rw-r--r--kode/kwsdl/schema/typestable.h89
-rw-r--r--kode/kwsdl/schema/xsdtype.h114
-rw-r--r--kode/kwsdl/service.cpp48
-rw-r--r--kode/kwsdl/service.h60
-rw-r--r--kode/kwsdl/tests/Makefile.am1
-rw-r--r--kode/kwsdl/tests/google/Makefile.am9
-rw-r--r--kode/kwsdl/tests/google/README8
-rw-r--r--kode/kwsdl/tests/google/directorycategory.cpp64
-rw-r--r--kode/kwsdl/tests/google/directorycategory.h44
-rw-r--r--kode/kwsdl/tests/google/directorycategoryarray.cpp52
-rw-r--r--kode/kwsdl/tests/google/directorycategoryarray.h43
-rw-r--r--kode/kwsdl/tests/google/googlesearch.cc94
-rw-r--r--kode/kwsdl/tests/google/googlesearch.hh60
-rw-r--r--kode/kwsdl/tests/google/googlesearchresult.cpp183
-rw-r--r--kode/kwsdl/tests/google/googlesearchresult.h73
-rw-r--r--kode/kwsdl/tests/google/googlesearchservice.cpp208
-rw-r--r--kode/kwsdl/tests/google/googlesearchservice.h60
-rw-r--r--kode/kwsdl/tests/google/main.cc23
-rw-r--r--kode/kwsdl/tests/google/resultelement.cpp156
-rw-r--r--kode/kwsdl/tests/google/resultelement.h66
-rw-r--r--kode/kwsdl/tests/google/resultelementarray.cpp52
-rw-r--r--kode/kwsdl/tests/google/resultelementarray.h43
-rw-r--r--kode/kwsdl/tests/google/serializer.cpp627
-rw-r--r--kode/kwsdl/tests/google/serializer.h103
-rw-r--r--kode/kwsdl/tests/google/transport.cpp75
-rw-r--r--kode/kwsdl/tests/google/transport.h50
-rw-r--r--kode/kwsdl/typemapper.cpp300
-rw-r--r--kode/kwsdl/typemapper.h85
-rw-r--r--kode/kwsdl/wscl/Makefile.am14
-rw-r--r--kode/kwsdl/wscl/conversation.cpp122
-rw-r--r--kode/kwsdl/wscl/conversation.h78
-rw-r--r--kode/kwsdl/wscl/documents.cpp107
-rw-r--r--kode/kwsdl/wscl/documents.h95
-rw-r--r--kode/kwsdl/wscl/interaction.cpp94
-rw-r--r--kode/kwsdl/wscl/interaction.h78
-rw-r--r--kode/kwsdl/wscl/parser.cpp224
-rw-r--r--kode/kwsdl/wscl/parser.h46
-rw-r--r--kode/kwsdl/wscl/transition.cpp63
-rw-r--r--kode/kwsdl/wscl/transition.h55
-rw-r--r--kode/kwsdl/wsdl.cpp135
-rw-r--r--kode/kwsdl/wsdl.h68
-rw-r--r--kode/kxml_compiler/Makefile.am9
-rw-r--r--kode/kxml_compiler/creator.cpp903
-rw-r--r--kode/kxml_compiler/creator.h115
-rw-r--r--kode/kxml_compiler/kxml_compiler.cpp177
-rw-r--r--kode/kxml_compiler/parser.cpp299
-rw-r--r--kode/kxml_compiler/parser.h134
-rw-r--r--kode/license.cpp93
-rw-r--r--kode/license.h49
-rw-r--r--kode/membervariable.cpp51
-rw-r--r--kode/membervariable.h44
-rw-r--r--kode/printer.cpp543
-rw-r--r--kode/printer.h75
-rw-r--r--kode/statemachine.cpp84
-rw-r--r--kode/statemachine.h52
-rw-r--r--kode/style.cpp54
-rw-r--r--kode/style.h48
-rw-r--r--kode/typedef.cpp38
-rw-r--r--kode/typedef.h46
-rw-r--r--kode/variable.cpp63
-rw-r--r--kode/variable.h60
158 files changed, 17927 insertions, 0 deletions
diff --git a/kode/Makefile.am b/kode/Makefile.am
new file mode 100644
index 000000000..393804fa3
--- /dev/null
+++ b/kode/Makefile.am
@@ -0,0 +1,21 @@
+SUBDIRS = . kxml_compiler #kwsdl
+
+INCLUDES = -I$(top_srcdir) $(all_includes)
+
+lib_LTLIBRARIES = libkode.la
+
+libkode_la_SOURCES = code.cpp enum.cpp style.cpp printer.cpp license.cpp file.cpp \
+ class.cpp \
+ function.cpp variable.cpp membervariable.cpp \
+ typedef.cpp statemachine.cpp automakefile.cpp
+libkode_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) \
+ -version-info 1:0:0 -no-undefined
+libkode_la_LIBADD = -lkdecore
+
+bin_PROGRAMS = kode
+
+kode_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kode_LDADD = libkode.la -lkabc
+kode_SOURCES = kodemain.cpp
+
+METASOURCES = AUTO
diff --git a/kode/README b/kode/README
new file mode 100644
index 000000000..b7b615c2a
--- /dev/null
+++ b/kode/README
@@ -0,0 +1,6 @@
+libkode is a helper library for programmatic generation of C++ code. It includes
+a program kode for generation of C++ template files and kxml_compiler for
+generation of C++ classes representing XML data described by RelaxNG schemes.
+
+If you have questions or comments please contact Cornelius Schumacher
+<schumacher@kde.org>.
diff --git a/kode/automakefile.cpp b/kode/automakefile.cpp
new file mode 100644
index 000000000..4ee5408fb
--- /dev/null
+++ b/kode/automakefile.cpp
@@ -0,0 +1,115 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "automakefile.h"
+
+using namespace KODE;
+
+AutoMakefile::Target::Target( const QString &type, const QString &name )
+ : mType( type ), mName( name )
+{
+}
+
+AutoMakefile::AutoMakefile()
+{
+}
+
+void AutoMakefile::addTarget( const Target &t )
+{
+ mTargets.append( t );
+ if ( mTargetTypes.find( t.type() ) == mTargetTypes.end() ) {
+ mTargetTypes.append( t.type() );
+ }
+}
+
+void AutoMakefile::addEntry( const QString &variable, const QString &value )
+{
+ if ( variable.isEmpty() ) {
+ mEntries.append( variable );
+ return;
+ }
+
+ QStringList::ConstIterator it = mEntries.find( variable );
+ if ( it == mEntries.end() ) {
+ mEntries.append( variable );
+ QMap<QString,QString>::Iterator it = mValues.find( variable );
+ if ( it == mValues.end() ) {
+ mValues.insert( variable, value );
+ } else {
+ mValues[ variable ].append( " " + value );
+ }
+ }
+}
+
+void AutoMakefile::newLine()
+{
+ addEntry( "" );
+}
+
+QString AutoMakefile::text() const
+{
+ QString out;
+
+ QStringList::ConstIterator it;
+ for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
+ QString variable = *it;
+ if ( variable.isEmpty() ) {
+ out += '\n';
+ } else {
+ out += variable + " = " + mValues[ variable ] + '\n';
+ }
+ }
+ out += '\n';
+
+ for( it = mTargetTypes.begin(); it != mTargetTypes.end(); ++it ) {
+ QString targetType = *it;
+
+ out += targetType + " = ";
+
+ Target::List::ConstIterator it2;
+ for( it2 = mTargets.begin(); it2 != mTargets.end(); ++it2 ) {
+ Target t = *it2;
+ if ( t.type() != targetType ) continue;
+
+ out += " " + t.name();
+ }
+ out += "\n\n";
+
+ for( it2 = mTargets.begin(); it2 != mTargets.end(); ++it2 ) {
+ Target t = *it2;
+ if ( t.type() != targetType ) continue;
+
+ QString name = t.name();
+ name.replace( '.', '_' );
+
+ out += name + "_SOURCES = " + t.sources() + '\n';
+ if ( !t.libAdd().isEmpty() )
+ out += name + "_LIBADD = " + t.libAdd() + '\n';
+ else
+ out += name + "_LDADD = " + t.ldAdd() + '\n';
+ out += name + "_LDFLAGS = " + t.ldFlags() + '\n';
+ }
+ out += '\n';
+
+ }
+
+ return out;
+}
diff --git a/kode/automakefile.h b/kode/automakefile.h
new file mode 100644
index 000000000..328d4fcf8
--- /dev/null
+++ b/kode/automakefile.h
@@ -0,0 +1,94 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_AUTOMAKEFILE_H
+#define KODE_AUTOMAKEFILE_H
+
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qmap.h>
+#include <qstringlist.h>
+
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT AutoMakefile
+{
+ public:
+ class KDE_EXPORT Target
+ {
+ public:
+ typedef QValueList<Target> List;
+
+ Target() {}
+ Target( const QString &type, const QString &name );
+
+ void setType( const QString &type ) { mType = type; }
+ QString type() const { return mType; }
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void setSources( const QString &sources ) { mSources = sources; }
+ QString sources() const { return mSources; }
+
+ void setLibAdd( const QString &libAdd ) { mLibAdd = libAdd; }
+ QString libAdd() const { return mLibAdd; }
+
+ void setLdAdd( const QString &ldAdd ) { mLdAdd = ldAdd; }
+ QString ldAdd() const { return mLdAdd; }
+
+ void setLdFlags( const QString &ldFlags ) { mLdFlags = ldFlags; }
+ QString ldFlags() const { return mLdFlags; }
+
+ private:
+ QString mType;
+ QString mName;
+
+ QString mSources;
+ QString mLibAdd;
+ QString mLdAdd;
+ QString mLdFlags;
+ };
+
+ AutoMakefile();
+
+ void addTarget( const Target &t );
+ Target::List targets() const { return mTargets; }
+
+ void addEntry( const QString &variable,
+ const QString &value = QString::null );
+
+ void newLine();
+
+ QString text() const;
+
+ private:
+ Target::List mTargets;
+ QStringList mTargetTypes;
+
+ QStringList mEntries;
+ QMap<QString,QString> mValues;
+};
+
+}
+
+#endif
diff --git a/kode/class.cpp b/kode/class.cpp
new file mode 100644
index 000000000..a65fac1ac
--- /dev/null
+++ b/kode/class.cpp
@@ -0,0 +1,176 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "class.h"
+
+#include <kdebug.h>
+
+using namespace KODE;
+
+Class::Class()
+{
+ mBaseClasses.setAutoDelete( true );
+}
+
+Class::Class( const QString &name, const QString &nameSpace )
+ : mName( name ), mNameSpace( nameSpace )
+{
+}
+
+Class::Class( const Class &c )
+{
+ *this = c;
+}
+
+Class &Class::operator=( const Class &c )
+{
+ if ( this == &c ) return *this;
+
+ mName = c.mName;
+ mNameSpace = c.mNameSpace;
+ mFunctions = c.mFunctions;
+ mMemberVariables = c.mMemberVariables;
+ mIncludes = c.mIncludes;
+ mHeaderIncludes = c.mHeaderIncludes;
+ mForwardDeclarations = c.mForwardDeclarations;
+ mEnums = c.mEnums;
+ mDocs = c.mDocs;
+
+ QPtrListIterator<Class> it( c.mBaseClasses );
+ while( it.current() ) {
+ mBaseClasses.append( new Class( *( it.current() ) ) );
+ ++it;
+ }
+
+ mTypedefs = c.mTypedefs;
+
+ return *this;
+}
+
+void Class::setName( const QString &name )
+{
+ mName = name;
+}
+
+void Class::setNameSpace( const QString &nameSpace )
+{
+ mNameSpace = nameSpace;
+}
+
+void Class::addInclude( const QString &include,
+ const QString &forwardDeclaration )
+{
+ if ( mIncludes.find( include ) == mIncludes.end() ) {
+ mIncludes.append( include );
+ }
+
+ if( !forwardDeclaration.isEmpty() &&
+ mForwardDeclarations.find( forwardDeclaration ) ==
+ mForwardDeclarations.end() ) {
+ mForwardDeclarations.append( forwardDeclaration );
+ }
+}
+
+void Class::addHeaderInclude( const QString &include )
+{
+ if ( include.isEmpty() )
+ return;
+
+ if ( mHeaderIncludes.find( include ) == mHeaderIncludes.end() ) {
+ mHeaderIncludes.append( include );
+ }
+}
+
+void Class::addHeaderIncludes( const QStringList &includes )
+{
+ QStringList::ConstIterator it;
+ for ( it = includes.begin(); it != includes.end(); ++it )
+ addHeaderInclude( *it );
+}
+
+void Class::addBaseClass( const Class &c )
+{
+ mBaseClasses.append( new Class( c ) );
+}
+
+void Class::addFunction( const Function &function )
+{
+ mFunctions.append( function );
+}
+
+void Class::addMemberVariable( const MemberVariable &v )
+{
+ mMemberVariables.append( v );
+}
+
+Class::List Class::baseClasses() const
+{
+ Class::List b;
+
+ QPtrListIterator<Class> it( mBaseClasses );
+ while( it.current() ) {
+ b.append( Class( *( it.current() ) ) );
+ ++it;
+ }
+
+ return b;
+}
+
+void Class::addTypedef( const Typedef &t )
+{
+ mTypedefs.append( t );
+}
+
+void Class::addEnum( const Enum &e )
+{
+ mEnums.append( e );
+}
+
+bool Class::isValid() const
+{
+ return !mName.isEmpty();
+}
+
+bool Class::hasFunction( const QString &functionName ) const
+{
+ Function::List::ConstIterator it;
+ for( it = mFunctions.begin(); it != mFunctions.end(); ++it ) {
+ if ( (*it).name() == functionName ) return true;
+ }
+
+ return false;
+}
+
+bool Class::isQObject() const
+{
+ Function::List::ConstIterator it;
+ for( it = mFunctions.begin(); it != mFunctions.end(); ++it ) {
+ if ( (*it).access() & Function::Signal || (*it).access() & Function::Slot )
+ return true;
+ }
+
+ return false;
+}
+
+void Class::setDocs( const QString &str )
+{
+ mDocs = str;
+}
diff --git a/kode/class.h b/kode/class.h
new file mode 100644
index 000000000..dde50e8bd
--- /dev/null
+++ b/kode/class.h
@@ -0,0 +1,98 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_CLASS_H
+#define KODE_CLASS_H
+
+#include "enum.h"
+#include "function.h"
+#include "membervariable.h"
+#include "typedef.h"
+
+#include <kdepimmacros.h>
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qptrlist.h>
+
+namespace KODE {
+
+class KDE_EXPORT Class
+{
+ public:
+ typedef QValueList<Class> List;
+
+ Class();
+ Class( const QString &name, const QString &nameSpace = QString::null );
+
+ Class( const Class & );
+ Class &operator=( const Class &c );
+
+ bool isValid() const;
+
+ void addInclude( const QString &file,
+ const QString &forwardDeclaration = QString::null );
+ void addHeaderInclude( const QString &file );
+ void addHeaderIncludes( const QStringList &files );
+ void addBaseClass( const Class & );
+ void addFunction( const Function & );
+ void addMemberVariable( const MemberVariable &v );
+ void addTypedef( const Typedef & );
+ void addEnum( const Enum & );
+
+ void setName( const QString &name );
+ QString name() const { return mName; }
+ void setNameSpace( const QString &nameSpace );
+ QString nameSpace() const { return mNameSpace; }
+ QStringList includes() const { return mIncludes; }
+ QStringList headerIncludes() const { return mHeaderIncludes; }
+ QStringList forwardDeclarations() const { return mForwardDeclarations; }
+ Function::List functions() const { return mFunctions; }
+ MemberVariable::List memberVariables() const { return mMemberVariables; }
+ Class::List baseClasses() const;
+ Typedef::List typedefs() const { return mTypedefs; }
+ Enum::List enums() const { return mEnums; }
+
+ void setDocs( const QString & );
+ QString docs() const { return mDocs; }
+
+ bool hasFunction( const QString &name ) const;
+
+ bool isQObject() const;
+
+ private:
+ // WARNING: If you add member variables, you have to adjust the copy
+ // constructor.
+ QString mName;
+ QString mNameSpace;
+ Function::List mFunctions;
+ MemberVariable::List mMemberVariables;
+ QStringList mIncludes;
+ QStringList mForwardDeclarations;
+ QStringList mHeaderIncludes;
+ QPtrList<Class> mBaseClasses;
+ Typedef::List mTypedefs;
+ Enum::List mEnums;
+ QString mDocs;
+};
+
+}
+
+#endif
diff --git a/kode/code.cpp b/kode/code.cpp
new file mode 100644
index 000000000..9d02736c6
--- /dev/null
+++ b/kode/code.cpp
@@ -0,0 +1,167 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "code.h"
+
+#include <kdebug.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+using namespace KODE;
+
+Code::Code()
+ : mIndent( 0 )
+{
+}
+
+Code::Code( int indent )
+ : mIndent( indent )
+{
+}
+
+void Code::clear()
+{
+ mIndent = 0;
+ mText = QString::null;
+}
+
+bool Code::isEmpty() const
+{
+ return mText.isEmpty();
+}
+
+void Code::setIndent( int indent )
+{
+ mIndent = indent;
+}
+
+void Code::indent()
+{
+ mIndent += 2;
+}
+
+void Code::unindent()
+{
+ mIndent -= 2;
+ if ( mIndent < 0 ) mIndent = 0;
+}
+
+void Code::addLine( const QString &line )
+{
+ mText += spaces( mIndent );
+ mText += line;
+ mText += '\n';
+}
+
+void Code::newLine()
+{
+ mText += '\n';
+}
+
+QString Code::spaces( int count )
+{
+ QString str;
+ for( int i = 0; i < count; ++i ) {
+ str += ' ';
+ }
+ return str;
+}
+
+void Code::addBlock( const QString &block )
+{
+ QStringList lines = QStringList::split( "\n", block, true );
+ if ( !lines.isEmpty() && lines.last().isEmpty() ) {
+ lines.pop_back();
+ }
+ QStringList::ConstIterator it;
+ for( it = lines.begin(); it != lines.end(); ++it ) {
+ if ( !(*it).isEmpty() ) mText += spaces( mIndent );
+ mText += *it;
+ mText += '\n';
+ }
+}
+
+void Code::addBlock( const QString &block, int indent )
+{
+ int tmp = mIndent;
+ mIndent = indent;
+ addBlock( block );
+ mIndent = tmp;
+}
+
+void Code::addBlock( const Code &c )
+{
+ addBlock( c.text() );
+}
+
+void Code::addWrappedText( const QString &txt )
+{
+ int maxWidth = 80 - mIndent;
+ unsigned int pos = 0;
+ while ( pos < txt.length() ) {
+ QString line = txt.mid( pos, maxWidth );
+ addLine( line );
+ pos += maxWidth;
+ }
+}
+
+void Code::addFormattedText( const QString &text )
+{
+ int maxWidth = 80 - mIndent;
+ int lineLength = 0;
+
+ QString line;
+ const QStringList words = QStringList::split( ' ', text, false );
+
+ QStringList::ConstIterator it;
+ for ( it = words.begin(); it != words.end(); ++it ) {
+ if ( (int)(*it).length() + lineLength >= maxWidth ) {
+ addLine( line );
+ line.truncate( 0 );
+ lineLength = 0;
+ }
+
+ line += *it + " ";
+ lineLength += (*it).length() + 1;
+ }
+
+ addLine( line );
+}
+
+Code &Code::operator+=( const QString &str )
+{
+ addLine( str );
+
+ return *this;
+}
+
+Code &Code::operator+=( const char *str )
+{
+ addLine( QString::fromLocal8Bit( str ) );
+ return *this;
+}
+
+Code &Code::operator+=( const Code &code )
+{
+ mText += code.mText;
+ return *this;
+}
diff --git a/kode/code.h b/kode/code.h
new file mode 100644
index 000000000..1723df905
--- /dev/null
+++ b/kode/code.h
@@ -0,0 +1,71 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_CODE_H
+#define KODE_CODE_H
+
+#include "license.h"
+
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qstringlist.h>
+#include <kdepimmacros.h>
+namespace KODE {
+
+class KDE_EXPORT Code
+{
+ public:
+ Code();
+ Code( int indent );
+
+ void clear();
+
+ bool isEmpty() const;
+
+ void setIndent( int indent );
+ void indent();
+ void unindent();
+
+ QString text() const { return mText; }
+
+ void addLine( const QString & );
+ void addBlock( const Code & );
+ void addBlock( const QString & );
+ void addBlock( const QString &, int indent );
+
+ void addWrappedText( const QString & );
+ void addFormattedText( const QString & );
+
+ void newLine();
+
+ Code &operator+=( const QString & );
+ Code &operator+=( const char * );
+ Code &operator+=( const Code & );
+
+ static QString spaces( int count );
+
+ private:
+ QString mText;
+ int mIndent;
+};
+
+}
+
+#endif
diff --git a/kode/enum.cpp b/kode/enum.cpp
new file mode 100644
index 000000000..3d8ac6081
--- /dev/null
+++ b/kode/enum.cpp
@@ -0,0 +1,58 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "enum.h"
+
+using namespace KODE;
+
+Enum::Enum()
+ : mCombinable( false )
+{
+}
+
+Enum::Enum( const QString &name, const QStringList &enums, bool combinable )
+ : mName( name ), mEnums( enums ), mCombinable( combinable )
+{
+}
+
+QString Enum::declaration() const
+{
+ QString retval( "enum " + mName + " {" );
+ uint value = 0;
+ QStringList::ConstIterator it;
+ for ( it = mEnums.begin(); it != mEnums.end(); ++it, ++value ) {
+ if ( mCombinable ) {
+ if ( it == mEnums.begin() )
+ retval += QString( " %1 = %2" ).arg( *it ).arg( 1 << value );
+ else
+ retval += QString( ", %1 = %2" ).arg( *it ).arg( 1 << value );
+ } else {
+ if ( it == mEnums.begin() )
+ retval += " " + *it;
+ else
+ retval += ", " + *it;
+ }
+ }
+
+ retval += " };";
+
+ return retval;
+}
diff --git a/kode/enum.h b/kode/enum.h
new file mode 100644
index 000000000..e3bc695aa
--- /dev/null
+++ b/kode/enum.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_ENUM_H
+#define KODE_ENUM_H
+
+#include <qstringlist.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT Enum
+{
+ public:
+ typedef QValueList<Enum> List;
+
+ Enum();
+ Enum( const QString &name, const QStringList &enums, bool combinable = false );
+
+ QString declaration() const;
+
+ private:
+ QString mName;
+ QStringList mEnums;
+ bool mCombinable;
+};
+
+}
+
+#endif
diff --git a/kode/file.cpp b/kode/file.cpp
new file mode 100644
index 000000000..fa93326c9
--- /dev/null
+++ b/kode/file.cpp
@@ -0,0 +1,158 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "file.h"
+
+#include <kdebug.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+using namespace KODE;
+
+File::File()
+ : mProject( "KDE" )
+{
+}
+
+void File::setFilename( const QString &filename )
+{
+ mFilename = filename;
+}
+
+QString File::filename() const
+{
+ if ( !mFilename.isEmpty() ) return mFilename;
+
+ if ( !mClasses.isEmpty() ) {
+ QString className = mClasses[ 0 ].name();
+ return className.lower();
+ }
+
+ return QString::null;
+}
+
+void File::setNameSpace( const QString &n )
+{
+ mNameSpace = n;
+}
+
+void File::setProject( const QString &project )
+{
+ if ( project.isEmpty() ) return;
+ mProject = project;
+}
+
+void File::addCopyright( int year, const QString &name, const QString &email )
+{
+ QString str = "Copyright (c) " + QString::number( year ) + " " + name + " <" +
+ email + ">";
+ mCopyrightStrings.append( str );
+}
+
+void File::setLicense( const License &l )
+{
+ mLicense = l;
+}
+
+void File::addInclude( const QString &i )
+{
+ QString include = i;
+ if( !include.endsWith( ".h" ) ) include.append( ".h" );
+
+ if ( mIncludes.find( include ) == mIncludes.end() ) {
+ mIncludes.append( include );
+ }
+}
+
+void File::insertClass( const Class &c )
+{
+ Class::List::Iterator it;
+ for( it = mClasses.begin(); it != mClasses.end(); ++it ) {
+ if ( (*it).name() == c.name() ) {
+ it = mClasses.remove( it );
+ mClasses.insert( it, c );
+ return;
+ }
+ }
+
+ mClasses.append( c );
+}
+
+bool File::hasClass( const QString &name )
+{
+ Class::List::ConstIterator it;
+ for( it = mClasses.begin(); it != mClasses.end(); ++it ) {
+ if ( (*it).name() == name ) break;
+ }
+ return it != mClasses.end();
+}
+
+Class File::findClass( const QString &name )
+{
+ Class::List::ConstIterator it;
+ for( it = mClasses.begin(); it != mClasses.end(); ++it ) {
+ if ( (*it).name() == name ) return *it;
+ }
+ return Class();
+}
+
+void File::addFileVariable( const Variable &v )
+{
+ mFileVariables.append( v );
+}
+
+void File::addFileFunction( const Function &f )
+{
+ mFileFunctions.append( f );
+}
+
+void File::addExternCDeclaration( const QString &s )
+{
+ mExternCDeclarations.append( s );
+}
+
+void File::clearClasses()
+{
+ mClasses.clear();
+}
+
+void File::clearFileFunctions()
+{
+ mFileFunctions.clear();
+}
+
+void File::clearFileVariables()
+{
+ mFileVariables.clear();
+}
+
+void File::clearCode()
+{
+ clearClasses();
+ clearFileFunctions();
+ clearFileVariables();
+}
+
+void File::addFileCode( const Code &c )
+{
+ mFileCode = c;
+}
diff --git a/kode/file.h b/kode/file.h
new file mode 100644
index 000000000..e4efdca6c
--- /dev/null
+++ b/kode/file.h
@@ -0,0 +1,99 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_FILE_H
+#define KODE_FILE_H
+
+#include "license.h"
+#include "code.h"
+#include "class.h"
+#include "membervariable.h"
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT File
+{
+ public:
+ File();
+
+ void setFilename( const QString & );
+ QString filename() const;
+
+ void setNameSpace( const QString & );
+ QString nameSpace() const { return mNameSpace; }
+
+ void setProject( const QString &project );
+ QString project() const { return mProject; }
+
+ void addCopyright( int year, const QString &name, const QString &email );
+ QStringList copyrightStrings() const { return mCopyrightStrings; }
+
+ void setLicense( const License & );
+ License license() const { return mLicense; }
+
+ void addInclude( const QString &include );
+ QStringList includes() const { return mIncludes; }
+
+ void insertClass( const Class & );
+ Class::List classes() const { return mClasses; }
+
+ bool hasClass( const QString &className );
+
+ Class findClass( const QString &name );
+
+ void clearClasses();
+ void clearFileFunctions();
+ void clearFileVariables();
+
+ void clearCode();
+
+ void addFileVariable( const Variable & );
+ Variable::List fileVariables() const { return mFileVariables; }
+
+ void addFileFunction( const Function & );
+ Function::List fileFunctions() const { return mFileFunctions; }
+
+ void addExternCDeclaration( const QString & );
+ QStringList externCDeclarations() const { return mExternCDeclarations; }
+
+ void addFileCode( const Code & );
+ Code fileCode() const { return mFileCode; }
+
+ private:
+ QString mFilename;
+ QString mNameSpace;
+ QString mProject;
+ QStringList mCopyrightStrings;
+ License mLicense;
+ QStringList mIncludes;
+ Class::List mClasses;
+ Variable::List mFileVariables;
+ Function::List mFileFunctions;
+ QStringList mExternCDeclarations;
+ Code mFileCode;
+};
+
+}
+
+#endif
diff --git a/kode/function.cpp b/kode/function.cpp
new file mode 100644
index 000000000..1e379e46c
--- /dev/null
+++ b/kode/function.cpp
@@ -0,0 +1,123 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "function.h"
+
+#include <kdebug.h>
+
+using namespace KODE;
+
+Function::Function()
+ : mAccess( Public ), mIsConst( false ), mIsStatic( false )
+{
+}
+
+Function::Function( const QString &name, const QString &returnType,
+ int access, bool isStatic )
+ : mAccess( access ), mIsConst( false ), mIsStatic( isStatic ),
+ mReturnType( returnType ), mName( name )
+{
+}
+
+void Function::setConst( bool isConst )
+{
+ mIsConst = isConst;
+}
+
+void Function::setStatic( bool isStatic )
+{
+ mIsStatic = isStatic;
+}
+
+void Function::addArgument( const QString &argument )
+{
+ mArguments.append( argument );
+}
+
+void Function::addInitializer( const QString &initializer )
+{
+ mInitializers.append( initializer );
+}
+
+void Function::setArgumentString( const QString &argumentString )
+{
+ mArguments.clear();
+ QStringList arguments = QStringList::split( ",", argumentString );
+ QStringList::ConstIterator it;
+ for( it = arguments.begin(); it != arguments.end(); ++it ) {
+ addArgument( *it );
+ }
+}
+
+void Function::setBody( const QString &body )
+{
+ mBody = body;
+}
+
+void Function::setBody( const Code &body )
+{
+ mBody = body.text();
+}
+
+void Function::addBodyLine( const QString &bodyLine )
+{
+ mBody.append( bodyLine );
+ if ( bodyLine.right( 1 ) != "\n" ) mBody.append( '\n' );
+}
+
+void Function::setAccess( int a )
+{
+ mAccess = a;
+}
+
+QString Function::accessAsString() const
+{
+ QString access;
+
+ if ( mAccess & Public )
+ access = "public";
+ if ( mAccess & Protected )
+ access = "protected";
+ if ( mAccess & Private )
+ access = "private";
+
+ if ( mAccess & Signal )
+ access = "signals";
+ if ( mAccess & Slot )
+ access += " slots";
+
+ return access;
+}
+
+void Function::setReturnType( const QString &str )
+{
+ mReturnType = str;
+}
+
+void Function::setName( const QString &str )
+{
+ mName = str;
+}
+
+void Function::setDocs( const QString &str )
+{
+ mDocs = str;
+}
diff --git a/kode/function.h b/kode/function.h
new file mode 100644
index 000000000..53ba43720
--- /dev/null
+++ b/kode/function.h
@@ -0,0 +1,91 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_FUNCTION_H
+#define KODE_FUNCTION_H
+
+#include "code.h"
+
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qstringlist.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT Function
+{
+ public:
+ typedef QValueList<Function> List;
+
+ enum AccessSpecifier { Public = 1, Protected = 2, Private = 4, Signal = 8, Slot = 16 };
+
+ Function();
+ Function( const QString &name, const QString &returnType = QString::null,
+ int access = Public, bool isStatic = false );
+
+ void setConst( bool isConst );
+ bool isConst() const { return mIsConst; }
+
+ void setStatic( bool isStatic );
+ bool isStatic() const { return mIsStatic; }
+
+ void addArgument( const QString &argument );
+ void setArgumentString( const QString &argumentString );
+
+ void addInitializer( const QString & );
+ QStringList initializers() const { return mInitializers; }
+
+ void setBody( const QString &body );
+ void setBody( const Code &code );
+ void addBodyLine( const QString &bodyLine );
+
+ void setAccess( int );
+ int access() const { return mAccess; }
+ QString accessAsString() const;
+
+ void setReturnType( const QString & );
+ QString returnType() const { return mReturnType; }
+
+ void setName( const QString & );
+ QString name() const { return mName; }
+
+ QStringList arguments() const { return mArguments; }
+
+ QString body() const { return mBody; }
+
+ void setDocs( const QString & );
+ QString docs() const { return mDocs; }
+
+ private:
+ int mAccess;
+ bool mIsConst;
+ bool mIsStatic;
+ QString mReturnType;
+ QString mName;
+ QStringList mArguments;
+ QStringList mInitializers;
+ QString mBody;
+ QString mDocs;
+};
+
+}
+
+#endif
diff --git a/kode/kodemain.cpp b/kode/kodemain.cpp
new file mode 100644
index 000000000..a567f20a0
--- /dev/null
+++ b/kode/kodemain.cpp
@@ -0,0 +1,633 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "code.h"
+#include "printer.h"
+#include "license.h"
+#include "automakefile.h"
+
+#include <kabc/stdaddressbook.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kconfig.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <ksimpleconfig.h>
+#include <ksavefile.h>
+#include <kprocess.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qfileinfo.h>
+#include <qregexp.h>
+
+#include <iostream>
+
+static const KCmdLineOptions options[] =
+{
+ { "c", 0, 0 },
+ { "create-class", I18N_NOOP("Create class"), 0 },
+ { "d", 0, 0 },
+ { "create-dialog", I18N_NOOP("Create dialog"), 0 },
+ { "create-kioslave", I18N_NOOP("Create kioslave"), 0 },
+ { "create-main", I18N_NOOP("Create main function template"), 0 },
+ { "y", 0, 0 },
+ { "codify", I18N_NOOP("Create generator code for given source"), 0 },
+ { "add-property", I18N_NOOP("Add property to class"), 0 },
+ { "inplace", I18N_NOOP("Change file in place"), 0 },
+ { "author-email <name>", I18N_NOOP("Add author with given email address"), 0 },
+ { "project <name>", I18N_NOOP("Name of project"), 0 },
+ { "gpl", I18N_NOOP("Use GPL as license"), 0 },
+ { "lgpl", I18N_NOOP("Use LGPL as license"), 0 },
+ { "classname <name>", I18N_NOOP("Name of class"), 0 },
+ { "filename <name>", I18N_NOOP("Name of file"), 0 },
+ { "namespace <name>", I18N_NOOP("Namespace"), 0 },
+ { "warning", I18N_NOOP("Create warning about code generation"), 0 },
+ { "qt-exception", I18N_NOOP("Add Qt exception to GPL"), 0 },
+ { "singleton", I18N_NOOP("Create a singleton class"), 0 },
+ { "protocol", I18N_NOOP("kioslave protocol"), 0 },
+ { "+[filename]", I18N_NOOP("Source code file name"), 0 },
+ KCmdLineLastOption
+};
+
+void addPropertyFunctions( QString &out, const QString &type,
+ const QString &name )
+{
+ // FIXME: Use KODE::Function
+
+ bool isReference = type.endsWith( "*" ) || type.endsWith( "&" );
+
+ QString argument;
+ QString upper = KODE::Style::upperFirst( name );
+ if ( !isReference ) {
+ argument = "const " + type + " &";
+ } else argument = type;
+
+ KODE::Code code;
+ code.setIndent( 4 );
+ code += "/**";
+ code += " Set .";
+ code += "*/";
+ code += "void set" + upper + "( " + argument + "v )";
+ code += "{";
+ code += " m" + upper + " = v;";
+ code += "}";
+
+ code += "/**";
+ code += " Get " + name + ". See set" + upper + "().";
+ code += "*/";
+ code += type + ( isReference ? "" : " " ) + name + "() const";
+ code += "{";
+ code += " return m" + upper + ";";
+ code += "}";
+
+ out += code.text();
+}
+
+void addPropertyVariable( QString &out, const QString &type,
+ const QString &name )
+{
+ QString upper = KODE::Style::upperFirst( name );
+ bool isReference = type.endsWith( "*" ) || type.endsWith( "&" );
+
+ KODE::Code code;
+ code.setIndent( 4 );
+ code += type + ( isReference ? "" : " " ) + "m" + upper + ";";
+
+ out += code.text();
+}
+
+// FIXME: Put addProperty in PropertyAdder class and add endReadAhead function.
+int addProperty( KCmdLineArgs *args )
+{
+ if ( args->count() != 3 ) {
+ std::cerr << "Usage: kode --add-property <class> <proprerty-type> "
+ << "<property-name>" << std::endl;
+ return 1;
+ }
+
+ QString className = args->arg( 0 );
+ QString type = args->arg( 1 );
+ QString name = args->arg( 2 );
+
+ kdDebug() << "Add property: class " << className << ": " << type << " " <<
+ name << endl;
+
+ QString headerFileName = className.lower() + ".h";
+
+ QFile headerFile( headerFileName );
+ if ( !headerFile.open( IO_ReadOnly ) ) {
+ std::cerr << "Unable to open file '" << headerFileName.utf8() << "'" <<
+ std::endl;
+ return 1;
+ }
+
+ QTextStream in( &headerFile );
+
+ enum State { FindClass, FindConstructor, FindProperties, FindPrivate,
+ FindVariables, Finish };
+ State state = FindClass;
+
+ QString accessor;
+ QString mutator;
+
+ QString out;
+
+ QString readAhead;
+
+ QString line;
+ while ( !( line = in.readLine() ).isNull() ) {
+// std::cout << line.utf8() << std::endl;
+ kdDebug() << state << " LINE: " << line << endl;
+ QString readAheadPrevious = readAhead;
+ readAhead += line + "\n";
+// out += line + "\n";
+ switch( state ) {
+ case FindClass:
+// if ( line.find( QRegExp( className ) ) >= 0 ) {
+ if ( line.find( QRegExp( "^\\s*class\\s+" + className ) ) >= 0 ) {
+ kdDebug() << " FOUND CLASS" << endl;
+ state = FindConstructor;
+ }
+ break;
+ case FindConstructor:
+ if ( line.find( QRegExp( "^\\s*" + className + "\\s*\\(" ) ) >= 0 ) {
+ kdDebug() << " FOUND CONSTRUCTOR" << endl;
+ out += readAhead;
+ readAhead = QString::null;
+ state = FindProperties;
+ }
+ break;
+ case FindProperties:
+ {
+ QRegExp re( "(\\w+)\\s*\\(" );
+ if ( re.search( line ) >= 0 ) {
+ QString function = re.cap( 1 ).lower();
+ if ( !function.isEmpty() ) {
+ kdDebug() << "Function: " << function << endl;
+ if ( function == className || function == "~" + className ) {
+ out += readAhead;
+ readAhead = QString::null;
+ } else {
+ if ( function.startsWith( "set" ) ) {
+ mutator = function.mid( 3 );
+ kdDebug() << "MUTATOR: " << mutator << endl;
+ } else {
+ if ( function == mutator ) {
+ accessor = function;
+ kdDebug() << "ACCESSOR: " << accessor << endl;
+ out += readAhead;
+ readAhead = QString::null;
+ } else {
+ kdDebug() << "CREATE PROPERTY" << endl;
+ out += readAheadPrevious;
+ addPropertyFunctions( out, type, name );
+ out += "\n";
+ readAhead = line + "\n";
+ state = FindPrivate;
+ }
+ }
+ }
+ }
+ } else if ( line.find( QRegExp( "\\s*protected" ) ) >= 0 ) {
+ state = FindPrivate;
+ } else if ( line.find( QRegExp( "\\s*private" ) ) >= 0 ) {
+ if ( accessor.isEmpty() ) {
+ addPropertyFunctions( out, type, name );
+ out += readAhead;
+ readAhead = QString::null;
+ addPropertyVariable( out, type, name );
+ state = Finish;
+ } else {
+ if ( accessor == mutator ) {
+ out += readAheadPrevious;
+ addPropertyFunctions( out, type, name );
+ out += "\n";
+ out += line + "\n";
+ readAhead = QString::null;
+ }
+ state = FindVariables;
+ }
+ }
+ }
+ break;
+ case FindPrivate:
+ if ( line.find( QRegExp( "\\s*private" ) ) >= 0 ) {
+ if ( accessor.isEmpty() ) {
+ out += readAhead;
+ readAhead = QString::null;
+ addPropertyVariable( out, type, name );
+ state = Finish;
+ } else {
+ state = FindVariables;
+ }
+ }
+ break;
+ case FindVariables:
+ {
+ if ( line.find( "m" + accessor.lower(), 0, false ) >= 0 ) {
+ out += readAhead;
+ readAhead = QString::null;
+ addPropertyVariable( out, type, name );
+ state = Finish;
+ }
+ }
+ break;
+ case Finish:
+ break;
+ }
+ }
+
+ headerFile.close();
+
+ out += readAhead;
+
+ if ( args->isSet( "inplace" ) ) {
+ QString headerFileNameOut = headerFileName + ".kodeorig" ;
+
+ KProcess proc;
+ proc << "cp" << QFile::encodeName( headerFileName ) <<
+ QFile::encodeName( headerFileNameOut );
+
+ if ( !proc.start( KProcess::Block ) ) {
+ kdError() << "Copy failed" << endl;
+ } else {
+ kdDebug() << "Write to original file." << endl;
+ if ( !headerFile.open( IO_WriteOnly ) ) {
+ kdError() << "Unable to open file '" << headerFileName <<
+ "' for writing." << endl;
+ return 1;
+ }
+ QTextStream o( &headerFile );
+ o << out << endl;
+ }
+ } else {
+ std::cout << out.utf8() << std::endl;
+ }
+
+ return 0;
+}
+
+int codify( KCmdLineArgs *args )
+{
+ if ( args->count() != 1 ) {
+ std::cerr << "Usage: kode --codify <sourcecodefile>" << std::endl;
+ return 1;
+ }
+
+ QString filename = args->arg( 0 );
+
+ QFile f( filename );
+ if ( !f.open( IO_ReadOnly ) ) {
+ kdError() << "Unable to open file '" << filename << "'." << endl;
+ return 1;
+ } else {
+ std::cout << "KODE::Code code;" << std::endl;
+ QTextStream ts( &f );
+ QString line;
+ while( !( line = ts.readLine() ).isNull() ) {
+ line.replace( "\\", "\\\\" );
+ line.replace( "\"", "\\\"" );
+ line = "code += \"" + line;
+ line.append( "\";" );
+ std::cout << line.local8Bit() << std::endl;
+ }
+ }
+
+ return 0;
+}
+
+int create( KCmdLineArgs *args )
+{
+ KODE::Printer p;
+ if ( args->isSet( "warning" ) ) p.setCreationWarning( true );
+
+ bool createKioslave = args->isSet( "create-kioslave" );
+ bool createMain = args->isSet( "create-main" );
+
+ QString filename = args->getOption( "filename" );
+
+ if ( createMain ) {
+ if ( filename.isEmpty() ) {
+ kdError() << "Error: No file name given." << endl;
+ return 1;
+ }
+
+ if ( filename.endsWith( ".cpp" ) ) {
+ filename = filename.left( filename.length() - 4 );
+ }
+ } else {
+ if ( !args->isSet( "classname" ) ) {
+ kdError() << "Error: No class name given." << endl;
+ return 1;
+ }
+ }
+
+ QString className = args->getOption( "classname" );
+
+ QString protocol;
+
+ if ( createKioslave ) {
+ if ( !args->isSet( "protocol" ) ) {
+ protocol = className.lower();
+ kdWarning() << "Warning: No protocol for kioslave given. Assuming '"
+ << protocol << "'" << endl;
+ } else {
+ protocol = args->getOption( "protocol" );
+ }
+ }
+
+ KODE::File file;
+
+ file.setProject( args->getOption( "project" ) );
+
+ QString authorEmail = args->getOption( "author-email" );
+ QString authorName;
+ KABC::Addressee a;
+ if ( authorEmail.isEmpty() ) {
+ a = KABC::StdAddressBook::self()->whoAmI();
+ authorEmail = a.preferredEmail();
+ } else {
+ KABC::Addressee::List as =
+ KABC::StdAddressBook::self()->findByEmail( authorEmail );
+ if ( as.isEmpty() ) {
+ kdDebug() << "Unable to find '" << authorEmail << "' in address book."
+ << endl;
+ } else {
+ a = as.first();
+ }
+ }
+ if ( !a.isEmpty() ) {
+ authorName = a.realName();
+ }
+ if ( !authorEmail.isEmpty() ) {
+ file.addCopyright( QDate::currentDate().year(), authorName, authorEmail );
+ }
+
+ KODE::License l;
+ if ( args->isSet( "gpl" ) ) l = KODE::License( KODE::License::GPL );
+ if ( args->isSet( "lgpl" ) ) l = KODE::License( KODE::License::LGPL );
+ l.setQtException( args->isSet( "qt-exception" ) );
+ file.setLicense( l );
+
+ file.setNameSpace( args->getOption( "namespace" ) );
+
+ if ( createMain ) {
+ file.addInclude( "kaboutdata.h" );
+ file.addInclude( "kapplication.h" );
+ file.addInclude( "kdebug" );
+ file.addInclude( "klocale" );
+ file.addInclude( "kcmdlineargs" );
+
+ KODE::Code code;
+ code += "static const KCmdLineOptions options[] =";
+ code += "{";
+ code += " { \"verbose\", \"Verbose output\", 0 },";
+ code += " KCmdLineLastOption";
+ code += "};";
+ file.addFileCode( code );
+
+ KODE::Function main( "main", "int" );
+ main.addArgument( "int argc" );
+ main.addArgument( "char **argv" );
+
+ code.clear();
+ code += "KAboutData aboutData(\"test\",\"Test\",\"0.1\");";
+ code += "KCmdLineArgs::init(argc,argv,&aboutData);";
+ code += "KCmdLineArgs::addCmdLineOptions( options );";
+ code += "";
+ code += "KApplication app;";
+ code += "";
+ code += "KCmdLineArgs *args = KCmdLineArgs::parsedArgs();";
+ code += "";
+ code += "Q_UNUSED( args );";
+ main.setBody( code );
+
+ file.addFileFunction( main );
+
+ file.setFilename( filename );
+
+ p.printImplementation( file, false );
+
+ return 0;
+ }
+
+ KODE::Class c( className );
+
+ if ( args->isSet( "create-dialog" ) ) {
+ c.addBaseClass( KODE::Class( "KDialogBase" ) );
+ c.addInclude( "kdialogbase.h" );
+ } else if ( createKioslave ) {
+ c.setDocs( "This class implements a kioslave for ..." );
+
+ c.addBaseClass( KODE::Class( "SlaveBase", "KIO" ) );
+ c.addHeaderInclude( "kio/slavebase.h" );
+
+ KODE::Function get( "get", "void" );
+ get.addArgument( "const KURL &url" );
+
+ KODE::Code code;
+
+ code += "kdDebug(7000) << \"" + className + "::get()\" << endl;";
+ code += "kdDebug(7000) << \" URL: \" << url.url() << endl;";
+ code += "#if 1";
+ code += "kdDebug(7000) << \" Path: \" << url.path() << endl;";
+ code += "kdDebug(7000) << \" Query: \" << url.query() << endl;";
+ code += "kdDebug(7000) << \" Protocol: \" << url.protocol() << endl;";
+ code += "kdDebug(7000) << \" Filename: \" << url.filename() << endl;";
+ code += "#endif";
+ code.newLine();
+
+ code += "mimeType( \"text/plain\" );";
+ code.newLine();
+
+ code += "QCString str( \"Hello!\" );";
+ code += "data( str );";
+ code.newLine();
+
+ code += "finished();";
+ code.newLine();
+
+ code += "kdDebug(7000) << \"" + className + "CgiProtocol::get() done\" << endl;";
+
+ get.setBody( code );
+
+ c.addFunction( get );
+
+
+ c.addInclude( "kinstance.h" );
+ c.addInclude( "kdebug.h" );
+ c.addInclude( "sys/types.h" );
+ c.addInclude( "unistd.h" );
+ c.addInclude( "stdlib.h" );
+
+ KODE::Function main( "kdemain", "int" );
+ main.addArgument( "int argc" );
+ main.addArgument( "char **argv" );
+
+ code.clear();
+
+ code += "KInstance instance( \"kio_" + protocol + "\" );";
+ code += "";
+ code += "kdDebug(7000) << \"Starting kio_" + protocol + "(pid: \" << getpid() << \")\" << endl;";
+ code += "";
+ code += "if (argc != 4) {";
+ code.indent();
+ code += "fprintf( stderr, \"Usage: kio_" + protocol + " protocol domain-socket1 domain-socket2\\n\");";
+ code += "exit( -1 );";
+ code.unindent();
+ code += "}";
+ code += "";
+ code += className + " slave( argv[2], argv[3] );";
+ code += "slave.dispatchLoop();";
+ code += "";
+ code += "return 0;";
+
+ main.setBody( code );
+
+ file.addFileFunction( main );
+
+ file.addExternCDeclaration( p.functionSignature( main ) );
+ }
+
+ KODE::Function constructor( className );
+
+ if ( args->isSet( "singleton" ) ) {
+ constructor.setAccess( KODE::Function::Private );
+
+ KODE::Function self( "self", className + " *" );
+ self.setStatic( true );
+
+ KODE::Code code;
+ code += "if ( !mSelf ) {";
+ code += " selfDeleter.setObject( mSelf, new " + className + "() );";
+ code += "}";
+ code += "return mSelf;";
+
+ self.setBody( code );
+
+ c.addFunction( self );
+
+ KODE::MemberVariable selfVar( "mSelf", className + " *", true );
+ selfVar.setInitializer( "0" );
+
+ c.addMemberVariable( selfVar );
+
+ KODE::Variable staticDeleter( "selfDeleter",
+ "KStaticDeleter<" + className + ">",
+ true );
+ file.addFileVariable( staticDeleter );
+ file.addInclude( "kstaticdeleter.h" );
+ }
+
+ if ( createKioslave ) {
+ constructor.addArgument( "const QCString &pool" );
+ constructor.addArgument( "const QCString &app" );
+
+ constructor.addInitializer( "SlaveBase( \"" + protocol + "\", pool, app )" );
+ }
+
+ c.addFunction( constructor );
+
+ file.insertClass( c );
+
+ p.printHeader( file );
+ p.printImplementation( file );
+
+ if ( createKioslave ) {
+ // Write automake Makefile
+ KODE::AutoMakefile am;
+
+ am.addEntry( "INCLUDES", "$(all_includes)" );
+ am.newLine();
+ am.addEntry( "noinst_HEADERS", className.lower() + ".h" );
+ am.newLine();
+ am.addEntry( "METASOURCES", "AUTO" );
+ am.newLine();
+ am.addEntry( "kdelnkdir", "$(kde_servicesdir)" );
+ am.addEntry( "kdelnk_DATA", protocol + ".protocol" );
+
+ KODE::AutoMakefile::Target t( "kde_module_LTLIBRARIES",
+ "kio_" + protocol + ".la" );
+ t.setSources( className.lower() + ".cpp" );
+ t.setLibAdd( "$(LIB_KIO)" );
+ t.setLdFlags( "$(all_libraries) -module $(KDE_PLUGIN)" );
+
+ am.addTarget( t );
+
+ p.printAutoMakefile( am );
+
+
+ // Write protocol file
+ QString protocolFilename = protocol + ".protocol";
+
+ QFileInfo fi( protocolFilename );
+ protocolFilename = fi.absFilePath();
+
+ KSaveFile::backupFile( protocolFilename, QString::null, ".backup" );
+
+ QFile::remove( protocolFilename );
+
+ KSimpleConfig protocolFile( protocolFilename );
+
+ protocolFile.setGroup( "Protocol" );
+ protocolFile.writeEntry( "exec", "kio_" + protocol );
+ protocolFile.writeEntry( "protocol", protocol );
+ protocolFile.writeEntry( "input", "none" );
+ protocolFile.writeEntry( "output", "filesystem" );
+ protocolFile.writeEntry( "reading", "true" );
+ protocolFile.writeEntry( "DocPath", "kioslave/" + protocol + ".html" );
+
+ protocolFile.sync();
+ }
+
+ return 0;
+}
+
+int main(int argc,char **argv)
+{
+ KAboutData aboutData( "kode", I18N_NOOP("KDE Code Generator"), "0.1" );
+ aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KApplication app;
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ if ( args->isSet( "create-class" ) || args->isSet( "create-dialog" ) ||
+ args->isSet( "create-kioslave" ) || args->isSet( "create-main" ) ) {
+ return create( args );
+ } else if ( args->isSet( "codify" ) ) {
+ return codify( args );
+ } else if ( args->isSet( "add-property" ) ) {
+ return addProperty( args );
+ } else {
+ std::cerr << "Error: No command given." << std::endl;
+ return 1;
+ }
+}
diff --git a/kode/kwsdl/Makefile.am b/kode/kwsdl/Makefile.am
new file mode 100644
index 000000000..bc7d0d1f3
--- /dev/null
+++ b/kode/kwsdl/Makefile.am
@@ -0,0 +1,19 @@
+SUBDIRS = schema . wscl tests kung
+
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libkdepim $(all_includes)
+
+lib_LTLIBRARIES = libwsdl.la
+
+libwsdl_la_SOURCES = binding.cpp message.cpp parser.cpp port.cpp service.cpp \
+ typemapper.cpp wsdl.cpp
+libwsdl_la_LDFLAGS = $(all_libraries) -version-info 1:0:0 -no-undefined
+libwsdl_la_LIBADD = -lkdecore schema/libschema.la
+
+bin_PROGRAMS = kwsdl_compiler
+
+kwsdl_compiler_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kwsdl_compiler_LDADD = ../libkode.la libwsdl.la
+kwsdl_compiler_SOURCES = compiler.cpp converter.cpp creator.cpp main.cpp \
+ namemapper.cpp
+
+METASOURCES = AUTO
diff --git a/kode/kwsdl/TODO b/kode/kwsdl/TODO
new file mode 100644
index 000000000..72ef5be67
--- /dev/null
+++ b/kode/kwsdl/TODO
@@ -0,0 +1,6 @@
+- support marshal/demarshal of attributes in complex types
+
+- correct namespace handling
+- implement 'list' and 'union' properties of SimpleType
+- fix the type vs. element issue (introduce anonymous types again)
+- code refactoring \ No newline at end of file
diff --git a/kode/kwsdl/binding.cpp b/kode/kwsdl/binding.cpp
new file mode 100644
index 000000000..540de5fbe
--- /dev/null
+++ b/kode/kwsdl/binding.cpp
@@ -0,0 +1,63 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "binding.h"
+
+using namespace KWSDL;
+
+Binding::Operation::Operation()
+{
+}
+
+Binding::Operation::Operation( const QString &name, const QString &action )
+ : mName( name ), mAction( action )
+{
+}
+
+Binding::Binding()
+{
+}
+
+Binding::Binding( const QString &name, const QString &type )
+ : mName( name ), mType( type )
+{
+}
+
+
+void Binding::addOperation( const Operation &operation )
+{
+ mOperations.append( operation );
+}
+
+Binding::Operation Binding::operation( const QString &name ) const
+{
+ Operation::List::ConstIterator it;
+ for ( it = mOperations.begin(); it != mOperations.end(); ++it )
+ if ( (*it).name() == name )
+ return *it;
+
+ return Operation();
+}
+
+Binding::Operation::List Binding::operations() const
+{
+ return mOperations;
+}
diff --git a/kode/kwsdl/binding.h b/kode/kwsdl/binding.h
new file mode 100644
index 000000000..eba155c7d
--- /dev/null
+++ b/kode/kwsdl/binding.h
@@ -0,0 +1,108 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_BINDING_H
+#define KWSDL_BINDING_H
+
+#include <qmap.h>
+
+namespace KWSDL {
+
+class Binding
+{
+ public:
+ typedef QValueList<Binding> List;
+
+ class Operation
+ {
+ public:
+ typedef QValueList<Operation> List;
+
+ class Item
+ {
+ public:
+ void setUse( const QString &use ) { mUse = use; }
+ QString use() const { return mUse; }
+
+ void setNameSpace( const QString &nameSpace ) { mNameSpace = nameSpace; }
+ QString nameSpace() const { return mNameSpace; }
+
+ void setEncodingStyle( const QString &encodingStyle ) { mEncodingStyle = encodingStyle; }
+ QString encodingStyle() const { return mEncodingStyle; }
+
+ private:
+ QString mUse;
+ QString mNameSpace;
+ QString mEncodingStyle;
+ };
+
+ Operation();
+ Operation( const QString &name, const QString &action );
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void setAction( const QString &action ) { mAction = action; }
+ QString action() const { return mAction; }
+
+ void setInput( const Item &item ) { mInput = item; }
+ Item input() const { return mInput; }
+
+ void setOutput( const Item &item ) { mOutput = item; }
+ Item output() const { return mOutput; }
+
+ private:
+ QString mName;
+ QString mAction;
+ Item mInput;
+ Item mOutput;
+ };
+
+ Binding();
+ Binding( const QString &name, const QString &type );
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void setType( const QString &type ) { mType = type; }
+ QString type() const { return mType; }
+
+ void setStyle( const QString &style ) { mStyle = style; }
+ QString style() const { return mStyle; }
+
+ void setTransport( const QString &transport ) { mTransport = transport; }
+ QString transport() const { return mTransport; }
+
+ void addOperation( const Operation &operation );
+ Operation operation( const QString &name ) const;
+ Operation::List operations() const;
+
+ private:
+ QString mName;
+ QString mType;
+ QString mStyle;
+ QString mTransport;
+ Operation::List mOperations;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/compiler.cpp b/kode/kwsdl/compiler.cpp
new file mode 100644
index 000000000..dbbe52b7e
--- /dev/null
+++ b/kode/kwsdl/compiler.cpp
@@ -0,0 +1,113 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qapplication.h>
+#include <qfile.h>
+
+#include <schema/fileprovider.h>
+
+#include "converter.h"
+#include "creator.h"
+
+#include "compiler.h"
+
+using namespace KWSDL;
+
+Compiler::Compiler()
+ : QObject( 0, "KWSDL::Compiler" )
+{
+}
+
+void Compiler::setWSDLUrl( const QString &wsdlUrl )
+{
+ mWSDLUrl = wsdlUrl;
+ mWSDLBaseUrl = mWSDLUrl.left( mWSDLUrl.findRev( '/' ) );
+
+ mParser.setSchemaBaseUrl( mWSDLBaseUrl );
+}
+
+void Compiler::setOutputDirectory( const QString &outputDirectory )
+{
+ mOutputDirectory = outputDirectory;
+
+ if ( !mOutputDirectory.endsWith( "/" ) )
+ mOutputDirectory.append( "/" );
+}
+
+void Compiler::setNameSpace( const QString &nameSpace )
+{
+ mNameSpace = nameSpace;
+}
+
+void Compiler::run()
+{
+ download();
+}
+
+void Compiler::download()
+{
+ Schema::FileProvider provider;
+
+ QString fileName;
+ if ( provider.get( mWSDLUrl, fileName ) ) {
+ QFile file( fileName );
+ if ( !file.open( IO_ReadOnly ) ) {
+ qDebug( "Unable to download schema file %s", mWSDLUrl.latin1() );
+ provider.cleanUp();
+ return;
+ }
+
+ QString errorMsg;
+ int errorLine, errorCol;
+ QDomDocument doc;
+ if ( !doc.setContent( &file, true, &errorMsg, &errorLine, &errorCol ) ) {
+ qDebug( "%s at (%d,%d)", errorMsg.latin1(), errorLine, errorCol );
+ return;
+ }
+
+ parse( doc.documentElement() );
+
+ provider.cleanUp();
+ }
+}
+
+void Compiler::parse( const QDomElement &element )
+{
+ mParser.parse( element );
+ create();
+}
+
+void Compiler::create()
+{
+ KWSDL::Converter converter;
+ converter.setWSDL( mParser.wsdl() );
+
+ converter.convert();
+
+ KWSDL::Creator creator;
+ creator.setOutputDirectory( mOutputDirectory );
+ creator.setNameSpace( mNameSpace );
+ creator.create( converter.classes() );
+
+ qApp->quit();
+}
+
+#include "compiler.moc"
diff --git a/kode/kwsdl/compiler.h b/kode/kwsdl/compiler.h
new file mode 100644
index 000000000..49626ba57
--- /dev/null
+++ b/kode/kwsdl/compiler.h
@@ -0,0 +1,62 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_COMPILER_H
+#define KWSDL_COMPILER_H
+
+#include <qdom.h>
+#include <qobject.h>
+
+#include "parser.h"
+
+namespace KWSDL {
+
+class Compiler : public QObject
+{
+ Q_OBJECT
+
+ public:
+ Compiler();
+
+ void setWSDLUrl( const QString &wsdlUrl );
+ void setOutputDirectory( const QString &outputDirectory );
+ void setNameSpace( const QString &nameSpace );
+
+ public slots:
+ void run();
+
+ private slots:
+ void download();
+ void parse( const QDomElement& );
+ void create();
+
+ private:
+ QString mWSDLUrl;
+ QString mOutputDirectory;
+ QString mNameSpace;
+
+ Parser mParser;
+ QString mWSDLBaseUrl;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/converter.cpp b/kode/kwsdl/converter.cpp
new file mode 100644
index 000000000..fc255d74e
--- /dev/null
+++ b/kode/kwsdl/converter.cpp
@@ -0,0 +1,998 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "converter.h"
+
+using namespace KWSDL;
+
+static QString capitalize( const QString &str )
+{
+ return str[ 0 ].upper() + str.mid( 1 );
+}
+
+static QString escapeEnum( const QString &str )
+{
+ QString enumStr = capitalize( str );
+
+ return enumStr.replace( "-", "_" );
+}
+
+Converter::Converter()
+{
+ mQObject = KODE::Class( "QObject" );
+}
+
+void Converter::setWSDL( const WSDL &wsdl )
+{
+ mWSDL = wsdl;
+ mTypeMapper.setTypes( wsdl.types() );
+}
+
+KODE::Class::List Converter::classes() const
+{
+ return mClasses;
+}
+
+void Converter::convert()
+{
+ createUtilClasses();
+ createTransportClass();
+
+ convertTypes( mWSDL.types() );
+
+ mClasses.append( mSerializer );
+
+ convertService( mWSDL.service() );
+}
+
+void Converter::convertTypes( const Schema::Types &types )
+{
+ Schema::SimpleType::List simpleTypes = types.simpleTypes();
+ Schema::SimpleType::List::ConstIterator simpleIt;
+ for ( simpleIt = simpleTypes.begin(); simpleIt != simpleTypes.end(); ++simpleIt )
+ convertSimpleType( &(*simpleIt) );
+
+ Schema::ComplexType::List complexTypes = types.complexTypes();
+ Schema::ComplexType::List::ConstIterator complexIt;
+ for ( complexIt = complexTypes.begin(); complexIt != complexTypes.end(); ++complexIt )
+ convertComplexType( &(*complexIt) );
+}
+
+void Converter::convertSimpleType( const Schema::SimpleType *type )
+{
+ KODE::Class newClass( type->name() );
+ newClass.addInclude( "serializer.h" );
+
+ KODE::Code ctorCode, dtorCode;
+
+ if ( !type->documentation().isEmpty() )
+ newClass.setDocs( type->documentation().simplifyWhiteSpace() );
+
+ if ( type->subType() == Schema::SimpleType::TypeRestriction ) {
+ /**
+ Use setter and getter method for enums as well.
+ */
+ if ( type->facetType() & Schema::SimpleType::ENUM ) {
+ QStringList enums = type->facetEnums();
+ for ( uint i = 0; i < enums.count(); ++i )
+ enums[ i ] = escapeEnum( enums[ i ] );
+
+ newClass.addEnum( KODE::Enum( "Type", enums ) );
+
+ // member variables
+ KODE::MemberVariable variable( "type", "Type" );
+ newClass.addMemberVariable( variable );
+
+ // setter method
+ KODE::Function setter( "setType", "void" );
+ setter.addArgument( "Type type" );
+ setter.setBody( variable.name() + " = type;" );
+
+ // getter method
+ KODE::Function getter( "type", capitalize( newClass.name() ) + "::Type" );
+ getter.setBody( " return " + variable.name() + ";" );
+ getter.setConst( true );
+
+ newClass.addFunction( setter );
+ newClass.addFunction( getter );
+ }
+
+ /**
+ A class can't derive from basic types (e.g. int or unsigned char), so
+ we add setter and getter methods to set the value of this class.
+ */
+ if ( type->baseType() != Schema::XSDType::ANYTYPE &&
+ type->baseType() != Schema::XSDType::INVALID &&
+ !(type->facetType() & Schema::SimpleType::ENUM) ) {
+
+ const QString baseName = type->baseTypeName();
+ const QString typeName = mTypeMapper.type( baseName );
+
+ // include header
+ QMap<QString, QString> headerDec = mTypeMapper.headerDec( baseName );
+ QMap<QString, QString>::ConstIterator it;
+ for ( it = headerDec.begin(); it != headerDec.end(); ++it ) {
+ if ( !it.key().isEmpty() )
+ newClass.addInclude( it.key(), it.data() );
+
+ if ( it.data().isEmpty() )
+ newClass.addHeaderInclude( it.key() );
+ }
+
+ // member variables
+ KODE::MemberVariable variable( "value", typeName + "*" );
+ newClass.addMemberVariable( variable );
+
+ ctorCode += variable.name() + " = 0;";
+ dtorCode += "delete " + variable.name() + ";";
+ dtorCode += variable.name() + " = 0;";
+
+ // setter method
+ KODE::Function setter( "setValue", "void" );
+ setter.addArgument( mTypeMapper.argument( "value", baseName ) );
+ setter.setBody( variable.name() + " = value;" );
+
+ // getter method
+ KODE::Function getter( "value", typeName + "*" );
+ getter.setBody( " return " + variable.name() + ";" );
+ getter.setConst( true );
+
+ newClass.addFunction( setter );
+ newClass.addFunction( getter );
+ }
+ } else if ( type->subType() == Schema::SimpleType::TypeList ) {
+ newClass.addHeaderInclude( "qptrlist.h" );
+ const QString baseName = type->listTypeName();
+ const QString typeName = mTypeMapper.type( baseName );
+
+ // include header
+ QMap<QString, QString> headerDec = mTypeMapper.headerDec( baseName );
+ QMap<QString, QString>::ConstIterator it;
+ for ( it = headerDec.begin(); it != headerDec.end(); ++it ) {
+ if ( !it.key().isEmpty() )
+ newClass.addInclude( it.key(), it.data() );
+
+ if ( it.data().isEmpty() )
+ newClass.addHeaderInclude( it.key() );
+ }
+
+ // member variables
+ KODE::MemberVariable variable( "entries", "QPtrList<" + typeName + ">*" );
+ newClass.addMemberVariable( variable );
+
+ ctorCode += variable.name() + " = 0;";
+ dtorCode += "delete " + variable.name() + ";";
+ dtorCode += variable.name() + " = 0;";
+
+ // setter method
+ KODE::Function setter( "setEntries", "void" );
+ setter.addArgument( mTypeMapper.argument( "entries", baseName, true ) );
+ setter.setBody( variable.name() + " = entries;" );
+
+ // getter method
+ KODE::Function getter( "entries", "QPtrList<" + typeName + ">*" );
+ getter.setBody( " return " + variable.name() + ";" );
+ getter.setConst( true );
+
+ newClass.addFunction( setter );
+ newClass.addFunction( getter );
+ }
+
+ createSimpleTypeSerializer( type );
+
+ KODE::Function ctor( capitalize( newClass.name() ) );
+ KODE::Function dtor( "~" + capitalize( newClass.name() ) );
+
+ ctor.setBody( ctorCode );
+ dtor.setBody( dtorCode );
+
+ newClass.addFunction( ctor );
+ newClass.addFunction( dtor );
+
+ mClasses.append( newClass );
+}
+
+void Converter::createSimpleTypeSerializer( const Schema::SimpleType *type )
+{
+ const QString typeName = mTypeMapper.type( type );
+ const QString baseType = mTypeMapper.type( type->baseTypeName() );
+
+ KODE::Function marshal( "marshal", "void" );
+ marshal.setStatic( true );
+ marshal.addArgument( "QDomDocument &doc" );
+ marshal.addArgument( "QDomElement &parent" );
+ marshal.addArgument( "const QString &name" );
+ marshal.addArgument( "const " + typeName + "* value" );
+
+ KODE::Function demarshal( "demarshal", "void" );
+ demarshal.setStatic( true );
+ demarshal.addArgument( "const QDomElement &parent" );
+ demarshal.addArgument( typeName + "* value" );
+
+ KODE::Code marshalCode, demarshalCode, code;
+
+ // include header
+ QMap<QString, QString> headerDec = mTypeMapper.headerDec( type->name() );
+ QMap<QString, QString>::ConstIterator it;
+ for ( it = headerDec.begin(); it != headerDec.end(); ++it ) {
+ if ( !it.key().isEmpty() )
+ mSerializer.addInclude( it.key(), it.data() );
+
+ if ( it.data().isEmpty() )
+ mSerializer.addHeaderInclude( it.key() );
+ }
+
+ if ( type->subType() == Schema::SimpleType::TypeRestriction ) {
+ // is an enumeration
+ if ( type->facetType() & Schema::SimpleType::ENUM ) {
+ QStringList enums = type->facetEnums();
+ QStringList escapedEnums;
+ for ( uint i = 0; i < enums.count(); ++i )
+ escapedEnums.append( escapeEnum( enums[ i ] ) );
+
+ // marshal value
+ KODE::Function marshalValue( "marshalValue", "QString" );
+ marshalValue.setStatic( true );
+ marshalValue.addArgument( "const " + typeName + "* value" );
+ code += "switch ( value->type() ) {";
+ code.indent();
+ for ( uint i = 0; i < enums.count(); ++i ) {
+ code += "case " + typeName + "::" + escapedEnums[ i ] + ":";
+ code.indent();
+ code += "return \"" + enums[ i ] + "\";";
+ code += "break;";
+ code.unindent();
+ }
+ code += "default:";
+ code.indent();
+ code += "qDebug( \"Unknown enum %d passed.\", value->type() );";
+ code += "break;";
+ code.unindent();
+ code.unindent();
+ code += "}";
+ code.newLine();
+ code += "return QString();";
+ marshalValue.setBody( code );
+
+ // marshal
+ marshalCode += "QDomElement root = doc.createElement( name );";
+ marshalCode += "root.setAttribute( \"xsi:type\", \"ns1:" + type->name() + "\" );";
+ marshalCode += "parent.appendChild( root );";
+ marshalCode += "root.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );";
+
+ // demarshal value
+ KODE::Function demarshalValue( "demarshalValue", "void" );
+ demarshalValue.setStatic( true );
+ demarshalValue.addArgument( "const QString &str" );
+ demarshalValue.addArgument( typeName + "* value" );
+ code.clear();
+ for ( uint i = 0; i < enums.count(); ++i ) {
+ code += "if ( str == \"" + enums[ i ] + "\" )";
+ code.indent();
+ code += "value->setType( " + typeName + "::" + escapedEnums[ i ] + " );";
+ code.unindent();
+ code.newLine();
+ }
+ demarshalValue.setBody( code );
+
+ // demarshal
+ demarshalCode += "Serializer::demarshalValue( parent.text(), value );";
+
+ mSerializer.addFunction( marshalValue );
+ mSerializer.addFunction( demarshalValue );
+ } else if ( type->baseType() != Schema::XSDType::INVALID ) {
+ marshalCode += "if ( value->value() ) {";
+ marshalCode.indent();
+ marshalCode += "Serializer::marshal( doc, parent, name, value->value() );";
+ marshalCode.unindent();
+ marshalCode += "}";
+
+ demarshalCode += "const QString text = parent.text();";
+ demarshalCode.newLine();
+ demarshalCode += "if ( !text.isEmpty() ) {";
+ demarshalCode.indent();
+ demarshalCode += baseType + "* data = new " + baseType + ";";
+ demarshalCode += "Serializer::demarshal( parent, value );";
+ demarshalCode += "value->setValue( data );";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+
+ KODE::Function marshalValue( "marshalValue", "QString" );
+ marshalValue.setStatic( true );
+ marshalValue.addArgument( "const " + typeName + "* value" );
+ marshalValue.setBody( "return Serializer::marshalValue( value->value() );" );
+
+ mSerializer.addFunction( marshalValue );
+
+ KODE::Function demarshalValue( "demarshalValue", "void" );
+ demarshalValue.setStatic( true );
+ demarshalValue.addArgument( "const QString &str" );
+ demarshalValue.addArgument( typeName + "* value" );
+ KODE::Code code;
+ code += baseType + "* data = new " + baseType + ";";
+ code += "Serializer::demarshalValue( str, data );";
+ code += "value->setValue( data );";
+ demarshalValue.setBody( code );
+
+ mSerializer.addFunction( demarshalValue );
+ }
+ } else if ( type->subType() == Schema::SimpleType::TypeList ) {
+ const QString listType = mTypeMapper.type( type->listTypeName() );
+
+ mSerializer.addInclude( "qstringlist.h" );
+
+ marshalCode += "if ( value->entries() ) {";
+ marshalCode.indent();
+ marshalCode += "QStringList list;";
+ marshalCode += "QPtrList<" + listType + ">* entries = value->entries();";
+ marshalCode += "QPtrListIterator<" + listType + "> it( *entries );";
+ marshalCode += "while ( it.current() != 0 ) {";
+ marshalCode.indent();
+ marshalCode += "list.append( Serializer::marshalValue( it.current() ) );";
+ marshalCode += "++it;";
+ marshalCode.unindent();
+ marshalCode += "}";
+ marshalCode.newLine();
+ marshalCode += "QDomElement element = doc.createElement( name );";
+ marshalCode += "parent.appendChild( element );";
+ marshalCode += "element.appendChild( doc.createTextNode( list.join( \" \" ) ) );";
+ marshalCode.unindent();
+ marshalCode += "}";
+
+ demarshalCode += "const QStringList list = QStringList::split( \" \", parent.text(), false );";
+ demarshalCode += "if ( !list.isEmpty() ) {";
+ demarshalCode.indent();
+ demarshalCode += "QPtrList<" + listType + ">* entries = new QPtrList<" + listType + ">;";
+ demarshalCode += "entries->setAutoDelete( true );";
+ demarshalCode += "QStringList::ConstIterator it;";
+ demarshalCode += "for ( it = list.begin(); it != list.end(); ++it ) {";
+ demarshalCode.indent();
+ demarshalCode += listType + " *entry = new " + listType + ";";
+ demarshalCode += "Serializer::demarshalValue( *it, entry );";
+ demarshalCode += "entries->append( entry );";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+ demarshalCode.newLine();
+ demarshalCode += "value->setEntries( entries );";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+ }
+
+ marshal.setBody( marshalCode );
+ mSerializer.addFunction( marshal );
+
+ demarshal.setBody( demarshalCode );
+ mSerializer.addFunction( demarshal );
+}
+
+void Converter::convertComplexType( const Schema::ComplexType *type )
+{
+ KODE::Class newClass( type->name() );
+ newClass.addInclude( "serializer.h" );
+
+ KODE::Code ctorCode, dtorCode;
+
+ if ( type->baseType() != Schema::XSDType::ANYTYPE && !type->isArray() ) {
+ QString baseName = mTypeMapper.type( type->baseTypeName() );
+ newClass.addBaseClass( KODE::Class( baseName ) );
+ newClass.addHeaderIncludes( mTypeMapper.header( type->baseTypeName() ) );
+ }
+
+ if ( !type->documentation().isEmpty() )
+ newClass.setDocs( type->documentation().simplifyWhiteSpace() );
+
+ // elements
+ Schema::Element::List elements = type->elements();
+ Schema::Element::List::ConstIterator elemIt;
+ for ( elemIt = elements.begin(); elemIt != elements.end(); ++elemIt ) {
+ QString typeName = mTypeMapper.type( &*elemIt );
+
+ if ( (*elemIt).maxOccurs() > 1 )
+ typeName = "QPtrList<" + typeName + ">";
+
+ // member variables
+ KODE::MemberVariable variable( (*elemIt).name(), typeName + "*" );
+ newClass.addMemberVariable( variable );
+
+ ctorCode += variable.name() + " = 0;";
+ dtorCode += "delete " + variable.name() + ";";
+ dtorCode += variable.name() + " = 0;";
+
+ QString upperName = (*elemIt).name();
+ QString lowerName = (*elemIt).name();
+ upperName[ 0 ] = upperName[ 0 ].upper();
+ lowerName[ 0 ] = lowerName[ 0 ].lower();
+
+ // setter method
+ KODE::Function setter( "set" + upperName, "void" );
+ setter.addArgument( mTypeMapper.argument( mNameMapper.escape( lowerName ), &*elemIt ) );
+ setter.setBody( variable.name() + " = " + mNameMapper.escape( lowerName ) + ";" );
+
+ // getter method
+ KODE::Function getter( mNameMapper.escape( lowerName ), typeName + "*" );
+ getter.setBody( " return " + variable.name() + ";" );
+ getter.setConst( true );
+
+ newClass.addFunction( setter );
+ newClass.addFunction( getter );
+
+ // include header
+ QMap<QString, QString> headerDec = mTypeMapper.headerDec( &*elemIt);
+ QMap<QString, QString>::ConstIterator it;
+ for ( it = headerDec.begin(); it != headerDec.end(); ++it ) {
+ if ( !it.key().isEmpty() )
+ newClass.addInclude( it.key(), it.data() );
+
+ if ( it.data().isEmpty() )
+ newClass.addHeaderInclude( it.key() );
+ }
+ }
+
+ // attributes
+ Schema::Attribute::List attributes = type->attributes();
+ Schema::Attribute::List::ConstIterator attrIt;
+ for ( attrIt = attributes.begin(); attrIt != attributes.end(); ++attrIt ) {
+ const QString typeName = mTypeMapper.type( &*attrIt );
+
+ // member variables
+ KODE::MemberVariable variable( (*attrIt).name(), typeName + "*" );
+ newClass.addMemberVariable( variable );
+
+ ctorCode += variable.name() + " = 0;";
+ dtorCode += "delete " + variable.name() + ";";
+ dtorCode += variable.name() + " = 0;";
+
+ QString upperName = (*attrIt).name();
+ QString lowerName = (*attrIt).name();
+ upperName[ 0 ] = upperName[ 0 ].upper();
+ lowerName[ 0 ] = lowerName[ 0 ].lower();
+
+ // setter method
+ KODE::Function setter( "set" + upperName, "void" );
+ setter.addArgument( mTypeMapper.argument( mNameMapper.escape( lowerName ), &*attrIt ) );
+ setter.setBody( variable.name() + " = " + mNameMapper.escape( lowerName ) + ";" );
+
+ // getter method
+ KODE::Function getter( mNameMapper.escape( lowerName ), typeName + "*" );
+ getter.setBody( " return " + variable.name() + ";" );
+ getter.setConst( true );
+
+ newClass.addFunction( setter );
+ newClass.addFunction( getter );
+
+ // include header
+ QMap<QString, QString> headerDec = mTypeMapper.headerDec( &*attrIt);
+ QMap<QString, QString>::ConstIterator it;
+ for ( it = headerDec.begin(); it != headerDec.end(); ++it ) {
+ if ( !it.key().isEmpty() )
+ newClass.addInclude( it.key(), it.data() );
+
+ if ( it.data().isEmpty() )
+ newClass.addHeaderInclude( it.key() );
+ }
+ }
+
+ createComplexTypeSerializer( type );
+
+ KODE::Function ctor( capitalize( newClass.name() ) );
+ KODE::Function dtor( "~" + capitalize( newClass.name() ) );
+
+ ctor.setBody( ctorCode );
+ dtor.setBody( dtorCode );
+
+ newClass.addFunction( ctor );
+ newClass.addFunction( dtor );
+
+ mClasses.append( newClass );
+}
+
+void Converter::createComplexTypeSerializer( const Schema::ComplexType *type )
+{
+ const QString typeName = mTypeMapper.type( type );
+
+ KODE::Function marshal( "marshal", "void" );
+ marshal.setStatic( true );
+ marshal.addArgument( "QDomDocument &doc" );
+ marshal.addArgument( "QDomElement &parent" );
+ marshal.addArgument( "const QString &name" );
+ marshal.addArgument( "const " + typeName + "* value" );
+
+ KODE::Function demarshal( "demarshal", "void" );
+ demarshal.setStatic( true );
+ demarshal.addArgument( "const QDomElement &parent" );
+ demarshal.addArgument( typeName + "* value" );
+
+ KODE::Code marshalCode, demarshalCode, demarshalFinalCode;
+
+ // include header
+ QMap<QString, QString> headerDec = mTypeMapper.headerDec( type->name() );
+ QMap<QString, QString>::ConstIterator it;
+ for ( it = headerDec.begin(); it != headerDec.end(); ++it ) {
+ if ( !it.key().isEmpty() )
+ mSerializer.addInclude( it.key(), it.data() );
+
+ if ( it.data().isEmpty() )
+ mSerializer.addHeaderInclude( it.key() );
+ }
+
+ marshalCode += "QDomElement root = doc.createElement( name );";
+ marshalCode += "root.setAttribute( \"xsi:type\", \"ns1:" + typeName + "\" );";
+ marshalCode += "parent.appendChild( root );";
+
+ demarshalCode += "QDomNode node = parent.firstChild();";
+ demarshalCode += "while ( !node.isNull() ) {";
+ demarshalCode.indent();
+ demarshalCode += "QDomElement element = node.toElement();";
+ demarshalCode += "if ( !element.isNull() ) {";
+ demarshalCode.indent();
+
+ // elements
+ Schema::Element::List elements = type->elements();
+ Schema::Element::List::ConstIterator elemIt;
+ for ( elemIt = elements.begin(); elemIt != elements.end(); ++elemIt ) {
+ const QString typeName = mTypeMapper.type( &*elemIt );
+
+ QString upperName = (*elemIt).name();
+ QString lowerName = (*elemIt).name();
+ upperName[ 0 ] = upperName[ 0 ].upper();
+ lowerName[ 0 ] = lowerName[ 0 ].lower();
+
+ KODE::Function setter( "set" + upperName, "void" );
+ KODE::Function getter( mNameMapper.escape( lowerName ), typeName + "*" );
+
+ if ( (*elemIt).maxOccurs() > 1 ) {
+ marshalCode += "if ( value->" + mNameMapper.escape( lowerName ) + "() ) {";
+ marshalCode.indent();
+ marshalCode += "const QPtrList<" + typeName + ">* list = value->" + mNameMapper.escape( lowerName ) + "();";
+ marshalCode.newLine();
+ marshalCode += "QDomElement element = doc.createElement( name );";
+ // no idea about the namespaces here...
+ marshalCode += "element.setAttribute( \"xmlns:ns1\", \"http://schemas.xmlsoap.org/soap/encoding/\" );";
+ marshalCode += "element.setAttribute( \"xsi:type\", \"ns1:Array\" );";
+ marshalCode += "element.setAttribute( \"ns1:arrayType\", \"ns1:" + typeName + "[\" + QString::number( list->count() ) + \"]\" );";
+ marshalCode += "parent.appendChild( element );";
+ marshalCode.newLine();
+ marshalCode += "QPtrListIterator<" + typeName + "> it( *list );";
+ marshalCode += "while ( it.current() != 0 ) {";
+ marshalCode.indent();
+ marshalCode += "Serializer::marshal( doc, element, \"item\", it.current() );";
+ marshalCode += "++it;";
+ marshalCode.unindent();
+ marshalCode += "}";
+ marshalCode.unindent();
+ marshalCode += "}";
+
+ const QString listName = mNameMapper.escape( lowerName ) + "List";
+ // TODO: prepend the code somehow
+ KODE::Code code;
+ code += "QPtrList<" + typeName + ">* " + listName + " = new QPtrList<" + typeName + ">();";
+ code += listName + "->setAutoDelete( true );";
+ code += demarshalCode;
+ demarshalCode = code;
+ demarshalCode += "if ( element.tagName() == \"item\" ) {";
+ demarshalCode.indent();
+ demarshalCode += typeName + " *item = new " + typeName + ";";
+ demarshalCode += "Serializer::demarshal( element, item );";
+ demarshalCode += listName + "->append( item );";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+
+ demarshalFinalCode += "value->" + setter.name() + "( " + listName + " );";
+ } else {
+ marshalCode += "if ( value->" + getter.name() + "() ) {";
+ marshalCode.indent();
+ marshalCode += "Serializer::marshal( doc, root, \"" + (*elemIt).name() + "\", value->" + getter.name() + "() );";
+ marshalCode.unindent();
+ marshalCode += "}";
+
+ demarshalCode += "if ( element.tagName() == \"" + (*elemIt).name() + "\" ) {";
+ demarshalCode.indent();
+ demarshalCode += typeName + "* item = new " + typeName + ";";
+ demarshalCode += "Serializer::demarshal( element, item );";
+ demarshalCode += "value->" + setter.name() + "( item );";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+ }
+ }
+
+ // attributes
+ Schema::Attribute::List attributes = type->attributes();
+ Schema::Attribute::List::ConstIterator attrIt;
+ for ( attrIt = attributes.begin(); attrIt != attributes.end(); ++attrIt ) {
+ const QString typeName = mTypeMapper.type( &*attrIt );
+
+ QString upperName = (*attrIt).name();
+ QString lowerName = (*attrIt).name();
+ upperName[ 0 ] = upperName[ 0 ].upper();
+ lowerName[ 0 ] = lowerName[ 0 ].lower();
+
+ KODE::Function setter( "set" + upperName, "void" );
+ KODE::Function getter( mNameMapper.escape( lowerName ), typeName + "*" );
+
+ marshalCode += "if ( value->" + mNameMapper.escape( lowerName ) + "() )";
+ marshalCode.indent();
+ marshalCode += "parent.setAttribute( \"" + (*attrIt).name() + "\","
+ "Serializer::marshalValue( value->" + mNameMapper.escape( lowerName ) + "() ) );";
+ marshalCode.newLine();
+
+ demarshalCode += "if ( element.hasAttribute( \"" + (*attrIt).name() + "\" ) ) {";
+ demarshalCode.indent();
+ demarshalCode += typeName + "* item = new " + typeName + ";";
+ demarshalCode += "Serializer::demarshalValue( element.attribute( \"" + (*attrIt).name() + "\" ), item );";
+ demarshalCode += "value->" + setter.name() + "( item );";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+ }
+
+ demarshalCode.unindent();
+ demarshalCode += "}";
+ demarshalCode += "node = node.nextSibling();";
+ demarshalCode.unindent();
+ demarshalCode += "}";
+ demarshalCode.newLine();
+ demarshalCode += demarshalFinalCode;
+
+ marshal.setBody( marshalCode );
+ mSerializer.addFunction( marshal );
+
+ demarshal.setBody( demarshalCode );
+ mSerializer.addFunction( demarshal );
+}
+
+void Converter::convertService( const Service &service )
+{
+ KODE::Class newClass( service.name() );
+ newClass.addBaseClass( mQObject );
+ newClass.addHeaderInclude( "qobject.h" );
+ newClass.addHeaderInclude( "qstring.h" );
+ newClass.addHeaderInclude( "transport.h" );
+
+ newClass.addInclude( "serializer.h" );
+
+ KODE::Function ctor( service.name() );
+ KODE::Function dtor( "~" + service.name() );
+ KODE::Code ctorCode, dtorCode;
+
+ const Service::Port::List servicePorts = service.ports();
+ Service::Port::List::ConstIterator it;
+ for ( it = servicePorts.begin(); it != servicePorts.end(); ++it ) {
+ Binding binding = mWSDL.findBinding( (*it).mBinding );
+
+ Port port = mWSDL.findPort( binding.type() );
+ const Port::Operation::List operations = port.operations();
+ Port::Operation::List::ConstIterator opIt;
+ for ( opIt = operations.begin(); opIt != operations.end(); ++opIt ) {
+ Message inputMessage = mWSDL.findMessage( (*opIt).input() );
+ Message outputMessage = mWSDL.findMessage( (*opIt).output() );
+
+ convertInputMessage( port, inputMessage, newClass );
+ convertOutputMessage( port, outputMessage, newClass );
+
+ KODE::MemberVariable transport( inputMessage.name() + "Transport", "Transport" );
+ ctorCode += transport.name() + " = new Transport( \"" + (*it).mLocation + "\" );";
+
+ ctorCode += "connect( " + transport.name() + ", SIGNAL( result( const QString& ) ),";
+ ctorCode.indent();
+ ctorCode += "this, SLOT( " + outputMessage.name() + "Slot( const QString& ) ) );";
+ ctorCode.unindent();
+
+ dtorCode += "delete " + transport.name() + ";";
+ dtorCode += transport.name() + " = 0;";
+ }
+ }
+
+ ctor.setBody( ctorCode );
+ newClass.addFunction( ctor );
+
+ dtor.setBody( dtorCode );
+ newClass.addFunction( dtor );
+
+ mClasses.append( newClass );
+}
+
+void Converter::convertInputMessage( const Port &port, const Message &message, KODE::Class &newClass )
+{
+ KODE::MemberVariable transport( message.name() + "Transport", "Transport*" );
+ newClass.addMemberVariable( transport );
+
+ // call
+ QString messageName = message.name();
+ messageName[ 0 ] = messageName[ 0 ].lower();
+ KODE::Function callFunc( mNameMapper.escape( messageName ), "void", KODE::Function::Public );
+
+ const Message::Part::List parts = message.parts();
+ Message::Part::List::ConstIterator it;
+ for ( it = parts.begin(); it != parts.end(); ++it ) {
+ newClass.addHeaderIncludes( mTypeMapper.header( (*it).type() ) );
+ QString lowerName = (*it).name();
+ lowerName[ 0 ] = lowerName[ 0 ].lower();
+ callFunc.addArgument( mTypeMapper.argument( mNameMapper.escape( lowerName ), (*it).type() ) );
+ }
+
+ KODE::Code code;
+ code += "QDomDocument doc( \"kwsdl\" );";
+ code += "doc.appendChild( doc.createProcessingInstruction( \"xml\", \"version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"\" ) );";
+ code += "QDomElement env = doc.createElement( \"SOAP-ENV:Envelope\" );";
+ code += "env.setAttribute( \"xmlns:SOAP-ENV\", \"http://schemas.xmlsoap.org/soap/envelope/\" );";
+ code += "env.setAttribute( \"xmlns:xsi\", \"http://www.w3.org/1999/XMLSchema-instance\" );";
+ code += "env.setAttribute( \"xmlns:xsd\", \"http://www.w3.org/1999/XMLSchema\" );";
+ code += "doc.appendChild( env );";
+ code += "QDomElement body = doc.createElement( \"SOAP-ENV:Body\" );";
+ code += "env.appendChild( body );";
+ code += "QDomElement method = doc.createElement( \"ns1:" + message.name() + "\" );";
+ QString nameSpace = mWSDL.findBindingOperation( port.name(), message.name() ).input().nameSpace();
+ code += "method.setAttribute( \"xmlns:ns1\", \"" + nameSpace + "\" );";
+ code += "method.setAttribute( \"SOAP-ENV:encodingStyle\", \"http://schemas.xmlsoap.org/soap/encoding/\" );";
+ code += "body.appendChild( method );";
+ code.newLine();
+
+ for ( it = parts.begin(); it != parts.end(); ++it ) {
+ QString lowerName = (*it).name();
+ lowerName[ 0 ] = lowerName[ 0 ].lower();
+ code += "Serializer::marshal( doc, method, \"" + (*it).name() + "\", " + mNameMapper.escape( lowerName ) + " );";
+ code += "delete " + mNameMapper.escape( lowerName ) + ";";
+ }
+
+ code += "qDebug( \"%s\", doc.toString().latin1() );";
+ code += transport.name() + "->query( doc.toString() );";
+ callFunc.setBody( code );
+
+ newClass.addFunction( callFunc );
+}
+
+void Converter::convertOutputMessage( const Port&, const Message &message, KODE::Class &newClass )
+{
+ Message::Part part = message.parts().first();
+
+ // signal
+ QString messageName = message.name();
+ messageName[ 0 ] = messageName[ 0 ].lower();
+ KODE::Function respSignal( messageName, "void", KODE::Function::Signal );
+
+ /**
+ If one output message is used by two input messages, don't define
+ it twice.
+ */
+ if ( newClass.hasFunction( respSignal.name() ) )
+ return;
+
+ const Message::Part::List parts = message.parts();
+ Message::Part::List::ConstIterator it;
+ for ( it = parts.begin(); it != parts.end(); ++it ) {
+ QStringList headers = mTypeMapper.header( (*it).type() );
+ for ( uint i = 0; i < headers.count(); ++i )
+ if ( !headers[ i ].isEmpty() )
+ newClass.addHeaderInclude( headers[ i ] );
+
+ respSignal.addArgument( mTypeMapper.argument( "value", (*it).type() ) );
+ }
+
+ newClass.addFunction( respSignal );
+
+ // slot
+ KODE::Function respSlot( messageName + "Slot", "void", KODE::Function::Slot | KODE::Function::Private );
+ respSlot.addArgument( "const QString &xml" );
+
+ KODE::Code code;
+ code += "QDomDocument doc;";
+ code += "QString errorMsg;";
+ code += "int column, row;";
+ code.newLine();
+ code += "qDebug( \"%s\", xml.latin1() );";
+ code.newLine();
+ code += "if ( !doc.setContent( xml, true, &errorMsg, &row, &column ) ) {";
+ code.indent();
+ code += "qDebug( \"Unable to parse xml: %s (%d:%d)\", errorMsg.latin1(), row, column );";
+ code += "return;";
+ code.unindent();
+ code += "}";
+ code.newLine();
+ code += mTypeMapper.type( part.type() ) + "* value = new " + mTypeMapper.type( part.type() ) + ";";
+ code += "QDomElement envelope = doc.documentElement();";
+ code += "QDomElement body = envelope.firstChild().toElement();";
+ code += "QDomElement method = body.firstChild().toElement();";
+ code += "Serializer::demarshal( method.firstChild().toElement(), value );";
+ code.newLine();
+ code += "emit " + respSignal.name() + "( value );";
+ respSlot.setBody( code );
+
+ newClass.addFunction( respSlot );
+}
+
+void Converter::createUtilClasses()
+{
+ mSerializer = KODE::Class( "Serializer" );
+ mSerializer.addHeaderInclude( "qcstring.h" );
+ mSerializer.addHeaderInclude( "qdom.h" );
+ mSerializer.addHeaderInclude( "qdatetime.h" );
+ mSerializer.addHeaderInclude( "qstring.h" );
+ mSerializer.addHeaderInclude( "qptrlist.h" );
+ mSerializer.addInclude( "kmdcodec.h" );
+
+ typedef struct {
+ QString type;
+ QString xsdType;
+ QString marshalCode;
+ QString demarshalCode;
+ } TypeEntry;
+
+ /**
+ I know the following code looks a bit ugly, but it saves us a lot
+ of typing and is easier to maintain at the end ;)
+ */
+ TypeEntry types[] = {
+ { "QString", "xsd:string", "*value", "str" },
+ { "bool", "xsd:boolean", "(*value ? \"true\" : \"false\")", "(str.lower() == \"true\" ? true : false)" },
+ { "float", "xsd:TODO", "QString::number( *value )", "str.toFloat()" },
+ { "int", "xsd:int", "QString::number( *value )", "str.toInt()" },
+ { "unsigned int", "xsd:unsignedByte", "QString::number( *value )", "str.toUInt()" },
+ { "double", "xsd:double", "QString::number( *value )", "str.toDouble()" },
+ { "char", "xsd:byte", "QString( QChar( *value ) )", "str[ 0 ].latin1()" },
+ { "unsigned char", "xsd:unsignedByte", "QString( QChar( *value ) )", "str[ 0 ].latin1()" },
+ { "short", "xsd:short", "QString::number( *value )", "str.toShort()" },
+ { "QByteArray", "xsd:base64Binary", "QString::fromUtf8( KCodecs::base64Encode( *value ) )", "KCodecs::base64Decode( str.utf8() )" },
+ { "QDateTime", "xsd:dateTime", "value->toString( Qt::ISODate )", "QDateTime::fromString( str, Qt::ISODate )" },
+ { "QDate", "xsd:date", "value->toString( Qt::ISODate )", "QDate::fromString( str, Qt::ISODate )" }
+ };
+
+ for ( uint i = 0; i < sizeof( types ) / sizeof( TypeEntry ); ++i ) {
+ KODE::Function marshal, demarshal;
+ KODE::Code code;
+
+ TypeEntry entry = types[ i ];
+
+ marshal = KODE::Function( "marshalValue", "QString" );
+ marshal.setStatic( true );
+ marshal.addArgument( "const " + entry.type + "* value" );
+
+ code.clear();
+ marshal.setBody( "return " + entry.marshalCode + ";" );
+
+ mSerializer.addFunction( marshal );
+
+ demarshal = KODE::Function( "demarshalValue", "void" );
+ demarshal.setStatic( true );
+ demarshal.addArgument( "const QString &str" );
+ demarshal.addArgument( entry.type + " *value" );
+ demarshal.setBody( "*value = " + entry.demarshalCode + ";" );
+
+ mSerializer.addFunction( demarshal );
+
+ marshal = KODE::Function( "marshal", "void" );
+ marshal.setStatic( true );
+ marshal.addArgument( "QDomDocument &doc" );
+ marshal.addArgument( "QDomElement &parent" );
+ marshal.addArgument( "const QString &name" );
+ marshal.addArgument( "const " + entry.type + "* value" );
+
+ code.clear();
+ code += "QDomElement element = doc.createElement( name );";
+ code += "element.setAttribute( \"xsi:type\", \"" + entry.xsdType + "\" );";
+ code += "element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );";
+ code += "parent.appendChild( element );";
+ marshal.setBody( code );
+
+ mSerializer.addFunction( marshal );
+
+ demarshal = KODE::Function( "demarshal", "void" );
+ demarshal.setStatic( true );
+ demarshal.addArgument( "const QDomElement &element" );
+ demarshal.addArgument( entry.type + "* value" );
+ demarshal.setBody( "Serializer::demarshalValue( element.text(), value );" );
+
+ mSerializer.addFunction( demarshal );
+ }
+}
+
+void Converter::createTransportClass()
+{
+ KODE::Class transport( "Transport" );
+ transport.addBaseClass( mQObject );
+ transport.addHeaderInclude( "qobject.h" );
+ transport.addHeaderInclude( "kio/job.h" );
+
+ transport.addInclude( "kdebug.h" );
+
+ KODE::MemberVariable url( "url", "QString" );
+ transport.addMemberVariable( url );
+
+ KODE::MemberVariable slotDataVar( "data", "QByteArray" );
+ transport.addMemberVariable( slotDataVar );
+
+ // ctor
+ KODE::Function ctor( "Transport" );
+ ctor.addArgument( "const QString &url" );
+ ctor.setBody( url.name() + " = url;" );
+
+ transport.addFunction( ctor );
+
+ // query
+ KODE::Function query( "query", "void" );
+ query.addArgument( "const QString &xml" );
+
+ KODE::Code queryCode;
+ queryCode += slotDataVar.name() + ".truncate( 0 );";
+ queryCode.newLine();
+ queryCode += "QByteArray postData;";
+ queryCode += "QDataStream stream( postData, IO_WriteOnly );";
+ queryCode += "stream.writeRawBytes( xml.utf8(), xml.utf8().length() );";
+ queryCode.newLine();
+ queryCode += "KIO::TransferJob* job = KIO::http_post( KURL( " + url.name() + " ), postData, false );";
+ queryCode += "if ( !job ) {";
+ queryCode.indent();
+ queryCode += "kdWarning() << \"Unable to create KIO job for \" << " + url.name() + " << endl;";
+ queryCode += "return;";
+ queryCode.unindent();
+ queryCode += "}";
+ queryCode.newLine();
+ queryCode += "job->addMetaData( \"UserAgent\", \"KWSDL\" );";
+ queryCode += "job->addMetaData( \"content-type\", \"Content-Type: text/xml; charset=utf-8\" );";
+ queryCode.newLine();
+ queryCode += "connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) );";
+ queryCode += "connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) );";
+
+ query.setBody( queryCode );
+
+ transport.addFunction( query );
+
+ // signal
+ KODE::Function result( "result", "void", KODE::Function::Signal );
+ result.addArgument( "const QString &xml" );
+
+ transport.addFunction( result );
+
+ // data slot
+ KODE::Function slotData( "slotData", "void", KODE::Function::Private | KODE::Function::Slot );
+
+ slotData.addArgument( "KIO::Job*" );
+ slotData.addArgument( "const QByteArray &data" );
+
+ KODE::Code slotDataCode;
+ slotDataCode += "unsigned int oldSize = " + slotDataVar.name() + ".size();";
+ slotDataCode += slotDataVar.name() + ".resize( oldSize + data.size() );";
+ slotDataCode += "memcpy( " + slotDataVar.name() + ".data() + oldSize, data.data(), data.size() );";
+
+ slotData.setBody( slotDataCode );
+
+ transport.addFunction( slotData );
+
+ // result slot
+ KODE::Function slotResult( "slotResult", "void", KODE::Function::Private | KODE::Function::Slot );
+ slotResult.addArgument( "KIO::Job* job" );
+
+ KODE::Code slotResultCode;
+ slotResultCode += "if ( job->error() != 0 ) {";
+ slotResultCode.indent();
+ slotResultCode += "kdWarning() << \"Error occurred \" << job->errorText() << endl;";
+ slotResultCode += "kdWarning() << " + slotDataVar.name() + " << endl;";
+ slotResultCode += "return;";
+ slotResultCode.unindent();
+ slotResultCode += "}";
+ slotResultCode.newLine();
+
+ slotResultCode += "emit result( QString::fromUtf8( " + slotDataVar.name() + ".data(), " + slotDataVar.name() + ".size() ) );";
+
+ slotResult.setBody( slotResultCode );
+
+ transport.addFunction( slotResult );
+
+ mClasses.append( transport );
+}
diff --git a/kode/kwsdl/converter.h b/kode/kwsdl/converter.h
new file mode 100644
index 000000000..45d530a3a
--- /dev/null
+++ b/kode/kwsdl/converter.h
@@ -0,0 +1,78 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_CONVERTER_H
+#define KWSDL_CONVERTER_H
+
+#include <kode/class.h>
+#include <schema/parser.h>
+
+/*
+#include "binding.h"
+#include "message.h"
+#include "port.h"
+#include "service.h"
+*/
+
+#include "namemapper.h"
+#include "typemapper.h"
+#include "wsdl.h"
+
+namespace KWSDL {
+
+class Converter
+{
+ public:
+ Converter();
+
+ void setWSDL( const WSDL &wsdl );
+
+ void convert();
+
+ KODE::Class::List classes() const;
+
+ private:
+ void convertTypes( const Schema::Types& );
+ void convertSimpleType( const Schema::SimpleType* );
+ void convertComplexType( const Schema::ComplexType* );
+
+ void createSimpleTypeSerializer( const Schema::SimpleType* );
+ void createComplexTypeSerializer( const Schema::ComplexType* );
+
+ void convertService( const Service& );
+ void convertInputMessage( const Port&, const Message&, KODE::Class& );
+ void convertOutputMessage( const Port&, const Message&, KODE::Class& );
+ void createUtilClasses();
+ void createTransportClass();
+
+ WSDL mWSDL;
+
+ KODE::Class::List mClasses;
+ KODE::Class mSerializer;
+ KODE::Class mQObject;
+
+ NameMapper mNameMapper;
+ TypeMapper mTypeMapper;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/creator.cpp b/kode/kwsdl/creator.cpp
new file mode 100644
index 000000000..53e82937e
--- /dev/null
+++ b/kode/kwsdl/creator.cpp
@@ -0,0 +1,71 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kode/file.h>
+#include <kode/printer.h>
+
+#include "creator.h"
+
+using namespace KWSDL;
+
+Creator::Creator()
+ : mOutputDirectory( "output/" )
+{
+}
+
+void Creator::create( const KODE::Class::List &list )
+{
+ KODE::Printer printer;
+ printer.setOutputDirectory( mOutputDirectory );
+
+ QStringList cppFiles;
+
+ KODE::Class::List::ConstIterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ KODE::File file;
+
+ if ( !mNameSpace.isEmpty() )
+ file.setNameSpace( mNameSpace );
+
+ file.setFilename( (*it).name().lower() );
+ file.addCopyright( 2005, "Tobias Koenig", "tokoe@kde.org" );
+ file.setLicense( KODE::License( KODE::License::GPL ) );
+
+ file.insertClass( *it );
+
+ printer.printHeader( file );
+ printer.printImplementation( file );
+
+ cppFiles.append( file.filename() + ".cpp" );
+ }
+
+ KODE::AutoMakefile::Target libTarget( "bin_PROGRAMS", "kwsdl" );
+ libTarget.setSources( "main.cc " + cppFiles.join( " " ) );
+ libTarget.setLdFlags( "$(all_libraries) $(KDE_RPATH)" );
+ libTarget.setLdAdd( "-lkdecore -lkio" );
+
+ KODE::AutoMakefile makefile;
+ makefile.addTarget( libTarget );
+ makefile.addEntry( "INCLUDES", "-I$(top_srcdir) -I$(top_srcdir)/libkdepim $(all_includes)" );
+ makefile.addEntry( "METASOURCES", "AUTO" );
+
+ printer.printAutoMakefile( makefile );
+}
diff --git a/kode/kwsdl/creator.h b/kode/kwsdl/creator.h
new file mode 100644
index 000000000..465c3302a
--- /dev/null
+++ b/kode/kwsdl/creator.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_CREATOR_H
+#define KWSDL_CREATOR_H
+
+#include <kode/class.h>
+
+namespace KWSDL {
+
+class Creator
+{
+ public:
+ Creator();
+
+ void setOutputDirectory( const QString &outputDirectory ) { mOutputDirectory = outputDirectory; }
+ QString outputDirectory() const { return mOutputDirectory; }
+
+ void setNameSpace( const QString &nameSpace ) { mNameSpace = nameSpace; }
+ QString nameSpace() const { return mNameSpace; }
+
+ void create( const KODE::Class::List &list );
+
+ private:
+ QString mOutputDirectory;
+ QString mNameSpace;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/kung/Makefile.am b/kode/kwsdl/kung/Makefile.am
new file mode 100644
index 000000000..1906ec1c1
--- /dev/null
+++ b/kode/kwsdl/kung/Makefile.am
@@ -0,0 +1,12 @@
+INCLUDES = -I$(top_srcdir) -I.. -I$(top_srcdir)/kode -I$(top_srcdir)/kode/kwsdl -I$(top_srcdir)/libkdepim $(all_includes)
+
+bin_PROGRAMS = kung
+kung_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kung_SOURCES = binaryinputfield.cpp boolinputfield.cpp complexbaseinputfield.cpp dateinputfield.cpp dispatcher.cpp \
+ doubleinputfield.cpp enuminputfield.cpp generalconversationmanager.cpp \
+ inputdialog.cpp inputfield.cpp inputfieldfactory.cpp \
+ integerinputfield.cpp listinputfield.cpp loader.cpp main.cpp outputdialog.cpp pageinputfield.cpp simplebaseinputfield.cpp \
+ stringinputfield.cpp timeinputfield.cpp transport.cpp wsclconversationmanager.cpp
+kung_LDADD = ../schema/libschema.la ../wscl/libwscl.la ../libwsdl.la -lkparts
+
+METASOURCES = AUTO
diff --git a/kode/kwsdl/kung/binaryinputfield.cpp b/kode/kwsdl/kung/binaryinputfield.cpp
new file mode 100644
index 000000000..f83e55b1f
--- /dev/null
+++ b/kode/kwsdl/kung/binaryinputfield.cpp
@@ -0,0 +1,186 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kfiledialog.h>
+#include <kio/netaccess.h>
+#include <kmdcodec.h>
+#include <kmessagebox.h>
+#include <kmimemagic.h>
+#include <klocale.h>
+#include <kparts/part.h>
+#include <kparts/componentfactory.h>
+#include <ktempfile.h>
+
+#include <qfile.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qwidget.h>
+
+#include <schema/simpletype.h>
+
+#include "binaryinputfield.h"
+
+BinaryInputField::BinaryInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mValue( 0 ), mTypeName( typeName )
+{
+}
+
+void BinaryInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "BinaryInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void BinaryInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:" + mTypeName );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void BinaryInputField::setData( const QString &data )
+{
+ KCodecs::base64Decode( data.utf8(), mValue );
+}
+
+QString BinaryInputField::data() const
+{
+ QByteArray data = KCodecs::base64Encode( mValue, false );
+ return QString::fromUtf8( data.data(), data.size() );
+}
+
+QWidget *BinaryInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new BinaryWidget( parent );
+
+ if ( !mValue.isEmpty() )
+ mInputWidget->setData( mValue );
+
+ return mInputWidget;
+}
+
+void BinaryInputField::valueChanged( const QByteArray &value )
+{
+ mValue = value;
+
+ emit modified();
+}
+
+
+BinaryWidget::BinaryWidget( QWidget *parent )
+ : QWidget( parent, "BinaryWidget" ),
+ mMainWidget( 0 )
+{
+ mLayout = new QGridLayout( this, 3, 2, 11, 6 );
+
+ mLoadButton = new QPushButton( i18n( "Load..." ), this );
+ mSaveButton = new QPushButton( i18n( "Save..." ), this );
+ mSaveButton->setEnabled( false );
+
+ mLayout->addWidget( mLoadButton, 0, 1 );
+ mLayout->addWidget( mSaveButton, 1, 1 );
+
+ connect( mLoadButton, SIGNAL( clicked() ), SLOT( load() ) );
+ connect( mSaveButton, SIGNAL( clicked() ), SLOT( save() ) );
+}
+
+void BinaryWidget::setData( const QByteArray &data )
+{
+ KMimeMagic magic;
+ QString mimetype;
+
+ delete mMainWidget;
+
+ KMimeMagicResult *result = magic.findBufferType( data );
+ if ( result->isValid() )
+ mimetype = result->mimeType();
+
+ if ( !mimetype.isEmpty() ) {
+ KParts::ReadOnlyPart *part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, QString::null, this, 0, this, 0 );
+ if ( part ) {
+ KTempFile file;
+ file.file()->writeBlock( data );
+ file.close();
+ part->openURL( KURL( file.name() ) );
+ mMainWidget = part->widget();
+ } else {
+ mMainWidget = new QLabel( i18n( "No part found for visualization of mimetype %1" ).arg( mimetype ), this );
+ }
+
+ mData = data;
+ mSaveButton->setEnabled( true );
+ } else {
+ mMainWidget = new QLabel( i18n( "Got data of unknown mimetype" ), this );
+ }
+
+ mLayout->addMultiCellWidget( mMainWidget, 0, 2, 0, 0 );
+ mMainWidget->show();
+}
+
+void BinaryWidget::load()
+{
+ KURL url = KFileDialog::getOpenURL( QString(), QString(), this );
+ if ( url.isEmpty() )
+ return;
+
+ QString tempFile;
+ if ( KIO::NetAccess::download( url, tempFile, this ) ) {
+ QFile file( tempFile );
+ if ( !file.open( IO_ReadOnly ) ) {
+ KMessageBox::error( this, i18n( "Unable to open file %1" ).arg( url.url() ) );
+ return;
+ }
+
+ QByteArray data = file.readAll();
+ setData( data );
+
+ file.close();
+ KIO::NetAccess::removeTempFile( tempFile );
+
+ emit valueChanged( data );
+ } else
+ KMessageBox::error( this, KIO::NetAccess::lastErrorString() );
+}
+
+void BinaryWidget::save()
+{
+ KURL url = KFileDialog::getSaveURL( QString(), QString(), this );
+ if ( url.isEmpty() )
+ return;
+
+ KTempFile tempFile;
+ tempFile.file()->writeBlock( mData );
+ tempFile.close();
+
+ if ( !KIO::NetAccess::upload( tempFile.name(), url, this ) )
+ KMessageBox::error( this, KIO::NetAccess::lastErrorString() );
+}
+
+#include "binaryinputfield.moc"
diff --git a/kode/kwsdl/kung/binaryinputfield.h b/kode/kwsdl/kung/binaryinputfield.h
new file mode 100644
index 000000000..eeb721d5f
--- /dev/null
+++ b/kode/kwsdl/kung/binaryinputfield.h
@@ -0,0 +1,83 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef BINARY_INPUTFIELD_H
+#define BINARY_INPUTFIELD_H
+
+#include <qwidget.h>
+
+#include "inputfield.h"
+
+class BinaryWidget;
+class QGridLayout;
+class QPushButton;
+
+class BinaryInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ BinaryInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void valueChanged( const QByteArray &value );
+
+ private:
+ BinaryWidget *mInputWidget;
+
+ QByteArray mValue;
+ QString mTypeName;
+};
+
+class BinaryWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ BinaryWidget( QWidget *parent );
+
+ void setData( const QByteArray &data );
+
+ signals:
+ void valueChanged( const QByteArray &data );
+
+ private slots:
+ void load();
+ void save();
+
+ private:
+ QByteArray mData;
+
+ QGridLayout *mLayout;
+ QPushButton *mLoadButton;
+ QPushButton *mSaveButton;
+ QWidget* mMainWidget;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/boolinputfield.cpp b/kode/kwsdl/kung/boolinputfield.cpp
new file mode 100644
index 000000000..69e0e8e04
--- /dev/null
+++ b/kode/kwsdl/kung/boolinputfield.cpp
@@ -0,0 +1,81 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qcheckbox.h>
+
+#include "boolinputfield.h"
+
+BoolInputField::BoolInputField( const QString &name, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mValue( false )
+{
+}
+
+void BoolInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "BoolInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void BoolInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:boolean" );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void BoolInputField::setData( const QString &data )
+{
+ mValue = ( data.lower() == "true" );
+}
+
+QString BoolInputField::data() const
+{
+ return ( mValue ? "true" : "false" );
+}
+
+QWidget *BoolInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new QCheckBox( parent );
+
+ mInputWidget->setChecked( mValue );
+
+ connect( mInputWidget, SIGNAL( toggled( bool ) ),
+ this, SLOT( inputChanged( bool ) ) );
+
+ return mInputWidget;
+}
+
+void BoolInputField::inputChanged( bool value )
+{
+ mValue = value;
+
+ emit modified();
+}
+
+#include "boolinputfield.moc"
diff --git a/kode/kwsdl/kung/boolinputfield.h b/kode/kwsdl/kung/boolinputfield.h
new file mode 100644
index 000000000..1ba5347b8
--- /dev/null
+++ b/kode/kwsdl/kung/boolinputfield.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef BOOL_INPUTFIELD_H
+#define BOOL_INPUTFIELD_H
+
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class QCheckBox;
+
+class BoolInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ BoolInputField( const QString &name, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( bool );
+
+ private:
+ QCheckBox *mInputWidget;
+ bool mValue;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/complexbaseinputfield.cpp b/kode/kwsdl/kung/complexbaseinputfield.cpp
new file mode 100644
index 000000000..26434940a
--- /dev/null
+++ b/kode/kwsdl/kung/complexbaseinputfield.cpp
@@ -0,0 +1,155 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include <schema/complextype.h>
+
+#include "inputfieldfactory.h"
+
+#include "complexbaseinputfield.h"
+
+ComplexBaseInputField::ComplexBaseInputField( const QString &name, const Schema::ComplexType *type )
+ : ComplexInputField( name, type )
+{
+ Schema::Element::List elements = type->elements();
+ Schema::Element::List::ConstIterator elemIt;
+ for ( elemIt = elements.begin(); elemIt != elements.end(); ++elemIt ) {
+ bool isList = ((*elemIt).maxOccurs() == UNBOUNDED);
+ InputField *field = InputFieldFactory::self()->createField( (*elemIt).name(), (*elemIt).typeName(), isList );
+ if ( !field ) {
+ qDebug( "ComplexBaseInputField: Unable to create field of type %s", type->baseTypeName().latin1() );
+ } else {
+ appendChild( field );
+ }
+ }
+
+ Schema::Attribute::List attributes = type->attributes();
+ Schema::Attribute::List::ConstIterator attrIt;
+ for ( attrIt = attributes.begin(); attrIt != attributes.end(); ++attrIt ) {
+ InputField *field = InputFieldFactory::self()->createField( (*attrIt).name(), (*attrIt).typeName() );
+ if ( !field ) {
+ qDebug( "ComplexBaseInputField: Unable to create field of type %s", type->baseTypeName().latin1() );
+ } else {
+ appendChild( field );
+ }
+ }
+}
+
+void ComplexBaseInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "ComplexBaseInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ // elements
+ if ( mType->isArray() ) {
+ InputField *field = childField( "item" );
+ field->setXMLData( element );
+ } else {
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement child = node.toElement();
+ if ( !child.isNull() ) {
+ InputField *field = childField( child.tagName() );
+ if ( !field ) {
+ qDebug( "ComplexBaseInputField: Child field %s does not exists", child.tagName().latin1() );
+ } else {
+ field->setXMLData( child );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+ }
+
+ // attributes
+ QDomNamedNodeMap nodes = element.attributes();
+ for ( uint i = 0; i < nodes.count(); ++i ) {
+ QDomNode node = nodes.item( i );
+ QDomAttr attr = node.toAttr();
+
+ InputField *field = childField( attr.name() );
+ if ( !field ) {
+ qDebug( "ComplexBaseInputField: Child field %s does not exists", attr.name().latin1() );
+ } else {
+ field->setData( attr.value() );
+ }
+ }
+}
+
+void ComplexBaseInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+
+ Schema::Element::List elements = mType->elements();
+ Schema::Element::List::ConstIterator elemIt;
+ for ( elemIt = elements.begin(); elemIt != elements.end(); ++elemIt ) {
+ InputField *field = childField( (*elemIt).name() );
+ if ( !field ) {
+ qDebug( "ComplexBaseInputField: No child found" );
+ } else {
+ field->xmlData( document, element );
+ }
+ }
+
+ Schema::Attribute::List attributes = mType->attributes();
+ Schema::Attribute::List::ConstIterator attrIt;
+ for ( attrIt = attributes.begin(); attrIt != attributes.end(); ++attrIt ) {
+ InputField *field = childField( (*attrIt).name() );
+ if ( !field ) {
+ qDebug( "ComplexBaseInputField: No child found" );
+ } else {
+ element.setAttribute( field->name(), field->data() );
+ }
+ }
+
+ parent.appendChild( element );
+}
+
+void ComplexBaseInputField::setData( const QString& )
+{
+}
+
+QString ComplexBaseInputField::data() const
+{
+ return QString();
+}
+
+QWidget *ComplexBaseInputField::createWidget( QWidget *parent )
+{
+ QGroupBox *inputWidget = new QGroupBox( mName, parent );
+ inputWidget->setColumnLayout( 0, Qt::Horizontal );
+ QGridLayout *layout = new QGridLayout( inputWidget->layout(), 2, 2, 6 );
+
+ InputField::List::Iterator it;
+ int row = 0;
+ for ( it = mFields.begin(); it != mFields.end(); ++it, ++row ) {
+ QLabel *label = new QLabel( (*it)->name(), inputWidget );
+ layout->addWidget( label, row, 0 );
+ layout->addWidget( (*it)->createWidget( inputWidget ), row, 1 );
+ }
+
+ return inputWidget;
+}
diff --git a/kode/kwsdl/kung/complexbaseinputfield.h b/kode/kwsdl/kung/complexbaseinputfield.h
new file mode 100644
index 000000000..e8d563ae2
--- /dev/null
+++ b/kode/kwsdl/kung/complexbaseinputfield.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef COMPLEXBASE_INPUTFIELD_H
+#define COMPLEXBASE_INPUTFIELD_H
+
+#include "inputfield.h"
+
+class ComplexBaseInputField : public ComplexInputField
+{
+ public:
+ ComplexBaseInputField( const QString &name, const Schema::ComplexType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+};
+
+#endif
diff --git a/kode/kwsdl/kung/conversationmanager.h b/kode/kwsdl/kung/conversationmanager.h
new file mode 100644
index 000000000..6ef403c7b
--- /dev/null
+++ b/kode/kwsdl/kung/conversationmanager.h
@@ -0,0 +1,37 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef CONVERSATIONMANAGER_H
+#define CONVERSATIONMANAGER_H
+
+#include <qstringlist.h>
+
+class ConversationManager
+{
+ public:
+ /**
+ Returns a list of all actions which can be called after the
+ current action with a special condition.
+ */
+ virtual QStringList nextActions( const QString &currentAction, const QString &condition = QString() ) = 0;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/dateinputfield.cpp b/kode/kwsdl/kung/dateinputfield.cpp
new file mode 100644
index 000000000..ff60da20f
--- /dev/null
+++ b/kode/kwsdl/kung/dateinputfield.cpp
@@ -0,0 +1,81 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kdatepicker.h>
+
+#include "dateinputfield.h"
+
+DateInputField::DateInputField( const QString &name, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mValue( QDate::currentDate() )
+{
+}
+
+void DateInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "DateInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void DateInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:date" );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void DateInputField::setData( const QString &data )
+{
+ mValue = QDate::fromString( data, Qt::ISODate );
+}
+
+QString DateInputField::data() const
+{
+ return mValue.toString( Qt::ISODate );
+}
+
+QWidget *DateInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new KDatePicker( parent );
+
+ mInputWidget->setDate( mValue );
+
+ connect( mInputWidget, SIGNAL( dateChanged( QDate ) ),
+ this, SLOT( inputChanged( QDate ) ) );
+
+ return mInputWidget;
+}
+
+void DateInputField::inputChanged( QDate date )
+{
+ mValue = date;
+
+ emit modified();
+}
+
+#include "dateinputfield.moc"
diff --git a/kode/kwsdl/kung/dateinputfield.h b/kode/kwsdl/kung/dateinputfield.h
new file mode 100644
index 000000000..a42e22102
--- /dev/null
+++ b/kode/kwsdl/kung/dateinputfield.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef DATE_INPUTFIELD_H
+#define DATE_INPUTFIELD_H
+
+#include <qdatetime.h>
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class KDatePicker;
+
+class DateInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ DateInputField( const QString &name, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( QDate );
+
+ private:
+ KDatePicker *mInputWidget;
+ QDate mValue;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/dispatcher.cpp b/kode/kwsdl/kung/dispatcher.cpp
new file mode 100644
index 000000000..79f6bd949
--- /dev/null
+++ b/kode/kwsdl/kung/dispatcher.cpp
@@ -0,0 +1,153 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qapplication.h>
+#include <qtimer.h>
+#include <qwidget.h>
+
+#include <kinputdialog.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include "generalconversationmanager.h"
+#include "inputdialog.h"
+#include "inputfieldfactory.h"
+#include "outputdialog.h"
+#include "pageinputfield.h"
+#include "transport.h"
+
+#include "dispatcher.h"
+
+Dispatcher::Dispatcher()
+ : QObject( 0, "Dispatcher" ),
+ mConversationManager( 0 )
+{
+}
+
+Dispatcher::~Dispatcher()
+{
+ delete mConversationManager;
+ mConversationManager = 0;
+}
+
+void Dispatcher::setWSDL( const KWSDL::WSDL &wsdl )
+{
+ mWSDL = wsdl;
+
+ InputFieldFactory::self()->setTypes( mWSDL.types() );
+
+ mConversationManager = new GeneralConversationManager( mWSDL );
+
+ mTransport = new Transport( mWSDL.service().ports().first().mLocation );
+ connect( mTransport, SIGNAL( result( const QString& ) ),
+ this, SLOT( result( const QString& ) ) );
+ connect( mTransport, SIGNAL( error( const QString& ) ),
+ this, SLOT( error( const QString& ) ) );
+}
+
+void Dispatcher::run()
+{
+ nextMessage();
+}
+
+void Dispatcher::nextMessage()
+{
+ if ( !mConversationManager ) {
+ qDebug( "No conversation manager set... aborting" );
+ return;
+ }
+
+ QStringList items = mConversationManager->nextActions( mLastMessage, QString() );
+
+ mCurrentMessage = QString();
+ if ( items.count() > 1 ) {
+ mCurrentMessage = KInputDialog::getItem( i18n( "Select a functionality of the service:" ), i18n( "Functions" ),
+ items );
+ } else
+ mCurrentMessage = items.first();
+
+ if ( mCurrentMessage.isEmpty() ) {
+ qApp->quit();
+ return;
+ }
+
+ KWSDL::Message message = mWSDL.findMessage( mCurrentMessage );
+ InputField *field = new PageInputField( message.name(), message );
+ QWidget *page = field->createWidget( 0 );
+
+ InputDialog dlg( page, 0 );
+ if ( dlg.exec() ) {
+ QDomDocument doc( "kwsdl" );
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+ QDomElement env = doc.createElement( "SOAP-ENV:Envelope" );
+ env.setAttribute( "xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" );
+ env.setAttribute( "xmlns:xsi", "http://www.w3.org/1999/XMLSchema-instance" );
+ env.setAttribute( "xmlns:xsd", "http://www.w3.org/1999/XMLSchema" );
+ doc.appendChild( env );
+
+ QDomElement body = doc.createElement( "SOAP-ENV:Body" );
+ env.appendChild( body );
+
+ field->xmlData( doc, body );
+
+ QDomElement method = body.firstChild().toElement();
+ QString nameSpace = mWSDL.findBindingOperation( "", message.name() ).input().nameSpace();
+ method.setAttribute( "xmlns:ns1", "urn:GoogleSearch" );
+ method.setAttribute( "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/" );
+ body.appendChild( method );
+
+ if ( mTransport ) {
+ qDebug( "%s", doc.toString( 2 ).latin1() );
+ mTransport->query( doc.toString( 2 ) );
+ }
+ } else
+ qApp->quit();
+}
+
+void Dispatcher::result( const QString &xml )
+{
+ qDebug( "Got data %s", xml.latin1() );
+
+ KWSDL::Message message = mWSDL.findOutputMessage( mCurrentMessage );
+ InputField *field = new PageInputField( message.name(), message );
+
+ QDomDocument doc;
+ doc.setContent( xml, true );
+
+ field->setXMLData( doc.documentElement().firstChild().firstChild().toElement() );
+ QWidget *page = field->createWidget( 0 );
+
+ OutputDialog dlg( page, 0 );
+ dlg.exec();
+
+ mLastMessage = mCurrentMessage;
+
+ QTimer::singleShot( 0, this, SLOT( nextMessage() ) );
+}
+
+void Dispatcher::error( const QString &errorMsg )
+{
+ KMessageBox::error( 0, errorMsg );
+
+ QTimer::singleShot( 0, this, SLOT( nextMessage() ) );
+}
+
+#include "dispatcher.moc"
diff --git a/kode/kwsdl/kung/dispatcher.h b/kode/kwsdl/kung/dispatcher.h
new file mode 100644
index 000000000..892635d50
--- /dev/null
+++ b/kode/kwsdl/kung/dispatcher.h
@@ -0,0 +1,58 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef DISPATCHER_H
+#define DISPATCHER_H
+
+#include <qobject.h>
+
+#include <kwsdl/wsdl.h>
+
+class ConversationManager;
+class Transport;
+
+class Dispatcher : public QObject
+{
+ Q_OBJECT
+
+ public:
+ Dispatcher();
+ ~Dispatcher();
+
+ void setWSDL( const KWSDL::WSDL &wsdl );
+
+ void run();
+
+ private slots:
+ void nextMessage();
+ void result( const QString &xml );
+ void error( const QString &errorMsg );
+
+ private:
+ KWSDL::WSDL mWSDL;
+
+ QString mCurrentMessage;
+ QString mLastMessage;
+ ConversationManager *mConversationManager;
+ Transport *mTransport;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/doubleinputfield.cpp b/kode/kwsdl/kung/doubleinputfield.cpp
new file mode 100644
index 000000000..4c19abf97
--- /dev/null
+++ b/kode/kwsdl/kung/doubleinputfield.cpp
@@ -0,0 +1,94 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <knuminput.h>
+
+#include <schema/simpletype.h>
+
+#include "doubleinputfield.h"
+
+DoubleInputField::DoubleInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mValue( 0 ), mTypeName( typeName )
+{
+}
+
+void DoubleInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "DoubleInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void DoubleInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:" + mTypeName );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void DoubleInputField::setData( const QString &data )
+{
+ mValue = data.toDouble();
+}
+
+QString DoubleInputField::data() const
+{
+ return QString::number( mValue );
+}
+
+QWidget *DoubleInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new KDoubleSpinBox( parent );
+
+ if ( mType ) {
+ if ( mType->facetType() & Schema::SimpleType::MININC )
+ mInputWidget->setMinValue( mType->facetMinimumInclusive() );
+ if ( mType->facetType() & Schema::SimpleType::MINEX )
+ mInputWidget->setMinValue( mType->facetMinimumExclusive() + 1 );
+ if ( mType->facetType() & Schema::SimpleType::MAXINC )
+ mInputWidget->setMaxValue( mType->facetMaximumInclusive() );
+ if ( mType->facetType() & Schema::SimpleType::MAXEX )
+ mInputWidget->setMaxValue( mType->facetMaximumExclusive() - 1 );
+ }
+
+ mInputWidget->setValue( mValue );
+
+ connect( mInputWidget, SIGNAL( valueChanged( double ) ),
+ this, SLOT( inputChanged( double ) ) );
+
+ return mInputWidget;
+}
+
+void DoubleInputField::inputChanged( double value )
+{
+ mValue = value;
+
+ emit modified();
+}
+
+#include "doubleinputfield.moc"
diff --git a/kode/kwsdl/kung/doubleinputfield.h b/kode/kwsdl/kung/doubleinputfield.h
new file mode 100644
index 000000000..f1eeb789e
--- /dev/null
+++ b/kode/kwsdl/kung/doubleinputfield.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef DOUBLE_INPUTFIELD_H
+#define DOUBLE_INPUTFIELD_H
+
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class KDoubleSpinBox;
+
+class DoubleInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ DoubleInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( double );
+
+ private:
+ KDoubleSpinBox *mInputWidget;
+ double mValue;
+ QString mTypeName;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/enuminputfield.cpp b/kode/kwsdl/kung/enuminputfield.cpp
new file mode 100644
index 000000000..61ff328d6
--- /dev/null
+++ b/kode/kwsdl/kung/enuminputfield.cpp
@@ -0,0 +1,86 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kcombobox.h>
+
+#include <schema/simpletype.h>
+
+#include "enuminputfield.h"
+
+EnumInputField::EnumInputField( const QString &name, const Schema::SimpleType *type )
+ : SimpleInputField( name, type )
+{
+ mEnums = type->facetEnums();
+
+ mValue = mEnums.first();
+}
+
+void EnumInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "EnumInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void EnumInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:string" );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void EnumInputField::setData( const QString &data )
+{
+ mValue = data;
+}
+
+QString EnumInputField::data() const
+{
+ return mValue;
+}
+
+QWidget *EnumInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new KComboBox( parent );
+
+ mInputWidget->insertStringList( mEnums );
+ mInputWidget->setCurrentItem( mEnums.findIndex( mValue ) );
+
+ connect( mInputWidget, SIGNAL( activated( int ) ),
+ this, SLOT( inputChanged( int ) ) );
+
+ return mInputWidget;
+}
+
+void EnumInputField::inputChanged( int value )
+{
+ mValue = mEnums[ value ];
+
+ emit modified();
+}
+
+#include "enuminputfield.moc"
diff --git a/kode/kwsdl/kung/enuminputfield.h b/kode/kwsdl/kung/enuminputfield.h
new file mode 100644
index 000000000..40369273c
--- /dev/null
+++ b/kode/kwsdl/kung/enuminputfield.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef ENUM_INPUTFIELD_H
+#define ENUM_INPUTFIELD_H
+
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class KComboBox;
+
+class EnumInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ EnumInputField( const QString &name, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( int );
+
+ private:
+ KComboBox *mInputWidget;
+ QString mValue;
+ QStringList mEnums;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/generalconversationmanager.cpp b/kode/kwsdl/kung/generalconversationmanager.cpp
new file mode 100644
index 000000000..266eca3b3
--- /dev/null
+++ b/kode/kwsdl/kung/generalconversationmanager.cpp
@@ -0,0 +1,51 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "generalconversationmanager.h"
+
+GeneralConversationManager::GeneralConversationManager( const KWSDL::WSDL &wsdl )
+ : mWSDL( wsdl )
+{
+ const KWSDL::Service::Port::List servicePorts = mWSDL.service().ports();
+ KWSDL::Service::Port::List::ConstIterator it;
+ for ( it = servicePorts.begin(); it != servicePorts.end(); ++it ) {
+ KWSDL::Binding binding = mWSDL.findBinding( (*it).mBinding );
+
+ KWSDL::Port port = mWSDL.findPort( binding.type() );
+ const KWSDL::Port::Operation::List operations = port.operations();
+ KWSDL::Port::Operation::List::ConstIterator opIt;
+ for ( opIt = operations.begin(); opIt != operations.end(); ++opIt ) {
+ mInputMessages.append( mWSDL.findMessage( (*opIt).input() ) );
+ mOutputMessages.append( mWSDL.findMessage( (*opIt).output() ) );
+ }
+ }
+}
+
+QStringList GeneralConversationManager::nextActions( const QString&, const QString& )
+{
+ QStringList actions;
+
+ KWSDL::Message::List::ConstIterator it;
+ for ( it = mInputMessages.begin(); it != mInputMessages.end(); ++it )
+ actions.append( (*it).name() );
+
+ return actions;
+}
diff --git a/kode/kwsdl/kung/generalconversationmanager.h b/kode/kwsdl/kung/generalconversationmanager.h
new file mode 100644
index 000000000..2f0297577
--- /dev/null
+++ b/kode/kwsdl/kung/generalconversationmanager.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef GENERAL_CONVERSATIONMANAGER_H
+#define GENERAL_CONVERSATIONMANAGER_H
+
+#include <kwsdl/wsdl.h>
+
+#include "conversationmanager.h"
+
+class GeneralConversationManager : public ConversationManager
+{
+ public:
+ GeneralConversationManager( const KWSDL::WSDL &wsdl );
+
+ virtual QStringList nextActions( const QString &currentAction, const QString &condition = QString() );
+
+ private:
+ KWSDL::WSDL mWSDL;
+
+ KWSDL::Message::List mInputMessages;
+ KWSDL::Message::List mOutputMessages;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/inputdialog.cpp b/kode/kwsdl/kung/inputdialog.cpp
new file mode 100644
index 000000000..2885fdc4b
--- /dev/null
+++ b/kode/kwsdl/kung/inputdialog.cpp
@@ -0,0 +1,32 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <klocale.h>
+
+#include "inputdialog.h"
+
+InputDialog::InputDialog( QWidget *page, QWidget *parent )
+ : KDialogBase( Swallow, "", Ok | Cancel, Ok, parent, "", true, true )
+{
+ setMainWidget( page );
+
+ setButtonText( Ok, i18n( "Send" ) );
+}
diff --git a/kode/kwsdl/kung/inputdialog.h b/kode/kwsdl/kung/inputdialog.h
new file mode 100644
index 000000000..10b107c3a
--- /dev/null
+++ b/kode/kwsdl/kung/inputdialog.h
@@ -0,0 +1,33 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef INPUTDIALOG_H
+#define INPUTDIALOG_H
+
+#include <kdialogbase.h>
+
+class InputDialog : public KDialogBase
+{
+ public:
+ InputDialog( QWidget *page, QWidget *parent );
+};
+
+#endif
diff --git a/kode/kwsdl/kung/inputfield.cpp b/kode/kwsdl/kung/inputfield.cpp
new file mode 100644
index 000000000..d4efcbe49
--- /dev/null
+++ b/kode/kwsdl/kung/inputfield.cpp
@@ -0,0 +1,102 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <schema/complextype.h>
+#include <schema/simpletype.h>
+
+#include "inputfield.h"
+
+InputField::InputField( const QString &name )
+ : QObject( 0, QString( "InputField( %1 )" ).arg( name ).latin1() ),
+ mName( name )
+{
+}
+
+InputField::~InputField()
+{
+ InputField::List::Iterator it;
+ for ( it = mFields.begin(); it != mFields.end(); ++it )
+ delete *it;
+
+ mFields.clear();
+}
+
+QString InputField::name() const
+{
+ return mName;
+}
+
+void InputField::appendChild( InputField *field )
+{
+ mFields.append( field );
+}
+
+void InputField::removeChild( InputField *field )
+{
+ mFields.remove( field );
+}
+
+InputField *InputField::childField( const QString &name ) const
+{
+ InputField::List::ConstIterator it;
+ for ( it = mFields.begin(); it != mFields.end(); ++it )
+ if ( (*it)->name() == name )
+ return *it;
+
+ return 0;
+}
+
+InputField::List InputField::childFields() const
+{
+ return mFields;
+}
+
+SimpleInputField::SimpleInputField( const QString &name, const Schema::SimpleType *type )
+ : InputField( name ), mType( 0 )
+{
+ if ( type ) {
+ mType = new Schema::SimpleType();
+ *mType = *type;
+ }
+}
+
+SimpleInputField::~SimpleInputField()
+{
+ delete mType;
+ mType = 0;
+}
+
+ComplexInputField::ComplexInputField( const QString &name, const Schema::ComplexType *type )
+ : InputField( name ), mType( 0 )
+{
+ if ( type ) {
+ mType = new Schema::ComplexType();
+ *mType = *type;
+ }
+}
+
+ComplexInputField::~ComplexInputField()
+{
+ delete mType;
+ mType = 0;
+}
+
+#include "inputfield.moc"
diff --git a/kode/kwsdl/kung/inputfield.h b/kode/kwsdl/kung/inputfield.h
new file mode 100644
index 000000000..71030bdaa
--- /dev/null
+++ b/kode/kwsdl/kung/inputfield.h
@@ -0,0 +1,146 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef INPUTFIELD_H
+#define INPUTFIELD_H
+
+#include <qdom.h>
+#include <qobject.h>
+#include <qstring.h>
+#include <qvaluelist.h>
+
+class QWidget;
+
+namespace Schema {
+class SimpleType;
+class ComplexType;
+}
+
+/**
+ Abstract base class for all kinds of input fields.
+ */
+class InputField : public QObject
+{
+ Q_OBJECT
+
+ public:
+ typedef QValueList<InputField*> List;
+
+ /**
+ Constructs a input field.
+ */
+ InputField( const QString &name );
+
+ /**
+ Destructor.
+ */
+ virtual ~InputField();
+
+ /**
+ Returns the name of the field.
+ */
+ QString name() const;
+
+ /**
+ Sets the xml data of this field.
+ */
+ virtual void setXMLData( const QDomElement &element ) = 0;
+
+ /**
+ Returns the xml value of this field.
+ */
+ virtual void xmlData( QDomDocument &document, QDomElement &parent ) = 0;
+
+ /**
+ Sets the plain data of this field as string.
+ */
+ virtual void setData( const QString &data ) = 0;
+
+ /**
+ Returns the data of this field as string.
+ */
+ virtual QString data() const = 0;
+
+ /**
+ Returns a pointer to a new created input widget which can be used to
+ to modify the value.
+ */
+ virtual QWidget *createWidget( QWidget *parent ) = 0;
+
+ /**
+ Add a child field.
+ */
+ virtual void appendChild( InputField *field );
+
+ /**
+ Removes a child field.
+ */
+ virtual void removeChild( InputField *field );
+
+ /**
+ Returns a field with the given name or 0 when no field with this name
+ exists.
+ */
+ virtual InputField *childField( const QString &name ) const;
+
+ /**
+ Returns a list of all child fields.
+ */
+ virtual InputField::List childFields() const;
+
+ signals:
+ /**
+ This signal is emitted whenever the value is changed by the user.
+ */
+ void modified();
+
+ protected:
+ QString mName;
+ InputField::List mFields;
+};
+
+/**
+ Abstract base class for simple input fields like text or number input.
+ */
+class SimpleInputField : public InputField
+{
+ public:
+ SimpleInputField( const QString &name, const Schema::SimpleType *type );
+ ~SimpleInputField();
+
+ protected:
+ Schema::SimpleType *mType;
+};
+
+/**
+ Abstract base class for complex input fields like pages, lists or tables.
+ */
+class ComplexInputField : public InputField
+{
+ public:
+ ComplexInputField( const QString &name, const Schema::ComplexType *type );
+ ~ComplexInputField();
+
+ protected:
+ Schema::ComplexType *mType;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/inputfieldfactory.cpp b/kode/kwsdl/kung/inputfieldfactory.cpp
new file mode 100644
index 000000000..43a844c65
--- /dev/null
+++ b/kode/kwsdl/kung/inputfieldfactory.cpp
@@ -0,0 +1,123 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kstaticdeleter.h>
+
+#include <schema/types.h>
+
+#include "binaryinputfield.h"
+#include "boolinputfield.h"
+#include "complexbaseinputfield.h"
+#include "dateinputfield.h"
+#include "doubleinputfield.h"
+#include "enuminputfield.h"
+#include "integerinputfield.h"
+#include "listinputfield.h"
+#include "simplebaseinputfield.h"
+#include "stringinputfield.h"
+#include "timeinputfield.h"
+
+#include "inputfieldfactory.h"
+
+InputFieldFactory *InputFieldFactory::mSelf = 0;
+static KStaticDeleter<InputFieldFactory> inputFieldFactoryDeleter;
+
+InputFieldFactory::InputFieldFactory()
+{
+}
+
+InputFieldFactory::~InputFieldFactory()
+{
+}
+
+void InputFieldFactory::setTypes( const Schema::Types &types )
+{
+ mTypes = types;
+}
+
+InputField *InputFieldFactory::createField( const QString &name, const QString &typeName, bool isList )
+{
+ Schema::SimpleType::List simpleTypes = mTypes.simpleTypes();
+ Schema::SimpleType::List::ConstIterator simpleIt;
+ for ( simpleIt = simpleTypes.begin(); simpleIt != simpleTypes.end(); ++simpleIt ) {
+ if ( (*simpleIt).name() == typeName ) {
+ if ( isList )
+ return new ListInputField( name, typeName, 0 );
+ else
+ return new SimpleBaseInputField( name, &(*simpleIt) );
+ }
+ }
+
+ Schema::ComplexType::List complexTypes = mTypes.complexTypes();
+ Schema::ComplexType::List::ConstIterator complexIt;
+ for ( complexIt = complexTypes.begin(); complexIt != complexTypes.end(); ++complexIt ) {
+ if ( (*complexIt).name() == typeName ) {
+ if ( isList )
+ return new ListInputField( name, typeName, 0 );
+ else
+ return new ComplexBaseInputField( name, &(*complexIt) );
+ }
+ }
+
+ return createBasicField( name, typeName, 0, isList );
+}
+
+InputField *InputFieldFactory::createBasicField( const QString &name, const QString &typeName,
+ const Schema::SimpleType *type, bool isList )
+{
+ if ( isList )
+ return new ListInputField( name, typeName, 0 );
+
+ if ( typeName == "string" || typeName == "language" ) {
+ if ( type && type->facetType() & Schema::SimpleType::ENUM )
+ return new EnumInputField( name, type );
+ else
+ return new StringInputField( name, typeName, type );
+ } else if ( typeName == "int" || typeName == "unsignedInt" ||
+ typeName == "byte" || typeName == "unsignedByte" ||
+ typeName == "integer" || typeName == "positiveInteger" || typeName == "negativeInteger" ||
+ typeName == "nonNegativeInteger" || typeName == "nonPositiveInteger" ||
+ typeName == "long" || typeName == "unsignedLong" ||
+ typeName == "short" || typeName == "unsignedShort" ) {
+ return new IntegerInputField( name, typeName, type );
+ } else if ( typeName == "double" || typeName == "float" || typeName == "decimal" ) {
+ return new DoubleInputField( name, typeName, type );
+ } else if ( typeName == "boolean" ) {
+ return new BoolInputField( name, type );
+ } else if ( typeName == "date" ) {
+ return new DateInputField( name, type );
+ } else if ( typeName == "time" ) {
+ return new TimeInputField( name, type );
+ } else if ( typeName == "base64Binary" ) {
+ return new BinaryInputField( name, typeName, type );
+ } else {
+ qDebug( "InputFieldFactory: Unknown type %s", typeName.latin1() );
+ return 0;
+ }
+}
+
+InputFieldFactory* InputFieldFactory::self()
+{
+ if ( !mSelf )
+ inputFieldFactoryDeleter.setObject( mSelf, new InputFieldFactory() );
+
+ return mSelf;
+}
diff --git a/kode/kwsdl/kung/inputfieldfactory.h b/kode/kwsdl/kung/inputfieldfactory.h
new file mode 100644
index 000000000..2c1e30eb9
--- /dev/null
+++ b/kode/kwsdl/kung/inputfieldfactory.h
@@ -0,0 +1,69 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef INPUTFIELD_FACTORY_H
+#define INPUTFIELD_FACTORY_H
+
+#include "inputfield.h"
+
+#include <schema/types.h>
+
+namespace Schema {
+class SimpleType;
+};
+
+/**
+ Factory class, which creates InputFields for a given type.
+ */
+class InputFieldFactory
+{
+ public:
+ /**
+ Destructor.
+ */
+ ~InputFieldFactory();
+
+ /**
+ Creates an input field of the given type with the given name.
+ */
+ InputField *createField( const QString &name, const QString &typeName, bool isList = false );
+
+ /**
+ Creates an input field of the given type with the given name.
+ */
+ InputField *createBasicField( const QString &name, const QString &typeName, const Schema::SimpleType *type, bool isList = false );
+
+ /**
+ Sets the types description, so that the factory can pass
+ them to the input fields.
+ */
+ void setTypes( const Schema::Types &types );
+
+ static InputFieldFactory* self();
+
+ private:
+ InputFieldFactory();
+
+ static InputFieldFactory *mSelf;
+ Schema::Types mTypes;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/integerinputfield.cpp b/kode/kwsdl/kung/integerinputfield.cpp
new file mode 100644
index 000000000..a06136823
--- /dev/null
+++ b/kode/kwsdl/kung/integerinputfield.cpp
@@ -0,0 +1,132 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <knuminput.h>
+
+#include <schema/simpletype.h>
+
+#include <limits.h>
+
+#include "integerinputfield.h"
+
+IntegerInputField::IntegerInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mValue( 0 ), mTypeName( typeName )
+{
+}
+
+void IntegerInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "IntegerInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void IntegerInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:" + mTypeName );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void IntegerInputField::setData( const QString &data )
+{
+ mValue = data.toInt();
+}
+
+QString IntegerInputField::data() const
+{
+ return QString::number( mValue );
+}
+
+QWidget *IntegerInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new KIntSpinBox( parent );
+
+ // basic restrictions
+ if ( mTypeName == "byte" ) {
+ mInputWidget->setMinValue( CHAR_MIN );
+ mInputWidget->setMaxValue( CHAR_MAX );
+ } else if ( mTypeName == "unsignedByte" ) {
+ mInputWidget->setMinValue( 0 );
+ mInputWidget->setMaxValue( UCHAR_MAX );
+ } else if ( mTypeName == "integer" || mTypeName == "int" ) {
+ mInputWidget->setMinValue( INT_MIN );
+ mInputWidget->setMaxValue( INT_MAX );
+ } else if ( mTypeName == "positiveInteger" ) {
+ mInputWidget->setMinValue( 1 );
+ mInputWidget->setMaxValue( UINT_MAX );
+ } else if ( mTypeName == "negativeInteger" ) {
+ mInputWidget->setMinValue( INT_MIN );
+ mInputWidget->setMaxValue( -1 );
+ } else if ( mTypeName == "nonNegativeInteger" || mTypeName == "unsignedInt" ) {
+ mInputWidget->setMinValue( 0 );
+ mInputWidget->setMaxValue( UINT_MAX );
+ } else if ( mTypeName == "nonPositiveInteger" ) {
+ mInputWidget->setMinValue( INT_MIN );
+ mInputWidget->setMaxValue( 0 );
+ } else if ( mTypeName == "long" ) {
+ mInputWidget->setMinValue( LONG_MIN );
+ mInputWidget->setMaxValue( LONG_MAX );
+ } else if ( mTypeName == "unsignedlong" ) {
+ mInputWidget->setMinValue( 0 );
+ mInputWidget->setMaxValue( ULONG_MAX );
+ } else if ( mTypeName == "short" ) {
+ mInputWidget->setMinValue( SHRT_MIN );
+ mInputWidget->setMaxValue( SHRT_MAX );
+ } else if ( mTypeName == "unsignedShort" ) {
+ mInputWidget->setMinValue( 0 );
+ mInputWidget->setMaxValue( USHRT_MAX );
+ }
+
+ if ( mType ) {
+ if ( mType->facetType() & Schema::SimpleType::MININC )
+ mInputWidget->setMinValue( mType->facetMinimumInclusive() );
+ if ( mType->facetType() & Schema::SimpleType::MINEX )
+ mInputWidget->setMinValue( mType->facetMinimumExclusive() + 1 );
+ if ( mType->facetType() & Schema::SimpleType::MAXINC )
+ mInputWidget->setMaxValue( mType->facetMaximumInclusive() );
+ if ( mType->facetType() & Schema::SimpleType::MAXEX )
+ mInputWidget->setMaxValue( mType->facetMaximumExclusive() - 1 );
+ }
+
+ mInputWidget->setValue( mValue );
+
+ connect( mInputWidget, SIGNAL( valueChanged( int ) ),
+ this, SLOT( inputChanged( int ) ) );
+
+ return mInputWidget;
+}
+
+void IntegerInputField::inputChanged( int value )
+{
+ mValue = value;
+
+ emit modified();
+}
+
+#include "integerinputfield.moc"
diff --git a/kode/kwsdl/kung/integerinputfield.h b/kode/kwsdl/kung/integerinputfield.h
new file mode 100644
index 000000000..6576aa1df
--- /dev/null
+++ b/kode/kwsdl/kung/integerinputfield.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef INTEGER_INPUTFIELD_H
+#define INTEGER_INPUTFIELD_H
+
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class KIntSpinBox;
+
+class IntegerInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ IntegerInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( int );
+
+ private:
+ KIntSpinBox *mInputWidget;
+ int mValue;
+ QString mTypeName;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/listinputfield.cpp b/kode/kwsdl/kung/listinputfield.cpp
new file mode 100644
index 000000000..a812df6a9
--- /dev/null
+++ b/kode/kwsdl/kung/listinputfield.cpp
@@ -0,0 +1,189 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qpushbutton.h>
+
+#include <klocale.h>
+
+#include <schema/simpletype.h>
+
+#include "inputdialog.h"
+#include "inputfieldfactory.h"
+#include "outputdialog.h"
+
+#include "listinputfield.h"
+
+ListInputField::ListInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ), mTypeName( typeName )
+{
+}
+
+void ListInputField::setXMLData( const QDomElement &element )
+{
+ InputField::List::Iterator it;
+ for ( it = mFields.begin(); it != mFields.end(); ++it ) {
+ delete *it;
+ }
+ mFields.clear();
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement child = node.toElement();
+ if ( !child.isNull() ) {
+ InputField *field = InputFieldFactory::self()->createField( name(), mTypeName );
+ if ( field ) {
+ field->setXMLData( child );
+ appendChild( field );
+ } else
+ qDebug( "ListInputField: Unable to create field of type %s", mTypeName.latin1() );
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void ListInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ InputField::List::Iterator it;
+ for ( it = mFields.begin(); it != mFields.end(); ++it ) {
+ (*it)->xmlData( document, parent );
+ }
+}
+
+void ListInputField::setData( const QString& )
+{
+}
+
+QString ListInputField::data() const
+{
+ return QString();
+}
+
+QWidget *ListInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new ListWidget( this, name(), mTypeName, parent );
+
+ return mInputWidget;
+}
+
+
+ListWidget::ListWidget( InputField *parentField, const QString &name, const QString &type, QWidget *parent )
+ : QWidget( parent ),
+ mParentField( parentField ), mName( name ), mType( type )
+{
+ QGridLayout *layout = new QGridLayout( this, 4, 2, 11, 6 );
+
+ mView = new QListBox( this );
+ layout->addMultiCellWidget( mView, 0, 3, 0, 0 );
+
+ mAddButton = new QPushButton( i18n( "Add" ), this );
+ layout->addWidget( mAddButton, 0, 1 );
+
+ mEditButton = new QPushButton( i18n( "Edit..." ), this );
+ layout->addWidget( mEditButton, 1, 1 );
+
+ mRemoveButton = new QPushButton( i18n( "Remove" ), this );
+ layout->addWidget( mRemoveButton, 2, 1 );
+
+ connect( mAddButton, SIGNAL( clicked() ), SLOT( add() ) );
+ connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) );
+ connect( mRemoveButton, SIGNAL( clicked() ), SLOT( remove() ) );
+
+ update();
+}
+
+void ListWidget::update()
+{
+ int pos = mView->currentItem();
+ mView->clear();
+
+ const InputField::List fields = mParentField->childFields();
+ InputField::List::ConstIterator it;
+ for ( it = fields.begin(); it != fields.end(); ++it )
+ mView->insertItem( (*it)->name() );
+
+ mView->setCurrentItem( pos );
+
+ updateButtons();
+}
+
+void ListWidget::add()
+{
+ InputField *field = InputFieldFactory::self()->createField( mName, mType );
+ if ( !field ) {
+ qDebug( "ListInputField: Unable to create field of type %s", mType.latin1() );
+ return;
+ }
+
+ InputDialog dlg( field->createWidget( this ), this );
+ if ( dlg.exec() ) {
+ mParentField->appendChild( field );
+
+ update();
+ } else
+ delete field;
+}
+
+void ListWidget::edit()
+{
+ int pos = mView->currentItem();
+
+ if ( pos == -1 )
+ return;
+
+ InputField *field = mParentField->childFields()[ pos ];
+ if ( !field )
+ return;
+
+ OutputDialog dlg( field->createWidget( this ), this );
+ dlg.exec();
+
+ update();
+}
+
+void ListWidget::remove()
+{
+ int pos = mView->currentItem();
+
+ if ( pos == -1 )
+ return;
+
+ InputField *field = mParentField->childFields()[ pos ];
+ if ( !field )
+ return;
+
+ mParentField->removeChild( field );
+ delete field;
+
+ update();
+}
+
+void ListWidget::updateButtons()
+{
+ bool enabled = (mParentField->childFields().count() > 0);
+
+ mEditButton->setEnabled( enabled );
+ mRemoveButton->setEnabled( enabled );
+}
+
+#include "listinputfield.moc"
diff --git a/kode/kwsdl/kung/listinputfield.h b/kode/kwsdl/kung/listinputfield.h
new file mode 100644
index 000000000..3b3779e25
--- /dev/null
+++ b/kode/kwsdl/kung/listinputfield.h
@@ -0,0 +1,80 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef LIST_INPUTFIELD_H
+#define LIST_INPUTFIELD_H
+
+#include <qwidget.h>
+
+#include "inputfield.h"
+
+class ListWidget;
+class QListBox;
+class QPushButton;
+
+class ListInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ ListInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private:
+ ListWidget *mInputWidget;
+ QString mTypeName;
+};
+
+class ListWidget : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ListWidget( InputField *parentField, const QString &name, const QString &type, QWidget *parent );
+
+ void update();
+
+ private slots:
+ void add();
+ void edit();
+ void remove();
+
+ private:
+ void updateButtons();
+
+ InputField *mParentField;
+ QString mName;
+ QString mType;
+
+ QListBox *mView;
+ QPushButton *mAddButton;
+ QPushButton *mEditButton;
+ QPushButton *mRemoveButton;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/loader.cpp b/kode/kwsdl/kung/loader.cpp
new file mode 100644
index 000000000..1b13549fa
--- /dev/null
+++ b/kode/kwsdl/kung/loader.cpp
@@ -0,0 +1,89 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qfile.h>
+
+#include <schema/fileprovider.h>
+
+#include "dispatcher.h"
+
+#include "loader.h"
+
+Loader::Loader()
+ : QObject( 0, "KWSDL::Loader" )
+{
+}
+
+void Loader::setWSDLUrl( const QString &wsdlUrl )
+{
+ mWSDLUrl = wsdlUrl;
+ mWSDLBaseUrl = mWSDLUrl.left( mWSDLUrl.findRev( '/' ) );
+
+ mParser.setSchemaBaseUrl( mWSDLBaseUrl );
+}
+
+void Loader::run()
+{
+ download();
+}
+
+void Loader::download()
+{
+ Schema::FileProvider provider;
+
+ QString fileName;
+ if ( provider.get( mWSDLUrl, fileName ) ) {
+ QFile file( fileName );
+ if ( !file.open( IO_ReadOnly ) ) {
+ qDebug( "Unable to download wsdl file %s", mWSDLUrl.latin1() );
+ provider.cleanUp();
+ return;
+ }
+
+ QString errorMsg;
+ int errorLine, errorCol;
+ QDomDocument doc;
+ if ( !doc.setContent( &file, true, &errorMsg, &errorLine, &errorCol ) ) {
+ qDebug( "%s at (%d,%d)", errorMsg.latin1(), errorLine, errorCol );
+ return;
+ }
+
+ parse( doc.documentElement() );
+
+ provider.cleanUp();
+ }
+}
+
+void Loader::parse( const QDomElement &element )
+{
+ mParser.parse( element );
+ execute();
+}
+
+void Loader::execute()
+{
+ mDispatcher = new Dispatcher;
+ mDispatcher->setWSDL( mParser.wsdl() );
+
+ mDispatcher->run();
+}
+
+#include "loader.moc"
diff --git a/kode/kwsdl/kung/loader.h b/kode/kwsdl/kung/loader.h
new file mode 100644
index 000000000..2229eb23a
--- /dev/null
+++ b/kode/kwsdl/kung/loader.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef LOADER_H
+#define LOADER_H
+
+#include <kwsdl/parser.h>
+
+class Dispatcher;
+
+class Loader : public QObject
+{
+ Q_OBJECT
+
+ public:
+ Loader();
+
+ void setWSDLUrl( const QString &wsdlUrl );
+
+ public slots:
+ void run();
+
+ private slots:
+ void download();
+ void parse( const QDomElement& );
+ void execute();
+
+ private:
+ QString mWSDLUrl;
+
+ KWSDL::Parser mParser;
+ QString mWSDLBaseUrl;
+
+ Dispatcher *mDispatcher;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/main.cpp b/kode/kwsdl/kung/main.cpp
new file mode 100644
index 000000000..92de443ff
--- /dev/null
+++ b/kode/kwsdl/kung/main.cpp
@@ -0,0 +1,64 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <qtimer.h>
+
+#include "loader.h"
+
+static const KCmdLineOptions options[] =
+{
+ { "+wsdl", I18N_NOOP( "Location of WSDL file" ), 0 },
+ KCmdLineLastOption
+};
+
+int main( int argc, char **argv )
+{
+ KAboutData aboutData( "kung", I18N_NOOP( "KDE WSDL Interpreter" ), "0.1",
+ I18N_NOOP( "KDE WSDL Interpreter" ),
+ KAboutData::License_LGPL );
+
+ aboutData.addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ if ( args->count() == 0 ) {
+ kdError() << "No WSDL file given." << endl;
+ return 1;
+ }
+
+ KApplication app;
+
+ Loader loader;
+ loader.setWSDLUrl( args->url( 0 ).path() );
+
+ QTimer::singleShot( 0, &loader, SLOT( run() ) );
+
+ return app.exec();
+}
diff --git a/kode/kwsdl/kung/outputdialog.cpp b/kode/kwsdl/kung/outputdialog.cpp
new file mode 100644
index 000000000..7a04db478
--- /dev/null
+++ b/kode/kwsdl/kung/outputdialog.cpp
@@ -0,0 +1,30 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <klocale.h>
+
+#include "outputdialog.h"
+
+OutputDialog::OutputDialog( QWidget *page, QWidget *parent )
+ : KDialogBase( Swallow, "", Ok, Ok, parent, "", true, true )
+{
+ setMainWidget( page );
+}
diff --git a/kode/kwsdl/kung/outputdialog.h b/kode/kwsdl/kung/outputdialog.h
new file mode 100644
index 000000000..e671e0841
--- /dev/null
+++ b/kode/kwsdl/kung/outputdialog.h
@@ -0,0 +1,33 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef OUTPUTDIALOG_H
+#define OUTPUTDIALOG_H
+
+#include <kdialogbase.h>
+
+class OutputDialog : public KDialogBase
+{
+ public:
+ OutputDialog( QWidget *page, QWidget *parent );
+};
+
+#endif
diff --git a/kode/kwsdl/kung/pageinputfield.cpp b/kode/kwsdl/kung/pageinputfield.cpp
new file mode 100644
index 000000000..36a5b02da
--- /dev/null
+++ b/kode/kwsdl/kung/pageinputfield.cpp
@@ -0,0 +1,107 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include "inputfieldfactory.h"
+
+#include "pageinputfield.h"
+
+PageInputField::PageInputField( const QString &name, const KWSDL::Message &message )
+ : InputField( name ),
+ mMessage( message )
+{
+ KWSDL::Message::Part::List parts = message.parts();
+ KWSDL::Message::Part::List::ConstIterator it;
+ for ( it = parts.begin(); it != parts.end(); ++it ) {
+ InputField *field = InputFieldFactory::self()->createField( (*it).name(), (*it).type() );
+ if ( !field ) {
+ qDebug( "PageInputField: Unable to create input field for %s (%s)", (*it).name().latin1(), (*it).type().latin1() );
+ } else {
+ appendChild( field );
+ }
+ }
+}
+
+void PageInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "PageInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement child = node.toElement();
+ if ( !child.isNull() ) {
+ InputField *field = childField( child.tagName() );
+ if ( !field ) {
+ qDebug( "PageInputField: Child field %s does not exists", child.tagName().latin1() );
+ } else {
+ field->setXMLData( child );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void PageInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( "ns1:" + mName );
+
+ InputField::List::Iterator it;
+ for ( it = mFields.begin(); it != mFields.end(); ++it )
+ (*it)->xmlData( document, element );
+
+ parent.appendChild( element );
+}
+
+void PageInputField::setData( const QString& )
+{
+}
+
+QString PageInputField::data() const
+{
+ return QString();
+}
+
+QWidget *PageInputField::createWidget( QWidget *parent )
+{
+ QWidget *mInputWidget = new QWidget( parent, "PageInputWidget" );
+ QGridLayout *layout = new QGridLayout( mInputWidget, 2, 2, 11, 6 );
+
+ InputField::List::Iterator it;
+ int row = 0;
+ for ( it = mFields.begin(); it != mFields.end(); ++it, ++row ) {
+ QLabel *label = new QLabel( (*it)->name(), mInputWidget );
+ label->setAlignment( Qt::AlignTop );
+ layout->addWidget( label, row, 0 );
+ layout->addWidget( (*it)->createWidget( mInputWidget ), row, 1 );
+ }
+
+ layout->setRowStretch( ++row, 1 );
+
+ return mInputWidget;
+}
+
+#include "pageinputfield.moc"
diff --git a/kode/kwsdl/kung/pageinputfield.h b/kode/kwsdl/kung/pageinputfield.h
new file mode 100644
index 000000000..c63e97aeb
--- /dev/null
+++ b/kode/kwsdl/kung/pageinputfield.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef PAGE_INPUTFIELD_H
+#define PAGE_INPUTFIELD_H
+
+#include <qobject.h>
+
+#include <kwsdl/message.h>
+
+#include "inputfield.h"
+
+class PageInputField : public InputField
+{
+ Q_OBJECT
+
+ public:
+ PageInputField( const QString &name, const KWSDL::Message &message );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private:
+ QWidget *mInputWidget;
+ const KWSDL::Message mMessage;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/simplebaseinputfield.cpp b/kode/kwsdl/kung/simplebaseinputfield.cpp
new file mode 100644
index 000000000..f9cb1bd56
--- /dev/null
+++ b/kode/kwsdl/kung/simplebaseinputfield.cpp
@@ -0,0 +1,120 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <schema/simpletype.h>
+
+#include "inputfieldfactory.h"
+
+#include "simplebaseinputfield.h"
+
+SimpleBaseInputField::SimpleBaseInputField( const QString &name, const Schema::SimpleType *type )
+ : SimpleInputField( name, type )
+{
+ if ( type->subType() == Schema::SimpleType::TypeRestriction ) {
+ InputField *field = InputFieldFactory::self()->createBasicField( name, type->baseTypeName(), type );
+ if ( !field ) {
+ qDebug( "SimpleBaseInputField: Unable to create field of type %s", type->baseTypeName().latin1() );
+ } else {
+ appendChild( field );
+ }
+ } else {
+ qDebug( "SimpleBaseInputField: Unsupported subtype" );
+ }
+}
+
+void SimpleBaseInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "SimpleBaseInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ if ( mType->subType() == Schema::SimpleType::TypeRestriction ) {
+ InputField *field = childField( element.tagName() );
+ if ( !field ) {
+ qDebug( "SimpleBaseInputField: Child field %s does not exists", element.tagName().latin1() );
+ } else {
+ field->setXMLData( element );
+ }
+ } else {
+ qDebug( "SimpleBaseInputField: Unsupported subtype" );
+ }
+}
+
+void SimpleBaseInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ if ( mType->subType() == Schema::SimpleType::TypeRestriction ) {
+ InputField *field = mFields.first();
+ if ( !field ) {
+ qDebug( "SimpleBaseInputField: No child found" );
+ } else {
+ field->xmlData( document, parent );
+ }
+ } else {
+ qDebug( "SimpleBaseInputField: Unsupported subtype" );
+ }
+}
+
+void SimpleBaseInputField::setData( const QString &data )
+{
+ if ( mType->subType() == Schema::SimpleType::TypeRestriction ) {
+ InputField *field = mFields.first();
+ if ( !field ) {
+ qDebug( "SimpleBaseInputField: No child found" );
+ } else {
+ field->setData( data );
+ }
+ } else {
+ qDebug( "SimpleBaseInputField: Unsupported subtype" );
+ }
+}
+
+QString SimpleBaseInputField::data() const
+{
+ if ( mType->subType() == Schema::SimpleType::TypeRestriction ) {
+ InputField *field = mFields.first();
+ if ( !field ) {
+ qDebug( "SimpleBaseInputField: No child found" );
+ } else {
+ field->data();
+ }
+ } else {
+ qDebug( "SimpleBaseInputField: Unsupported subtype" );
+ }
+
+ return QString();
+}
+
+QWidget *SimpleBaseInputField::createWidget( QWidget *parent )
+{
+ if ( mType->subType() == Schema::SimpleType::TypeRestriction ) {
+ InputField *field = mFields.first();
+ if ( !field ) {
+ qDebug( "SimpleBaseInputField: No child found" );
+ return 0;
+ } else {
+ return field->createWidget( parent );
+ }
+ } else {
+ qDebug( "SimpleBaseInputField: Unsupported subtype" );
+ return 0;
+ }
+}
diff --git a/kode/kwsdl/kung/simplebaseinputfield.h b/kode/kwsdl/kung/simplebaseinputfield.h
new file mode 100644
index 000000000..7af65ab37
--- /dev/null
+++ b/kode/kwsdl/kung/simplebaseinputfield.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef SIMPLEBASE_INPUTFIELD_H
+#define SIMPLEBASE_INPUTFIELD_H
+
+#include "inputfield.h"
+
+class SimpleBaseInputField : public SimpleInputField
+{
+ public:
+ SimpleBaseInputField( const QString &name, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+};
+
+#endif
diff --git a/kode/kwsdl/kung/stringinputfield.cpp b/kode/kwsdl/kung/stringinputfield.cpp
new file mode 100644
index 000000000..e0dc10ccc
--- /dev/null
+++ b/kode/kwsdl/kung/stringinputfield.cpp
@@ -0,0 +1,100 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qlineedit.h>
+#include <qvalidator.h>
+
+#include <schema/simpletype.h>
+
+#include "stringinputfield.h"
+
+StringInputField::StringInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mTypeName( typeName )
+{
+}
+
+void StringInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "StringInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void StringInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:" + mTypeName );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void StringInputField::setData( const QString &data )
+{
+ mValue = data;
+}
+
+QString StringInputField::data() const
+{
+ return mValue;
+}
+
+QWidget *StringInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new QLineEdit( parent );
+
+ if ( mType ) {
+ if ( mType->facetType() & Schema::SimpleType::LENGTH ) // TODO: using QValidator here?
+ mInputWidget->setMaxLength( mType->facetLength() );
+
+ if ( mType->facetType() & Schema::SimpleType::MINLEN ) {
+ // TODO: using QValidator here?
+ // mInputWidget->setMaxLength( type->facetMinimumLength() );
+ }
+
+ if ( mType->facetType() & Schema::SimpleType::MAXLEN )
+ mInputWidget->setMaxLength( mType->facetMaximumLength() );
+
+ if ( mType->facetType() & Schema::SimpleType::PATTERN )
+ mInputWidget->setValidator( new QRegExpValidator( mType->facetPattern(), mInputWidget ) );
+ }
+
+ mInputWidget->setText( mValue );
+
+ connect( mInputWidget, SIGNAL( textChanged( const QString& ) ),
+ this, SLOT( inputChanged( const QString& ) ) );
+
+ return mInputWidget;
+}
+
+void StringInputField::inputChanged( const QString &text )
+{
+ mValue = text;
+
+ emit modified();
+}
+
+#include "stringinputfield.moc"
diff --git a/kode/kwsdl/kung/stringinputfield.h b/kode/kwsdl/kung/stringinputfield.h
new file mode 100644
index 000000000..2713dded8
--- /dev/null
+++ b/kode/kwsdl/kung/stringinputfield.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef STRING_INPUTFIELD_H
+#define STRING_INPUTFIELD_H
+
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class QLineEdit;
+
+class StringInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ StringInputField( const QString &name, const QString &typeName, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( const QString& );
+
+ private:
+ QLineEdit *mInputWidget;
+ QString mValue;
+ QString mTypeName;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/timeinputfield.cpp b/kode/kwsdl/kung/timeinputfield.cpp
new file mode 100644
index 000000000..0864b8c17
--- /dev/null
+++ b/kode/kwsdl/kung/timeinputfield.cpp
@@ -0,0 +1,81 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <ktimewidget.h>
+
+#include "timeinputfield.h"
+
+TimeInputField::TimeInputField( const QString &name, const Schema::SimpleType *type )
+ : SimpleInputField( name, type ),
+ mValue( QTime::currentTime() )
+{
+}
+
+void TimeInputField::setXMLData( const QDomElement &element )
+{
+ if ( mName != element.tagName() ) {
+ qDebug( "TimeInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
+ return;
+ }
+
+ setData( element.text() );
+}
+
+void TimeInputField::xmlData( QDomDocument &document, QDomElement &parent )
+{
+ QDomElement element = document.createElement( mName );
+ element.setAttribute( "xsi:type", "xsd:time" );
+ QDomText text = document.createTextNode( data() );
+ element.appendChild( text );
+
+ parent.appendChild( element );
+}
+
+void TimeInputField::setData( const QString &data )
+{
+ mValue = QTime::fromString( data, Qt::ISODate );
+}
+
+QString TimeInputField::data() const
+{
+ return mValue.toString( Qt::ISODate );
+}
+
+QWidget *TimeInputField::createWidget( QWidget *parent )
+{
+ mInputWidget = new KTimeWidget( parent );
+
+ mInputWidget->setTime( mValue );
+
+ connect( mInputWidget, SIGNAL( valueChanged( const QTime& ) ),
+ this, SLOT( inputChanged( const QTime& ) ) );
+
+ return mInputWidget;
+}
+
+void TimeInputField::inputChanged( const QTime &time )
+{
+ mValue = time;
+
+ emit modified();
+}
+
+#include "timeinputfield.moc"
diff --git a/kode/kwsdl/kung/timeinputfield.h b/kode/kwsdl/kung/timeinputfield.h
new file mode 100644
index 000000000..6edf9540e
--- /dev/null
+++ b/kode/kwsdl/kung/timeinputfield.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef TIME_INPUTFIELD_H
+#define TIME_INPUTFIELD_H
+
+#include <qdatetime.h>
+#include <qobject.h>
+
+#include "inputfield.h"
+
+class KTimeWidget;
+
+class TimeInputField : public SimpleInputField
+{
+ Q_OBJECT
+
+ public:
+ TimeInputField( const QString &name, const Schema::SimpleType *type );
+
+ virtual void setXMLData( const QDomElement &element );
+ virtual void xmlData( QDomDocument &document, QDomElement &parent );
+
+ virtual void setData( const QString &data );
+ virtual QString data() const;
+
+ virtual QWidget *createWidget( QWidget *parent );
+
+ private slots:
+ void inputChanged( const QTime& );
+
+ private:
+ KTimeWidget *mInputWidget;
+ QTime mValue;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/transport.cpp b/kode/kwsdl/kung/transport.cpp
new file mode 100644
index 000000000..5cb414c99
--- /dev/null
+++ b/kode/kwsdl/kung/transport.cpp
@@ -0,0 +1,69 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "transport.h"
+
+#include <kdebug.h>
+
+Transport::Transport( const QString &url )
+{
+ mUrl = url;
+ qDebug( "url=%s", url.latin1() );
+}
+
+void Transport::query( const QString &xml )
+{
+ mData.truncate( 0 );
+
+ QByteArray postData;
+ QDataStream stream( postData, IO_WriteOnly );
+ stream.writeRawBytes( xml.utf8(), xml.utf8().length() );
+
+ KIO::TransferJob* job = KIO::http_post( KURL( mUrl ), postData, false );
+ if ( !job ) {
+ kdWarning() << "Unable to create KIO job for " << mUrl << endl;
+ return;
+ }
+
+ job->addMetaData( "UserAgent", "KDE Kung" );
+ job->addMetaData( "content-type", "Content-Type: text/xml; charset=utf-8" );
+
+ connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) );
+ connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) );
+}
+
+void Transport::slotData( KIO::Job*, const QByteArray &data )
+{
+ unsigned int oldSize = mData.size();
+ mData.resize( oldSize + data.size() );
+ memcpy( mData.data() + oldSize, data.data(), data.size() );
+}
+
+void Transport::slotResult( KIO::Job* job )
+{
+ if ( job->error() != 0 )
+ emit error( job->errorText() );
+ else
+ emit result( QString::fromUtf8( mData.data(), mData.size() ) );
+}
+
+
+#include "transport.moc"
+
diff --git a/kode/kwsdl/kung/transport.h b/kode/kwsdl/kung/transport.h
new file mode 100644
index 000000000..5b7662fe1
--- /dev/null
+++ b/kode/kwsdl/kung/transport.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#ifndef TRANSPORT_H
+#define TRANSPORT_H
+
+#include <qobject.h>
+#include <kio/job.h>
+
+class Transport : public QObject
+{
+ Q_OBJECT
+
+ public:
+ Transport( const QString &url );
+ void query( const QString &xml );
+
+ signals:
+ void result( const QString &xml );
+ void error( const QString &errorMsg );
+
+ private slots:
+ void slotData( KIO::Job*, const QByteArray &data );
+ void slotResult( KIO::Job* job );
+
+ private:
+ QString mUrl;
+ QByteArray mData;
+};
+
+#endif
diff --git a/kode/kwsdl/kung/wsclconversationmanager.cpp b/kode/kwsdl/kung/wsclconversationmanager.cpp
new file mode 100644
index 000000000..c553edee6
--- /dev/null
+++ b/kode/kwsdl/kung/wsclconversationmanager.cpp
@@ -0,0 +1,50 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "wsclconversationmanager.h"
+
+WSCLConversationManager::WSCLConversationManager()
+{
+}
+
+WSCLConversationManager::WSCLConversationManager( const WSCL::Conversation &conversation )
+ : mConversation( conversation )
+{
+}
+
+void WSCLConversationManager::setConversation( const WSCL::Conversation &conversation )
+{
+ mConversation = conversation;
+}
+
+QStringList WSCLConversationManager::nextActions( const QString &currentAction, const QString &condition )
+{
+ WSCL::Transition::List transitions = mConversation.transitions();
+ WSCL::Transition::List::ConstIterator it;
+ for ( it = transitions.begin(); it != transitions.end(); ++it ) {
+ if ( (*it).sourceInteraction() == currentAction ) {
+ if ( (*it).sourceInteractionCondition() == condition )
+ return (*it).destinationInteraction();
+ }
+ }
+
+ return QStringList();
+}
diff --git a/kode/kwsdl/kung/wsclconversationmanager.h b/kode/kwsdl/kung/wsclconversationmanager.h
new file mode 100644
index 000000000..eb02ab708
--- /dev/null
+++ b/kode/kwsdl/kung/wsclconversationmanager.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of Kung.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef WSCL_CONVERSATIONMANAGER_H
+#define WSCL_CONVERSATIONMANAGER_H
+
+#include <wscl/conversation.h>
+
+#include "conversationmanager.h"
+
+class WSCLConversationManager : public ConversationManager
+{
+ public:
+ WSCLConversationManager();
+ WSCLConversationManager( const WSCL::Conversation &conversation );
+
+ void setConversation( const WSCL::Conversation &conversation );
+
+ QStringList nextActions( const QString &currentAction, const QString &condition = QString() );
+
+ private:
+ WSCL::Conversation mConversation;
+};
+
+#endif
diff --git a/kode/kwsdl/main.cpp b/kode/kwsdl/main.cpp
new file mode 100644
index 000000000..c793dde79
--- /dev/null
+++ b/kode/kwsdl/main.cpp
@@ -0,0 +1,77 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "compiler.h"
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <qdir.h>
+#include <qfile.h>
+#include <qtimer.h>
+
+static const KCmdLineOptions options[] =
+{
+ { "d", 0, 0 },
+ { "directory <dir>", I18N_NOOP( "Directory to generate files in" ), "." },
+ { "n", 0, 0 },
+ { "namespace <namespace>", I18N_NOOP( "Namespace of the created classes" ), "." },
+ { "+wsdl", I18N_NOOP( "WSDL file" ), 0 },
+ KCmdLineLastOption
+};
+
+int main( int argc, char **argv )
+{
+ KAboutData aboutData( "kwsdl_compiler", I18N_NOOP( "KDE wsdl compiler" ), "0.1",
+ I18N_NOOP( "KDE WSDL Compiler" ),
+ KAboutData::License_LGPL );
+
+ aboutData.addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ if ( args->count() < 1 || args->count() > 1 ) {
+ qDebug( "Invalid arguments, try --help." );
+ return 1;
+ }
+
+ KApplication app( false, false );
+
+ QString outputDirectory = QFile::decodeName( args->getOption( "directory" ) );
+ if ( outputDirectory.isEmpty() )
+ outputDirectory = QDir::current().path();
+
+ KWSDL::Compiler compiler;
+ compiler.setWSDLUrl( args->url( 0 ).path() );
+ compiler.setOutputDirectory( outputDirectory );
+ if ( args->isSet( "namespace" ) )
+ compiler.setNameSpace( args->getOption( "namespace" ) );
+
+ QTimer::singleShot( 0, &compiler, SLOT( run() ) );
+
+ return app.exec();
+}
diff --git a/kode/kwsdl/message.cpp b/kode/kwsdl/message.cpp
new file mode 100644
index 000000000..ee1abbc06
--- /dev/null
+++ b/kode/kwsdl/message.cpp
@@ -0,0 +1,72 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "message.h"
+
+using namespace KWSDL;
+
+Message::Part::Part()
+{
+}
+
+Message::Part::Part( const QString &name, const QString &type )
+ : mName( name ), mType( type )
+{
+}
+
+Message::Message()
+{
+}
+
+Message::Message( const QString &name )
+ : mName( name )
+{
+}
+
+void Message::setName( const QString &name )
+{
+ mName = name;
+}
+
+QString Message::name() const
+{
+ return mName;
+}
+
+void Message::addPart( const Part &part )
+{
+ mParts.append( part );
+}
+
+Message::Part Message::part( const QString &name ) const
+{
+ Part::List::ConstIterator it;
+ for ( it = mParts.begin(); it != mParts.end(); ++it )
+ if ( (*it).name() == name )
+ return *it;
+
+ return Part();
+}
+
+Message::Part::List Message::parts() const
+{
+ return mParts;
+}
diff --git a/kode/kwsdl/message.h b/kode/kwsdl/message.h
new file mode 100644
index 000000000..c8b1d4eda
--- /dev/null
+++ b/kode/kwsdl/message.h
@@ -0,0 +1,71 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_MESSAGE_H
+#define KWSDL_MESSAGE_H
+
+#include <qmap.h>
+
+namespace KWSDL {
+
+class Message
+{
+ public:
+ typedef QValueList<Message> List;
+
+ class Part
+ {
+ public:
+ typedef QMap<QString, Part> Map;
+ typedef QValueList<Part> List;
+
+ Part();
+ Part( const QString &name, const QString &type );
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void setType( const QString &type ) { mType = type; }
+ QString type() const { return mType; }
+
+ private:
+ QString mName;
+ QString mType;
+ };
+
+ Message();
+ Message( const QString &name );
+
+ void setName( const QString &name );
+ QString name() const;
+
+ void addPart( const Part &part );
+ Part part( const QString &name ) const;
+ Part::List parts() const;
+
+ private:
+ QString mName;
+ Part::List mParts;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/namemapper.cpp b/kode/kwsdl/namemapper.cpp
new file mode 100644
index 000000000..e11d2ef0c
--- /dev/null
+++ b/kode/kwsdl/namemapper.cpp
@@ -0,0 +1,45 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "namemapper.h"
+
+using namespace KWSDL;
+
+NameMapper::NameMapper()
+{
+ mKeyWords << "delete" << "class" << "default" << "new" << "not";
+}
+
+QString NameMapper::escape( const QString &name ) const
+{
+ if ( mKeyWords.contains( name ) )
+ return "_" + name;
+ else
+ return name;
+}
+
+QString NameMapper::unescape( const QString &name ) const
+{
+ if ( name.startsWith( "_" ) )
+ return name.mid( 1 );
+ else
+ return name;
+}
diff --git a/kode/kwsdl/namemapper.h b/kode/kwsdl/namemapper.h
new file mode 100644
index 000000000..88c29a49d
--- /dev/null
+++ b/kode/kwsdl/namemapper.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_NAMEMAPPER_H
+#define KWSDL_NAMEMAPPER_H
+
+#include <qstringlist.h>
+
+namespace KWSDL {
+
+class NameMapper
+{
+ public:
+ NameMapper();
+
+ QString escape( const QString &name ) const;
+ QString unescape( const QString &name ) const;
+
+ private:
+ QStringList mKeyWords;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/parser.cpp b/kode/kwsdl/parser.cpp
new file mode 100644
index 000000000..ab168b579
--- /dev/null
+++ b/kode/kwsdl/parser.cpp
@@ -0,0 +1,240 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qdom.h>
+
+#include "parser.h"
+
+using namespace KWSDL;
+
+static QString sns( const QString &str )
+{
+ int pos = str.find( ':' );
+ if ( pos != -1 )
+ return str.mid( pos + 1 );
+ else
+ return str;
+}
+
+Parser::Parser()
+{
+}
+
+WSDL Parser::wsdl() const
+{
+ WSDL wsdl;
+
+ wsdl.setBindings( mBindings );
+ wsdl.setMessages( mMessages );
+ wsdl.setPorts( mPorts );
+ wsdl.setService( mService );
+ wsdl.setTypes( mParser.types() );
+
+ return wsdl;
+}
+
+void Parser::reset()
+{
+ mMessages.clear();
+ mPorts.clear();
+ mService = Service();
+ mParser.clear();
+}
+
+void Parser::setSchemaBaseUrl( const QString &url )
+{
+ mParser.setSchemaBaseUrl( url );
+}
+
+void Parser::parse( const QDomElement &root )
+{
+ reset();
+
+ QDomNode node = root.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "types" )
+ parseTypes( element );
+ else if ( element.tagName() == "message" ) {
+ Message message( element.attribute( "name" ) );
+ parseMessage( element, message );
+ mMessages.append( message );
+ } else if ( element.tagName() == "portType" ) {
+ Port port( sns( element.attribute( "name" ) ) );
+ parsePortType( element, port );
+ mPorts.append( port );
+ } else if ( element.tagName() == "binding" ) {
+ parseBinding( element );
+ } else if ( element.tagName() == "service" ) {
+ mService = Service( sns( element.attribute( "name" ) ) );
+ parseService( element );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseTypes( const QDomElement &parent )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "schema" )
+ mParser.parseSchemaTag( element );
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseMessage( const QDomElement &parent, Message &message )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "part" ) {
+
+ // HACK(groupwise): is element valid here as attribute?
+ QString type = sns( element.attribute( "type" ) );
+ if ( type.isEmpty() )
+ type = sns( element.attribute( "element" ) );
+
+ Message::Part part( sns( element.attribute( "name" ) ), type );
+ message.addPart( part );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parsePortType( const QDomElement &parent, Port &port )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "operation" ) {
+ QString input, output;
+
+ QDomNode childNode = element.firstChild();
+ while ( !childNode.isNull() ) {
+ QDomElement childElement = childNode.toElement();
+ if ( !childElement.isNull() ) {
+ if ( childElement.tagName() == "input" )
+ input = sns( childElement.attribute( "message" ) );
+ else if ( childElement.tagName() == "output" )
+ output = sns( childElement.attribute( "message" ) );
+ }
+
+ childNode = childNode.nextSibling();
+ }
+
+ Port::Operation operation( sns( element.attribute( "name" ) ), input, output );
+ port.addOperation( operation );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseBinding( const QDomElement &parent )
+{
+ Binding binding( sns( parent.attribute( "name" ) ), sns( parent.attribute( "type" ) ) );
+
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "binding" ) {
+ binding.setStyle( element.attribute( "style" ) );
+ binding.setTransport( element.attribute( "transport" ) );
+ } else if ( element.tagName() == "operation" ) {
+ Binding::Operation operation;
+ operation.setName( element.attribute( "name" ) );
+
+ QDomNode opNode = element.firstChild();
+ while ( !opNode.isNull() ) {
+ QDomElement opElement = opNode.toElement();
+ if ( !opElement.isNull() ) {
+ if ( opElement.tagName() == "operation" )
+ operation.setAction( opElement.attribute( "soapAction" ) );
+ else if ( opElement.tagName() == "input" ) {
+ QDomElement inputElement = opElement.firstChild().toElement();
+
+ Binding::Operation::Item input;
+ input.setUse( inputElement.attribute( "use" ) );
+ input.setNameSpace( inputElement.attribute( "namespace" ) );
+ input.setEncodingStyle( inputElement.attribute( "encodingStyle" ) );
+
+ operation.setInput( input );
+ } else if ( opElement.tagName() == "output" ) {
+ QDomElement outputElement = opElement.firstChild().toElement();
+
+ Binding::Operation::Item output;
+ output.setUse( outputElement.attribute( "use" ) );
+ output.setNameSpace( outputElement.attribute( "namespace" ) );
+ output.setEncodingStyle( outputElement.attribute( "encodingStyle" ) );
+
+ operation.setOutput( output );
+ }
+ }
+
+ opNode = opNode.nextSibling();
+ }
+
+ binding.addOperation( operation );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+ mBindings.append( binding );
+}
+
+void Parser::parseService( const QDomElement &parent )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "port" ) {
+ Service::Port port;
+ port.mName = sns( element.attribute( "name" ) );
+ port.mBinding = sns( element.attribute( "binding" ) );
+ QDomNode childNode = element.firstChild();
+ if ( !childNode.isNull() ) {
+ QDomElement childElement = childNode.toElement();
+ port.mLocation = childElement.attribute( "location" );
+ }
+ mService.addPort( port );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
diff --git a/kode/kwsdl/parser.h b/kode/kwsdl/parser.h
new file mode 100644
index 000000000..f075efa70
--- /dev/null
+++ b/kode/kwsdl/parser.h
@@ -0,0 +1,64 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_PARSER_H
+#define KWSDL_PARSER_H
+
+#include <qdom.h>
+#include <qvaluelist.h>
+
+#include <schema/parser.h>
+
+#include "wsdl.h"
+
+namespace KWSDL {
+
+class Parser
+{
+ public:
+ Parser();
+
+ void parse( const QDomElement &element );
+ void reset();
+
+ void setSchemaBaseUrl( const QString& );
+
+ WSDL wsdl() const;
+
+ private:
+ void parseTypes( const QDomElement& );
+ void parseMessage( const QDomElement&, Message& );
+ void parsePortType( const QDomElement&, Port& );
+ void parseBinding( const QDomElement& );
+ void parseService( const QDomElement& );
+
+ void parseSchema( const QDomElement& );
+
+ Binding::List mBindings;
+ Message::List mMessages;
+ Port::List mPorts;
+ Service mService;
+ Schema::Parser mParser;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/port.cpp b/kode/kwsdl/port.cpp
new file mode 100644
index 000000000..90381f9df
--- /dev/null
+++ b/kode/kwsdl/port.cpp
@@ -0,0 +1,62 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "port.h"
+
+using namespace KWSDL;
+
+Port::Operation::Operation()
+{
+}
+
+Port::Operation::Operation( const QString &name, const QString &input, const QString &output )
+ : mName( name ), mInput( input ), mOutput( output )
+{
+}
+
+Port::Port()
+{
+}
+
+Port::Port( const QString &name )
+ : mName( name )
+{
+}
+
+void Port::addOperation( const Operation &operation )
+{
+ mOperations.append( operation );
+}
+
+Port::Operation Port::operation( const QString &name ) const
+{
+ Operation::List::ConstIterator it;
+ for ( it = mOperations.begin(); it != mOperations.end(); ++it )
+ if ( (*it).name() == name )
+ return *it;
+
+ return Operation();
+}
+
+Port::Operation::List Port::operations() const
+{
+ return mOperations;
+}
diff --git a/kode/kwsdl/port.h b/kode/kwsdl/port.h
new file mode 100644
index 000000000..b0e982086
--- /dev/null
+++ b/kode/kwsdl/port.h
@@ -0,0 +1,75 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_PORT_H
+#define KWSDL_PORT_H
+
+#include <qmap.h>
+
+namespace KWSDL {
+
+class Port
+{
+ public:
+ typedef QValueList<Port> List;
+
+ class Operation
+ {
+ public:
+ typedef QValueList<Operation> List;
+ typedef QMap<QString, Operation> Map;
+
+ Operation();
+ Operation( const QString &name, const QString &input, const QString &output );
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void setInput( const QString &input ) { mInput = input; }
+ QString input() const { return mInput; }
+
+ void setOutput( const QString &output ) { mOutput = output; }
+ QString output() const { return mOutput; }
+
+ private:
+ QString mName;
+ QString mInput;
+ QString mOutput;
+ };
+
+ Port();
+ Port( const QString &name );
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void addOperation( const Operation &operation );
+ Operation operation( const QString &name ) const;
+ Operation::List operations() const;
+
+ private:
+ QString mName;
+ Operation::List mOperations;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/Makefile.am b/kode/kwsdl/schema/Makefile.am
new file mode 100644
index 000000000..9b98340f4
--- /dev/null
+++ b/kode/kwsdl/schema/Makefile.am
@@ -0,0 +1,15 @@
+INCLUDES = -I$(top_srcdir) -I.. -I$(top_srcdir)/libkdepim $(all_includes)
+
+lib_LTLIBRARIES = libschema.la
+
+libschema_la_SOURCES = attribute.cpp complextype.cpp element.cpp fileprovider.cpp \
+ parser.cpp qualifiedname.cpp simpletype.cpp types.cpp typestable.cpp
+libschema_la_LDFLAGS = $(all_libraries) -version-info 1:0:0 -no-undefined
+libschema_la_LIBADD = -lqt-mt -lkdecore -lkio
+
+#bin_PROGRAMS = schematest
+#schematest_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+#schematest_SOURCES = main.cpp
+#schematest_LDADD = libschema.la
+
+METASOURCES = AUTO
diff --git a/kode/kwsdl/schema/attribute.cpp b/kode/kwsdl/schema/attribute.cpp
new file mode 100644
index 000000000..9be9be790
--- /dev/null
+++ b/kode/kwsdl/schema/attribute.cpp
@@ -0,0 +1,80 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "attribute.h"
+
+using namespace Schema;
+
+
+Attribute::Attribute( const QString &name, int type, bool qualified,
+ const QString &defaultValue, const QString &fixedValue,
+ bool use )
+ : mName( name ), mType( type ), mQualified( qualified ),
+ mDefaultValue( defaultValue ), mFixedValue( fixedValue ),
+ mUse( use )
+{
+}
+
+Attribute::Attribute()
+ : mType( 0 ), mQualified( false ), mUse( false )
+{
+}
+
+QString Attribute::name() const
+{
+ return mName;
+}
+
+int Attribute::type() const
+{
+ return mType;
+}
+
+void Attribute::setTypeName( const QString &typeName )
+{
+ mTypeName = typeName;
+}
+
+QString Attribute::typeName() const
+{
+ return mTypeName;
+}
+
+QString Attribute::defaultValue() const
+{
+ return mDefaultValue;
+}
+
+QString Attribute::fixedValue() const
+{
+ return mFixedValue;
+}
+
+bool Attribute::isQualified() const
+{
+ return mQualified;
+}
+
+bool Attribute::isUsed() const
+{
+ return mUse;
+}
diff --git a/kode/kwsdl/schema/attribute.h b/kode/kwsdl/schema/attribute.h
new file mode 100644
index 000000000..62db99d7d
--- /dev/null
+++ b/kode/kwsdl/schema/attribute.h
@@ -0,0 +1,68 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_ATTRIBUTE_H
+#define SCHEMA_ATTRIBUTE_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+namespace Schema {
+
+class Attribute
+{
+ public:
+ typedef QValueList<Attribute> List;
+ typedef QValueList<Attribute*> PtrList;
+
+ Attribute();
+
+ Attribute( const QString &name, int type, bool qualified = false,
+ const QString &defaultValue = QString(),
+ const QString &fixedValue = QString(),
+ bool use = true );
+
+ QString name() const;
+ int type() const;
+
+ void setTypeName( const QString &typeName );
+ QString typeName() const;
+
+ QString defaultValue() const;
+ QString fixedValue() const;
+
+ bool isQualified() const;
+ bool isUsed() const;
+
+ private:
+ QString mName;
+ int mType;
+ QString mTypeName;
+ bool mQualified;
+ QString mDefaultValue;
+ QString mFixedValue;
+ bool mUse;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/complextype.cpp b/kode/kwsdl/schema/complextype.cpp
new file mode 100644
index 000000000..418fdf92f
--- /dev/null
+++ b/kode/kwsdl/schema/complextype.cpp
@@ -0,0 +1,403 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "complextype.h"
+
+using namespace Schema;
+
+ComplexType::ComplexType( const QString &nameSpace )
+ : mNameSpace( nameSpace ), mType ( 0 ), mContentModel( COMPLEX ),
+ mMixed( false ), mAnonymous( false ), mIsArray( false ), mContentType( 0 ),
+ mTopLevelGroup( ALL ), mCurrentGroup( 0 ), mPreviousGroup( 0 ),
+ mForwardElementRef( false ), mForwardAttributeRef( false )
+{
+ mBaseType.typeId = XSDType::ANYTYPE;
+ mBaseType.derivation = Extension;
+ mBaseType.type = 0;
+}
+
+ComplexType::ComplexType()
+ : mType ( 0 ), mContentModel( COMPLEX ),
+ mMixed( false ), mAnonymous( false ), mIsArray( false ), mContentType( 0 ),
+ mTopLevelGroup( ALL ), mCurrentGroup( 0 ), mPreviousGroup( 0 ),
+ mForwardElementRef( false ), mForwardAttributeRef( false )
+{
+ mBaseType.typeId = XSDType::ANYTYPE;
+ mBaseType.derivation = Extension;
+ mBaseType.type = 0;
+}
+
+ComplexType::~ComplexType()
+{
+}
+
+QString ComplexType::name() const
+{
+ return mName;
+}
+
+QualifiedName ComplexType::qualifiedName() const
+{
+ QualifiedName qn( mName );
+ qn.setNameSpace( mNameSpace );
+ return qn;
+}
+
+void ComplexType::setDocumentation( const QString &documentation )
+{
+ mDocumentation = documentation;
+}
+
+QString ComplexType::documentation() const
+{
+ return mDocumentation;
+}
+
+int ComplexType::type() const
+{
+ return mType;
+}
+
+int ComplexType::contentModel() const
+{
+ return mContentModel;
+}
+
+int ComplexType::contentType() const
+{
+ return mContentType;
+}
+
+bool ComplexType::isSimple() const
+{
+ return false;
+}
+
+int ComplexType::attributeType( int index )
+{
+ return attribute( index )->type();
+}
+
+QString ComplexType::attributeName( int index )
+{
+ return attribute( index )->name();
+}
+
+int ComplexType::elementType( int index )
+{
+ return element( index )->type();
+}
+
+QString ComplexType::elementName( int index )
+{
+ return element( index )->name();
+}
+
+int ComplexType::numElements() const
+{
+ return mElements.count();
+}
+
+int ComplexType::numAttributes() const
+{
+ return mAttributes.count();
+}
+
+bool ComplexType::isAnonymous() const
+{
+ return mAnonymous;
+}
+
+void ComplexType::setBaseTypeName( const QString &baseTypeName )
+{
+ mBaseType.name = baseTypeName;
+}
+
+QString ComplexType::baseTypeName() const
+{
+ return mBaseType.name;
+}
+
+int ComplexType::baseType() const
+{
+ return mBaseType.typeId;
+}
+
+int ComplexType::baseDerivation() const
+{
+ return mBaseType.derivation;
+}
+
+ComplexType::Compositor ComplexType::topLevelGroup() const
+{
+ return mTopLevelGroup;
+}
+
+ComplexType::Compositor ComplexType::groupType( int groupId ) const
+{
+ return mGroups[ groupId ].type;
+}
+
+const Element *ComplexType::element( const QString &name )
+{
+ Element::List::ConstIterator it;
+ for ( it = mElements.begin(); it != mElements.end(); ++it ) {
+ if ( (*it).name() == name )
+ return &(*it);
+ }
+
+ return 0;
+}
+
+Element *ComplexType::element( int id )
+{
+ if ( id < 0 || id >= (int)mElements.count() ) {
+ qDebug( "tried to access non existent element" );
+ return 0;
+ }
+
+ Element::List::Iterator it = mElements.begin();
+ for ( int i = 0; i < (int)mElements.count(); ++i, ++it )
+ if ( id == i )
+ return &(*it);
+
+ return 0;
+}
+
+const Attribute *ComplexType::attribute( const QString &name )
+{
+ Attribute::List::ConstIterator it;
+ for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
+ if ( (*it).name() == name )
+ return &(*it);
+ }
+
+ return 0;
+}
+
+Attribute *ComplexType::attribute( int id )
+{
+ if ( id < 0 || id >= (int)mAttributes.count() ) {
+ qDebug( "tried to access non existent attributes" );
+ return 0;
+ }
+
+ Attribute::List::Iterator it = mAttributes.begin();
+ for ( int i = 0; i < (int)mAttributes.count(); ++i, ++it )
+ if ( id == i )
+ return &(*it);
+
+ return 0;
+}
+
+void ComplexType::setElements( const Element::List &elements )
+{
+ mElements = elements;
+}
+
+Element::List ComplexType::elements() const
+{
+ return mElements;
+}
+
+void ComplexType::setAttributes( const Attribute::List &attributes )
+{
+ mAttributes = attributes;
+}
+
+Attribute::List ComplexType::attributes() const
+{
+ return mAttributes;
+}
+
+bool ComplexType::isArray() const
+{
+ return mIsArray;
+}
+
+void ComplexType::setType( int type )
+{
+ mType = type;
+}
+void ComplexType::setIsArray( bool isArray )
+{
+ mIsArray = isArray;
+}
+void ComplexType::setBaseType( int type, Derivation derivation, const XSDType *ptr )
+{
+ mBaseType.typeId = type;
+ mBaseType.derivation = derivation;
+ mBaseType.type = ptr;
+}
+
+void ComplexType::setAnonymous( bool anonymous )
+{
+ mAnonymous = anonymous;
+}
+
+void ComplexType::setName( const QString &name )
+{
+ mName = name;
+}
+
+void ComplexType::setContentType( int contentType )
+{
+ mContentType = contentType;
+}
+
+void ComplexType::setContentModel( int model )
+{
+ mContentModel = model;
+ if ( mContentModel == MIXED ) {
+ mMixed = true;
+ qDebug( "Mixed content not supported" );
+ } else
+ mMixed = false;
+}
+
+void ComplexType::addAttribute( const QString &name, int type_id, bool qualified,
+ const QString &defaultValue, const QString &fixedValue,
+ bool use )
+{
+ if ( type_id == 0 ) {
+ qDebug( "ComplexType:addAttribute(): No type given for attribute" );
+ return;
+ }
+
+ Attribute attribute( name, type_id, qualified, defaultValue, fixedValue, use );
+
+ Attribute *attributePtr = (Attribute*)this->attribute( name );
+ if ( attributePtr )
+ *attributePtr = attribute;
+ else
+ mAttributes.append( attribute );
+}
+
+
+void ComplexType::addAttributeRef( const QualifiedName &name, bool qualified, bool use )
+{
+ addAttribute( name.localName(), XSDType::ANYTYPE, qualified, QString(), QString(), use );
+ mForwardAttributeRef = true;
+}
+
+
+void ComplexType::addElement( const QString &name, int type_id, int minOccurs,
+ int maxOccurs, bool qualified,
+ const QString &defaultValue, const QString &fixedValue,
+ const QString &documentation )
+{
+ if ( type_id == 0 ) {
+ qDebug( "ComplexType:addElement() :No type given for element " );
+ return;
+ }
+
+ if ( mTopLevelGroup == ALL && maxOccurs > 1 && mIsArray == false ) {
+ qDebug( "Inside an <all> group elements can occur only once" );
+ return;
+ }
+
+ Element element( name, type_id, minOccurs, maxOccurs, qualified, defaultValue, fixedValue );
+ element.setGroupId( mCurrentGroup );
+ element.setDocumentation( documentation );
+ Element *elementPtr = (Element*)this->element( name );
+
+ if ( elementPtr )
+ *elementPtr = element;
+ else
+ mElements.append( element );
+}
+
+void ComplexType::addElementRef( const QualifiedName &name, int minOccurs, int maxOccurs )
+{
+ addElement( name.localName(), XSDType::ANYTYPE, minOccurs, maxOccurs );
+ mForwardElementRef = true;
+}
+
+void ComplexType::matchElementRef( const QString &name, Element &element )
+{
+ if ( mForwardElementRef ) {
+ Element *elementPtr = (Element*)this->element( name );
+ if ( elementPtr ) {
+ // these values are specific to the occurrence of the element inside another XML type
+ // so we shouldnt delete them
+ int min = elementPtr->minOccurs();
+ int max = elementPtr->maxOccurs();
+ int gId = elementPtr->groupId();
+ *elementPtr = element;
+ elementPtr->setMinOccurs( min );
+ elementPtr->setMaxOccurs( max );
+ elementPtr->setGroupId( gId );
+ }
+ }
+}
+
+void ComplexType::matchAttributeRef( const QString &name, Attribute &attribute )
+{
+ if ( mForwardAttributeRef ) {
+ Attribute *attributePtr = (Attribute*)this->attribute( name );
+ if ( attributePtr )
+ *attributePtr = attribute;
+ }
+}
+
+void ComplexType::setCompositor( Compositor type, bool open, int minOccurs, int maxOccurs )
+{
+ if ( open ) {
+ mPreviousGroup = mCurrentGroup++;
+ if ( mPreviousGroup == 0 )
+ mTopLevelGroup = type;
+ else if ( mTopLevelGroup == this->ALL ) {
+ qDebug( "This cannot occur inside a top level <all> compositor" );
+ return;
+ }
+
+ if ( type == this->ALL && mPreviousGroup != 0 ) {
+ qDebug( "<all> can occur only at the top level" );
+ return;
+ }
+
+ if ( type == this->ALL && (minOccurs != 1 || maxOccurs != 1) ) {
+ qDebug( "<all> can have min/max of only 1 " );
+ return;
+ }
+
+ mGroups.append( CompositorStruct( type, minOccurs, maxOccurs ) );
+ } else
+ mCurrentGroup = mPreviousGroup;
+}
+
+bool ComplexType::checkOccurrences()
+{
+ Element::List::ConstIterator it;
+ for ( it = mElements.begin(); it != mElements.end(); ++it )
+ if ( (*it).occurrence() < (*it).minOccurs() )
+ return false;
+
+ return true;
+}
+
+void ComplexType::resetCounters()
+{
+ Element::List::Iterator it;
+ for ( it = mElements.begin(); it != mElements.end(); ++it )
+ (*it).setOccurrence( 0 );
+}
diff --git a/kode/kwsdl/schema/complextype.h b/kode/kwsdl/schema/complextype.h
new file mode 100644
index 000000000..8664e007a
--- /dev/null
+++ b/kode/kwsdl/schema/complextype.h
@@ -0,0 +1,181 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_COMPLEXTYPE_H
+#define SCHEMA_COMPLEXTYPE_H
+
+#include <qstring.h>
+
+#include "attribute.h"
+#include "element.h"
+#include "qualifiedname.h"
+#include "xsdtype.h"
+
+namespace Schema {
+
+class ComplexType : public XSDType
+{
+ public:
+ typedef QValueList<ComplexType> List;
+
+ typedef enum {
+ SEQ = 0,
+ CHOICE,
+ ALL
+ } Compositor;
+
+ typedef enum {
+ Restriction,
+ Extension
+ } Derivation;
+
+ ComplexType();
+ ComplexType( const QString& );
+ ~ComplexType();
+
+ void setName( const QString &name );
+ QString name() const;
+
+ QualifiedName qualifiedName() const;
+
+ void setDocumentation( const QString &documentation );
+ QString documentation() const;
+
+ void setType( int type );
+ int type() const;
+
+ void setContentType( int contentType );
+ int contentType() const;
+
+ void setContentModel( int model );
+ int contentModel() const;
+
+ bool isSimple() const;
+
+ int attributeType( int index );
+ QString attributeName( int index );
+
+ int elementType( int index );
+ QString elementName( int index );
+
+ int numElements() const;
+ int numAttributes() const;
+
+ void setAnonymous( bool anonymous );
+ bool isAnonymous() const;
+
+ void setBaseType( int type, Derivation derivation, const XSDType *ptr );
+ void setBaseTypeName( const QString &baseTypeName );
+
+ int baseType() const;
+ int baseDerivation() const;
+ QString baseTypeName() const;
+
+ Compositor topLevelGroup() const;
+ Compositor groupType( int groupId ) const;
+
+ const Element *element( const QString &name );
+ const Attribute *attribute( const QString &name );
+ Element *element( int id );
+ Attribute *attribute( int id );
+
+ void setElements( const Element::List &elements );
+ Element::List elements() const;
+
+ void setAttributes( const Attribute::List &attributes );
+ Attribute::List attributes() const;
+
+ void setIsArray( bool isArray );
+ bool isArray() const;
+
+ void setCompositor( Compositor type, bool open = true, int minOccurs = 1, int maxOccurs = 1 );
+
+ void addAttribute( const QString &name, int type_id, bool qualified = false,
+ const QString &defaultValue = QString(),
+ const QString &fixedValue = QString(),
+ bool use = false );
+ void addAttributeRef( const QualifiedName &name, bool qualified, bool use );
+
+ void addElement( const QString &name, int type_id, int minOccurs = 1,
+ int maxOccurs = 1, bool qualified = false,
+ const QString &defaultValue = QString(),
+ const QString &fixedValue = QString(),
+ const QString &documentation = QString() );
+ void addElementRef( const QualifiedName &name, int minOccurs, int maxOccurs );
+
+ void matchAttributeRef( const QString &name, Attribute &attribute );
+ void matchElementRef( const QString &name, Element &element );
+
+ bool checkOccurrences();
+ void resetCounters();
+
+ private:
+ QString mName;
+ QString mNameSpace;
+ QString mDocumentation;
+ int mType;
+
+ Element::List mElements;
+ Attribute::List mAttributes;
+
+ int mContentModel;
+ bool mMixed;
+ bool mAnonymous;
+ bool mIsArray;
+ int mContentType;
+
+ struct
+ {
+ int typeId;
+ Derivation derivation;
+ const XSDType *type;
+ QString name;
+ } mBaseType;
+
+ struct CompositorStruct
+ {
+ CompositorStruct()
+ {
+ }
+
+ CompositorStruct( Compositor _type, int min = 1, int max = 1 )
+ : type( _type ), minOccurs( min ), maxOccurs( max )
+ {
+ }
+
+ Compositor type;
+ int minOccurs;
+ int maxOccurs;
+ };
+
+ QValueList<struct CompositorStruct> mGroups;
+
+ Compositor mTopLevelGroup;
+ int mCurrentGroup;
+ int mPreviousGroup;
+ bool mForwardElementRef;
+ bool mForwardAttributeRef;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/element.cpp b/kode/kwsdl/schema/element.cpp
new file mode 100644
index 000000000..bfb745e2b
--- /dev/null
+++ b/kode/kwsdl/schema/element.cpp
@@ -0,0 +1,130 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "element.h"
+
+using namespace Schema;
+
+
+Element::Element()
+ : mType( 0 ), mMinOccurs( 1 ), mMaxOccurs( 1 ), mQualified( false ),
+ mOccurrence( 0 )
+{
+}
+
+Element::Element( const QString &name, int type, int minOccurs, int maxOccurs,
+ bool qualified, const QString &defaultValue, const QString &fixedValue )
+ : mName( name ), mType( type ), mMinOccurs( minOccurs ), mMaxOccurs( maxOccurs ),
+ mQualified( qualified ), mDefaultValue( defaultValue ), mFixedValue( fixedValue ),
+ mOccurrence( 0 )
+{
+}
+
+QString Element::name() const
+{
+ return mName;
+}
+
+void Element::setType( int type )
+{
+ mType = type;
+}
+
+int Element::type() const
+{
+ return mType;
+}
+
+void Element::setTypeName( const QString &typeName )
+{
+ mTypeName = typeName;
+}
+
+QString Element::typeName() const
+{
+ return mTypeName;
+}
+
+void Element::setDocumentation( const QString &documentation )
+{
+ mDocumentation = documentation;
+}
+
+QString Element::documentation() const
+{
+ return mDocumentation;
+}
+
+void Element::setGroupId( int group )
+{
+ mGroupId = group;
+}
+
+int Element::groupId() const
+{
+ return mGroupId;
+}
+
+void Element::setMinOccurs( int minOccurs )
+{
+ mMinOccurs = minOccurs;
+}
+
+int Element::minOccurs() const
+{
+ return mMinOccurs;
+}
+
+void Element::setMaxOccurs( int maxOccurs )
+{
+ mMaxOccurs = maxOccurs;
+}
+
+int Element::maxOccurs() const
+{
+ return mMaxOccurs;
+}
+
+QString Element::defaultValue() const
+{
+ return mDefaultValue;
+}
+
+QString Element::fixedValue() const
+{
+ return mFixedValue;
+}
+
+bool Element::isQualified() const
+{
+ return mQualified;
+}
+
+void Element::setOccurrence( int occurrence )
+{
+ mOccurrence = occurrence;
+}
+
+int Element::occurrence() const
+{
+ return mOccurrence;
+}
diff --git a/kode/kwsdl/schema/element.h b/kode/kwsdl/schema/element.h
new file mode 100644
index 000000000..6335693f6
--- /dev/null
+++ b/kode/kwsdl/schema/element.h
@@ -0,0 +1,89 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_ELEMENT_H
+#define SCHEMA_ELEMENT_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+#define UNBOUNDED 1000
+
+namespace Schema {
+
+class Element
+{
+ public:
+ typedef QValueList<Element> List;
+ typedef QValueList<Element*> PtrList;
+
+ Element();
+
+ Element( const QString &name, int type, int minOccurs = 1, int maxOccurs = 1,
+ bool qualified = false, const QString &defaultValue = QString(),
+ const QString &fixedValue = QString() );
+
+ QString name() const;
+
+ void setType( int id );
+ int type() const;
+
+ void setTypeName( const QString &typeName );
+ QString typeName() const;
+
+ void setDocumentation( const QString &documentation );
+ QString documentation() const;
+
+ void setGroupId( int group );
+ int groupId() const;
+
+ void setMinOccurs( int minOccurs );
+ int minOccurs() const;
+
+ void setMaxOccurs( int maxOccurs );
+ int maxOccurs() const;
+
+ QString defaultValue() const;
+ QString fixedValue() const;
+
+ bool isQualified() const;
+
+ void setOccurrence( int occurrence );
+ int occurrence() const;
+
+ private:
+ QString mName;
+ int mType;
+ QString mTypeName;
+ QString mDocumentation;
+ int mMinOccurs;
+ int mMaxOccurs;
+ bool mQualified;
+ QString mDefaultValue;
+ QString mFixedValue;
+ int mGroupId;
+ int mOccurrence;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/fileprovider.cpp b/kode/kwsdl/schema/fileprovider.cpp
new file mode 100644
index 000000000..642592bf4
--- /dev/null
+++ b/kode/kwsdl/schema/fileprovider.cpp
@@ -0,0 +1,105 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include <unistd.h>
+
+#include <qapplication.h>
+#include <qeventloop.h>
+#include <qfile.h>
+
+#include <kio/job.h>
+#include <ktempfile.h>
+
+#include "fileprovider.h"
+
+using namespace Schema;
+
+FileProvider::FileProvider()
+ : QObject( 0 ), mBlocked( false )
+{
+}
+
+bool FileProvider::get( const QString &url, QString &target )
+{
+ if ( !mFileName.isEmpty() )
+ cleanUp();
+
+ if ( target.isEmpty() ) {
+ KTempFile tmpFile;
+ target = tmpFile.name();
+ mFileName = target;
+ }
+
+ mData.truncate( 0 );
+
+ qDebug( "Downloading external schema '%s'", url.latin1() );
+
+ KIO::TransferJob* job = KIO::get( KURL( url ), false, false );
+ connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
+ this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) );
+ connect( job, SIGNAL( result( KIO::Job* ) ),
+ this, SLOT( slotResult( KIO::Job* ) ) );
+
+ mBlocked = true;
+ while ( mBlocked ) {
+ qApp->eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
+ usleep( 500 );
+ }
+
+ return true;
+}
+
+void FileProvider::cleanUp()
+{
+ ::unlink( QFile::encodeName( mFileName ) );
+ mFileName = QString();
+}
+
+void FileProvider::slotData( KIO::Job*, const QByteArray &data )
+{
+ unsigned int oldSize = mData.size();
+ mData.resize( oldSize + data.size() );
+ memcpy( mData.data() + oldSize, data.data(), data.size() );
+}
+
+void FileProvider::slotResult( KIO::Job *job )
+{
+ if ( job->error() ) {
+ qDebug( "%s", job->errorText().latin1() );
+ return;
+ }
+
+ QFile file( mFileName );
+ if ( !file.open( IO_WriteOnly ) ) {
+ qDebug( "Unable to create temporary file" );
+ return;
+ }
+
+ qDebug( "Download successful" );
+ file.writeBlock( mData );
+ file.close();
+
+ mData.truncate( 0 );
+
+ mBlocked = false;
+}
+
+#include "fileprovider.moc"
diff --git a/kode/kwsdl/schema/fileprovider.h b/kode/kwsdl/schema/fileprovider.h
new file mode 100644
index 000000000..8b2903c50
--- /dev/null
+++ b/kode/kwsdl/schema/fileprovider.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_FILEPROVIDER_H
+#define SCHEMA_FILEPROVIDER_H
+
+#include <qobject.h>
+
+namespace KIO {
+class Job;
+}
+
+namespace Schema {
+
+class FileProvider : QObject
+{
+ Q_OBJECT
+
+ public:
+ FileProvider();
+
+ bool get( const QString &url, QString &target );
+ void cleanUp();
+
+ private slots:
+ void slotData( KIO::Job*, const QByteArray& );
+ void slotResult( KIO::Job* );
+
+ private:
+ QString mFileName;
+ QByteArray mData;
+ bool mBlocked;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/parser.cpp b/kode/kwsdl/schema/parser.cpp
new file mode 100644
index 000000000..ec0daabe4
--- /dev/null
+++ b/kode/kwsdl/schema/parser.cpp
@@ -0,0 +1,1095 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include <qdir.h>
+#include <qfile.h>
+#include <qurl.h>
+
+#include "fileprovider.h"
+#include "parser.h"
+
+using namespace Schema;
+
+const QString soapEncUri = "http://schemas.xmlsoap.org/soap/encoding/";
+const QString wsdlUri = "http://schemas.xmlsoap.org/wsdl/";
+
+
+Parser::Parser( const QString &nameSpace )
+ : mNameSpace( nameSpace )
+{
+ mElementQualified = false;
+ mAttributeQualified = false;
+}
+
+Parser::~Parser()
+{
+ clear();
+}
+
+Types Parser::types() const
+{
+ Types types;
+
+ SimpleType::List simpleTypes;
+ ComplexType::List complexTypes;
+
+ for ( int i = 0; i < numTypes(); i++ ) {
+ const XSDType *pType = type( i + XSDType::ANYURI + 1 );
+ if ( pType != 0 ) {
+ if ( pType->isSimple() ) {
+ const SimpleType *simpleType = static_cast<const SimpleType*>( pType );
+
+ SimpleType type = *simpleType;
+ type.setBaseTypeName( mTypesTable.typeName( type.baseType() ) );
+ type.setListTypeName( mTypesTable.typeName( type.listType() ) );
+
+ simpleTypes.append( type );
+ } else {
+ const ComplexType *complexType = static_cast<const ComplexType*>( pType );
+
+ ComplexType type = *complexType;
+ type.setBaseTypeName( mTypesTable.typeName( type.baseType() ) );
+
+ Schema::Element::List elements = type.elements();
+ Schema::Element::List::Iterator elemIt;
+ for ( elemIt = elements.begin(); elemIt != elements.end(); ++elemIt )
+ (*elemIt).setTypeName( mTypesTable.typeName( (*elemIt).type() ) );
+ type.setElements( elements );
+
+ Schema::Attribute::List attributes = type.attributes();
+ Schema::Attribute::List::Iterator attrIt;
+ for ( attrIt = attributes.begin(); attrIt != attributes.end(); ++attrIt )
+ (*attrIt).setTypeName( mTypesTable.typeName( (*attrIt).type() ) );
+ type.setAttributes( attributes );
+
+ complexTypes.append( type );
+ }
+ }
+ }
+
+ Element::List elements;
+
+ for ( uint i = 0; i < mElements.count(); ++i ) {
+ Element element = *mElements[ i ];
+ element.setTypeName( mTypesTable.typeName( element.type() ) );
+ elements.append( element );
+ }
+
+ types.setSimpleTypes( simpleTypes );
+ types.setComplexTypes( complexTypes );
+ types.setElements( elements );
+
+ return types;
+}
+
+void Parser::clear()
+{
+ mTypesTable.clear();
+ mImportedSchemas.clear();
+
+ for ( uint i = 0; i < mElements.count(); ++i )
+ delete mElements[ i ];
+
+ for ( uint i = 0; i < mAttributes.count(); ++i )
+ delete mAttributes[ i ];
+}
+
+void Parser::setSchemaBaseUrl( const QString &url )
+{
+ mSchemaBaseUrl = url;
+}
+
+void Parser::parseNameSpace( const QDomElement &element )
+{
+ QDomNamedNodeMap attributes = element.attributes();
+ for ( uint i = 0; i < attributes.count(); ++i ) {
+ QDomNode node = attributes.item( i );
+ QDomAttr attribute = node.toAttr();
+
+ if ( attribute.name().startsWith( "xmlns:" ) )
+ mNameSpaceMap.insert( attribute.value(), attribute.name().mid( 6 ) );
+ }
+}
+
+bool Parser::parseSchemaTag( const QDomElement &root )
+{
+ QualifiedName name = root.tagName();
+ if ( name.localName() != "schema" )
+ return false;
+
+ if ( root.hasAttribute( "targetNamespace" ) )
+ mNameSpace = root.attribute( "targetNamespace" );
+
+ if ( root.hasAttribute( "elementFormDefault" ) ) {
+ const QString value = root.attribute( "elementFormDefault" );
+ if ( value == "unqualified" )
+ mElementQualified = false;
+ else if ( value == "qualified" )
+ mElementQualified = true;
+ }
+
+ mTypesTable.setTargetNamespace( mNameSpace );
+
+/*
+ for (i = xParser->getNamespaceCount(xParser->getDepth()) - 1;
+ i > xParser->getNamespaceCount(xParser->getDepth() - 1) - 1; i--)
+ if (xParser->getNamespaceUri(i) == mNameSpace)
+ m_tnsPrefix = xParser->getNamespacePrefix(i);
+*/
+
+ QDomNode node = root.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+
+ QualifiedName name = element.tagName();
+ if ( name.localName() == "import" ) {
+ parseImport( element );
+ } else if ( name.localName() == "element" ) {
+ parseElement( element );
+ } else if ( name.localName() == "complexType" ) {
+ XSDType *type = parseComplexType( element );
+ mTypesTable.addType( type );
+ } else if ( name.localName() == "simpleType" ) {
+ XSDType *type = parseSimpleType( element );
+ mTypesTable.addType( type );
+ } else if ( name.localName() == "attribute" ) {
+ parseAttribute( element );
+ } else if ( name.localName() == "annotation" ) {
+ parseAnnotation( element );
+ } else if ( name.localName() == "import" ) {
+ // TODO
+ } else if ( name.localName() == "include" ) {
+ // TODO
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+ if ( shouldResolve() ) {
+ resolveForwardElementRefs();
+ resolveForwardAttributeRefs();
+ resolveForwardDerivations();
+ }
+
+ return true;
+}
+
+void Parser::parseImport( const QDomElement &element )
+{
+ QString location = element.attribute( "schemaLocation" );
+ if ( !location.isEmpty() ) {
+ // don't import a schema twice
+ if ( mImportedSchemas.contains( location ) )
+ return;
+ else
+ mImportedSchemas.append( location );
+
+ importSchema( location );
+ }
+}
+
+void Parser::parseAnnotation( const QDomElement& )
+{
+}
+
+void Parser::parseAnnotation( const QDomElement &element, QString &documentation )
+{
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "documentation" )
+ documentation = childElement.text().stripWhiteSpace();
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseAnnotation( const QDomElement &element, ComplexType *complexType )
+{
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "documentation" )
+ complexType->setDocumentation( childElement.text().stripWhiteSpace() );
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseAnnotation( const QDomElement &element, SimpleType *simpleType )
+{
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "documentation" )
+ simpleType->setDocumentation( childElement.text().stripWhiteSpace() );
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+XSDType *Parser::parseComplexType( const QDomElement &element )
+{
+ ComplexType *newType = new ComplexType( mNameSpace );
+
+ newType->setName( element.attribute( "name" ) );
+ if ( element.hasAttribute( "mixed" ) )
+ newType->setContentModel( newType->MIXED );
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "all" ) {
+ all( childElement, newType );
+ } else if ( name.localName() == "sequence" ) {
+ cs( childElement, newType );
+ } else if ( name.localName() == "choice" ) {
+ cs( childElement, newType );
+ } else if ( name.localName() == "attribute" ) {
+ addAttribute( childElement, newType );
+ } else if ( name.localName() == "anyAttribute" ) {
+ addAnyAttribute( childElement, newType );
+ } else if ( name.localName() == "complexContent" ) {
+ parseComplexContent( childElement, newType );
+ } else if ( name.localName() == "simpleContent" ) {
+ parseSimpleContent( childElement, newType );
+ } else if ( name.localName() == "annotation" ) {
+ parseAnnotation( childElement, newType );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+ return newType;
+}
+
+void Parser::all( const QDomElement &element, ComplexType * ct )
+{
+ int min, max;
+ QString tmp;
+
+ min = element.attribute( "minOccurs", "1" ).toInt();
+ max = element.attribute( "maxOccurs", "1" ).toInt();
+ ct->setCompositor( ct->ALL, true, min, max );
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "element" ) {
+ addElement( childElement, ct );
+ } else if ( name.localName() == "annotation" ) {
+ parseAnnotation( childElement, ct );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+/*
+ if (xParser->getName() == "all"
+ && xParser->getEventType() == xParser->END_TAG)
+ ct->setCompositor(ct->ALL, false);
+*/
+
+ return;
+}
+
+
+void Parser::cs( const QDomElement &element, ComplexType *ct )
+{
+ int min = 1, max = 1;
+
+ QualifiedName name = element.tagName();
+ if ( name.localName() == "choice" || name.localName() == "sequence" ) {
+ min = element.attribute( "minOccurs", "1" ).toInt();
+ QString value = element.attribute( "maxOccurs", "1" );
+ if ( value == "unbounded" )
+ max = UNBOUNDED;
+ else
+ max = value.toInt();
+
+ if ( name.localName() == "choice" )
+ ct->setCompositor( ct->CHOICE, true, min, max );
+ else
+ ct->setCompositor( ct->SEQ, true, min, max );
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+ QualifiedName csName = childElement.tagName();
+ if ( csName.localName() == "element" )
+ addElement( childElement, ct );
+ else if ( csName.localName() == "any" )
+ addAny( childElement, ct );
+ else if ( csName.localName() == "choice" )
+ cs( childElement, ct );
+ else if ( csName.localName() == "sequence" )
+ cs( childElement, ct );
+ }
+
+ node = node.nextSibling();
+ }
+
+ if ( name.localName() == "choice")
+ ct->setCompositor( ct->CHOICE, false );
+ else
+ ct->setCompositor( ct->SEQ, false );
+ }
+
+ return;
+}
+
+void Parser::addElement( const QDomElement &element, ComplexType *cType )
+{
+ QString name, fixedValue, defaultValue, documentation;
+ QualifiedName refName;
+ int type_id = 0, minOccurs = 1, maxOccurs = 1;
+ bool qualified = false, added = false, nill = false;
+ XSDType *elemType;
+
+ name = element.attribute( "name" );
+ QualifiedName typeName = element.attribute( "type" );
+// typeName.setNamespace(xParser->getNamespace(typeName.getPrefix()));
+ type_id = typeId( typeName, true );
+
+ if ( element.hasAttribute( "form" ) ) {
+ if ( element.attribute( "form" ) == "qualified" )
+ qualified = true;
+ else if ( element.attribute( "form" ) == "unqualified" )
+ qualified = false;
+ }
+
+ if ( element.hasAttribute( "ref" ) ) {
+ refName = element.attribute( "ref" );
+// refName.setNamespace(xParser->getNamespace(refName.getPrefix()));
+
+ Element *e = 0;
+ if ( refName.nameSpace() == mNameSpace )
+ e = this->element( elementId( refName ) );
+
+ if ( e == 0 ) {
+ added = true;
+ mForwardElementRef.append( refName );
+ } else {
+ name = e->name();
+ type_id = e->type();
+ qualified = e->isQualified();
+ defaultValue = e->defaultValue();
+ fixedValue = e->fixedValue();
+ }
+ }
+
+ minOccurs = element.attribute( "minOccurs", "1" ).toInt();
+ QString value = element.attribute( "maxOccurs", "1" );
+ if ( value == "unbounded" )
+ maxOccurs = UNBOUNDED;
+ else
+ maxOccurs = value.toInt();
+
+ defaultValue = element.attribute( "default" );
+ fixedValue = element.attribute( "fixed" );
+
+ if ( element.hasAttribute( "nillable" ) )
+ nill = true;
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+
+ QualifiedName childName = childElement.tagName();
+ if ( childName.localName() == "complexType" ) {
+ elemType = parseComplexType( childElement );
+
+ // create an anonymous type
+ ComplexType *ct = (ComplexType *) elemType;
+ if ( ct->numElements() == 1
+ && ct->elementType( 0 ) == XSDType::ANY
+ && ct->elementName( 0 ) == "any" ) {
+
+ // if the complex type is <any> then we dont need a type for it.
+ // make the parent's type as XSDType::ANY
+ delete ct;
+ type_id = XSDType::ANY;
+ } else {
+ elemType->setName( name );
+ type_id = mTypesTable.addType( elemType );
+ }
+ } else if ( childName.localName() == "simpleType" ) {
+ elemType = parseSimpleType( childElement );
+
+ //create an anonymous type
+ type_id = mTypesTable.addType( elemType );
+ } else if ( childName.localName() == "annotation" ) {
+ parseAnnotation( childElement, documentation );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+ if ( nill && type_id == 0 )
+ type_id = XSDType::ANYTYPE;
+
+ if ( !added ) {
+ cType->addElement( name, type_id, minOccurs, maxOccurs, qualified, defaultValue, fixedValue, documentation );
+ } else {
+ cType->addElementRef( refName, minOccurs, maxOccurs );
+ }
+}
+
+void Parser::addAny( const QDomElement &element, ComplexType *cType )
+{
+ QString ns, any( "any" );
+ int type_id = XSDType::ANY, min = 1, max = 1;
+
+ ns = element.attribute( "namespace" );
+ min = element.attribute( "minOccurs", "1" ).toInt();
+ QString value = element.attribute( "maxOccurs", "1" );
+ if ( value == "unbounded" )
+ max = UNBOUNDED;
+ else
+ max = value.toInt();
+
+ cType->addElement( any, type_id, min, max, false, ns );
+}
+
+void Parser::addAnyAttribute( const QDomElement &element, ComplexType *cType )
+{
+ QString ns, anyAttribute( "anyAttribute" );
+
+ ns = element.attribute( "namespace" );
+
+ cType->addAttribute( anyAttribute, XSDType::ANY, false, ns );
+}
+
+void Parser::addAttribute( const QDomElement &element, ComplexType *cType )
+{
+ QString name, fixedVal, defaultVal;
+ int type_id = 0;
+ bool qualified = false, use = false, added = false;
+ QualifiedName refAttribute;
+
+ name = element.attribute( "name" );
+
+ if ( element.hasAttribute( "type" ) ) {
+ QualifiedName typeName = element.attribute( "type" );
+// typeName.setNamespace(xParser->getNamespace(typeName.getPrefix()));
+ type_id = typeId( typeName, true );
+ }
+
+ if ( element.hasAttribute( "form" ) ) {
+ if ( element.attribute( "form" ) == "qualified" )
+ qualified = true;
+ else if ( element.attribute( "form" ) == "unqualified" )
+ qualified = false;
+ }
+
+ if ( element.hasAttribute( "ref" ) ) {
+ refAttribute = element.attribute( "ref" );
+// refAttribute.setNamespace(xParser->getNamespace(refAttribute.getPrefix()));
+
+ Attribute *attribute = 0;
+ if ( refAttribute.nameSpace() == mNameSpace )
+ attribute = this->attribute( attributeId( refAttribute ) );
+
+ if ( attribute == 0 ) {
+ added = true;
+ mForwardAttributeRef.append( refAttribute );
+ } else {
+ name = attribute->name();
+ type_id = attribute->type();
+ qualified = attribute->isQualified();
+ defaultVal = attribute->defaultValue();
+ fixedVal = attribute->fixedValue();
+ }
+ }
+
+ defaultVal = element.attribute( "default" );
+ fixedVal = element.attribute( "fixed" );
+
+ if ( element.hasAttribute( "use" ) ) {
+ if ( element.attribute( "use" ) == "optional" )
+ use = false;
+ else if ( element.attribute( "use" ) == "required" )
+ use = true;
+ }
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+
+ QualifiedName childName = childElement.tagName();
+ if ( childName.localName() == "simpleType" ) {
+ XSDType *elemType = parseSimpleType( childElement );
+
+ elemType->setName( name );
+ type_id = mTypesTable.addType( elemType );
+ } else if ( childName.localName() == "annotation" ) {
+ // TKO: we have to pass it to the element here...
+ parseAnnotation( childElement );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+ if ( !added )
+ cType->addAttribute( name, type_id, qualified, defaultVal, fixedVal, use );
+ else
+ cType->addAttributeRef( refAttribute, qualified, use );
+}
+
+XSDType *Parser::parseSimpleType( const QDomElement &element )
+{
+ SimpleType *st = new SimpleType( mNameSpace );
+
+ int basetype_id = XSDType::INVALID;
+
+ st->setName( element.attribute( "name" ) );
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "restriction" ) {
+ st->setSubType( SimpleType::TypeRestriction );
+
+ QualifiedName typeName( childElement.attribute( "base" ) );
+// typeName.setNamespace(xParser->getNamespace(typeName.getPrefix()));
+ st->setBaseType( basetype_id = typeId( typeName, true ) );
+
+ parseRestriction( childElement, st );
+ } else if ( name.localName() == "union" ) {
+ st->setSubType( SimpleType::TypeUnion );
+ qDebug( "simpletype::union not supported" );
+ } else if ( name.localName() == "list" ) {
+ st->setSubType( SimpleType::TypeList );
+ if ( childElement.hasAttribute( "itemType" ) ) {
+ QualifiedName typeName( childElement.attribute( "itemType" ) );
+ int type = typeId( typeName, true );
+ st->setListType( type );
+ } else {
+ // TODO: add support for anonymous types
+ }
+ } else if ( name.localName() == "annotation" ) {
+ parseAnnotation( childElement, st );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+
+ return st;
+}
+
+void Parser::parseRestriction( const QDomElement &element, SimpleType *st )
+{
+ if ( st->baseType() == 0 )
+ qDebug( "<restriction>:unkown BaseType" );
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+
+ if ( !st->isValidFacet( childElement.tagName() ) ) {
+ qDebug( "<restriction>: %s is not a valid facet for the simple type", childElement.tagName().latin1() );
+ continue;
+ }
+
+ st->setFacetValue( childElement.attribute( "value" ) );
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseComplexContent( const QDomElement &element, ComplexType *ct )
+{
+ QualifiedName typeName;
+
+ if ( element.attribute( "mixed" ) == "true" ) {
+ qDebug( "<complexContent>: No support for mixed=true" );
+ return;
+ }
+
+ ct->setContentModel( ct->COMPLEX );
+
+ QDomNode node = element.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement childElement = node.toElement();
+ if ( !childElement.isNull() ) {
+ QualifiedName name = childElement.tagName();
+
+ if ( name.localName() == "restriction" || name.localName() == "extension" ) {
+ typeName = childElement.attribute( "base" );
+// typeName.setNamespace(xParser->getNamespace(typeName.getPrefix()));
+
+ ComplexType::Derivation type = ( name.localName() == "restriction" ? ComplexType::Restriction : ComplexType::Extension );
+ if ( this->type( typeName ) != 0 ) { // type already known
+ ct->setBaseType( typeId( typeName, true ), type, this->type( typeName ) );
+ } else {
+ ForwardDerivation entry;
+ entry.type = ct->qualifiedName();
+ entry.baseType = typeName;
+ entry.derivation = type;
+ mForwardDerivations.append( entry );
+ }
+
+ // if the base soapenc:Array, then read only the arrayType attribute and nothing else
+ if ( typeName.localName() == "Array" ) {
+ QDomElement arrayElement = childElement.firstChild().toElement();
+ ct->setIsArray( true );
+
+ QualifiedName arrayType( arrayElement.attribute( "arrayType" ) );
+// arrayType.setNamespace(xParser->getNamespace(arrayType.getPrefix()));
+ ct->addElement( "item", typeId( arrayType, true ), 0, UNBOUNDED );
+ } else {
+ QDomNode childNode = childElement.firstChild();
+ while ( !childNode.isNull() ) {
+ QDomElement ctElement = childNode.toElement();
+ if ( !ctElement.isNull() ) {
+ QualifiedName name = ctElement.tagName();
+
+ if ( name.localName() == "all" ) {
+ all( ctElement, ct );
+ } else if ( name.localName() == "sequence" ) {
+ cs( ctElement, ct );
+ } else if ( name.localName() == "choice" ) {
+ cs( ctElement, ct );
+ } else if ( name.localName() == "attribute" ) {
+ addAttribute( ctElement, ct );
+ } else if ( name.localName() == "anyAttribute" ) {
+ addAnyAttribute( ctElement, ct );
+ }
+ }
+
+ childNode = childNode.nextSibling();
+ }
+ }
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::parseSimpleContent( const QDomElement &element, ComplexType *ct )
+{
+ ct->setContentModel( ct->SIMPLE );
+
+ const QDomElement childElement = element.firstChild().toElement();
+
+ QualifiedName name = childElement.tagName();
+ if ( name.localName() == "restriction" ) {
+ SimpleType *st = new SimpleType( mNameSpace );
+
+ if ( childElement.hasAttribute( "base" ) ) {
+ int basetype_id = 0;
+
+ QualifiedName typeName( childElement.attribute( "base" ) );
+// typeName.setNamespace(xParser->getNamespace(typeName.getPrefix()));
+ st->setBaseType( basetype_id = typeId( typeName, true ) );
+ }
+
+ parseRestriction( childElement, st );
+ int typeId = mTypesTable.addType( st );
+ if ( typeId == 0 ) {
+ qDebug( "Could not add type in types table" );
+ return;
+ }
+
+ ct->setContentType( typeId );
+ } else if ( name.localName() == "extension" ) {
+ // This extension does not use the full model that can come in ComplexContent.
+ // It uses the simple model. No particle allowed, only attributes
+
+ if ( childElement.hasAttribute( "base" ) ) {
+ int basetype_id = 0;
+
+ QualifiedName typeName( childElement.attribute( "base" ) );
+// typeName.setNamespace(xParser->getNamespace(typeName.getPrefix()));
+ ct->setContentType( basetype_id = typeId( typeName, true ) );
+
+ QDomNode childNode = childElement.firstChild();
+ while ( !childNode.isNull() ) {
+ QDomElement ctElement = childNode.toElement();
+ if ( !ctElement.isNull() ) {
+ QualifiedName name = ctElement.tagName();
+ if ( name.localName() == "attribute" )
+ addAttribute( ctElement, ct );
+ }
+
+ childNode = childNode.nextSibling();
+ }
+ }
+ }
+}
+
+bool Parser::isBasicType( int type ) const
+{
+ if ( type > XSDType::ANYURI )
+ return false;
+ else
+ return true;
+}
+
+void Parser::parseElement( const QDomElement &element )
+{
+ ComplexType *ct = new ComplexType( mNameSpace );
+ addElement( element, ct );
+
+ ComplexType *elementType = (ComplexType*)type( ct->element( 0 )->name() );
+ if ( elementType ) {
+ elementType->setDocumentation( ct->element( 0 )->documentation() );
+ }
+
+ Element *elementPtr = new Element();
+ *elementPtr = (*ct->element( 0 ));
+ delete ct;
+
+ mElements.append( elementPtr );
+}
+
+void Parser::parseAttribute( const QDomElement &element )
+{
+ ComplexType *ct = new ComplexType( mNameSpace );
+ addAttribute( element, ct );
+
+ Attribute *attributePtr = new Attribute();
+ *attributePtr = (*ct->attribute( 0 ));
+ delete ct;
+
+ mAttributes.append( attributePtr );
+}
+
+int Parser::addExternalElement( const QString &name, int localTypeId )
+{
+ Element *element = new Element( name, localTypeId );
+ mElements.append( element );
+
+ return mElements.count() - 1;
+}
+
+int Parser::typeId( const QualifiedName &type, bool create )
+{
+ QualifiedName typeName( type );
+
+ QString typens = typeName.nameSpace();
+ if ( typens.isEmpty() )
+ typeName.setNameSpace( typens = mNameSpace );
+
+ if ( typens == mNameSpace || typens == SchemaUri ) {
+ return mTypesTable.typeId( typeName, create );
+ } else {
+ return mTypesTable.addExternalTypeId( typeName, 0 );
+ }
+}
+
+QString Parser::typeName( int id ) const
+{
+ return mTypesTable.typeName( id );
+}
+
+bool Parser::finalize()
+{
+ if ( mTypesTable.detectUndefinedTypes() )
+ return false;
+ else
+ return true;
+}
+
+void Parser::resolveForwardElementRefs()
+{
+ if ( mForwardElementRef.isEmpty() )
+ return;
+
+ QualifiedName::List::ConstIterator it;
+ for ( it = mForwardElementRef.begin(); it != mForwardElementRef.end(); ++it ) {
+ Element *e = element( elementId( *it ) );
+ if ( e )
+ mTypesTable.resolveForwardElementRefs( (*it).localName(), *e );
+ else
+ qDebug( "Could not resolve element reference %s ", (*it).localName().latin1() );
+ }
+}
+
+
+void Parser::resolveForwardAttributeRefs()
+{
+ if ( mForwardAttributeRef.isEmpty() )
+ return;
+
+ QualifiedName::List::ConstIterator it;
+ for ( it = mForwardAttributeRef.begin(); it != mForwardAttributeRef.end(); ++it ) {
+ Attribute *a = attribute( attributeId( *it ) );
+ if ( a )
+ mTypesTable.resolveForwardAttributeRefs( (*it).localName(), *a );
+ else
+ qDebug( "Could not resolve attribute reference %s ", (*it).localName().latin1() );
+ }
+}
+
+void Parser::resolveForwardDerivations()
+{
+ if ( mForwardDerivations.isEmpty() )
+ return;
+
+ int id;
+ ComplexType *type = 0;
+
+ QValueList<ForwardDerivation>::ConstIterator it;
+ for ( it = mForwardDerivations.begin(); it != mForwardDerivations.end(); ++it ) {
+ if ( ( id = typeId( (*it).type, false ) ) == 0 )
+ continue;
+ else
+ type = (ComplexType*)mTypesTable.typePtr( id );
+
+ if ( type )
+ type->setBaseType( typeId( (*it).baseType, true ), (*it).derivation, this->type( (*it).baseType ) );
+ }
+
+ mForwardDerivations.clear();
+}
+
+int Parser::elementId( const QualifiedName &type )
+{
+ QualifiedName typeName( type );
+
+ QString typens = typeName.nameSpace();
+ if ( typens.isEmpty() )
+ typeName.setNameSpace( typens = mNameSpace );
+
+ int i = 0;
+
+ // check if it is a global element
+ for ( i = 0; i < (int)mElements.count(); i++ )
+ if ( mElements[ i ]->name() == typeName.localName() )
+ return i;
+
+ return -1;
+}
+
+int Parser::elementType( const QualifiedName &type )
+{
+ int id = elementId( type );
+
+ if ( id == -1 )
+ return 0;
+
+ Element *e = element( id );
+ if ( e != 0 )
+ return e->type();
+ else
+ return 0;
+}
+
+Element *Parser::element( const QualifiedName &name ) const
+{
+ QualifiedName elementName( name );
+
+ QString typens = elementName.nameSpace();
+ if ( typens.isEmpty() )
+ elementName.setNameSpace( typens = mNameSpace );
+
+ if ( typens == mNameSpace || typens == SchemaUri ) {
+ int i = 0;
+
+ // check if it is a global element
+ for ( i = 0; i < (int)mElements.count(); i++ )
+ if ( mElements[ i ]->name() == elementName.localName() )
+ return mElements[ i ];
+
+ return 0;
+ }
+
+ return 0;
+}
+
+Element *Parser::element( int id ) const
+{
+ if ( id >= 0 && id < (int)mElements.count() )
+ return mElements[ id ];
+ else
+ return 0;
+}
+
+Element::PtrList Parser::elements() const
+{
+ return mElements;
+}
+
+int Parser::attributeId( const QualifiedName &type ) const
+{
+ QualifiedName typeName( type );
+
+ QString typens = typeName.nameSpace();
+ if ( typens.isEmpty() )
+ typeName.setNameSpace( typens = mNameSpace );
+
+ if ( typens != mNameSpace && typens != SchemaUri ) {
+ qDebug( "Namespace does not match" );
+ return -1;
+ }
+
+ // check if it is a global attribute
+ for ( int i = 0; i < (int)mAttributes.count(); i++ )
+ if ( mAttributes[ i ]->name() == typeName.localName() )
+ return i;
+
+ return -1;
+}
+
+int Parser::attributeType( const QualifiedName &type )
+{
+ int attId = attributeId( type );
+ if ( attId == -1 )
+ return 0;
+
+ Attribute *a = attribute( attId );
+ if ( a != 0 )
+ return a->type();
+ else
+ return 0;
+}
+
+Attribute *Parser::attribute( int id ) const
+{
+ if ( id >= 0 && id < (int)mAttributes.count() )
+ return mAttributes[ id ];
+ else
+ return 0;
+}
+
+Attribute *Parser::attribute( const QualifiedName &name ) const
+{
+ int id = attributeId( name );
+ if ( id != -1 )
+ return mAttributes[ id ];
+ else
+ return 0;
+}
+
+QString Parser::targetNamespace() const
+{
+ return mNameSpace;
+}
+
+const XSDType *Parser::type( int id ) const
+{
+ return (const XSDType *)mTypesTable.typePtr( id );
+}
+
+const XSDType *Parser::type( const QualifiedName &type )
+{
+ int id;
+
+ if ( ( id = typeId( type, false ) ) == 0 )
+ return 0;
+ else
+ return (const XSDType *)mTypesTable.typePtr( id );
+}
+
+int Parser::numTypes() const
+{
+ return mTypesTable.numTypes();
+}
+
+int Parser::numElements() const
+{
+ return mElements.count();
+}
+
+int Parser::numAttributes() const
+{
+ return mAttributes.count();
+}
+
+bool Parser::shouldResolve()
+{
+ return true;
+}
+
+void Parser::importSchema( const QString &location )
+{
+ FileProvider provider;
+ QString fileName;
+ QString schemaLocation( location );
+
+ QUrl url( location );
+ QDir dir( location );
+
+ if ( (url.protocol().isEmpty() || url.protocol() == "file") && dir.isRelative() )
+ schemaLocation = mSchemaBaseUrl + "/" + location;
+
+ if ( provider.get( schemaLocation, fileName ) ) {
+ QFile file( fileName );
+ if ( !file.open( IO_ReadOnly ) ) {
+ qDebug( "Unable to open file %s", file.name().latin1() );
+ return;
+ }
+
+ QDomDocument doc( "kwsdl" );
+ QString errorMsg;
+ int errorLine, errorColumn;
+ bool ok = doc.setContent( &file, true, &errorMsg, &errorLine, &errorColumn );
+ if ( !ok ) {
+ qDebug( "Error[%d:%d] %s", errorLine, errorColumn, errorMsg.latin1() );
+ return;
+ }
+
+ QDomNodeList nodes = doc.elementsByTagName( "schema" );
+ if ( nodes.count() > 0 ) {
+ QDomElement schemaElement = nodes.item( 0 ).toElement();
+ parseSchemaTag( schemaElement );
+ } else {
+ qDebug( "No schema tag found in schema file" );
+ }
+
+ file.close();
+
+ provider.cleanUp();
+ }
+}
diff --git a/kode/kwsdl/schema/parser.h b/kode/kwsdl/schema/parser.h
new file mode 100644
index 000000000..afaf3dae6
--- /dev/null
+++ b/kode/kwsdl/schema/parser.h
@@ -0,0 +1,139 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_PARSER_H
+#define SCHEMA_PARSER_H
+
+#include <qdom.h>
+#include <qvaluelist.h>
+
+#include "types.h"
+#include "typestable.h"
+
+namespace Schema {
+
+class Parser
+{
+ public:
+ Parser( const QString &nameSpace = QString() );
+
+ ~Parser();
+
+ Types types() const;
+
+ void clear();
+ void setSchemaBaseUrl( const QString& );
+
+ void parseNameSpace( const QDomElement &element );
+ bool parseSchemaTag( const QDomElement &element );
+
+ const XSDType *type( const QualifiedName &type );
+ const XSDType *type( int id ) const;
+ int numTypes() const;
+
+ QString typeName( int id ) const;
+
+ Element *element( const QualifiedName &element ) const;
+ Element *element( int id ) const;
+ Element::PtrList elements() const;
+ int numElements() const;
+
+ Attribute *attribute( const QualifiedName &attribute ) const;
+ Attribute *attribute( int id ) const;
+ int numAttributes() const;
+
+ QString targetNamespace() const;
+
+ int typeId( const QualifiedName &name, bool create = false );
+
+ bool isBasicType( int sType ) const;
+
+ bool finalize();
+
+ int elementId( const QualifiedName &type );
+ int elementType( const QualifiedName &type );
+ int attributeId( const QualifiedName &type ) const;
+ int attributeType( const QualifiedName &type );
+
+ private:
+ void parseImport( const QDomElement& );
+ void parseElement( const QDomElement& );
+ void parseAttribute( const QDomElement& );
+
+ void parseAnnotation( const QDomElement& );
+ void parseAnnotation( const QDomElement&, QString& );
+ void parseAnnotation( const QDomElement&, ComplexType* );
+ void parseAnnotation( const QDomElement&, SimpleType* );
+ XSDType *parseComplexType( const QDomElement& );
+
+ void all( const QDomElement&, ComplexType* );
+ void cs( const QDomElement&, ComplexType* );
+
+ void addElement( const QDomElement&, ComplexType* );
+
+ void addAttribute( const QDomElement&, ComplexType* );
+ void addAny( const QDomElement&, ComplexType* );
+ void addAnyAttribute( const QDomElement&, ComplexType* );
+ int addExternalElement( const QString&, int );
+
+ XSDType *parseSimpleType( const QDomElement& );
+ void parseRestriction( const QDomElement&, SimpleType* );
+ void parseComplexContent( const QDomElement&, ComplexType* );
+ void parseSimpleContent( const QDomElement&, ComplexType* );
+
+
+ void resolveForwardElementRefs();
+ void resolveForwardAttributeRefs();
+ void resolveForwardDerivations();
+ bool shouldResolve();
+
+ void importSchema( const QString &location );
+
+ bool mElementQualified;
+ bool mAttributeQualified;
+ QMap<QString, QString> mNameSpaceMap;
+ QString mNameSpace;
+ QString mPrefix;
+
+ TypesTable mTypesTable;
+ Element::PtrList mElements;
+ Attribute::PtrList mAttributes;
+
+ QualifiedName::List mForwardElementRef;
+ QualifiedName::List mForwardAttributeRef;
+
+ typedef struct {
+ QualifiedName type;
+ QualifiedName baseType;
+ ComplexType::Derivation derivation;
+ } ForwardDerivation;
+
+ QValueList<ForwardDerivation> mForwardDerivations;
+ QStringList mImportedSchemas;
+ QString mSchemaBaseUrl;
+};
+
+}
+
+#endif
+
+
diff --git a/kode/kwsdl/schema/qualifiedname.cpp b/kode/kwsdl/schema/qualifiedname.cpp
new file mode 100644
index 000000000..5b19f1669
--- /dev/null
+++ b/kode/kwsdl/schema/qualifiedname.cpp
@@ -0,0 +1,78 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "qualifiedname.h"
+
+using namespace Schema;
+
+QualifiedName::QualifiedName( const QString &name )
+{
+ parse( name );
+}
+
+QualifiedName::QualifiedName()
+{
+}
+
+void QualifiedName::operator=( const QString &name )
+{
+ parse( name );
+}
+
+QString QualifiedName::localName() const
+{
+ return mLocalName;
+}
+
+QString QualifiedName::prefix() const
+{
+ return mPrefix;
+}
+
+void QualifiedName::setNameSpace( const QString &nameSpace )
+{
+ mNameSpace = nameSpace;
+}
+
+QString QualifiedName::nameSpace() const
+{
+ return mNameSpace;
+}
+
+bool QualifiedName::operator==( const QualifiedName &qn ) const
+{
+ return (qn.nameSpace() == mNameSpace && qn.localName() == mLocalName );
+}
+
+void QualifiedName::parse( const QString &str )
+{
+ int pos = str.find( ':' );
+ if ( pos != -1 ) {
+ mPrefix = str.left( pos );
+ mLocalName = str.mid( pos + 1 );
+ } else
+ mLocalName = str;
+
+ if ( mLocalName.endsWith( "[]" ) )
+ mLocalName.truncate( mLocalName.length() - 2 );
+}
+
diff --git a/kode/kwsdl/schema/qualifiedname.h b/kode/kwsdl/schema/qualifiedname.h
new file mode 100644
index 000000000..5b2f59bcd
--- /dev/null
+++ b/kode/kwsdl/schema/qualifiedname.h
@@ -0,0 +1,59 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_QUALIFIEDNAME_H
+#define SCHEMA_QUALIFIEDNAME_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+namespace Schema {
+
+class QualifiedName
+{
+ public:
+ typedef QValueList<QualifiedName> List;
+
+ QualifiedName();
+ QualifiedName( const QString &name );
+
+ void operator=( const QString &name );
+
+ QString localName() const;
+ QString prefix() const;
+
+ void setNameSpace( const QString &nameSpace );
+ QString nameSpace() const;
+
+ bool operator==( const QualifiedName& ) const;
+
+ private:
+ void parse( const QString& );
+
+ QString mNameSpace;
+ QString mLocalName;
+ QString mPrefix;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/simpletype.cpp b/kode/kwsdl/schema/simpletype.cpp
new file mode 100644
index 000000000..6943563f4
--- /dev/null
+++ b/kode/kwsdl/schema/simpletype.cpp
@@ -0,0 +1,301 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "simpletype.h"
+
+using namespace Schema;
+
+SimpleType::SimpleType()
+ : mBaseType( 0 ), mContentModel( SIMPLE ),
+ mRestriction( false ), mFacetId( NONE ), mAnonymous( false ),
+ mSubType( TypeRestriction ), mListType( INVALID )
+{
+}
+
+SimpleType::SimpleType( const QString &nameSpace )
+ : mNameSpace( nameSpace ), mBaseType( 0 ), mContentModel( SIMPLE ),
+ mRestriction( false ), mFacetId( NONE ), mAnonymous( false ),
+ mSubType( TypeRestriction ), mListType( INVALID )
+{
+}
+
+SimpleType::~SimpleType()
+{
+}
+
+void SimpleType::setName( const QString &name )
+{
+ mName = name;
+}
+
+QString SimpleType::name() const
+{
+ return mName;
+}
+
+QualifiedName SimpleType::qualifiedName() const
+{
+ QualifiedName qn( mName );
+ qn.setNameSpace( mNameSpace );
+ return qn;
+}
+
+void SimpleType::setDocumentation( const QString &documentation )
+{
+ mDocumentation = documentation;
+}
+
+QString SimpleType::documentation() const
+{
+ return mDocumentation;
+}
+
+void SimpleType::setType( int type )
+{
+ mType = type;
+}
+
+int SimpleType::type() const
+{
+ return mType;
+}
+
+void SimpleType::setBaseType( int baseType )
+{
+ mBaseType = baseType;
+ mRestriction = true;
+}
+
+int SimpleType::baseType() const
+{
+ return mBaseType;
+}
+
+void SimpleType::setBaseTypeName( const QString &baseTypeName )
+{
+ mBaseTypeName = baseTypeName;
+}
+
+QString SimpleType::baseTypeName() const
+{
+ return mBaseTypeName;
+}
+
+void SimpleType::setSubType( SubType subType )
+{
+ mSubType = subType;
+}
+
+SimpleType::SubType SimpleType::subType() const
+{
+ return mSubType;
+}
+
+void SimpleType::setListType( int listType )
+{
+ mListType = listType;
+}
+
+int SimpleType::listType() const
+{
+ return mListType;
+}
+
+void SimpleType::setListTypeName( const QString &name )
+{
+ mListTypeName = name;
+}
+
+QString SimpleType::listTypeName() const
+{
+ return mListTypeName;
+}
+
+void SimpleType::setContentModel( int contentModel )
+{
+ mContentModel = contentModel;
+}
+
+int SimpleType::contentModel() const
+{
+ return mContentModel;
+}
+
+void SimpleType::setAnonymous( bool anonymous )
+{
+ mAnonymous = anonymous;
+}
+
+bool SimpleType::isAnonymous() const
+{
+ return mAnonymous;
+}
+
+bool SimpleType::isValidFacet( const QString &facet )
+{
+ if ( mBaseType == 0 ) {
+ qDebug( "isValidFacet:Unknown base type" );
+ return false;
+ }
+
+ if ( facet == "length" )
+ mFacetId |= LENGTH;
+ else if ( facet == "minLength" )
+ mFacetId |= MINLEN;
+ else if ( facet == "maxLength" )
+ mFacetId |= MAXLEN;
+ else if ( facet == "enumeration" )
+ mFacetId |= ENUM;
+ else if ( facet == "whiteSpace" )
+ mFacetId |= WSP;
+ else if ( facet == "pattern" )
+ mFacetId |= PATTERN;
+ else if ( facet == "maxInclusive" )
+ mFacetId |= MAXINC;
+ else if ( facet == "maxExclusive" )
+ mFacetId |= MAXEX;
+ else if ( facet == "minInclusive" )
+ mFacetId |= MININC;
+ else if ( facet == "minExclusive" )
+ mFacetId |= MINEX;
+ else if ( facet == "totalDigits" )
+ mFacetId |= TOT;
+ else if ( facet == "fractionDigits" )
+ mFacetId |= FRAC;
+ else {
+ mFacetId = NONE;
+ return false;
+ }
+
+ return true;
+}
+
+void SimpleType::setFacetValue( const QString &value )
+{
+ int number = -1;
+
+ if ( mFacetId & ENUM ) {
+ mEnums.append( value );
+ } else if ( mFacetId & PATTERN ) {
+ mFacetValue.pattern = value;
+ } else if ( mFacetId & WSP ) {
+ if ( value == "preserve" )
+ mFacetValue.wsp = PRESERVE;
+ else if ( value == "collapse" )
+ mFacetValue.wsp = COLLAPSE;
+ else if ( value == "replace" )
+ mFacetValue.wsp = REPLACE;
+ else {
+ qDebug( "Invalid facet value for whitespace" );
+ return;
+ }
+ } else {
+ number = value.toInt();
+ }
+
+ if ( mFacetId & MAXEX ) {
+ mFacetValue.valRange.maxex = number;
+ } else if ( mFacetId & MAXINC ) {
+ mFacetValue.valRange.maxinc = number;
+ } else if ( mFacetId & MININC ) {
+ mFacetValue.valRange.mininc = number;
+ } else if ( mFacetId & MINEX ) {
+ mFacetValue.valRange.minex = number;
+ } else if ( mFacetId & MAXEX ) {
+ mFacetValue.valRange.maxex = number;
+ } else if ( mFacetId & LENGTH ) {
+ mFacetValue.length = number;
+ } else if ( mFacetId & MINLEN ) {
+ mFacetValue.lenRange.minlen = number;
+ } else if ( mFacetId & MAXLEN ) {
+ mFacetValue.lenRange.maxlen = number;
+ } else if ( mFacetId & TOT ) {
+ mFacetValue.tot = number;
+ } else if ( mFacetId & FRAC ) {
+ mFacetValue.frac = number;
+ }
+}
+
+int SimpleType::facetType() const
+{
+ return mFacetId;
+}
+
+int SimpleType::facetLength() const
+{
+ return mFacetValue.length;
+}
+
+int SimpleType::facetMinimumLength() const
+{
+ return mFacetValue.lenRange.minlen;
+}
+
+int SimpleType::facetMaximumLength() const
+{
+ return mFacetValue.lenRange.maxlen;
+}
+
+QStringList SimpleType::facetEnums() const
+{
+ return mEnums;
+}
+
+SimpleType::WhiteSpaceType SimpleType::facetWhiteSpace() const
+{
+ return mFacetValue.wsp;
+}
+
+int SimpleType::facetMinimumInclusive() const
+{
+ return mFacetValue.valRange.mininc;
+}
+
+int SimpleType::facetMaximumInclusive() const
+{
+ return mFacetValue.valRange.maxinc;
+}
+
+int SimpleType::facetMinimumExclusive() const
+{
+ return mFacetValue.valRange.minex;
+}
+
+int SimpleType::facetMaximumExclusive() const
+{
+ return mFacetValue.valRange.maxex;
+}
+
+int SimpleType::facetTotalDigits() const
+{
+ return mFacetValue.tot;
+}
+
+int SimpleType::facetFractionDigits() const
+{
+ return mFacetValue.frac;
+}
+
+QString SimpleType::facetPattern() const
+{
+ return mFacetValue.pattern;
+}
diff --git a/kode/kwsdl/schema/simpletype.h b/kode/kwsdl/schema/simpletype.h
new file mode 100644
index 000000000..12d129a48
--- /dev/null
+++ b/kode/kwsdl/schema/simpletype.h
@@ -0,0 +1,163 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_SIMPLETYPE_H
+#define SCHEMA_SIMPLETYPE_H
+
+#include <qstringlist.h>
+
+#include "qualifiedname.h"
+#include "xsdtype.h"
+
+namespace Schema {
+
+class SimpleType : public XSDType
+{
+ public:
+ typedef QValueList<SimpleType> List;
+
+ enum FacetType
+ {
+ NONE = 0,
+ LENGTH = 1,
+ MINLEN = 2,
+ MAXLEN = 4,
+ ENUM = 8,
+ WSP = 16,
+ MAXINC = 32,
+ MININC = 64,
+ MAXEX = 128,
+ MINEX = 256,
+ TOT = 512,
+ FRAC = 1024,
+ PATTERN = 2048
+ };
+
+ enum WhiteSpaceType
+ {
+ PRESERVE,
+ REPLACE,
+ COLLAPSE
+ };
+
+ enum SubType
+ {
+ TypeRestriction,
+ TypeList,
+ TypeUnion
+ };
+
+ SimpleType();
+ SimpleType( const QString &nameSpace );
+ ~SimpleType();
+
+ void setName( const QString &name );
+ QString name() const;
+
+ QualifiedName qualifiedName() const;
+
+ void setDocumentation( const QString &documentation );
+ QString documentation() const;
+
+ void setType( int type );
+ int type() const;
+
+ void setBaseType( int baseType );
+ int baseType() const;
+
+ void setBaseTypeName( const QString &baseTypeName );
+ QString baseTypeName() const;
+
+ void setSubType( SubType subType );
+ SubType subType() const;
+
+ void setListType( int listType );
+ void setListTypeName( const QString &name );
+
+ int listType() const;
+ QString listTypeName() const;
+
+ void setContentModel( int contentModel );
+ int contentModel() const;
+
+ void setAnonymous( bool anonymous );
+ bool isAnonymous() const;
+
+ bool isValidFacet( const QString &facet );
+ void setFacetValue( const QString &value );
+
+ int facetType() const;
+
+ int facetLength() const;
+ int facetMinimumLength() const;
+ int facetMaximumLength() const;
+ QStringList facetEnums() const;
+ WhiteSpaceType facetWhiteSpace() const;
+ int facetMinimumInclusive() const;
+ int facetMaximumInclusive() const;
+ int facetMinimumExclusive() const;
+ int facetMaximumExclusive() const;
+ int facetTotalDigits() const;
+ int facetFractionDigits() const;
+ QString facetPattern() const;
+
+ private:
+ QString mName;
+ QString mNameSpace;
+ QString mDocumentation;
+ int mType;
+ int mBaseType;
+ QString mBaseTypeName;
+ int mContentModel;
+ bool mRestriction;
+ int mFacetId;
+ bool mAnonymous;
+ QStringList mEnums;
+ SubType mSubType;
+
+ int mListType;
+ QString mListTypeName;
+
+ typedef struct
+ {
+ int length;
+ struct
+ {
+ int minlen, maxlen;
+ } lenRange;
+ WhiteSpaceType wsp;
+ struct
+ {
+ int maxinc, mininc, maxex, minex;
+ } valRange;
+ int tot;
+ int frac;
+ QString pattern;
+ } FacetValueType;
+
+
+ FacetValueType mFacetValue;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/types.cpp b/kode/kwsdl/schema/types.cpp
new file mode 100644
index 000000000..dc750e450
--- /dev/null
+++ b/kode/kwsdl/schema/types.cpp
@@ -0,0 +1,54 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "types.h"
+
+using namespace Schema;
+
+void Types::setSimpleTypes( const SimpleType::List &simpleTypes )
+{
+ mSimpleTypes = simpleTypes;
+}
+
+SimpleType::List Types::simpleTypes() const
+{
+ return mSimpleTypes;
+}
+
+void Types::setComplexTypes( const ComplexType::List &complexTypes )
+{
+ mComplexTypes = complexTypes;
+}
+
+ComplexType::List Types::complexTypes() const
+{
+ return mComplexTypes;
+}
+
+void Types::setElements( const Element::List &elements )
+{
+ mElements = elements;
+}
+
+Element::List Types::elements() const
+{
+ return mElements;
+}
diff --git a/kode/kwsdl/schema/types.h b/kode/kwsdl/schema/types.h
new file mode 100644
index 000000000..97b3b5dc7
--- /dev/null
+++ b/kode/kwsdl/schema/types.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_TYPES_H
+#define SCHEMA_TYPES_H
+
+#include "complextype.h"
+#include "element.h"
+#include "simpletype.h"
+
+namespace Schema {
+
+class Types
+{
+ public:
+ void setSimpleTypes( const SimpleType::List &simpleTypes );
+ SimpleType::List simpleTypes() const;
+
+ void setComplexTypes( const ComplexType::List &complexTypes );
+ ComplexType::List complexTypes() const;
+
+ void setElements( const Element::List &elements );
+ Element::List elements() const;
+
+ private:
+ SimpleType::List mSimpleTypes;
+ ComplexType::List mComplexTypes;
+ Element::List mElements;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/typestable.cpp b/kode/kwsdl/schema/typestable.cpp
new file mode 100644
index 000000000..8e0e66dd0
--- /dev/null
+++ b/kode/kwsdl/schema/typestable.cpp
@@ -0,0 +1,251 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "typestable.h"
+
+#include <kdebug.h>
+
+using namespace Schema;
+
+TypesTable::TypesTable()
+{
+ mCurrentId = XSDType::ANYURI + 1;
+
+//map of simple types
+ mBasicTypes["string"] = XSDType::STRING;
+ mBasicTypes["integer"] = XSDType::INTEGER;
+ mBasicTypes["int"] = XSDType::INT;
+ mBasicTypes["byte"] = XSDType::BYTE;
+ mBasicTypes["unsignedByte"] = XSDType::UBYTE;
+ mBasicTypes["positiveInteger"] = XSDType::POSINT;
+ mBasicTypes["unsignedInt"] = XSDType::UINT;
+ mBasicTypes["long"] = XSDType::LONG;
+ mBasicTypes["unsignedLong"] = XSDType::ULONG;
+ mBasicTypes["short"] = XSDType::SHORT;
+ mBasicTypes["unsignedShort"] = XSDType::USHORT;
+ mBasicTypes["decimal"] = XSDType::DECIMAL;
+ mBasicTypes["float"] = XSDType::FLOAT;
+ mBasicTypes["double"] = XSDType::DOUBLE;
+ mBasicTypes["boolean"] = XSDType::BOOLEAN;
+ mBasicTypes["time"] = XSDType::TIME;
+ mBasicTypes["dateTime"] = XSDType::DATETIME;
+ mBasicTypes["date"] = XSDType::DATE;
+ mBasicTypes["token"] = XSDType::TOKEN;
+ mBasicTypes["QName"] = XSDType::QNAME;
+ mBasicTypes["NCName"] = XSDType::NCNAME;
+ mBasicTypes["NMTOKEN"] = XSDType::NMTOKEN;
+ mBasicTypes["NMTOKENS"] = XSDType::NMTOKENS;
+ mBasicTypes["base64Binary"] = XSDType::BASE64BIN;
+ mBasicTypes["hexBinary"] = XSDType::HEXBIN;
+ mBasicTypes["anyType"] = XSDType::ANYTYPE;
+ mBasicTypes["any"] = XSDType::ANY;
+ mBasicTypes["anyURI"] = XSDType::ANYURI;
+}
+
+TypesTable::~TypesTable()
+{
+ clear();
+}
+
+void TypesTable::clear()
+{
+ QMap<QString, int>::Iterator it;
+ for ( it = mUserTypes.begin(); it != mUserTypes.end(); ++it )
+ delete typePtr( it.data() );
+
+ mUserTypes.clear();
+ mTypes.clear();
+}
+
+int TypesTable::numExtRefs() const
+{
+ return mExternRefs.count();
+}
+
+QualifiedName TypesTable::extRefName( int index ) const
+{
+ return mExternRefs[ index ].qname;
+}
+
+int TypesTable::extRefType( int index ) const
+{
+ return mExternRefs[ index ].localTypeId;
+}
+
+int TypesTable::addType( XSDType *type )
+{
+ QualifiedName qn = type->qualifiedName();
+ QString type_name( qn.localName() );
+
+ int i = 0;
+
+ if ( type_name.isEmpty() ) {
+ // create an anonymous type name
+ type_name.sprintf( "type%d", mTypes.count() );
+ type->setName( type_name );
+ type->setAnonymous( true ); //auto generated name
+ }
+
+ // add the typename and its id to the map
+ if ( (i = mUserTypes[type_name]) != 0 ) {
+ // this type was refernced earlier.
+ mTypes[i - (XSDType::ANYURI + 1)] = type;
+ type->setType( i );
+ return i;
+ } else {
+ mUserTypes[ type_name ] = mCurrentId;
+ type->setType( mCurrentId );
+ mTypes.append( type );
+ mCurrentId++;
+ return mCurrentId - 1;
+ }
+}
+
+int TypesTable::typeId( const QualifiedName &name, bool create )
+{
+ int typeId;
+
+ if ( name.nameSpace() == SchemaUri ) { // this is one of the basic types
+ typeId = mBasicTypes[ name.localName() ];
+ if ( typeId == 0 ) // if this is a basic type which is not mapped, treat as string
+ typeId = XSDType::STRING;
+ } else if ( name.nameSpace() == mNameSpace )
+ typeId = mUserTypes[ name.localName() ];
+ else { // the type does not belong to this schema
+ return 0;
+ }
+
+ if ( typeId == 0 && create ) {
+ // handle forward reference
+ // create an id and return its value
+ mUserTypes[name.localName()] = mCurrentId;
+ mTypes.append( 0 );
+ mCurrentId++;
+ typeId = mCurrentId - 1;
+ }
+
+ return typeId;
+}
+
+QString TypesTable::typeName( int id ) const
+{
+ if ( id < 0 )
+ return QString();
+
+ QMap<QString, int>::ConstIterator it;
+
+ if ( id >= 0 && id <= XSDType::ANYURI ) {
+ for ( it = mBasicTypes.begin(); it != mBasicTypes.end(); ++it )
+ if ( id == it.data() )
+ return it.key();
+ }
+
+ for ( it = mUserTypes.begin(); it != mUserTypes.end(); ++it )
+ if ( id == it.data() )
+ return it.key();
+
+ return "<unknown type>";
+}
+
+int TypesTable::addExternalTypeId( const QualifiedName &type, XSDType *pType )
+{
+ for ( int i = 0; i < (int)mExternRefs.count(); i++ )
+ if ( mExternRefs[i].qname == type )
+ return mExternRefs[i].localTypeId;
+
+ struct ExternRef ref;
+ ref.qname = (pType) ? pType->qualifiedName() : type;
+ ref.localTypeId = mCurrentId;
+ mExternRefs.append( ref );
+
+ mTypes.append( pType );
+ mCurrentId++;
+
+ return ref.localTypeId;
+}
+
+// adds a type into a type table for a given type id
+// used for types present in imported schemas but referenced in current schema
+int TypesTable::addExtType( XSDType *type, int localId )
+{
+ int index = localId - XSDType::ANYURI - 1;
+ if ( index >= (int)mTypes.count() )
+ return 0;
+
+ mTypes[ index ] = type;
+ return localId;
+}
+
+bool TypesTable::detectUndefinedTypes()
+{
+ for ( int i = 0; i < (int)mTypes.count(); i++ )
+ if ( mTypes[i] == 0 )
+ return true;
+
+ return false;
+}
+
+void TypesTable::resolveForwardElementRefs( const QString &name, Element &element )
+{
+ for ( int i = 0; i < (int)mTypes.count(); i++ )
+ if ( mTypes[i] != 0 ) {
+ if ( !mTypes[i]->isSimple() ) {
+ ComplexType *ct = (ComplexType*)mTypes[i];
+ ct->matchElementRef( name, element );
+ }
+ }
+}
+
+void TypesTable::resolveForwardAttributeRefs( const QString &name, Attribute &attribute )
+{
+ for ( int i = 0; i < (int)mTypes.count(); i++ )
+ if ( mTypes[i] != 0 ) {
+ if ( !mTypes[i]->isSimple() ) {
+ ComplexType *ct = (ComplexType*)mTypes[i];
+ ct->matchAttributeRef( name, attribute );
+ }
+ }
+}
+
+XSDType *TypesTable::typePtr( int id ) const
+{
+ // this is a basic XSD type
+ if ( id < XSDType::ANYURI + 1 || id > XSDType::ANYURI + (int)mTypes.count() )
+ return 0;
+
+ return mTypes[ id - (SimpleType::ANYURI + 1) ];
+}
+
+int TypesTable::numTypes() const
+{
+ return mTypes.count();
+}
+
+void TypesTable::setTargetNamespace( const QString &nameSpace )
+{
+ mNameSpace = nameSpace;
+}
+
+QString TypesTable::targetNamespace() const
+{
+ return mNameSpace;
+}
diff --git a/kode/kwsdl/schema/typestable.h b/kode/kwsdl/schema/typestable.h
new file mode 100644
index 000000000..6dfa378ed
--- /dev/null
+++ b/kode/kwsdl/schema/typestable.h
@@ -0,0 +1,89 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_TYPESTABLE_H
+#define SCHEMA_TYPESTABLE_H
+
+#include <qmap.h>
+#include <qstring.h>
+
+#include "complextype.h"
+#include "simpletype.h"
+
+namespace Schema {
+
+class TypesTable
+{
+ public:
+ TypesTable();
+ ~TypesTable();
+
+ void clear();
+
+ int addType( XSDType *type );
+ int addExtType( XSDType *type, int id );
+
+ int typeId( const QualifiedName &name, bool create = false );
+
+ QString typeName( int id ) const;
+
+ int addExternalTypeId( const QualifiedName &type, XSDType *type );
+
+ int numExtRefs() const;
+ QualifiedName extRefName( int index ) const;
+ int extRefType( int index ) const;
+
+ void resolveForwardElementRefs( const QString &name, Element &element );
+ void resolveForwardAttributeRefs( const QString &name, Attribute &attribute );
+
+ XSDType *typePtr( int id ) const;
+
+ int numTypes() const;
+
+ bool detectUndefinedTypes();
+
+ void setTargetNamespace( const QString &nameSpace );
+ QString targetNamespace() const;
+
+ private:
+ QValueList<XSDType*> mTypes;
+
+ //maintains a map of all user defined type names and their ids
+ QMap<QString, int> mUserTypes;
+ QMap<QString, int> mBasicTypes;
+
+ int mCurrentId;
+
+ QString mNameSpace;
+
+ struct ExternRef
+ {
+ int localTypeId;
+ QualifiedName qname;
+ };
+
+ QValueList<struct ExternRef> mExternRefs;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/schema/xsdtype.h b/kode/kwsdl/schema/xsdtype.h
new file mode 100644
index 000000000..b1bc4a7f8
--- /dev/null
+++ b/kode/kwsdl/schema/xsdtype.h
@@ -0,0 +1,114 @@
+/*
+ This file is part of KDE Schema Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+ based on wsdlpull parser by Vivek Krishna
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SCHEMA_XSDTYPE_H
+#define SCHEMA_XSDTYPE_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+#include <qmap.h>
+
+#include "qualifiedname.h"
+
+namespace Schema {
+
+const QString SchemaUri = "http://www.w3.org/2001/XMLSchema";
+
+class XSDType
+{
+ public:
+ typedef QValueList<const XSDType*> List;
+
+ enum
+ {
+ SIMPLE = 0,
+ COMPLEX,
+ MIXED
+ };
+
+ enum
+ {
+ INVALID = 0,
+ STRING = 1,
+ INTEGER,
+ INT,
+ BYTE,
+ UBYTE,
+ POSINT,
+ UINT,
+ LONG,
+ ULONG,
+ SHORT,
+ USHORT,
+ DECIMAL,
+ FLOAT,
+ DOUBLE,
+ BOOLEAN,
+ TIME,
+ DATETIME,
+ DATE,
+ TOKEN,
+ QNAME,
+ NCNAME,
+ NMTOKEN,
+ NMTOKENS,
+ BASE64BIN,
+ HEXBIN,
+ ANY,
+ ANYTYPE,
+ ANYURI
+ };
+
+ XSDType( const QString& )
+ {
+ };
+
+ XSDType()
+ {
+ };
+
+ virtual ~XSDType()
+ {
+ };
+
+ virtual QString name() const = 0;
+ virtual QualifiedName qualifiedName() const = 0;
+ virtual QString documentation() const = 0;
+ virtual int contentModel() const = 0;
+ virtual int type() const = 0;
+ virtual bool isAnonymous() const = 0;
+
+ virtual bool isSimple() const
+ {
+ return true;
+ }
+
+ virtual void setName( const QString& ) = 0;
+ virtual void setDocumentation( const QString& ) = 0;
+ virtual void setContentModel( int ) = 0;
+ virtual void setType( int ) = 0;
+ virtual void setAnonymous( bool ) = 0;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/service.cpp b/kode/kwsdl/service.cpp
new file mode 100644
index 000000000..a34e1df49
--- /dev/null
+++ b/kode/kwsdl/service.cpp
@@ -0,0 +1,48 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "service.h"
+
+using namespace KWSDL;
+
+Service::Service()
+{
+}
+
+Service::Service( const QString &name )
+ : mName( name )
+{
+}
+
+void Service::addPort( const Port &port )
+{
+ mPorts.insert( port.mName, port );
+}
+
+Service::Port Service::port( const QString &name ) const
+{
+ return mPorts[ name ];
+}
+
+Service::Port::List Service::ports() const
+{
+ return mPorts.values();
+}
diff --git a/kode/kwsdl/service.h b/kode/kwsdl/service.h
new file mode 100644
index 000000000..25f00d9b4
--- /dev/null
+++ b/kode/kwsdl/service.h
@@ -0,0 +1,60 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_SERVICE_H
+#define KWSDL_SERVICE_H
+
+#include <qmap.h>
+#include <qstringlist.h>
+
+namespace KWSDL {
+
+class Service
+{
+ public:
+ class Port
+ {
+ public:
+ typedef QValueList<Port> List;
+
+ QString mName;
+ QString mBinding;
+ QString mLocation;
+ };
+
+ Service();
+ Service( const QString &name );
+
+ void setName( const QString &name ) { mName = name; }
+ QString name() const { return mName; }
+
+ void addPort( const Port &port );
+ Port port( const QString &name ) const;
+ Port::List ports() const;
+
+ private:
+ QString mName;
+ QMap<QString, Port> mPorts;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/tests/Makefile.am b/kode/kwsdl/tests/Makefile.am
new file mode 100644
index 000000000..fbd398ee6
--- /dev/null
+++ b/kode/kwsdl/tests/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = google
diff --git a/kode/kwsdl/tests/google/Makefile.am b/kode/kwsdl/tests/google/Makefile.am
new file mode 100644
index 000000000..171f0c5cb
--- /dev/null
+++ b/kode/kwsdl/tests/google/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libkdepim $(all_includes)
+METASOURCES = AUTO
+
+bin_PROGRAMS = googletest
+
+googletest_SOURCES = main.cc googlesearch.cc transport.cpp resultelementarray.cpp directorycategoryarray.cpp googlesearchresult.cpp directorycategory.cpp resultelement.cpp serializer.cpp googlesearchservice.cpp
+googletest_LDADD = -lkdecore -lkio
+googletest_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+
diff --git a/kode/kwsdl/tests/google/README b/kode/kwsdl/tests/google/README
new file mode 100644
index 000000000..cfe831598
--- /dev/null
+++ b/kode/kwsdl/tests/google/README
@@ -0,0 +1,8 @@
+This application shows how easy it is to use a web service with
+code, generated by kwsdl_compiler.
+
+Only the files main.cc, googlesearch.cc and googlesearch.hh are
+written manually, all other files were created by
+
+ kwsdl_compiler -d kwsdl/tests/google/ GoogleSearch.wsdl
+
diff --git a/kode/kwsdl/tests/google/directorycategory.cpp b/kode/kwsdl/tests/google/directorycategory.cpp
new file mode 100644
index 000000000..87f9c5f1a
--- /dev/null
+++ b/kode/kwsdl/tests/google/directorycategory.cpp
@@ -0,0 +1,64 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "directorycategory.h"
+
+#include <serializer.h>
+#include <qstring.h>
+
+void DirectoryCategory::setFullViewableName( QString* fullViewableName )
+{
+ mFullViewableName = fullViewableName;
+}
+
+QString*DirectoryCategory::fullViewableName() const
+{
+ return mFullViewableName;
+}
+
+void DirectoryCategory::setSpecialEncoding( QString* specialEncoding )
+{
+ mSpecialEncoding = specialEncoding;
+}
+
+QString*DirectoryCategory::specialEncoding() const
+{
+ return mSpecialEncoding;
+}
+
+DirectoryCategory::DirectoryCategory()
+{
+ mFullViewableName = 0;
+ mSpecialEncoding = 0;
+}
+
+DirectoryCategory::~DirectoryCategory()
+{
+ delete mFullViewableName;
+ mFullViewableName = 0;
+ delete mSpecialEncoding;
+ mSpecialEncoding = 0;
+}
+
+
diff --git a/kode/kwsdl/tests/google/directorycategory.h b/kode/kwsdl/tests/google/directorycategory.h
new file mode 100644
index 000000000..0ce1c417d
--- /dev/null
+++ b/kode/kwsdl/tests/google/directorycategory.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef DIRECTORYCATEGORY_H
+#define DIRECTORYCATEGORY_H
+
+class QString;
+
+class DirectoryCategory
+{
+ public:
+ void setFullViewableName( QString* fullViewableName );
+ QString*fullViewableName() const;
+ void setSpecialEncoding( QString* specialEncoding );
+ QString*specialEncoding() const;
+ DirectoryCategory();
+ ~DirectoryCategory();
+
+ private:
+ QString*mFullViewableName;
+ QString*mSpecialEncoding;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/directorycategoryarray.cpp b/kode/kwsdl/tests/google/directorycategoryarray.cpp
new file mode 100644
index 000000000..724cf26cf
--- /dev/null
+++ b/kode/kwsdl/tests/google/directorycategoryarray.cpp
@@ -0,0 +1,52 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "directorycategoryarray.h"
+
+#include <serializer.h>
+#include <directorycategory.h>
+#include <qptrlist.h>
+
+void DirectoryCategoryArray::setItems( QPtrList<DirectoryCategory>* items )
+{
+ mItems = items;
+}
+
+QPtrList<DirectoryCategory>*DirectoryCategoryArray::items() const
+{
+ return mItems;
+}
+
+DirectoryCategoryArray::DirectoryCategoryArray()
+{
+ mItems = 0;
+}
+
+DirectoryCategoryArray::~DirectoryCategoryArray()
+{
+ delete mItems;
+ mItems = 0;
+}
+
+
diff --git a/kode/kwsdl/tests/google/directorycategoryarray.h b/kode/kwsdl/tests/google/directorycategoryarray.h
new file mode 100644
index 000000000..db19d9bfa
--- /dev/null
+++ b/kode/kwsdl/tests/google/directorycategoryarray.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef DIRECTORYCATEGORYARRAY_H
+#define DIRECTORYCATEGORYARRAY_H
+
+#include <qptrlist.h>
+
+class DirectoryCategory;
+
+class DirectoryCategoryArray
+{
+ public:
+ void setItems( QPtrList<DirectoryCategory>* items );
+ QPtrList<DirectoryCategory>*items() const;
+ DirectoryCategoryArray();
+ ~DirectoryCategoryArray();
+
+ private:
+ QPtrList<DirectoryCategory>*mItems;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/googlesearch.cc b/kode/kwsdl/tests/google/googlesearch.cc
new file mode 100644
index 000000000..2e1374b47
--- /dev/null
+++ b/kode/kwsdl/tests/google/googlesearch.cc
@@ -0,0 +1,94 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "googlesearch.hh"
+#include "resultelement.h"
+#include "resultelementarray.h"
+
+GoogleSearch::GoogleSearch()
+ : QObject( 0, "" )
+{
+ connect( &mService, SIGNAL( doGetCachedPageResponse( QByteArray* ) ),
+ this, SLOT( cachedPageResult( QByteArray* ) ) );
+ connect( &mService, SIGNAL( doSpellingSuggestionResponse( QString* ) ),
+ this, SLOT( spellingSuggestionResult( QString* ) ) );
+ connect( &mService, SIGNAL( doGoogleSearchResponse( GoogleSearchResult* ) ),
+ this, SLOT( googleSearchResult( GoogleSearchResult* ) ) );
+
+ mKey = "";
+}
+
+void GoogleSearch::cachedPage( const QString &url )
+{
+ mService.doGetCachedPage( new QString( mKey ), new QString( url ) );
+}
+
+void GoogleSearch::spellingSuggestion( const QString &phrase )
+{
+ mService.doSpellingSuggestion( new QString( mKey ), new QString( phrase ) );
+}
+
+void GoogleSearch::googleSearch( const QString &query, int start, int maxResults, bool filter,
+ const QString &restrict, bool safeSearch, const QString &lr, const QString &ie,
+ const QString &oe )
+{
+ mService.doGoogleSearch( new QString( mKey ), new QString( query ), new int( start ), new int( maxResults ),
+ new bool( filter ), new QString( restrict ), new bool( safeSearch ), new QString( lr ),
+ new QString( ie ), new QString( oe ) );
+}
+
+void GoogleSearch::cachedPageResult( QByteArray *array )
+{
+ qDebug( "--------------- Cached Page Results ---------------------" );
+ qDebug( "%s", array->data() );
+ qDebug( "---------------------------------------------------------" );
+
+ delete array;
+}
+
+void GoogleSearch::spellingSuggestionResult( QString *word )
+{
+ qDebug( "--------------- Spelling Suggestion ---------------------" );
+ qDebug( "%s", word->latin1() );
+ qDebug( "---------------------------------------------------------" );
+
+ delete word;
+}
+
+void GoogleSearch::googleSearchResult( GoogleSearchResult *result )
+{
+ qDebug( "--------------------- Search Results ---------------------" );
+ ResultElementArray *array = result->resultElements();
+ QPtrList<ResultElement> *list = array->items();
+ QPtrListIterator<ResultElement> it( *list );
+ while ( it.current() != 0 ) {
+ qDebug( "%s: %s", it.current()->summary()->latin1(), it.current()->uRL()->latin1() );
+ ++it;
+ }
+ qDebug( "---------------------------------------------------------" );
+
+ delete result;
+}
+
+#include "googlesearch.moc"
diff --git a/kode/kwsdl/tests/google/googlesearch.hh b/kode/kwsdl/tests/google/googlesearch.hh
new file mode 100644
index 000000000..21aed9574
--- /dev/null
+++ b/kode/kwsdl/tests/google/googlesearch.hh
@@ -0,0 +1,60 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef GOOGLESEARCH_H
+#define GOOGLESEARCH_H
+
+#include <qobject.h>
+#include "googlesearchservice.h"
+
+class GoogleSearch : public QObject
+{
+ Q_OBJECT
+
+ public:
+ GoogleSearch();
+
+ void cachedPage( const QString &url );
+ void spellingSuggestion( const QString &phrase );
+ void googleSearch( const QString &query,
+ int start,
+ int maxResults,
+ bool filter,
+ const QString &restrict,
+ bool safeSearch,
+ const QString &lr,
+ const QString &ie,
+ const QString &oe );
+
+ private slots:
+ void cachedPageResult( QByteArray* );
+ void spellingSuggestionResult( QString* );
+ void googleSearchResult( GoogleSearchResult* );
+
+ private:
+ QString mKey;
+ GoogleSearchService mService;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/googlesearchresult.cpp b/kode/kwsdl/tests/google/googlesearchresult.cpp
new file mode 100644
index 000000000..2d3ce11e2
--- /dev/null
+++ b/kode/kwsdl/tests/google/googlesearchresult.cpp
@@ -0,0 +1,183 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "googlesearchresult.h"
+
+#include <serializer.h>
+#include <qstring.h>
+#include <resultelementarray.h>
+#include <directorycategoryarray.h>
+
+void GoogleSearchResult::setDocumentFiltering( bool* documentFiltering )
+{
+ mDocumentFiltering = documentFiltering;
+}
+
+bool*GoogleSearchResult::documentFiltering() const
+{
+ return mDocumentFiltering;
+}
+
+void GoogleSearchResult::setSearchComments( QString* searchComments )
+{
+ mSearchComments = searchComments;
+}
+
+QString*GoogleSearchResult::searchComments() const
+{
+ return mSearchComments;
+}
+
+void GoogleSearchResult::setEstimatedTotalResultsCount( int* estimatedTotalResultsCount )
+{
+ mEstimatedTotalResultsCount = estimatedTotalResultsCount;
+}
+
+int*GoogleSearchResult::estimatedTotalResultsCount() const
+{
+ return mEstimatedTotalResultsCount;
+}
+
+void GoogleSearchResult::setEstimateIsExact( bool* estimateIsExact )
+{
+ mEstimateIsExact = estimateIsExact;
+}
+
+bool*GoogleSearchResult::estimateIsExact() const
+{
+ return mEstimateIsExact;
+}
+
+void GoogleSearchResult::setResultElements( ResultElementArray* resultElements )
+{
+ mResultElements = resultElements;
+}
+
+ResultElementArray*GoogleSearchResult::resultElements() const
+{
+ return mResultElements;
+}
+
+void GoogleSearchResult::setSearchQuery( QString* searchQuery )
+{
+ mSearchQuery = searchQuery;
+}
+
+QString*GoogleSearchResult::searchQuery() const
+{
+ return mSearchQuery;
+}
+
+void GoogleSearchResult::setStartIndex( int* startIndex )
+{
+ mStartIndex = startIndex;
+}
+
+int*GoogleSearchResult::startIndex() const
+{
+ return mStartIndex;
+}
+
+void GoogleSearchResult::setEndIndex( int* endIndex )
+{
+ mEndIndex = endIndex;
+}
+
+int*GoogleSearchResult::endIndex() const
+{
+ return mEndIndex;
+}
+
+void GoogleSearchResult::setSearchTips( QString* searchTips )
+{
+ mSearchTips = searchTips;
+}
+
+QString*GoogleSearchResult::searchTips() const
+{
+ return mSearchTips;
+}
+
+void GoogleSearchResult::setDirectoryCategories( DirectoryCategoryArray* directoryCategories )
+{
+ mDirectoryCategories = directoryCategories;
+}
+
+DirectoryCategoryArray*GoogleSearchResult::directoryCategories() const
+{
+ return mDirectoryCategories;
+}
+
+void GoogleSearchResult::setSearchTime( double* searchTime )
+{
+ mSearchTime = searchTime;
+}
+
+double*GoogleSearchResult::searchTime() const
+{
+ return mSearchTime;
+}
+
+GoogleSearchResult::GoogleSearchResult()
+{
+ mDocumentFiltering = 0;
+ mSearchComments = 0;
+ mEstimatedTotalResultsCount = 0;
+ mEstimateIsExact = 0;
+ mResultElements = 0;
+ mSearchQuery = 0;
+ mStartIndex = 0;
+ mEndIndex = 0;
+ mSearchTips = 0;
+ mDirectoryCategories = 0;
+ mSearchTime = 0;
+}
+
+GoogleSearchResult::~GoogleSearchResult()
+{
+ delete mDocumentFiltering;
+ mDocumentFiltering = 0;
+ delete mSearchComments;
+ mSearchComments = 0;
+ delete mEstimatedTotalResultsCount;
+ mEstimatedTotalResultsCount = 0;
+ delete mEstimateIsExact;
+ mEstimateIsExact = 0;
+ delete mResultElements;
+ mResultElements = 0;
+ delete mSearchQuery;
+ mSearchQuery = 0;
+ delete mStartIndex;
+ mStartIndex = 0;
+ delete mEndIndex;
+ mEndIndex = 0;
+ delete mSearchTips;
+ mSearchTips = 0;
+ delete mDirectoryCategories;
+ mDirectoryCategories = 0;
+ delete mSearchTime;
+ mSearchTime = 0;
+}
+
+
diff --git a/kode/kwsdl/tests/google/googlesearchresult.h b/kode/kwsdl/tests/google/googlesearchresult.h
new file mode 100644
index 000000000..542fb6864
--- /dev/null
+++ b/kode/kwsdl/tests/google/googlesearchresult.h
@@ -0,0 +1,73 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef GOOGLESEARCHRESULT_H
+#define GOOGLESEARCHRESULT_H
+
+class QString;
+class ResultElementArray;
+class DirectoryCategoryArray;
+
+class GoogleSearchResult
+{
+ public:
+ void setDocumentFiltering( bool* documentFiltering );
+ bool*documentFiltering() const;
+ void setSearchComments( QString* searchComments );
+ QString*searchComments() const;
+ void setEstimatedTotalResultsCount( int* estimatedTotalResultsCount );
+ int*estimatedTotalResultsCount() const;
+ void setEstimateIsExact( bool* estimateIsExact );
+ bool*estimateIsExact() const;
+ void setResultElements( ResultElementArray* resultElements );
+ ResultElementArray*resultElements() const;
+ void setSearchQuery( QString* searchQuery );
+ QString*searchQuery() const;
+ void setStartIndex( int* startIndex );
+ int*startIndex() const;
+ void setEndIndex( int* endIndex );
+ int*endIndex() const;
+ void setSearchTips( QString* searchTips );
+ QString*searchTips() const;
+ void setDirectoryCategories( DirectoryCategoryArray* directoryCategories );
+ DirectoryCategoryArray*directoryCategories() const;
+ void setSearchTime( double* searchTime );
+ double*searchTime() const;
+ GoogleSearchResult();
+ ~GoogleSearchResult();
+
+ private:
+ bool*mDocumentFiltering;
+ QString*mSearchComments;
+ int*mEstimatedTotalResultsCount;
+ bool*mEstimateIsExact;
+ ResultElementArray*mResultElements;
+ QString*mSearchQuery;
+ int*mStartIndex;
+ int*mEndIndex;
+ QString*mSearchTips;
+ DirectoryCategoryArray*mDirectoryCategories;
+ double*mSearchTime;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/googlesearchservice.cpp b/kode/kwsdl/tests/google/googlesearchservice.cpp
new file mode 100644
index 000000000..555850713
--- /dev/null
+++ b/kode/kwsdl/tests/google/googlesearchservice.cpp
@@ -0,0 +1,208 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "googlesearchservice.h"
+
+#include <serializer.h>
+
+void GoogleSearchService::doGetCachedPage( QString* key, QString* url )
+{
+ QDomDocument doc( "kwsdl" );
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+ QDomElement env = doc.createElement( "SOAP-ENV:Envelope" );
+ env.setAttribute( "xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" );
+ env.setAttribute( "xmlns:xsi", "http://www.w3.org/1999/XMLSchema-instance" );
+ env.setAttribute( "xmlns:xsd", "http://www.w3.org/1999/XMLSchema" );
+ doc.appendChild( env );
+ QDomElement body = doc.createElement( "SOAP-ENV:Body" );
+ env.appendChild( body );
+ QDomElement method = doc.createElement( "ns1:doGetCachedPage" );
+ method.setAttribute( "xmlns:ns1", "urn:GoogleSearch" );
+ method.setAttribute( "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/" );
+ body.appendChild( method );
+
+ Serializer::marshal( doc, method, "key", key );
+ delete key;
+ Serializer::marshal( doc, method, "url", url );
+ delete url;
+ qDebug( "%s", doc.toString().latin1() );
+ mDoGetCachedPageTransport->query( doc.toString() );
+}
+
+void GoogleSearchService::doGetCachedPageResponseSlot( const QString &xml )
+{
+ QDomDocument doc;
+ QString errorMsg;
+ int column, row;
+
+ qDebug( "%s", xml.latin1() );
+
+ if ( !doc.setContent( xml, true, &errorMsg, &row, &column ) ) {
+ qDebug( "Unable to parse xml: %s (%d:%d)", errorMsg.latin1(), row, column );
+ return;
+ }
+
+ QByteArray* value = new QByteArray;
+ QDomElement envelope = doc.documentElement();
+ QDomElement body = envelope.firstChild().toElement();
+ QDomElement method = body.firstChild().toElement();
+ Serializer::demarshal( method.firstChild().toElement(), value );
+
+ emit doGetCachedPageResponse( value );
+}
+
+void GoogleSearchService::doSpellingSuggestion( QString* key, QString* phrase )
+{
+ QDomDocument doc( "kwsdl" );
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+ QDomElement env = doc.createElement( "SOAP-ENV:Envelope" );
+ env.setAttribute( "xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" );
+ env.setAttribute( "xmlns:xsi", "http://www.w3.org/1999/XMLSchema-instance" );
+ env.setAttribute( "xmlns:xsd", "http://www.w3.org/1999/XMLSchema" );
+ doc.appendChild( env );
+ QDomElement body = doc.createElement( "SOAP-ENV:Body" );
+ env.appendChild( body );
+ QDomElement method = doc.createElement( "ns1:doSpellingSuggestion" );
+ method.setAttribute( "xmlns:ns1", "urn:GoogleSearch" );
+ method.setAttribute( "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/" );
+ body.appendChild( method );
+
+ Serializer::marshal( doc, method, "key", key );
+ delete key;
+ Serializer::marshal( doc, method, "phrase", phrase );
+ delete phrase;
+ qDebug( "%s", doc.toString().latin1() );
+ mDoSpellingSuggestionTransport->query( doc.toString() );
+}
+
+void GoogleSearchService::doSpellingSuggestionResponseSlot( const QString &xml )
+{
+ QDomDocument doc;
+ QString errorMsg;
+ int column, row;
+
+ qDebug( "%s", xml.latin1() );
+
+ if ( !doc.setContent( xml, true, &errorMsg, &row, &column ) ) {
+ qDebug( "Unable to parse xml: %s (%d:%d)", errorMsg.latin1(), row, column );
+ return;
+ }
+
+ QString* value = new QString;
+ QDomElement envelope = doc.documentElement();
+ QDomElement body = envelope.firstChild().toElement();
+ QDomElement method = body.firstChild().toElement();
+ Serializer::demarshal( method.firstChild().toElement(), value );
+
+ emit doSpellingSuggestionResponse( value );
+}
+
+void GoogleSearchService::doGoogleSearch( QString* key, QString* q, int* start, int* maxResults, bool* filter, QString* restrict, bool* safeSearch, QString* lr, QString* ie, QString* oe )
+{
+ QDomDocument doc( "kwsdl" );
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
+ QDomElement env = doc.createElement( "SOAP-ENV:Envelope" );
+ env.setAttribute( "xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" );
+ env.setAttribute( "xmlns:xsi", "http://www.w3.org/1999/XMLSchema-instance" );
+ env.setAttribute( "xmlns:xsd", "http://www.w3.org/1999/XMLSchema" );
+ doc.appendChild( env );
+ QDomElement body = doc.createElement( "SOAP-ENV:Body" );
+ env.appendChild( body );
+ QDomElement method = doc.createElement( "ns1:doGoogleSearch" );
+ method.setAttribute( "xmlns:ns1", "urn:GoogleSearch" );
+ method.setAttribute( "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/" );
+ body.appendChild( method );
+
+ Serializer::marshal( doc, method, "key", key );
+ delete key;
+ Serializer::marshal( doc, method, "q", q );
+ delete q;
+ Serializer::marshal( doc, method, "start", start );
+ delete start;
+ Serializer::marshal( doc, method, "maxResults", maxResults );
+ delete maxResults;
+ Serializer::marshal( doc, method, "filter", filter );
+ delete filter;
+ Serializer::marshal( doc, method, "restrict", restrict );
+ delete restrict;
+ Serializer::marshal( doc, method, "safeSearch", safeSearch );
+ delete safeSearch;
+ Serializer::marshal( doc, method, "lr", lr );
+ delete lr;
+ Serializer::marshal( doc, method, "ie", ie );
+ delete ie;
+ Serializer::marshal( doc, method, "oe", oe );
+ delete oe;
+ qDebug( "%s", doc.toString().latin1() );
+ mDoGoogleSearchTransport->query( doc.toString() );
+}
+
+void GoogleSearchService::doGoogleSearchResponseSlot( const QString &xml )
+{
+ QDomDocument doc;
+ QString errorMsg;
+ int column, row;
+
+ qDebug( "%s", xml.latin1() );
+
+ if ( !doc.setContent( xml, true, &errorMsg, &row, &column ) ) {
+ qDebug( "Unable to parse xml: %s (%d:%d)", errorMsg.latin1(), row, column );
+ return;
+ }
+
+ GoogleSearchResult* value = new GoogleSearchResult;
+ QDomElement envelope = doc.documentElement();
+ QDomElement body = envelope.firstChild().toElement();
+ QDomElement method = body.firstChild().toElement();
+ Serializer::demarshal( method.firstChild().toElement(), value );
+
+ emit doGoogleSearchResponse( value );
+}
+
+GoogleSearchService::GoogleSearchService()
+{
+ mDoGetCachedPageTransport = new Transport( "http://api.google.com/search/beta2" );
+ connect( mDoGetCachedPageTransport, SIGNAL( result( const QString& ) ),
+ this, SLOT( doGetCachedPageResponseSlot( const QString& ) ) );
+ mDoSpellingSuggestionTransport = new Transport( "http://api.google.com/search/beta2" );
+ connect( mDoSpellingSuggestionTransport, SIGNAL( result( const QString& ) ),
+ this, SLOT( doSpellingSuggestionResponseSlot( const QString& ) ) );
+ mDoGoogleSearchTransport = new Transport( "http://api.google.com/search/beta2" );
+ connect( mDoGoogleSearchTransport, SIGNAL( result( const QString& ) ),
+ this, SLOT( doGoogleSearchResponseSlot( const QString& ) ) );
+}
+
+GoogleSearchService::~GoogleSearchService()
+{
+ delete mDoGetCachedPageTransport;
+ mDoGetCachedPageTransport = 0;
+ delete mDoSpellingSuggestionTransport;
+ mDoSpellingSuggestionTransport = 0;
+ delete mDoGoogleSearchTransport;
+ mDoGoogleSearchTransport = 0;
+}
+
+
+#include "googlesearchservice.moc"
+
diff --git a/kode/kwsdl/tests/google/googlesearchservice.h b/kode/kwsdl/tests/google/googlesearchservice.h
new file mode 100644
index 000000000..cc8bef027
--- /dev/null
+++ b/kode/kwsdl/tests/google/googlesearchservice.h
@@ -0,0 +1,60 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef GOOGLESEARCHSERVICE_H
+#define GOOGLESEARCHSERVICE_H
+
+#include <qobject.h>
+#include <qstring.h>
+#include <transport.h>
+#include <qcstring.h>
+#include <googlesearchresult.h>
+
+class GoogleSearchService : public QObject
+{
+ Q_OBJECT
+
+ public:
+ void doGetCachedPage( QString* key, QString* url );
+ void doSpellingSuggestion( QString* key, QString* phrase );
+ void doGoogleSearch( QString* key, QString* q, int* start, int* maxResults, bool* filter, QString* restrict, bool* safeSearch, QString* lr, QString* ie, QString* oe );
+ GoogleSearchService();
+ ~GoogleSearchService();
+
+ signals:
+ void doGetCachedPageResponse( QByteArray* value );
+ void doSpellingSuggestionResponse( QString* value );
+ void doGoogleSearchResponse( GoogleSearchResult* value );
+
+ private slots:
+ void doGetCachedPageResponseSlot( const QString &xml );
+ void doSpellingSuggestionResponseSlot( const QString &xml );
+ void doGoogleSearchResponseSlot( const QString &xml );
+
+ private:
+ Transport*mDoGetCachedPageTransport;
+ Transport*mDoSpellingSuggestionTransport;
+ Transport*mDoGoogleSearchTransport;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/main.cc b/kode/kwsdl/tests/google/main.cc
new file mode 100644
index 000000000..fd4b82462
--- /dev/null
+++ b/kode/kwsdl/tests/google/main.cc
@@ -0,0 +1,23 @@
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kmdcodec.h>
+
+#include "googlesearch.hh"
+
+int main( int argc, char **argv )
+{
+ KAboutData aboutData( "kgooglesearch", "KDE Google Search", "0.1", "", KAboutData::License_GPL );
+ aboutData.addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+
+ KApplication app( false, false );
+
+ GoogleSearch search;
+
+ search.googleSearch( "foobar", 0, 10, true, "", false, "", "latin1", "latin1" );
+ search.spellingSuggestion( "guugel" );
+
+ return app.exec();
+}
diff --git a/kode/kwsdl/tests/google/resultelement.cpp b/kode/kwsdl/tests/google/resultelement.cpp
new file mode 100644
index 000000000..b02b8ca44
--- /dev/null
+++ b/kode/kwsdl/tests/google/resultelement.cpp
@@ -0,0 +1,156 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "resultelement.h"
+
+#include <serializer.h>
+#include <qstring.h>
+#include <directorycategory.h>
+
+void ResultElement::setSummary( QString* summary )
+{
+ mSummary = summary;
+}
+
+QString*ResultElement::summary() const
+{
+ return mSummary;
+}
+
+void ResultElement::setURL( QString* uRL )
+{
+ mURL = uRL;
+}
+
+QString*ResultElement::uRL() const
+{
+ return mURL;
+}
+
+void ResultElement::setSnippet( QString* snippet )
+{
+ mSnippet = snippet;
+}
+
+QString*ResultElement::snippet() const
+{
+ return mSnippet;
+}
+
+void ResultElement::setTitle( QString* title )
+{
+ mTitle = title;
+}
+
+QString*ResultElement::title() const
+{
+ return mTitle;
+}
+
+void ResultElement::setCachedSize( QString* cachedSize )
+{
+ mCachedSize = cachedSize;
+}
+
+QString*ResultElement::cachedSize() const
+{
+ return mCachedSize;
+}
+
+void ResultElement::setRelatedInformationPresent( bool* relatedInformationPresent )
+{
+ mRelatedInformationPresent = relatedInformationPresent;
+}
+
+bool*ResultElement::relatedInformationPresent() const
+{
+ return mRelatedInformationPresent;
+}
+
+void ResultElement::setHostName( QString* hostName )
+{
+ mHostName = hostName;
+}
+
+QString*ResultElement::hostName() const
+{
+ return mHostName;
+}
+
+void ResultElement::setDirectoryCategory( DirectoryCategory* directoryCategory )
+{
+ mDirectoryCategory = directoryCategory;
+}
+
+DirectoryCategory*ResultElement::directoryCategory() const
+{
+ return mDirectoryCategory;
+}
+
+void ResultElement::setDirectoryTitle( QString* directoryTitle )
+{
+ mDirectoryTitle = directoryTitle;
+}
+
+QString*ResultElement::directoryTitle() const
+{
+ return mDirectoryTitle;
+}
+
+ResultElement::ResultElement()
+{
+ mSummary = 0;
+ mURL = 0;
+ mSnippet = 0;
+ mTitle = 0;
+ mCachedSize = 0;
+ mRelatedInformationPresent = 0;
+ mHostName = 0;
+ mDirectoryCategory = 0;
+ mDirectoryTitle = 0;
+}
+
+ResultElement::~ResultElement()
+{
+ delete mSummary;
+ mSummary = 0;
+ delete mURL;
+ mURL = 0;
+ delete mSnippet;
+ mSnippet = 0;
+ delete mTitle;
+ mTitle = 0;
+ delete mCachedSize;
+ mCachedSize = 0;
+ delete mRelatedInformationPresent;
+ mRelatedInformationPresent = 0;
+ delete mHostName;
+ mHostName = 0;
+ delete mDirectoryCategory;
+ mDirectoryCategory = 0;
+ delete mDirectoryTitle;
+ mDirectoryTitle = 0;
+}
+
+
diff --git a/kode/kwsdl/tests/google/resultelement.h b/kode/kwsdl/tests/google/resultelement.h
new file mode 100644
index 000000000..4a24f7291
--- /dev/null
+++ b/kode/kwsdl/tests/google/resultelement.h
@@ -0,0 +1,66 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef RESULTELEMENT_H
+#define RESULTELEMENT_H
+
+class QString;
+class DirectoryCategory;
+
+class ResultElement
+{
+ public:
+ void setSummary( QString* summary );
+ QString*summary() const;
+ void setURL( QString* uRL );
+ QString*uRL() const;
+ void setSnippet( QString* snippet );
+ QString*snippet() const;
+ void setTitle( QString* title );
+ QString*title() const;
+ void setCachedSize( QString* cachedSize );
+ QString*cachedSize() const;
+ void setRelatedInformationPresent( bool* relatedInformationPresent );
+ bool*relatedInformationPresent() const;
+ void setHostName( QString* hostName );
+ QString*hostName() const;
+ void setDirectoryCategory( DirectoryCategory* directoryCategory );
+ DirectoryCategory*directoryCategory() const;
+ void setDirectoryTitle( QString* directoryTitle );
+ QString*directoryTitle() const;
+ ResultElement();
+ ~ResultElement();
+
+ private:
+ QString*mSummary;
+ QString*mURL;
+ QString*mSnippet;
+ QString*mTitle;
+ QString*mCachedSize;
+ bool*mRelatedInformationPresent;
+ QString*mHostName;
+ DirectoryCategory*mDirectoryCategory;
+ QString*mDirectoryTitle;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/resultelementarray.cpp b/kode/kwsdl/tests/google/resultelementarray.cpp
new file mode 100644
index 000000000..f356f0101
--- /dev/null
+++ b/kode/kwsdl/tests/google/resultelementarray.cpp
@@ -0,0 +1,52 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "resultelementarray.h"
+
+#include <serializer.h>
+#include <qptrlist.h>
+#include <resultelement.h>
+
+void ResultElementArray::setItems( QPtrList<ResultElement>* items )
+{
+ mItems = items;
+}
+
+QPtrList<ResultElement>*ResultElementArray::items() const
+{
+ return mItems;
+}
+
+ResultElementArray::ResultElementArray()
+{
+ mItems = 0;
+}
+
+ResultElementArray::~ResultElementArray()
+{
+ delete mItems;
+ mItems = 0;
+}
+
+
diff --git a/kode/kwsdl/tests/google/resultelementarray.h b/kode/kwsdl/tests/google/resultelementarray.h
new file mode 100644
index 000000000..2d63fe4dd
--- /dev/null
+++ b/kode/kwsdl/tests/google/resultelementarray.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef RESULTELEMENTARRAY_H
+#define RESULTELEMENTARRAY_H
+
+#include <qptrlist.h>
+
+class ResultElement;
+
+class ResultElementArray
+{
+ public:
+ void setItems( QPtrList<ResultElement>* items );
+ QPtrList<ResultElement>*items() const;
+ ResultElementArray();
+ ~ResultElementArray();
+
+ private:
+ QPtrList<ResultElement>*mItems;
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/serializer.cpp b/kode/kwsdl/tests/google/serializer.cpp
new file mode 100644
index 000000000..595666fab
--- /dev/null
+++ b/kode/kwsdl/tests/google/serializer.cpp
@@ -0,0 +1,627 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "serializer.h"
+
+#include <kmdcodec.h>
+#include <resultelementarray.h>
+#include <directorycategoryarray.h>
+#include <googlesearchresult.h>
+#include <directorycategory.h>
+#include <resultelement.h>
+
+QString Serializer::marshalValue( const QString* value )
+{
+ return *value;
+}
+
+void Serializer::demarshalValue( const QString &str, QString *value )
+{
+ *value = str;
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QString* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:string" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, QString* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const bool* value )
+{
+ return (*value ? "true" : "false");
+}
+
+void Serializer::demarshalValue( const QString &str, bool *value )
+{
+ *value = (str.lower() == "true" ? true : false);
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const bool* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:boolean" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, bool* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const float* value )
+{
+ return QString::number( *value );
+}
+
+void Serializer::demarshalValue( const QString &str, float *value )
+{
+ *value = str.toFloat();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const float* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:TODO" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, float* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const int* value )
+{
+ return QString::number( *value );
+}
+
+void Serializer::demarshalValue( const QString &str, int *value )
+{
+ *value = str.toInt();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const int* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:int" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, int* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const unsigned int* value )
+{
+ return QString::number( *value );
+}
+
+void Serializer::demarshalValue( const QString &str, unsigned int *value )
+{
+ *value = str.toUInt();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const unsigned int* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:unsignedByte" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, unsigned int* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const double* value )
+{
+ return QString::number( *value );
+}
+
+void Serializer::demarshalValue( const QString &str, double *value )
+{
+ *value = str.toDouble();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const double* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:double" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, double* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const char* value )
+{
+ return QString( QChar( *value ) );
+}
+
+void Serializer::demarshalValue( const QString &str, char *value )
+{
+ *value = str[ 0 ].latin1();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const char* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:byte" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, char* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const unsigned char* value )
+{
+ return QString( QChar( *value ) );
+}
+
+void Serializer::demarshalValue( const QString &str, unsigned char *value )
+{
+ *value = str[ 0 ].latin1();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const unsigned char* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:unsignedByte" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, unsigned char* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const short* value )
+{
+ return QString::number( *value );
+}
+
+void Serializer::demarshalValue( const QString &str, short *value )
+{
+ *value = str.toShort();
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const short* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:short" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, short* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const QByteArray* value )
+{
+ return QString::fromUtf8( KCodecs::base64Encode( *value ) );
+}
+
+void Serializer::demarshalValue( const QString &str, QByteArray *value )
+{
+ *value = KCodecs::base64Decode( str.utf8() );
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QByteArray* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:base64Binary" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, QByteArray* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const QDateTime* value )
+{
+ return value->toString( Qt::ISODate );
+}
+
+void Serializer::demarshalValue( const QString &str, QDateTime *value )
+{
+ *value = QDateTime::fromString( str, Qt::ISODate );
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QDateTime* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:dateTime" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, QDateTime* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+QString Serializer::marshalValue( const QDate* value )
+{
+ return value->toString( Qt::ISODate );
+}
+
+void Serializer::demarshalValue( const QString &str, QDate *value )
+{
+ *value = QDate::fromString( str, Qt::ISODate );
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QDate* value )
+{
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xsi:type", "xsd:date" );
+ element.appendChild( doc.createTextNode( Serializer::marshalValue( value ) ) );
+ parent.appendChild( element );
+}
+
+void Serializer::demarshal( const QDomElement &element, QDate* value )
+{
+ Serializer::demarshalValue( element.text(), value );
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const ResultElementArray* value )
+{
+ QDomElement root = doc.createElement( name );
+ root.setAttribute( "xsi:type", "ns1:ResultElementArray" );
+ parent.appendChild( root );
+ if ( value->items() ) {
+ const QPtrList<ResultElement>* list = value->items();
+
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xmlns:ns1", "http://schemas.xmlsoap.org/soap/encoding/" );
+ element.setAttribute( "xsi:type", "ns1:Array" );
+ element.setAttribute( "ns1:arrayType", "ns1:ResultElement[" + QString::number( list->count() ) + "]" );
+ parent.appendChild( element );
+
+ QPtrListIterator<ResultElement> it( *list );
+ while ( it.current() != 0 ) {
+ Serializer::marshal( doc, element, "item", it.current() );
+ ++it;
+ }
+ }
+}
+
+void Serializer::demarshal( const QDomElement &parent, ResultElementArray* value )
+{
+ QPtrList<ResultElement>* itemsList = new QPtrList<ResultElement>();
+ itemsList->setAutoDelete( true );
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "item" ) {
+ ResultElement *item = new ResultElement;
+ Serializer::demarshal( element, item );
+ itemsList->append( item );
+ }
+ }
+ node = node.nextSibling();
+ }
+
+ value->setItems( itemsList );
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const DirectoryCategoryArray* value )
+{
+ QDomElement root = doc.createElement( name );
+ root.setAttribute( "xsi:type", "ns1:DirectoryCategoryArray" );
+ parent.appendChild( root );
+ if ( value->items() ) {
+ const QPtrList<DirectoryCategory>* list = value->items();
+
+ QDomElement element = doc.createElement( name );
+ element.setAttribute( "xmlns:ns1", "http://schemas.xmlsoap.org/soap/encoding/" );
+ element.setAttribute( "xsi:type", "ns1:Array" );
+ element.setAttribute( "ns1:arrayType", "ns1:DirectoryCategory[" + QString::number( list->count() ) + "]" );
+ parent.appendChild( element );
+
+ QPtrListIterator<DirectoryCategory> it( *list );
+ while ( it.current() != 0 ) {
+ Serializer::marshal( doc, element, "item", it.current() );
+ ++it;
+ }
+ }
+}
+
+void Serializer::demarshal( const QDomElement &parent, DirectoryCategoryArray* value )
+{
+ QPtrList<DirectoryCategory>* itemsList = new QPtrList<DirectoryCategory>();
+ itemsList->setAutoDelete( true );
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "item" ) {
+ DirectoryCategory *item = new DirectoryCategory;
+ Serializer::demarshal( element, item );
+ itemsList->append( item );
+ }
+ }
+ node = node.nextSibling();
+ }
+
+ value->setItems( itemsList );
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const GoogleSearchResult* value )
+{
+ QDomElement root = doc.createElement( name );
+ root.setAttribute( "xsi:type", "ns1:GoogleSearchResult" );
+ parent.appendChild( root );
+ if ( value->documentFiltering() ) {
+ Serializer::marshal( doc, root, "documentFiltering", value->documentFiltering() );
+ }
+ if ( value->searchComments() ) {
+ Serializer::marshal( doc, root, "searchComments", value->searchComments() );
+ }
+ if ( value->estimatedTotalResultsCount() ) {
+ Serializer::marshal( doc, root, "estimatedTotalResultsCount", value->estimatedTotalResultsCount() );
+ }
+ if ( value->estimateIsExact() ) {
+ Serializer::marshal( doc, root, "estimateIsExact", value->estimateIsExact() );
+ }
+ if ( value->resultElements() ) {
+ Serializer::marshal( doc, root, "resultElements", value->resultElements() );
+ }
+ if ( value->searchQuery() ) {
+ Serializer::marshal( doc, root, "searchQuery", value->searchQuery() );
+ }
+ if ( value->startIndex() ) {
+ Serializer::marshal( doc, root, "startIndex", value->startIndex() );
+ }
+ if ( value->endIndex() ) {
+ Serializer::marshal( doc, root, "endIndex", value->endIndex() );
+ }
+ if ( value->searchTips() ) {
+ Serializer::marshal( doc, root, "searchTips", value->searchTips() );
+ }
+ if ( value->directoryCategories() ) {
+ Serializer::marshal( doc, root, "directoryCategories", value->directoryCategories() );
+ }
+ if ( value->searchTime() ) {
+ Serializer::marshal( doc, root, "searchTime", value->searchTime() );
+ }
+}
+
+void Serializer::demarshal( const QDomElement &parent, GoogleSearchResult* value )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "documentFiltering" ) {
+ bool* item = new bool;
+ Serializer::demarshal( element, item );
+ value->setDocumentFiltering( item );
+ }
+ if ( element.tagName() == "searchComments" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setSearchComments( item );
+ }
+ if ( element.tagName() == "estimatedTotalResultsCount" ) {
+ int* item = new int;
+ Serializer::demarshal( element, item );
+ value->setEstimatedTotalResultsCount( item );
+ }
+ if ( element.tagName() == "estimateIsExact" ) {
+ bool* item = new bool;
+ Serializer::demarshal( element, item );
+ value->setEstimateIsExact( item );
+ }
+ if ( element.tagName() == "resultElements" ) {
+ ResultElementArray* item = new ResultElementArray;
+ Serializer::demarshal( element, item );
+ value->setResultElements( item );
+ }
+ if ( element.tagName() == "searchQuery" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setSearchQuery( item );
+ }
+ if ( element.tagName() == "startIndex" ) {
+ int* item = new int;
+ Serializer::demarshal( element, item );
+ value->setStartIndex( item );
+ }
+ if ( element.tagName() == "endIndex" ) {
+ int* item = new int;
+ Serializer::demarshal( element, item );
+ value->setEndIndex( item );
+ }
+ if ( element.tagName() == "searchTips" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setSearchTips( item );
+ }
+ if ( element.tagName() == "directoryCategories" ) {
+ DirectoryCategoryArray* item = new DirectoryCategoryArray;
+ Serializer::demarshal( element, item );
+ value->setDirectoryCategories( item );
+ }
+ if ( element.tagName() == "searchTime" ) {
+ double* item = new double;
+ Serializer::demarshal( element, item );
+ value->setSearchTime( item );
+ }
+ }
+ node = node.nextSibling();
+ }
+
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const DirectoryCategory* value )
+{
+ QDomElement root = doc.createElement( name );
+ root.setAttribute( "xsi:type", "ns1:DirectoryCategory" );
+ parent.appendChild( root );
+ if ( value->fullViewableName() ) {
+ Serializer::marshal( doc, root, "fullViewableName", value->fullViewableName() );
+ }
+ if ( value->specialEncoding() ) {
+ Serializer::marshal( doc, root, "specialEncoding", value->specialEncoding() );
+ }
+}
+
+void Serializer::demarshal( const QDomElement &parent, DirectoryCategory* value )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "fullViewableName" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setFullViewableName( item );
+ }
+ if ( element.tagName() == "specialEncoding" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setSpecialEncoding( item );
+ }
+ }
+ node = node.nextSibling();
+ }
+
+}
+
+void Serializer::marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const ResultElement* value )
+{
+ QDomElement root = doc.createElement( name );
+ root.setAttribute( "xsi:type", "ns1:ResultElement" );
+ parent.appendChild( root );
+ if ( value->summary() ) {
+ Serializer::marshal( doc, root, "summary", value->summary() );
+ }
+ if ( value->uRL() ) {
+ Serializer::marshal( doc, root, "URL", value->uRL() );
+ }
+ if ( value->snippet() ) {
+ Serializer::marshal( doc, root, "snippet", value->snippet() );
+ }
+ if ( value->title() ) {
+ Serializer::marshal( doc, root, "title", value->title() );
+ }
+ if ( value->cachedSize() ) {
+ Serializer::marshal( doc, root, "cachedSize", value->cachedSize() );
+ }
+ if ( value->relatedInformationPresent() ) {
+ Serializer::marshal( doc, root, "relatedInformationPresent", value->relatedInformationPresent() );
+ }
+ if ( value->hostName() ) {
+ Serializer::marshal( doc, root, "hostName", value->hostName() );
+ }
+ if ( value->directoryCategory() ) {
+ Serializer::marshal( doc, root, "directoryCategory", value->directoryCategory() );
+ }
+ if ( value->directoryTitle() ) {
+ Serializer::marshal( doc, root, "directoryTitle", value->directoryTitle() );
+ }
+}
+
+void Serializer::demarshal( const QDomElement &parent, ResultElement* value )
+{
+ QDomNode node = parent.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "summary" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setSummary( item );
+ }
+ if ( element.tagName() == "URL" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setURL( item );
+ }
+ if ( element.tagName() == "snippet" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setSnippet( item );
+ }
+ if ( element.tagName() == "title" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setTitle( item );
+ }
+ if ( element.tagName() == "cachedSize" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setCachedSize( item );
+ }
+ if ( element.tagName() == "relatedInformationPresent" ) {
+ bool* item = new bool;
+ Serializer::demarshal( element, item );
+ value->setRelatedInformationPresent( item );
+ }
+ if ( element.tagName() == "hostName" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setHostName( item );
+ }
+ if ( element.tagName() == "directoryCategory" ) {
+ DirectoryCategory* item = new DirectoryCategory;
+ Serializer::demarshal( element, item );
+ value->setDirectoryCategory( item );
+ }
+ if ( element.tagName() == "directoryTitle" ) {
+ QString* item = new QString;
+ Serializer::demarshal( element, item );
+ value->setDirectoryTitle( item );
+ }
+ }
+ node = node.nextSibling();
+ }
+
+}
+
+
diff --git a/kode/kwsdl/tests/google/serializer.h b/kode/kwsdl/tests/google/serializer.h
new file mode 100644
index 000000000..d2db93d87
--- /dev/null
+++ b/kode/kwsdl/tests/google/serializer.h
@@ -0,0 +1,103 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef SERIALIZER_H
+#define SERIALIZER_H
+
+#include <qcstring.h>
+#include <qdom.h>
+#include <qdatetime.h>
+#include <qstring.h>
+#include <qptrlist.h>
+
+class ResultElementArray;
+class DirectoryCategoryArray;
+class GoogleSearchResult;
+class DirectoryCategory;
+class ResultElement;
+
+class Serializer
+{
+ public:
+ static QString marshalValue( const QString* value );
+ static void demarshalValue( const QString &str, QString *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QString* value );
+ static void demarshal( const QDomElement &element, QString* value );
+ static QString marshalValue( const bool* value );
+ static void demarshalValue( const QString &str, bool *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const bool* value );
+ static void demarshal( const QDomElement &element, bool* value );
+ static QString marshalValue( const float* value );
+ static void demarshalValue( const QString &str, float *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const float* value );
+ static void demarshal( const QDomElement &element, float* value );
+ static QString marshalValue( const int* value );
+ static void demarshalValue( const QString &str, int *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const int* value );
+ static void demarshal( const QDomElement &element, int* value );
+ static QString marshalValue( const unsigned int* value );
+ static void demarshalValue( const QString &str, unsigned int *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const unsigned int* value );
+ static void demarshal( const QDomElement &element, unsigned int* value );
+ static QString marshalValue( const double* value );
+ static void demarshalValue( const QString &str, double *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const double* value );
+ static void demarshal( const QDomElement &element, double* value );
+ static QString marshalValue( const char* value );
+ static void demarshalValue( const QString &str, char *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const char* value );
+ static void demarshal( const QDomElement &element, char* value );
+ static QString marshalValue( const unsigned char* value );
+ static void demarshalValue( const QString &str, unsigned char *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const unsigned char* value );
+ static void demarshal( const QDomElement &element, unsigned char* value );
+ static QString marshalValue( const short* value );
+ static void demarshalValue( const QString &str, short *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const short* value );
+ static void demarshal( const QDomElement &element, short* value );
+ static QString marshalValue( const QByteArray* value );
+ static void demarshalValue( const QString &str, QByteArray *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QByteArray* value );
+ static void demarshal( const QDomElement &element, QByteArray* value );
+ static QString marshalValue( const QDateTime* value );
+ static void demarshalValue( const QString &str, QDateTime *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QDateTime* value );
+ static void demarshal( const QDomElement &element, QDateTime* value );
+ static QString marshalValue( const QDate* value );
+ static void demarshalValue( const QString &str, QDate *value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const QDate* value );
+ static void demarshal( const QDomElement &element, QDate* value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const ResultElementArray* value );
+ static void demarshal( const QDomElement &parent, ResultElementArray* value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const DirectoryCategoryArray* value );
+ static void demarshal( const QDomElement &parent, DirectoryCategoryArray* value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const GoogleSearchResult* value );
+ static void demarshal( const QDomElement &parent, GoogleSearchResult* value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const DirectoryCategory* value );
+ static void demarshal( const QDomElement &parent, DirectoryCategory* value );
+ static void marshal( QDomDocument &doc, QDomElement &parent, const QString &name, const ResultElement* value );
+ static void demarshal( const QDomElement &parent, ResultElement* value );
+
+};
+
+#endif
diff --git a/kode/kwsdl/tests/google/transport.cpp b/kode/kwsdl/tests/google/transport.cpp
new file mode 100644
index 000000000..4f4583ba2
--- /dev/null
+++ b/kode/kwsdl/tests/google/transport.cpp
@@ -0,0 +1,75 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "transport.h"
+
+#include <kdebug.h>
+
+Transport::Transport( const QString &url )
+{
+ mUrl = url;
+}
+
+void Transport::query( const QString &xml )
+{
+ mData.truncate( 0 );
+
+ QByteArray postData;
+ QDataStream stream( postData, IO_WriteOnly );
+ stream.writeRawBytes( xml.utf8(), xml.utf8().length() );
+
+ KIO::TransferJob* job = KIO::http_post( KURL( mUrl ), postData, false );
+ if ( !job ) {
+ kdWarning() << "Unable to create KIO job for " << mUrl << endl;
+ return;
+ }
+
+ job->addMetaData( "UserAgent", "KWSDL" );
+ job->addMetaData( "content-type", "Content-Type: text/xml; charset=utf-8" );
+
+ connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) );
+ connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) );
+}
+
+void Transport::slotData( KIO::Job*, const QByteArray &data )
+{
+ unsigned int oldSize = mData.size();
+ mData.resize( oldSize + data.size() );
+ memcpy( mData.data() + oldSize, data.data(), data.size() );
+}
+
+void Transport::slotResult( KIO::Job* job )
+{
+ if ( job->error() != 0 ) {
+ kdWarning() << "Error occurred " << job->errorText() << endl;
+ kdWarning() << mData << endl;
+ return;
+ }
+
+ emit result( QString::fromUtf8( mData.data(), mData.size() ) );
+}
+
+
+#include "transport.moc"
+
diff --git a/kode/kwsdl/tests/google/transport.h b/kode/kwsdl/tests/google/transport.h
new file mode 100644
index 000000000..b39d6e82c
--- /dev/null
+++ b/kode/kwsdl/tests/google/transport.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+#ifndef TRANSPORT_H
+#define TRANSPORT_H
+
+#include <qobject.h>
+#include <kio/job.h>
+
+class Transport : public QObject
+{
+ Q_OBJECT
+
+ public:
+ Transport( const QString &url );
+ void query( const QString &xml );
+
+ signals:
+ void result( const QString &xml );
+
+ private slots:
+ void slotData( KIO::Job*, const QByteArray &data );
+ void slotResult( KIO::Job* job );
+
+ private:
+ QString mUrl;
+ QByteArray mData;
+};
+
+#endif
diff --git a/kode/kwsdl/typemapper.cpp b/kode/kwsdl/typemapper.cpp
new file mode 100644
index 000000000..b8d1a80ba
--- /dev/null
+++ b/kode/kwsdl/typemapper.cpp
@@ -0,0 +1,300 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qmap.h>
+
+#include <schema/attribute.h>
+#include <schema/complextype.h>
+#include <schema/element.h>
+#include <schema/simpletype.h>
+#include <schema/xsdtype.h>
+
+#include "typemapper.h"
+
+using namespace KWSDL;
+
+TypeMapper::TypeMapper()
+{
+ mMap.insert( "any", TypeInfo( "any", "QString", "qstring.h" ) );
+ mMap.insert( "anyURI", TypeInfo( "anyUri", "QString", "qstring.h" ) );
+ mMap.insert( "base64Binary", TypeInfo( "base64Binary", "QByteArray", "qcstring.h" ) );
+ mMap.insert( "binary", TypeInfo( "binary", "QByteArray", "qcstring.h" ) );
+ mMap.insert( "boolean", TypeInfo( "boolean", "bool", "" ) );
+ mMap.insert( "byte", TypeInfo( "byte", "char", "" ) );
+ mMap.insert( "date", TypeInfo( "date", "QDate", "qdatetime.h" ) );
+ mMap.insert( "dateTime", TypeInfo( "dateTime", "QDateTime", "qdatetime.h" ) );
+ mMap.insert( "decimal", TypeInfo( "decimal", "float", "" ) );
+ mMap.insert( "double", TypeInfo( "double", "double", "" ) );
+ mMap.insert( "duration", TypeInfo( "duration", "QString", "qstring.h" ) ); // TODO: add duration class
+ mMap.insert( "int", TypeInfo( "int", "int", "" ) );
+ mMap.insert( "language", TypeInfo( "language", "QString", "qstring.h" ) );
+ mMap.insert( "short", TypeInfo( "short", "short", "" ) );
+ mMap.insert( "string", TypeInfo( "string", "QString", "qstring.h" ) );
+ mMap.insert( "unsignedByte", TypeInfo( "unsignedByte", "unsigned char", "" ) );
+ mMap.insert( "unsignedInt", TypeInfo( "unsignedInt", "unsigned int", "" ) );
+}
+
+void TypeMapper::setTypes( const Schema::Types &types )
+{
+ mTypes = types;
+}
+
+QString TypeMapper::type( const Schema::XSDType *type ) const
+{
+ QString typeName = type->name();
+ typeName[ 0 ] = typeName[ 0 ].upper();
+
+ return typeName;
+}
+
+QString TypeMapper::type( const Schema::Element *element ) const
+{
+ QString typeName = element->typeName();
+
+ QString type;
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() )
+ type = it.data().type;
+
+ if ( type.isEmpty() ) {
+ type = typeName;
+ type[ 0 ] = type[ 0 ].upper();
+ }
+
+ return type;
+}
+
+QString TypeMapper::type( const Schema::Attribute *attribute ) const
+{
+ QString typeName = attribute->typeName();
+
+ QString type;
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() )
+ type = it.data().type;
+
+ if ( type.isEmpty() ) {
+ type = typeName;
+ type[ 0 ] = type[ 0 ].upper();
+ }
+
+ return type;
+}
+
+QString TypeMapper::type( const QString &typeName ) const
+{
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() )
+ return it.data().type;
+
+ Schema::SimpleType::List simpleTypes = mTypes.simpleTypes();
+ Schema::SimpleType::List::ConstIterator simpleIt;
+ for ( simpleIt = simpleTypes.begin(); simpleIt != simpleTypes.end(); ++simpleIt ) {
+ if ( (*simpleIt).name() == typeName ) {
+ return type( &(*simpleIt) );
+ }
+ }
+
+ Schema::ComplexType::List complexTypes = mTypes.complexTypes();
+ Schema::ComplexType::List::ConstIterator complexIt;
+ for ( complexIt = complexTypes.begin(); complexIt != complexTypes.end(); ++complexIt ) {
+ if ( (*complexIt).name() == typeName ) {
+ return type( &(*complexIt) );
+ }
+ }
+
+ Schema::Element::List elements = mTypes.elements();
+ Schema::Element::List::ConstIterator elemIt;
+ for ( elemIt = elements.begin(); elemIt != elements.end(); ++elemIt ) {
+ if ( (*elemIt).name() == typeName ) {
+ return type( &(*elemIt) );
+ }
+ }
+
+ return QString();
+}
+
+QStringList TypeMapper::header( const Schema::XSDType *type ) const
+{
+ return type->name().lower() + ".h";
+}
+
+QStringList TypeMapper::header( const Schema::Element *element ) const
+{
+ QString typeName = element->typeName();
+
+ QStringList headers;
+
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() ) {
+ if ( !it.data().header.isEmpty() )
+ headers.append( it.data().header );
+ } else
+ headers.append( typeName.lower() + ".h" );
+
+ if ( element->maxOccurs() > 1 )
+ headers.append( "qptrlist.h" );
+
+ return headers;
+}
+
+QMap<QString, QString> TypeMapper::headerDec( const Schema::Element *element ) const
+{
+ QString typeName = element->typeName();
+
+ QMap<QString, QString> headers;
+
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() ) {
+ if ( !it.data().header.isEmpty() ) {
+ if ( it.data().type == "QByteArray" )
+ headers.insert( it.data().header, QString() );
+ else
+ headers.insert( it.data().header, it.data().type );
+ }
+ } else {
+ typeName[ 0 ] = typeName[ 0 ].upper();
+ headers.insert( typeName.lower() + ".h", typeName );
+ }
+
+ if ( element->maxOccurs() > 1 )
+ headers.insert( "qptrlist.h", QString() );
+
+ return headers;
+}
+
+QStringList TypeMapper::header( const Schema::Attribute *attribute ) const
+{
+ QString typeName = attribute->typeName();
+
+ QStringList headers;
+
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() ) {
+ if ( !it.data().header.isEmpty() )
+ headers.append( it.data().header );
+ } else
+ headers.append( typeName.lower() + ".h" );
+
+ return headers;
+}
+
+QMap<QString, QString> TypeMapper::headerDec( const Schema::Attribute *attribute ) const
+{
+ QString typeName = attribute->typeName();
+
+ QMap<QString, QString> headers;
+
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() ) {
+ if ( !it.data().header.isEmpty() ) {
+ if ( it.data().type == "QByteArray" )
+ headers.insert( it.data().header, QString() );
+ else
+ headers.insert( it.data().header, it.data().type );
+ }
+ } else {
+ typeName[ 0 ] = typeName[ 0 ].upper();
+ headers.insert( typeName.lower() + ".h", typeName );
+ }
+
+ return headers;
+}
+
+QStringList TypeMapper::header( const QString &typeName ) const
+{
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() )
+ return it.data().header;
+
+ const QString convertedType = type( typeName );
+ if ( isBaseType( convertedType ) ) {
+ for ( it = mMap.begin(); it != mMap.end(); ++it )
+ if ( it.data().type == convertedType )
+ return it.data().header;
+ } else
+ return typeName.lower() + ".h";
+
+ return QStringList();
+}
+
+QMap<QString, QString> TypeMapper::headerDec( const QString &typeName ) const
+{
+ QString type( typeName );
+ QMap<QString, QString> headers;
+
+ // check basic types
+ QMap<QString, TypeInfo>::ConstIterator it = mMap.find( typeName );
+ if ( it != mMap.end() ) {
+ if ( !it.data().header.isEmpty() ) {
+ if ( it.data().type == "QByteArray" )
+ headers.insert( it.data().header, QString() );
+ else
+ headers.insert( it.data().header, it.data().type );
+ }
+ } else {
+ type[ 0 ] = type[ 0 ].upper();
+ headers.insert( typeName.lower() + ".h", type );
+ }
+
+ return headers;
+}
+
+QString TypeMapper::argument( const QString &name, const Schema::Element *element ) const
+{
+ QString typeName = type( element );
+
+ if ( element->maxOccurs() > 1 )
+ return "QPtrList<" + typeName + ">* " + name;
+ else
+ return typeName + "* " + name;
+}
+
+QString TypeMapper::argument( const QString &name, const Schema::Attribute *attribute ) const
+{
+ return type( attribute ) + "* " + name;
+}
+
+QString TypeMapper::argument( const QString &name, const QString &typeName, bool isList ) const
+{
+ if ( isList ) {
+ return "QPtrList<" + type( typeName ) + ">* " + name;
+ } else {
+ return type( typeName ) + "* " + name;
+ }
+}
+
+bool TypeMapper::isBaseType( const QString &type ) const
+{
+ QMap<QString, TypeInfo>::ConstIterator it;
+ for ( it = mMap.begin(); it != mMap.end(); ++it )
+ if ( it.data().type == type )
+ return true;
+
+ return false;
+}
diff --git a/kode/kwsdl/typemapper.h b/kode/kwsdl/typemapper.h
new file mode 100644
index 000000000..529b004fe
--- /dev/null
+++ b/kode/kwsdl/typemapper.h
@@ -0,0 +1,85 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_TYPEMAPPER_H
+#define KWSDL_TYPEMAPPER_H
+
+#include <qstringlist.h>
+
+#include <schema/types.h>
+
+namespace Schema {
+class Attribute;
+class Element;
+class XSDType;
+};
+
+namespace KWSDL {
+
+class TypeInfo
+{
+ public:
+ TypeInfo()
+ {}
+
+ TypeInfo( const QString &_xsdType, const QString &_type, const QString &_header )
+ : xsdType( _xsdType ), type( _type ), header( _header )
+ {}
+
+ QString xsdType;
+ QString type;
+ QString header;
+};
+
+class TypeMapper
+{
+ public:
+ TypeMapper();
+
+ void setTypes( const Schema::Types &types );
+
+ QString type( const Schema::XSDType *type ) const;
+ QString type( const Schema::Element *element ) const;
+ QString type( const Schema::Attribute *attribute ) const;
+ QString type( const QString &typeName ) const;
+
+ QStringList header( const Schema::XSDType *type ) const;
+ QStringList header( const Schema::Element *element ) const;
+ QMap<QString,QString> headerDec( const Schema::Element *element ) const;
+ QStringList header( const Schema::Attribute *attribute ) const;
+ QMap<QString,QString> headerDec( const Schema::Attribute *attribute ) const;
+ QStringList header( const QString &typeName ) const;
+ QMap<QString,QString> headerDec( const QString &typeName ) const;
+
+ QString argument( const QString &name, const Schema::Element *element ) const;
+ QString argument( const QString &name, const Schema::Attribute *attribute ) const;
+ QString argument( const QString &name, const QString &typeName, bool isList = false ) const;
+
+ private:
+ bool isBaseType( const QString& ) const;
+
+ QMap<QString, TypeInfo> mMap;
+ Schema::Types mTypes;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/wscl/Makefile.am b/kode/kwsdl/wscl/Makefile.am
new file mode 100644
index 000000000..9f02543f7
--- /dev/null
+++ b/kode/kwsdl/wscl/Makefile.am
@@ -0,0 +1,14 @@
+INCLUDES = -I$(top_srcdir) -I.. -I$(top_srcdir)/libkdepim $(all_includes)
+
+lib_LTLIBRARIES = libwscl.la
+
+libwscl_la_SOURCES = conversation.cpp documents.cpp interaction.cpp parser.cpp transition.cpp
+libwscl_la_LDFLAGS = $(all_libraries) -version-info 1:0:0 -no-undefined
+libwscl_la_LIBADD = -lqt-mt
+
+#bin_PROGRAMS = wscltest
+#wscltest_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+#wscltest_SOURCES = main.cpp
+#wscltest_LDADD = libwscl.la
+
+METASOURCES = AUTO
diff --git a/kode/kwsdl/wscl/conversation.cpp b/kode/kwsdl/wscl/conversation.cpp
new file mode 100644
index 000000000..692f566fb
--- /dev/null
+++ b/kode/kwsdl/wscl/conversation.cpp
@@ -0,0 +1,122 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "conversation.h"
+
+using namespace WSCL;
+
+Conversation::Conversation()
+{
+}
+
+Conversation::~Conversation()
+{
+}
+
+void Conversation::setName( const QString &name )
+{
+ mName = name;
+}
+
+QString Conversation::name() const
+{
+ return mName;
+}
+
+void Conversation::setVersion( const QString &version )
+{
+ mVersion = version;
+}
+
+QString Conversation::version() const
+{
+ return mVersion;
+}
+
+void Conversation::setDescription( const QString &description )
+{
+ mDescription = description;
+}
+
+QString Conversation::description() const
+{
+ return mDescription;
+}
+
+void Conversation::setNameSpace( const QString &nameSpace )
+{
+ mNameSpace = nameSpace;
+}
+
+QString Conversation::nameSpace() const
+{
+ return mNameSpace;
+}
+
+void Conversation::setSchema( const QString &schema )
+{
+ mSchema = schema;
+}
+
+QString Conversation::schema() const
+{
+ return mSchema;
+}
+
+void Conversation::setInitialInteraction( const QString &initialInteraction )
+{
+ mInitialInteraction = initialInteraction;
+}
+
+QString Conversation::initialInteraction() const
+{
+ return mInitialInteraction;
+}
+
+void Conversation::setFinalInteraction( const QString &finalInteraction )
+{
+ mFinalInteraction = finalInteraction;
+}
+
+QString Conversation::finalInteraction() const
+{
+ return mFinalInteraction;
+}
+
+void Conversation::setInteractions( const Interaction::List &interactions )
+{
+ mInteractions = interactions;
+}
+
+Interaction::List Conversation::interactions() const
+{
+ return mInteractions;
+}
+
+void Conversation::setTransitions( const Transition::List &transitions )
+{
+ mTransitions = transitions;
+}
+
+Transition::List Conversation::transitions() const
+{
+ return mTransitions;
+}
diff --git a/kode/kwsdl/wscl/conversation.h b/kode/kwsdl/wscl/conversation.h
new file mode 100644
index 000000000..757edfab9
--- /dev/null
+++ b/kode/kwsdl/wscl/conversation.h
@@ -0,0 +1,78 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WSCL_CONVERSATION_H
+#define WSCL_CONVERSATION_H
+
+#include "interaction.h"
+#include "transition.h"
+
+namespace WSCL {
+
+class Conversation
+{
+ public:
+ Conversation();
+ ~Conversation();
+
+ void setName( const QString &name );
+ QString name() const;
+
+ void setVersion( const QString &version );
+ QString version() const;
+
+ void setDescription( const QString &description );
+ QString description() const;
+
+ void setNameSpace( const QString &nameSpace );
+ QString nameSpace() const;
+
+ void setSchema( const QString &schema );
+ QString schema() const;
+
+ void setInitialInteraction( const QString &initialInteraction );
+ QString initialInteraction() const;
+
+ void setFinalInteraction( const QString &finalInteraction );
+ QString finalInteraction() const;
+
+ void setInteractions( const Interaction::List &interactions );
+ Interaction::List interactions() const;
+
+ void setTransitions( const Transition::List &transitions );
+ Transition::List transitions() const;
+
+ private:
+ QString mName;
+ QString mVersion;
+ QString mDescription;
+ QString mNameSpace;
+ QString mSchema;
+ QString mInitialInteraction;
+ QString mFinalInteraction;
+
+ Interaction::List mInteractions;
+ Transition::List mTransitions;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/wscl/documents.cpp b/kode/kwsdl/wscl/documents.cpp
new file mode 100644
index 000000000..92b7928e4
--- /dev/null
+++ b/kode/kwsdl/wscl/documents.cpp
@@ -0,0 +1,107 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "documents.h"
+
+using namespace WSCL;
+
+void XMLDocument::setId( const QString &id )
+{
+ mId = id;
+}
+
+QString XMLDocument::id() const
+{
+ return mId;
+}
+
+void XMLDocument::setSchema( const QString &schema )
+{
+ mSchema = schema;
+}
+
+QString XMLDocument::schema() const
+{
+ return mSchema;
+}
+
+
+void ReceiveSendDocument::setInputDocument( const XMLDocument &document )
+{
+ mInputDocument = document;
+}
+
+XMLDocument ReceiveSendDocument::inputDocument() const
+{
+ return mInputDocument;
+}
+
+void ReceiveSendDocument::setOutputDocuments( const XMLDocument::List &documents )
+{
+ mOutputDocuments = documents;
+}
+
+XMLDocument::List ReceiveSendDocument::outputDocuments() const
+{
+ return mOutputDocuments;
+}
+
+
+void SendReceiveDocument::setInputDocuments( const XMLDocument::List &documents )
+{
+ mInputDocuments = documents;
+}
+
+XMLDocument::List SendReceiveDocument::inputDocuments() const
+{
+ return mInputDocuments;
+}
+
+void SendReceiveDocument::setOutputDocument( const XMLDocument &document )
+{
+ mOutputDocument = document;
+}
+
+XMLDocument SendReceiveDocument::outputDocument() const
+{
+ return mOutputDocument;
+}
+
+void ReceiveDocument::setInputDocument( const XMLDocument &document )
+{
+ mInputDocument = document;
+}
+
+XMLDocument ReceiveDocument::inputDocument() const
+{
+ return mInputDocument;
+}
+
+void SendDocument::setOutputDocument( const XMLDocument &document )
+{
+ mOutputDocument = document;
+}
+
+XMLDocument SendDocument::outputDocument() const
+{
+ return mOutputDocument;
+}
+
diff --git a/kode/kwsdl/wscl/documents.h b/kode/kwsdl/wscl/documents.h
new file mode 100644
index 000000000..2bba60ad1
--- /dev/null
+++ b/kode/kwsdl/wscl/documents.h
@@ -0,0 +1,95 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WSCL_DOCUMENTS_H
+#define WSCL_DOCUMENTS_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+namespace WSCL {
+
+class XMLDocument
+{
+ public:
+ typedef QValueList<XMLDocument> List;
+
+ void setId( const QString &id );
+ QString id() const;
+
+ void setSchema( const QString &schema );
+ QString schema() const;
+
+ private:
+ QString mId;
+ QString mSchema;
+};
+
+class ReceiveSendDocument
+{
+ public:
+ void setInputDocument( const XMLDocument &document );
+ XMLDocument inputDocument() const;
+
+ void setOutputDocuments( const XMLDocument::List &documents );
+ XMLDocument::List outputDocuments() const;
+
+ private:
+ XMLDocument mInputDocument;
+ XMLDocument::List mOutputDocuments;
+};
+
+class SendReceiveDocument
+{
+ public:
+ void setInputDocuments( const XMLDocument::List &documents );
+ XMLDocument::List inputDocuments() const;
+
+ void setOutputDocument( const XMLDocument &document );
+ XMLDocument outputDocument() const;
+
+ private:
+ XMLDocument::List mInputDocuments;
+ XMLDocument mOutputDocument;
+};
+
+class ReceiveDocument
+{
+ public:
+ void setInputDocument( const XMLDocument &document );
+ XMLDocument inputDocument() const;
+ private:
+ XMLDocument mInputDocument;
+};
+
+class SendDocument
+{
+ public:
+ void setOutputDocument( const XMLDocument &document );
+ XMLDocument outputDocument() const;
+
+ private:
+ XMLDocument mOutputDocument;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/wscl/interaction.cpp b/kode/kwsdl/wscl/interaction.cpp
new file mode 100644
index 000000000..ff88408a9
--- /dev/null
+++ b/kode/kwsdl/wscl/interaction.cpp
@@ -0,0 +1,94 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "interaction.h"
+
+using namespace WSCL;
+
+Interaction::Interaction()
+ : mType( Empty )
+{
+}
+
+Interaction::~Interaction()
+{
+}
+
+void Interaction::setId( const QString &id )
+{
+ mId = id;
+}
+
+QString Interaction::id() const
+{
+ return mId;
+}
+
+void Interaction::setType( Type type )
+{
+ mType = type;
+}
+
+Interaction::Type Interaction::type() const
+{
+ return mType;
+}
+
+void Interaction::setSendReceiveDocument( const SendReceiveDocument &document )
+{
+ mSendReceiveDocument = document;
+}
+
+SendReceiveDocument Interaction::sendReceiveDocument() const
+{
+ return mSendReceiveDocument;
+}
+
+void Interaction::setReceiveSendDocument( const ReceiveSendDocument &document )
+{
+ mReceiveSendDocument = document;
+}
+
+ReceiveSendDocument Interaction::receiveSendDocument() const
+{
+ return mReceiveSendDocument;
+}
+
+void Interaction::setReceiveDocument( const ReceiveDocument &document )
+{
+ mReceiveDocument = document;
+}
+
+ReceiveDocument Interaction::receiveDocument() const
+{
+ return mReceiveDocument;
+}
+
+void Interaction::setSendDocument( const SendDocument &document )
+{
+ mSendDocument = document;
+}
+
+SendDocument Interaction::sendDocument() const
+{
+ return mSendDocument;
+}
+
diff --git a/kode/kwsdl/wscl/interaction.h b/kode/kwsdl/wscl/interaction.h
new file mode 100644
index 000000000..2700d7c00
--- /dev/null
+++ b/kode/kwsdl/wscl/interaction.h
@@ -0,0 +1,78 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WSCL_INTERACTION_H
+#define WSCL_INTERACTION_H
+
+#include <qvaluelist.h>
+
+#include "documents.h"
+
+namespace WSCL {
+
+class Interaction
+{
+ public:
+ typedef QValueList<Interaction> List;
+
+ enum Type
+ {
+ ReceiveSend,
+ SendReceive,
+ Receive,
+ Send,
+ Empty
+ };
+
+ Interaction();
+ ~Interaction();
+
+ void setId( const QString &id );
+ QString id() const;
+
+ void setType( Type type );
+ Type type() const;
+
+ void setSendReceiveDocument( const SendReceiveDocument &document );
+ SendReceiveDocument sendReceiveDocument() const;
+
+ void setReceiveSendDocument( const ReceiveSendDocument &document );
+ ReceiveSendDocument receiveSendDocument() const;
+
+ void setReceiveDocument( const ReceiveDocument &document );
+ ReceiveDocument receiveDocument() const;
+
+ void setSendDocument( const SendDocument &document );
+ SendDocument sendDocument() const;
+
+ private:
+ QString mId;
+ Type mType;
+
+ SendReceiveDocument mSendReceiveDocument;
+ ReceiveSendDocument mReceiveSendDocument;
+ ReceiveDocument mReceiveDocument;
+ SendDocument mSendDocument;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/wscl/parser.cpp b/kode/kwsdl/wscl/parser.cpp
new file mode 100644
index 000000000..129c3c3dc
--- /dev/null
+++ b/kode/kwsdl/wscl/parser.cpp
@@ -0,0 +1,224 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include <qdom.h>
+
+#include "parser.h"
+
+using namespace WSCL;
+
+Parser::Parser()
+{
+}
+
+Parser::~Parser()
+{
+}
+
+void Parser::parse( const QString &xml )
+{
+ QDomDocument doc( "kwscl" );
+ QString errorMsg;
+ int errorLine, errorColumn;
+ bool ok = doc.setContent( xml, true, &errorMsg, &errorLine, &errorColumn );
+ if ( !ok ) {
+ qDebug( "Error parsing wscl (%d:%d) %s", errorLine, errorColumn, errorMsg.latin1() );
+ return;
+ }
+
+ QDomNodeList nodes = doc.elementsByTagName( "Conversation" );
+ if ( nodes.count() <= 0 ) {
+ qDebug( "No conversation tag found in wscl data" );
+ return;
+ }
+
+ QDomElement conversationElement = nodes.item( 0 ).toElement();
+
+ mConversation.setName( conversationElement.attribute( "name" ) );
+ mConversation.setVersion( conversationElement.attribute( "version" ) );
+ mConversation.setDescription( conversationElement.attribute( "description" ) );
+ mConversation.setNameSpace( conversationElement.attribute( "targetNamespace" ) );
+ mConversation.setSchema( conversationElement.attribute( "hrefSchema" ) );
+ mConversation.setInitialInteraction( conversationElement.attribute( "initialInteraction" ) );
+ mConversation.setFinalInteraction( conversationElement.attribute( "finalInteraction" ) );
+
+ QDomNode node = conversationElement.firstChild();
+ while ( !node.isNull() ) {
+ QDomElement element = node.toElement();
+ if ( !element.isNull() ) {
+ if ( element.tagName() == "ConversationInteractions" ) {
+ Interaction::List interactions;
+
+ QDomNode interactionNode = element.firstChild();
+ while ( !interactionNode.isNull() ) {
+ QDomElement interactionElement = interactionNode.toElement();
+ if ( !interactionElement.isNull() ) {
+ if ( interactionElement.tagName() != "Interaction" ) {
+ qDebug( "Expected tag name 'Interaction', got '%s'", interactionElement.tagName().latin1() );
+ continue;
+ }
+
+ Interaction interaction;
+ interaction.setId( interactionElement.attribute( "id" ) );
+ const QString type = interactionElement.attribute( "interactionType" );
+ if ( type == "ReceiveSend" )
+ interaction.setType( Interaction::ReceiveSend );
+ else if ( type == "SendReceive" )
+ interaction.setType( Interaction::SendReceive );
+ else if ( type == "Receive" )
+ interaction.setType( Interaction::Receive );
+ else if ( type == "Send" )
+ interaction.setType( Interaction::Send );
+ else if ( type == "Empty" )
+ interaction.setType( Interaction::Empty );
+ else
+ qDebug( "Unknown interaction type '%s'", type.latin1() );
+
+ XMLDocument::List inputDocuments;
+ XMLDocument::List outputDocuments;
+ XMLDocument inputDocument;
+ XMLDocument outputDocument;
+
+ QDomNode contentNode = interactionElement.firstChild();
+ while ( !contentNode.isNull() ) {
+ QDomElement contentElement = contentNode.toElement();
+ if ( !contentElement.isNull() ) {
+ const QString tagName = contentElement.tagName();
+ if ( tagName == "InboundXMLDocument" ) {
+ XMLDocument document;
+ document.setId( contentElement.attribute( "id" ) );
+ document.setSchema( contentElement.attribute( "hrefSchema" ) );
+
+ inputDocuments.append( document );
+ inputDocument = document;
+ } else if ( tagName == "OutboundXMLDocument" ) {
+ XMLDocument document;
+ document.setId( contentElement.attribute( "id" ) );
+ document.setSchema( contentElement.attribute( "hrefSchema" ) );
+
+ outputDocuments.append( document );
+ outputDocument = document;
+ }
+ }
+
+
+ contentNode = contentNode.nextSibling();
+ }
+
+ switch ( interaction.type() ) {
+ case Interaction::ReceiveSend:
+ {
+ ReceiveSendDocument document;
+ document.setInputDocument( inputDocument );
+ document.setOutputDocuments( outputDocuments );
+ interaction.setReceiveSendDocument( document );
+ }
+ break;
+ case Interaction::SendReceive:
+ {
+ SendReceiveDocument document;
+ document.setInputDocuments( inputDocuments );
+ document.setOutputDocument( outputDocument );
+ interaction.setSendReceiveDocument( document );
+ }
+ break;
+ case Interaction::Receive:
+ {
+ ReceiveDocument document;
+ document.setInputDocument( inputDocument );
+ interaction.setReceiveDocument( document );
+ }
+ break;
+ case Interaction::Send:
+ {
+ SendDocument document;
+ document.setOutputDocument( outputDocument );
+ interaction.setSendDocument( document );
+ }
+ break;
+ case Interaction::Empty:
+ default:
+ break;
+ }
+
+ interactions.append( interaction );
+ }
+
+ interactionNode = interactionNode.nextSibling();
+ }
+
+ mConversation.setInteractions( interactions );
+
+ } else if ( element.tagName() == "ConversationTransitions" ) {
+ Transition::List transitions;
+
+ QDomNode transitionNode = element.firstChild();
+ while ( !transitionNode.isNull() ) {
+ QDomElement transitionElement = transitionNode.toElement();
+ if ( !transitionElement.isNull() ) {
+ if ( transitionElement.tagName() != "Transition" ) {
+ qDebug( "Expected tag name 'Transition', got '%s'", transitionElement.tagName().latin1() );
+ continue;
+ }
+
+ Transition transition;
+
+ QDomNode contentNode = transitionElement.firstChild();
+ while ( !contentNode.isNull() ) {
+ QDomElement contentElement = contentNode.toElement();
+ if ( !contentElement.isNull() ) {
+ const QString tagName = contentElement.tagName();
+ if ( tagName == "SourceInteraction" )
+ transition.setSourceInteraction( contentElement.attribute( "href" ) );
+ else if ( tagName == "DestinationInteraction" )
+ transition.setDestinationInteraction( contentElement.attribute( "href" ) );
+ else if ( tagName == "SourceInteractionCondition" )
+ transition.setSourceInteractionCondition( contentElement.attribute( "href" ) );
+ else
+ qDebug( "Unknown transition element %s", tagName.latin1() );
+ }
+
+ contentNode = contentNode.nextSibling();
+ }
+
+ transitions.append( transition );
+ }
+
+ transitionNode = transitionNode.nextSibling();
+ }
+
+ mConversation.setTransitions( transitions );
+ }
+ }
+
+ node = node.nextSibling();
+ }
+}
+
+void Parser::reset()
+{
+ mConversation = Conversation();
+}
+
+Conversation Parser::conversation() const
+{
+ return mConversation;
+}
diff --git a/kode/kwsdl/wscl/parser.h b/kode/kwsdl/wscl/parser.h
new file mode 100644
index 000000000..8f8824747
--- /dev/null
+++ b/kode/kwsdl/wscl/parser.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WSCL_PARSER_H
+#define WSCL_PARSER_H
+
+#include "conversation.h"
+
+namespace WSCL {
+
+class Parser
+{
+ public:
+ Parser();
+ ~Parser();
+
+ void parse( const QString &xml );
+ void reset();
+
+ Conversation conversation() const;
+
+ private:
+ Conversation mConversation;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/wscl/transition.cpp b/kode/kwsdl/wscl/transition.cpp
new file mode 100644
index 000000000..c3a088a04
--- /dev/null
+++ b/kode/kwsdl/wscl/transition.cpp
@@ -0,0 +1,63 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "transition.h"
+
+using namespace WSCL;
+
+Transition::Transition()
+{
+}
+
+Transition::~Transition()
+{
+}
+
+void Transition::setSourceInteraction( const QString &sourceInteraction )
+{
+ mSourceInteraction = sourceInteraction;
+}
+
+QString Transition::sourceInteraction() const
+{
+ return mSourceInteraction;
+}
+
+void Transition::setDestinationInteraction( const QString &destinationInteraction )
+{
+ mDestinationInteraction = destinationInteraction;
+}
+
+QString Transition::destinationInteraction() const
+{
+ return mDestinationInteraction;
+}
+
+void Transition::setSourceInteractionCondition( const QString &sourceInteractionCondition )
+{
+ mSourceInteractionCondition = sourceInteractionCondition;
+}
+
+QString Transition::sourceInteractionCondition() const
+{
+ return mSourceInteractionCondition;
+}
+
diff --git a/kode/kwsdl/wscl/transition.h b/kode/kwsdl/wscl/transition.h
new file mode 100644
index 000000000..cb6d0a563
--- /dev/null
+++ b/kode/kwsdl/wscl/transition.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of KDE WSCL Parser
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WSCL_TRANSITION_H
+#define WSCL_TRANSITION_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+namespace WSCL {
+
+class Transition
+{
+ public:
+ typedef QValueList<Transition> List;
+
+ Transition();
+ ~Transition();
+
+ void setSourceInteraction( const QString &sourceInteraction );
+ QString sourceInteraction() const;
+
+ void setDestinationInteraction( const QString &destinationInteraction );
+ QString destinationInteraction() const;
+
+ void setSourceInteractionCondition( const QString &sourceInteractionCondition );
+ QString sourceInteractionCondition() const;
+
+ private:
+ QString mSourceInteraction;
+ QString mDestinationInteraction;
+ QString mSourceInteractionCondition;
+};
+
+}
+
+#endif
diff --git a/kode/kwsdl/wsdl.cpp b/kode/kwsdl/wsdl.cpp
new file mode 100644
index 000000000..c03692417
--- /dev/null
+++ b/kode/kwsdl/wsdl.cpp
@@ -0,0 +1,135 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "wsdl.h"
+
+using namespace KWSDL;
+
+void WSDL::setBindings( const Binding::List &bindings )
+{
+ mBindings = bindings;
+}
+
+Binding::List WSDL::bindings() const
+{
+ return mBindings;
+}
+
+void WSDL::setMessages( const Message::List &messages )
+{
+ mMessages = messages;
+}
+
+Message::List WSDL::messages() const
+{
+ return mMessages;
+}
+
+void WSDL::setPorts( const Port::List &ports )
+{
+ mPorts = ports;
+}
+
+Port::List WSDL::ports() const
+{
+ return mPorts;
+}
+
+void WSDL::setService( const Service &service )
+{
+ mService = service;
+}
+
+Service WSDL::service() const
+{
+ return mService;
+}
+
+void WSDL::setTypes( const Schema::Types &types )
+{
+ mTypes = types;
+}
+
+Schema::Types WSDL::types() const
+{
+ return mTypes;
+}
+
+Message WSDL::findMessage( const QString &name ) const
+{
+ Message::List::ConstIterator it;
+ for ( it = mMessages.begin(); it != mMessages.end(); ++it ) {
+ if ( (*it).name() == name ) {
+ return *it;
+ }
+ }
+
+ return Message();
+}
+
+Message WSDL::findOutputMessage( const QString &name ) const
+{
+ Port::List::ConstIterator it;
+ for ( it = mPorts.begin(); it != mPorts.end(); ++it ) {
+ Port::Operation::List operations = (*it).operations();
+ Port::Operation::List::ConstIterator opIt;
+ for ( opIt = operations.begin(); opIt != operations.end(); ++opIt ) {
+ if ( (*opIt).input() == name )
+ return findMessage( (*opIt).output() );
+ }
+ }
+
+ return Message();
+}
+
+Port WSDL::findPort( const QString &name ) const
+{
+ Port::List::ConstIterator it;
+ for ( it = mPorts.begin(); it != mPorts.end(); ++it ) {
+ if ( (*it).name() == name )
+ return *it;
+ }
+
+ return Port();
+}
+
+Binding WSDL::findBinding( const QString &name ) const
+{
+ Binding::List::ConstIterator it;
+ for ( it = mBindings.begin(); it != mBindings.end(); ++it ) {
+ if ( (*it).name() == name )
+ return *it;
+ }
+
+ return Binding();
+}
+
+Binding::Operation WSDL::findBindingOperation( const QString &portName, const QString &operationName ) const
+{
+ Binding::List::ConstIterator it;
+ for ( it = mBindings.begin(); it != mBindings.end(); ++it ) {
+ if ( (*it).type() == portName ) {
+ return (*it).operation( operationName );
+ }
+ }
+
+ return Binding::Operation();
+}
diff --git a/kode/kwsdl/wsdl.h b/kode/kwsdl/wsdl.h
new file mode 100644
index 000000000..e057ff101
--- /dev/null
+++ b/kode/kwsdl/wsdl.h
@@ -0,0 +1,68 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KWSDL_WSDL_H
+#define KWSDL_WSDL_H
+
+#include <schema/types.h>
+
+#include "binding.h"
+#include "message.h"
+#include "port.h"
+#include "service.h"
+
+namespace KWSDL {
+
+class WSDL
+{
+ public:
+ void setBindings( const Binding::List &bindings );
+ Binding::List bindings() const;
+
+ void setMessages( const Message::List &messages );
+ Message::List messages() const;
+
+ void setPorts( const Port::List &ports );
+ Port::List ports() const;
+
+ void setService( const Service &service );
+ Service service() const;
+
+ void setTypes( const Schema::Types &types );
+ Schema::Types types() const;
+
+ Message findMessage( const QString& ) const;
+ Message findOutputMessage( const QString& ) const;
+ Port findPort( const QString& ) const;
+ Binding findBinding( const QString& ) const;
+ Binding::Operation findBindingOperation( const QString&, const QString& ) const;
+
+ private:
+ Binding::List mBindings;
+ Message::List mMessages;
+ Port::List mPorts;
+ Service mService;
+ Schema::Types mTypes;
+};
+
+}
+
+#endif
diff --git a/kode/kxml_compiler/Makefile.am b/kode/kxml_compiler/Makefile.am
new file mode 100644
index 000000000..d42867185
--- /dev/null
+++ b/kode/kxml_compiler/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libkdepim $(all_includes)
+
+bin_PROGRAMS = kxml_compiler
+
+kxml_compiler_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kxml_compiler_LDADD = ../libkode.la -lkdecore
+kxml_compiler_SOURCES = parser.cpp creator.cpp kxml_compiler.cpp
+
+METASOURCES = AUTO
diff --git a/kode/kxml_compiler/creator.cpp b/kode/kxml_compiler/creator.cpp
new file mode 100644
index 000000000..1277d8d71
--- /dev/null
+++ b/kode/kxml_compiler/creator.cpp
@@ -0,0 +1,903 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "creator.h"
+
+#include <kode/code.h>
+#include <kode/printer.h>
+#include <kode/typedef.h>
+#include <kode/statemachine.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qdom.h>
+#include <qregexp.h>
+#include <qmap.h>
+
+#include <iostream>
+
+Creator::Creator( XmlParserType p, XmlWriterType w )
+ : mXmlParserType( p ), mXmlWriterType( w )
+{
+ setExternalClassNames();
+}
+
+void Creator::setExternalClassPrefix( const QString &prefix )
+{
+ mExternalClassPrefix = prefix;
+
+ setExternalClassNames();
+}
+
+void Creator::setExternalClassNames()
+{
+ mParserClass.setName( mExternalClassPrefix + "Parser" );
+ mWriterClass.setName( mExternalClassPrefix + "Writer" );
+}
+
+KODE::File &Creator::file() { return mFile; }
+
+QString Creator::upperFirst( const QString &str )
+{
+ return KODE::Style::upperFirst( str );
+}
+
+QString Creator::lowerFirst( const QString &str )
+{
+ return KODE::Style::lowerFirst( str );
+}
+
+void Creator::createProperty( KODE::Class &c, const QString &type,
+ const QString &name )
+{
+ KODE::MemberVariable v( name, type );
+ c.addMemberVariable( v );
+
+ KODE::Function mutator( "set" + upperFirst( name ), "void" );
+ mutator.addArgument( "const " + type + " &v" );
+ mutator.addBodyLine( v.name() + " = v;" );
+ c.addFunction( mutator );
+
+ KODE::Function accessor( name, type );
+ accessor.setConst( true );
+ accessor.addBodyLine( "return " + v.name() + ";" );
+ c.addFunction( accessor );
+}
+
+void Creator::createElementFunctions( KODE::Class &c, Element *e )
+{
+ if ( e->hasText ) {
+ createProperty( c, "QString", e->name );
+ if ( mXmlParserType == XmlParserCustomExternal ) {
+ createTextElementParserCustom( c, e );
+ }
+ return;
+ }
+
+ QString type = upperFirst( e->name );
+
+ if ( !mFile.hasClass( type ) ) {
+ createClass( e );
+ }
+
+ QString name = lowerFirst( e->name );
+
+ if ( e->pattern.oneOrMore || e->pattern.zeroOrMore ||
+ e->pattern.choice || e->pattern.optional ) {
+ registerListTypedef( type );
+
+ c.addHeaderInclude( "qvaluelist.h" );
+ type = type + "::List";
+ QString className = upperFirst( name );
+ name = name + "List";
+
+ KODE::Function adder( "add" + className, "void" );
+ adder.addArgument( className + " *v" );
+
+ KODE::Code code;
+ code += "m" + upperFirst( name ) + ".append( v );";
+
+ adder.setBody( code );
+
+ c.addFunction( adder );
+ }
+
+ createProperty( c, type, name );
+}
+
+void Creator::createClass( Element *element )
+{
+ QString className = upperFirst( element->name );
+
+ if ( mProcessedClasses.find( className ) != mProcessedClasses.end() ) {
+ return;
+ }
+
+ KODE::Class c( className );
+
+ mProcessedClasses.append( className );
+
+ QValueList<Attribute *>::ConstIterator itA;
+ for( itA = element->attributes.begin();
+ itA != element->attributes.end(); ++itA ) {
+ Attribute *a = *itA;
+
+ createProperty( c, "QString", a->name );
+ }
+
+ QValueList<Element *>::ConstIterator itE;
+ for( itE = element->elements.begin(); itE != element->elements.end();
+ ++itE ) {
+ createElementFunctions( c, *itE );
+ }
+
+ QValueList<Reference *>::ConstIterator itR;
+ for( itR = element->references.begin(); itR != element->references.end();
+ ++itR ) {
+ Element e;
+ e.name = (*itR)->name;
+ e.pattern = (*itR)->pattern;
+ createElementFunctions( c, &e );
+ }
+
+ createElementParser( c, element );
+ createElementWriter( c, element );
+
+ mFile.insertClass( c );
+}
+
+void Creator::createElementWriter( KODE::Class &c, Element *element )
+{
+ KODE::Function writer( "writeElement", "QString" );
+
+ KODE::Code code;
+
+ code += "QString xml;";
+
+ QString tag = "<" + element->name;
+
+ QValueList<Attribute *>::ConstIterator it3;
+ for( it3 = element->attributes.begin(); it3 != element->attributes.end();
+ ++it3 ) {
+ tag += " " + (*it3)->name + "=\\\"\" + " + (*it3)->name + "() + \"\\\"";
+ }
+
+ if ( element->isEmpty ) {
+ tag += "/";
+ }
+
+ tag += ">\\n";
+
+ code += "xml += indent() + \"" + tag + "\";";
+
+ if ( !element->isEmpty ) {
+ code += "indent( 2 );";
+
+ QValueList<Element *>::ConstIterator it;
+ for( it = element->elements.begin(); it != element->elements.end(); ++it ) {
+ Element *e = *it;
+ QString type = upperFirst( e->name );
+ if ( e->pattern.oneOrMore || e->pattern.zeroOrMore ) {
+ code += type + "::List list = " + e->name + "List();";
+ code += type + "::List::ConstIterator it;";
+ code += "for( it = list.begin(); it != list.end(); ++it ) {";
+ code.indent();
+ code += "xml += (*it)->writeElement();";
+ code.unindent();
+ code += "}";
+ } else {
+ if ( e->hasText ) {
+ code += "xml += indent() + \"<" + e->name + ">\" + " + e->name + "() + \"</" +
+ e->name + ">\\n\";";
+ } else {
+ code += "xml += " + type + "()->writeElement()";
+ }
+ }
+ }
+
+ QValueList<Reference *>::ConstIterator it2;
+ for( it2 = element->references.begin(); it2 != element->references.end();
+ ++it2 ) {
+ Reference *r = *it2;
+ QString type = upperFirst( r->name );
+ if ( r->pattern.oneOrMore || r->pattern.zeroOrMore ) {
+ code += type + "::List list2 = " + r->name + "List();";
+ code += type + "::List::ConstIterator it2;";
+ code += "for( it2 = list2.begin(); it2 != list2.end(); ++it2 ) {";
+ code.indent();
+ code += "xml += (*it2)->writeElement();";
+ code.unindent();
+ code += "}";
+ } else {
+ code += "xml += " + type + "()->writeElement()";
+ }
+ }
+
+ code += "indent( -2 );";
+
+ code += "xml += indent() + \"</" + element->name + ">\\n\";";
+ }
+
+ code += "return xml;";
+
+ writer.setBody( code );
+
+ c.addFunction( writer );
+}
+
+void Creator::createElementParser( KODE::Class &c, Element *e )
+{
+ switch ( mXmlParserType ) {
+ case XmlParserDom:
+ case XmlParserDomExternal:
+ createElementParserDom( c, e );
+ break;
+ case XmlParserCustomExternal:
+ createElementParserCustom( c, e );
+ break;
+ }
+}
+
+void Creator::createTextElementParserCustom( KODE::Class &, Element *e )
+{
+ KODE::Function parser( "parseElement" + upperFirst( e->name ), "QString" );
+
+ KODE::Code code;
+
+ code += "QString result;";
+ code.newLine();
+
+ KODE::StateMachine sm;
+
+ KODE::Code stateCode;
+
+ stateCode += "if ( c == '<' ) {";
+ stateCode += " state = TAG;";
+ stateCode += " tagStart = mRunning;";
+ stateCode += "} else if ( c == '&' ) {";
+ stateCode += " entityStart = mRunning + 1;";
+ stateCode += "} else if ( entityStart >= 0 && c == ';' ) {";
+ stateCode += " QString entity = mBuffer.mid( entityStart, mRunning - entityStart );";
+ stateCode += " if ( entity == \"quot\" ) result += '\"';";
+ stateCode += " entityStart = -1;";
+ stateCode += "} else if ( entityStart < 0 ) {";
+ stateCode += " result += c;";
+ stateCode += "}";
+
+ sm.setState( "TEXT", stateCode );
+
+ stateCode.clear();
+ stateCode += "if ( c == '/' ) {";
+ stateCode += " state = ENDTAG;";
+ stateCode += "} else {";
+ stateCode += " state = STARTTAG;";
+ stateCode += "}";
+
+ sm.setState( "TAG", stateCode );
+
+ stateCode.clear();
+ stateCode += "if ( c == '>' ) {";
+ stateCode += " state = TEXT;";
+ stateCode += " result += mBuffer.mid( tagStart, mRunning - tagStart + 1 );";
+ stateCode += "}";
+
+ sm.setState( "STARTTAG", stateCode );
+
+ stateCode.clear();
+ stateCode += "if ( c == '>' ) {";
+ stateCode += " state = TEXT;";
+ stateCode += " result += mBuffer.mid( tagStart, mRunning - tagStart + 1 );";
+ stateCode += "} else if ( foundText" + upperFirst( e->name ) + "() ) {";
+ stateCode += " return result;";
+ stateCode += "}";
+
+ sm.setState( "ENDTAG", stateCode );
+
+ sm.setInitialState( "STARTTAG" );
+
+ code.addBlock( sm.stateDefinition() );
+ code.newLine();
+ code += "int tagStart = -1;";
+ code += "int entityStart = -1;";
+ code.newLine();
+ code += "while ( mRunning < mBuffer.length() ) {";
+ code.indent();
+ code += "QChar c = mBuffer[ mRunning ];";
+ code.addBlock( sm.transitionLogic() );
+ code += "++mRunning;";
+ code.unindent();
+ code += "}";
+ code.newLine();
+ code += "return result;";
+
+ parser.setBody( code );
+
+ mParserClass.addFunction( parser );
+}
+
+void Creator::createElementParserCustom( KODE::Class &c, Element *e )
+{
+ KODE::Function parser( "parseElement" + upperFirst( e->name ),
+ c.name() + " *" );
+
+ KODE::Code code;
+
+ code += c.name() + " *result = new " + c.name() + "();";
+ code.newLine();
+
+ KODE::StateMachine sm;
+
+ if ( !e->isEmpty ) {
+ KODE::Code stateCode;
+ stateCode += "if ( c == '<' ) state = TAG;";
+
+ sm.setState( "WHITESPACE", stateCode );
+
+ stateCode.clear();
+ stateCode += "if ( c == '/' ) {";
+ stateCode += " state = ENDTAG;";
+ stateCode += "} else {";
+ stateCode += " state = STARTTAG;";
+ stateCode += "}";
+
+ sm.setState( "TAG", stateCode );
+
+ stateCode.clear();
+ if ( e->attributes.isEmpty() ) {
+ stateCode += " if ( c == '/' ) {";
+ stateCode += " return result;";
+ stateCode += " }";
+ }
+ stateCode += "if ( c == '>' ) {";
+ stateCode += " state = WHITESPACE;";
+ Element::List::ConstIterator it;
+ for( it = e->elements.begin(); it != e->elements.end(); ++it ) {
+ createFoundTextFunction( (*it)->name );
+
+ QString eName = upperFirst( (*it)->name );
+ stateCode += "} else if ( foundText" + eName + "() ) {";
+ QString line = " result->";
+ if ( (*it)->hasText ) line += "set";
+ else line += "add";
+ line += eName + "( parseElement" + eName + "() );";
+ stateCode += line;
+ stateCode += " state = WHITESPACE;";
+ }
+ Reference::List::ConstIterator it3;
+ for( it3 = e->references.begin(); it3 != e->references.end(); ++it3 ) {
+ createFoundTextFunction( (*it3)->name );
+
+ QString eName = upperFirst( (*it3)->name );
+ stateCode += "} else if ( foundText" + eName + "() ) {";
+ stateCode += " result->add" + eName + "( parseElement" + eName + "() );";
+ stateCode += " state = WHITESPACE;";
+ }
+ stateCode += "}";
+
+ sm.setState( "STARTTAG", stateCode );
+
+ stateCode.clear();
+ stateCode += "if ( c == '>' ) {";
+ stateCode += " state = WHITESPACE;";
+ stateCode += "} else if ( foundText" + c.name() + "() ) {";
+ stateCode += " return result;";
+ stateCode += "}";
+
+ sm.setState( "ENDTAG", stateCode );
+
+ if ( !e->attributes.isEmpty() ) {
+ stateCode.clear();
+ stateCode += "if ( c == '>' ) {";
+ stateCode += " state = WHITESPACE;";
+ stateCode += "}";
+
+ Attribute::List::ConstIterator it2;
+ for( it2 = e->attributes.begin(); it2 != e->attributes.end(); ++it2 ) {
+ bool first = it2 == e->attributes.begin();
+ stateCode.addBlock( createAttributeScanner( *it2, first ) );
+ }
+ stateCode += "} else if ( c =='/' ) {";
+ stateCode += " return result;";
+ stateCode += "}";
+
+ sm.setState( "ATTRIBUTES", stateCode );
+
+ sm.setInitialState( "ATTRIBUTES" );
+ } else {
+ sm.setInitialState( "STARTTAG" );
+ }
+
+ code.addBlock( sm.stateDefinition() );
+ code.newLine();
+ }
+
+ if ( !e->attributes.isEmpty() ) {
+ Attribute::List::ConstIterator it;
+ for( it = e->attributes.begin(); it != e->attributes.end(); ++it ) {
+ code += "bool found" + upperFirst( (*it)->name ) + " = false;";
+ }
+ code.newLine();
+ code += "int attrValueStart = -1;";
+ code.newLine();
+ }
+
+ code += "while ( mRunning < mBuffer.length() ) {";
+ code.indent();
+ code += "QChar c = mBuffer[ mRunning ];";
+
+ if ( e->isEmpty ) {
+ code += "if ( c == '>' ) {";
+ code += " return result;";
+ code += "}";
+
+ if ( !e->attributes.isEmpty() ) {
+ Attribute::List::ConstIterator it;
+ for( it = e->attributes.begin(); it != e->attributes.end(); ++it ) {
+ code.addBlock( createAttributeScanner( *it,
+ it == e->attributes.begin() ) );
+ }
+ code += "}";
+ }
+ } else {
+ code.addBlock( sm.transitionLogic() );
+ }
+
+ code += "++mRunning;";
+ code.unindent();
+ code += "}";
+ code.newLine();
+ code += "return result;";
+
+ parser.setBody( code );
+
+ mParserClass.addFunction( parser );
+}
+
+KODE::Code Creator::createAttributeScanner( Attribute *a, bool firstAttribute )
+{
+ KODE::Code code;
+
+ QString aName = upperFirst( a->name );
+
+ createFoundTextFunction( a->name );
+
+ QString line;
+ if ( !firstAttribute ) line = "} else ";
+ line += "if ( foundText" + aName + "() ) {";
+ code += line;
+ code += " found" + aName + "= true;";
+ code += "} else if ( found" + aName + " && c == '\"' ) {";
+ code += " if ( attrValueStart < 0 ) {";
+ code += " attrValueStart = mRunning + 1;";
+ code += " } else {";
+ code += " result->set" + aName + "( mBuffer.mid( attrValueStart,";
+ code += " mRunning - attrValueStart ) );";
+ code += " attrValueStart = -1;";
+ code += " found" + aName + " = false;";
+ code += " }";
+
+ return code;
+}
+
+void Creator::createElementParserDom( KODE::Class &c, Element *e )
+{
+ QString functionName;
+ if ( externalParser() ) functionName = "parseElement" + c.name();
+ else functionName = "parseElement";
+
+ KODE::Function parser( functionName, c.name() + " *" );
+ parser.setStatic( true );
+ parser.setDocs( "Parse XML object from DOM element." );
+
+ parser.addArgument( "const QDomElement &element" );
+
+ KODE::Code code;
+
+ code += "if ( element.tagName() != \"" + e->name + "\" ) {";
+ code.indent();
+ code += "kdError() << \"Expected '" + e->name + "', got '\" << " +
+ "element.tagName() << \"'.\" << endl;";
+ code += "return 0;";
+ code.unindent();
+ code += "}";
+ code.newLine();
+
+ code += c.name() + " *result = new " + c.name() + "();";
+ code.newLine();
+
+ code += "QDomNode n;";
+ code += "for( n = element.firstChild(); !n.isNull();"
+ " n = n.nextSibling() ) {";
+ code.indent();
+ code += "QDomElement e = n.toElement();";
+
+ QValueList<Element *>::ConstIterator it;
+ for( it = e->elements.begin(); it != e->elements.end(); ++it ) {
+ QString condition;
+ if ( it != e->elements.begin() ) condition = "else ";
+ condition += "if";
+
+ code += condition + " ( e.tagName() == \"" + (*it)->name + "\" ) {";
+ code.indent();
+
+ QString className = upperFirst( (*it)->name );
+
+ if ( (*it)->hasText ) {
+ code += "result->set" + className + "( e.text() );";
+ } else {
+ QString line = className + " *o = ";
+ if ( externalParser() ) {
+ line += "parseElement" + className;
+ } else {
+ line += className + "::parseElement";
+ }
+ line += "( e );";
+ code += line;
+
+ code += "if ( o ) result->add" + className + "( o );";
+ }
+
+ code.unindent();
+ code += "}";
+ }
+
+ code.newLine();
+
+ QValueList<Reference *>::ConstIterator it3;
+ for( it3 = e->references.begin(); it3 != e->references.end(); ++it3 ) {
+ QString condition;
+ if ( it3 != e->references.begin() ) condition = "else ";
+ condition += "if";
+
+ code += condition + " ( e.tagName() == \"" + (*it3)->name + "\" ) {";
+ code.indent();
+
+ QString className = upperFirst( (*it3)->name );
+
+ QString line = className + " *o = ";
+ if ( externalParser() ) {
+ line += "parseElement" + className;
+ } else {
+ line += className + "::parseElement";
+ }
+ line += "( e );";
+ code += line;
+
+ code += "if ( o ) result->add" + className + "( o );";
+
+ code.unindent();
+ code += "}";
+ }
+
+ code.unindent();
+ code += "}";
+ code.newLine();
+
+ QValueList<Attribute *>::ConstIterator it2;
+ for( it2 = e->attributes.begin(); it2 != e->attributes.end(); ++it2 ) {
+ code += "result->set" + upperFirst( (*it2)->name ) +
+ "( element.attribute( \"" + (*it2)->name + "\" ) );";
+ }
+ code.newLine();
+
+ code += "return result;";
+
+ parser.setBody( code );
+
+ if ( externalParser() ) {
+ mParserClass.addFunction( parser );
+ } else {
+ c.addFunction( parser );
+ }
+}
+
+void Creator::registerListTypedef( const QString &type )
+{
+ if ( !mListTypedefs.contains( type ) ) mListTypedefs.append( type );
+}
+
+void Creator::createListTypedefs()
+{
+ QStringList::ConstIterator it;
+ for( it = mListTypedefs.begin(); it != mListTypedefs.end(); ++it ) {
+ KODE::Class c = mFile.findClass( *it );
+ if ( !c.isValid() ) continue;
+ c.addTypedef( KODE::Typedef( "QValueList<" + *it + " *>", "List" ) );
+ mFile.insertClass( c );
+ }
+}
+
+void Creator::createIndenter( KODE::File &file )
+{
+ KODE::Function indenter( "indent", "QString" );
+ indenter.addArgument( "int n = 0" );
+
+ KODE::Code code;
+
+ code += "static int i = 0;";
+ code += "i += n;";
+ code += "QString space;";
+ code += "return space.fill( ' ', i );";
+
+ indenter.setBody( code );
+
+ file.addFileFunction( indenter );
+}
+
+void Creator::createFileWriter( Element *element, const QString &dtd )
+{
+ QString className = upperFirst( element->name );
+
+ KODE::Class c = mFile.findClass( className );
+
+ c.addInclude( "kdebug.h" );
+ c.addInclude( "qtextstream.h" );
+ c.addInclude( "qfile.h" );
+
+ if ( !externalWriter() ) {
+ createIndenter( mFile );
+ }
+
+ KODE::Function writer( "writeFile", "bool" );
+
+ writer.addArgument( "const QString &filename" );
+
+ c.addInclude( "qfile.h" );
+
+ KODE::Code code;
+
+ code += "QFile file( filename );";
+ code += "if ( !file.open( IO_WriteOnly ) ) {";
+ code += " kdError() << \"Unable to open file '\" << filename << \"'\" << endl;";
+ code += " return false;";
+ code += "}";
+ code += "";
+ code += "QTextStream ts( &file );";
+
+ code += "ts << \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n\";";
+ code += "ts << \"<!DOCTYPE features SYSTEM \\\"" + dtd + "\\\">\\n\";";
+
+ code += "ts << writeElement();";
+ code += "file.close();";
+ code += "";
+ code += "return true;";
+
+ writer.setBody( code );
+
+ c.addFunction( writer );
+
+ mFile.insertClass( c );
+}
+
+void Creator::createFileParser( Element *element )
+{
+ switch ( mXmlParserType ) {
+ case XmlParserDom:
+ case XmlParserDomExternal:
+ createFileParserDom( element );
+ break;
+ case XmlParserCustomExternal:
+ createFileParserCustom( element );
+ break;
+ }
+}
+
+void Creator::createFileParserCustom( Element *element )
+{
+ kdDebug() << "Creator::createFileParserCustom()" << endl;
+
+ QString className = upperFirst( element->name );
+
+ KODE::Function parser( "parseFile", className + " *" );
+
+ parser.addArgument( "const QString &filename" );
+
+ mParserClass.addInclude( "qfile.h" );
+ mParserClass.addInclude( "kdebug.h" );
+
+ mParserClass.addMemberVariable( KODE::MemberVariable( "mBuffer",
+ "QString" ) );
+ mParserClass.addMemberVariable( KODE::MemberVariable( "mRunning",
+ "unsigned int" ) );
+
+ KODE::Code code;
+
+ code += "QFile file( filename );";
+ code += "if ( !file.open( IO_ReadOnly ) ) {";
+ code += " kdError() << \"Unable to open file '\" << filename << \"'\" << endl;";
+ code += " return 0;";
+ code += "}";
+ code += "";
+ code += "QTextStream ts( &file );";
+ code += "mBuffer = ts.read();";
+ code += "";
+ code += "mRunning = 0;";
+ code.newLine();
+
+ KODE::StateMachine sm;
+
+ KODE::Code stateCode;
+
+ stateCode += "if ( c == '<' ) state = TAG;";
+
+ sm.setState( "WHITESPACE", stateCode );
+
+ stateCode.clear();
+
+ stateCode += "if ( c == '>' ) {";
+ stateCode += " state = WHITESPACE;";
+ stateCode += "} else if ( foundText" + className + "() ) {";
+ stateCode += " " + element->name + " = parseElement" + className + "();";
+ stateCode += " state = WHITESPACE;";
+ stateCode += "}";
+
+ createFoundTextFunction( element->name );
+
+ sm.setState( "TAG", stateCode );
+
+ code.addBlock( sm.stateDefinition() );
+ code.newLine();
+
+ code += className + " *" + element->name + " = 0;";
+ code.newLine();
+
+ code += "while ( mRunning < mBuffer.length() ) {";
+ code.indent();
+ code += "QChar c = mBuffer[ mRunning ];";
+ code.addBlock( sm.transitionLogic() );
+ code += "++mRunning;";
+ code.unindent();
+ code += "}";
+ code.newLine();
+
+ code += "return " + element->name + ";";
+
+ parser.setBody( code );
+
+ mParserClass.addFunction( parser );
+}
+
+void Creator::createFoundTextFunction( const QString &text )
+{
+ QString functionName = "foundText" + upperFirst( text );
+
+ if ( mParserClass.hasFunction( functionName ) ) return;
+
+ KODE::Function f( functionName, "bool" );
+
+ KODE::Code code;
+
+ code += "if ( mBuffer[ mRunning ] != '" + text.right( 1 ) + "' ) return false;";
+ code += "";
+ code += "return mBuffer.mid( mRunning - " +
+ QString::number( text.length() - 1 ) + ", " +
+ QString::number( text.length() ) + " ) == \"" + text + "\";";
+
+ f.setBody( code );
+
+ mParserClass.addFunction( f );
+}
+
+void Creator::createFileParserDom( Element *element )
+{
+ kdDebug() << "Creator::createFileParserDom()" << endl;
+
+ QString className = upperFirst( element->name );
+
+ KODE::Class c;
+
+ if ( externalParser() ) {
+ c = mParserClass;
+ } else {
+ c = mFile.findClass( className );
+ }
+
+ KODE::Function parser( "parseFile", className + " *" );
+ parser.setStatic( true );
+
+ parser.addArgument( "const QString &filename" );
+
+ c.addInclude( "qfile.h" );
+ c.addInclude( "qdom.h" );
+ c.addInclude( "kdebug.h" );
+
+ KODE::Code code;
+
+ code += "QFile file( filename );";
+ code += "if ( !file.open( IO_ReadOnly ) ) {";
+ code += " kdError() << \"Unable to open file '\" << filename << \"'\" << endl;";
+ code += " return 0;";
+ code += "}";
+ code += "";
+ code += "QString errorMsg;";
+ code += "int errorLine, errorCol;";
+ code += "QDomDocument doc;";
+ code += "if ( !doc.setContent( &file, false, &errorMsg, &errorLine, &errorCol ) ) {";
+ code += " kdError() << errorMsg << \" at \" << errorLine << \",\" << errorCol << endl;";
+ code += " return 0;";
+ code += "}";
+ code += "";
+ code += "kdDebug() << \"CONTENT:\" << doc.toString() << endl;";
+
+ code += "";
+
+ QString line = className + " *c = parseElement";
+ if ( externalParser() ) line += className;
+ line += "( doc.documentElement() );";
+ code += line;
+
+ code += "return c;";
+
+ parser.setBody( code );
+
+ c.addFunction( parser );
+
+ if ( externalParser() ) {
+ mParserClass = c;
+ } else {
+ mFile.insertClass( c );
+ }
+}
+
+void Creator::printFiles( KODE::Printer &printer )
+{
+ if ( externalParser() ) {
+ KODE::File parserFile( file() );
+ parserFile.setFilename( file().filename() + "_parser" );
+
+ parserFile.clearCode();
+
+ mParserClass.addHeaderInclude( file().filename() + ".h" );
+ parserFile.insertClass( mParserClass );
+
+ kdDebug() << "Print external parser." << endl;
+ printer.printHeader( parserFile );
+ printer.printImplementation( parserFile );
+ }
+
+ kdDebug() << "Print header" << endl;
+ printer.printHeader( file() );
+
+ kdDebug() << "Print implementation" << endl;
+ printer.printImplementation( file() );
+
+}
+
+bool Creator::externalParser() const
+{
+ return mXmlParserType == XmlParserDomExternal ||
+ mXmlParserType == XmlParserCustomExternal;
+}
+
+bool Creator::externalWriter() const
+{
+ return mXmlWriterType == XmlWriterCustomExternal;
+}
diff --git a/kode/kxml_compiler/creator.h b/kode/kxml_compiler/creator.h
new file mode 100644
index 000000000..6e0d6f8b3
--- /dev/null
+++ b/kode/kxml_compiler/creator.h
@@ -0,0 +1,115 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef CREATOR_H
+#define CREATOR_H
+
+#include "parser.h"
+
+#include <kode/code.h>
+#include <kode/printer.h>
+#include <kode/typedef.h>
+#include <kode/file.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qdom.h>
+#include <qregexp.h>
+#include <qmap.h>
+
+#include <iostream>
+
+class Creator
+{
+ public:
+ enum XmlParserType { XmlParserDom, XmlParserDomExternal,
+ XmlParserCustomExternal };
+ enum XmlWriterType { XmlWriterCustom, XmlWriterCustomExternal };
+
+ Creator( XmlParserType p = XmlParserDom,
+ XmlWriterType w = XmlWriterCustom );
+
+ void setExternalClassPrefix( const QString & );
+
+ bool externalParser() const;
+ bool externalWriter() const;
+
+ KODE::File &file();
+
+ QString upperFirst( const QString &str );
+ QString lowerFirst( const QString &str );
+
+ void createProperty( KODE::Class &c, const QString &type,
+ const QString &name );
+ void createElementFunctions( KODE::Class &c, Element *e );
+ void createClass( Element *element );
+
+ void registerListTypedef( const QString &type );
+
+ void createListTypedefs();
+
+ void createFileParser( Element *element );
+
+ void createFileWriter( Element *element, const QString &dtd );
+
+ void printFiles( KODE::Printer & );
+
+ protected:
+ void setExternalClassNames();
+
+ void createFileParserDom( Element *element );
+ void createFileParserCustom( Element *element );
+
+ void createElementParser( KODE::Class &c, Element *e );
+
+ void createElementParserDom( KODE::Class &c, Element *e );
+
+ void createElementParserCustom( KODE::Class &c, Element *e );
+ void createTextElementParserCustom( KODE::Class &c, Element *e );
+ KODE::Code createAttributeScanner( Attribute *a, bool firstAttribute );
+ void createFoundTextFunction( const QString &text );
+
+ void createElementWriter( KODE::Class &c, Element *e );
+
+ void createIndenter( KODE::File & );
+
+ private:
+ XmlParserType mXmlParserType;
+ XmlWriterType mXmlWriterType;
+ QString mExternalClassPrefix;
+
+ KODE::File mFile;
+ KODE::Class mParserClass;
+ KODE::Class mWriterClass;
+ QStringList mProcessedClasses;
+ QStringList mListTypedefs;
+};
+
+#endif
diff --git a/kode/kxml_compiler/kxml_compiler.cpp b/kode/kxml_compiler/kxml_compiler.cpp
new file mode 100644
index 000000000..62b2162c5
--- /dev/null
+++ b/kode/kxml_compiler/kxml_compiler.cpp
@@ -0,0 +1,177 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "parser.h"
+#include "creator.h"
+
+#include <kode/code.h>
+#include <kode/printer.h>
+#include <kode/typedef.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qdom.h>
+#include <qregexp.h>
+#include <qmap.h>
+
+#include <iostream>
+
+static const KCmdLineOptions options[] =
+{
+ { "d", 0, 0 },
+ { "directory <dir>", I18N_NOOP("Directory to generate files in"), "." },
+ { "+dtd", I18N_NOOP("DTD of XML file"), 0 },
+ { "external-parser", I18N_NOOP("Generate parser in separate source file"),
+ 0 },
+ { "custom-parser", I18N_NOOP("Generate parser customized for schema"), 0 },
+ KCmdLineLastOption
+};
+
+int main( int argc, char **argv )
+{
+ KAboutData aboutData( "kxml_compiler", I18N_NOOP("KDE xml compiler"), "0.1",
+ I18N_NOOP("KDE XML Compiler") , KAboutData::License_LGPL );
+ aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
+
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KInstance app( &aboutData );
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ if ( args->count() < 1 ) {
+ kdError() << "Too few arguments." << endl;
+ return 1;
+ }
+ if ( args->count() > 1 ) {
+ kdError() << "Too many arguments." << endl;
+ return 1;
+ }
+
+ QString baseDir = QFile::decodeName( args->getOption( "directory" ) );
+ if ( !baseDir.endsWith( "/" ) ) baseDir.append( "/" );
+
+ QString dtdFilename = args->url( 0 ).path();
+
+ QString baseName = args->url( 0 ).fileName();
+ int pos = baseName.findRev( '.' );
+ if ( pos > 0 ) baseName = baseName.left( pos );
+
+
+ QFile dtdFile( dtdFilename );
+ if ( !dtdFile.open( IO_ReadOnly ) ) {
+ kdError() << "Unable to open '" << dtdFilename << "'" << endl;
+ return 1;
+ }
+
+ QString errorMsg;
+ int errorLine, errorCol;
+ QDomDocument doc;
+ if ( !doc.setContent( &dtdFile, false, &errorMsg, &errorLine, &errorCol ) ) {
+ kdError() << errorMsg << " at " << errorLine << "," << errorCol << endl;
+ return 1;
+ }
+
+ kdDebug() << "Begin parsing" << endl;
+
+ Parser p;
+ Element *start = p.parse( doc.documentElement() );
+ if ( !start ) {
+ kdError() << "Could not find start element" << endl;
+ return 1;
+ }
+
+ p.dumpDefinitionMap();
+
+// return 0;
+
+ p.substituteReferences( start );
+
+#if 0
+ std::cout << "--- TREE:" << std::endl;
+ p.dumpTree( start );
+#endif
+
+ kdDebug() << "Begin creating code" << endl;
+
+ Creator::XmlParserType pt;
+ if ( args->isSet( "custom-parser" ) ) {
+ pt = Creator::XmlParserCustomExternal;
+ } else if ( args->isSet( "external-parser" ) ) {
+ pt = Creator::XmlParserDomExternal;
+ } else {
+ pt = Creator::XmlParserDom;
+ }
+
+ Creator c( pt );
+
+ kdDebug() << "Create classes" << endl;
+ QValueList<Element *>::ConstIterator it;
+ for( it = start->elements.begin(); it != start->elements.end(); ++it ) {
+ c.createClass( *it );
+ }
+ kdDebug() << "Create parser" << endl;
+ for( it = start->elements.begin(); it != start->elements.end(); ++it ) {
+ c.setExternalClassPrefix( c.upperFirst( (*it)->name ) );
+ c.createFileParser( *it );
+ c.createFileWriter( *it, dtdFilename.replace( "rng", "dtd" ) );
+ }
+
+ c.createListTypedefs();
+
+#if 0
+ QValueList<Reference *>::ConstIterator it2;
+ for( it2 = start->references.begin(); it2 != start->references.end();
+ ++it2 ) {
+ Element e;
+ e.name = (*it2)->name;
+ e.pattern = (*it2)->pattern;
+ c.createClass( &e );
+ }
+#endif
+
+ kdDebug() << "Begin printing code" << endl;
+
+ KODE::File &f = c.file();
+
+ f.setFilename( baseName );
+
+ KODE::Printer printer;
+ printer.setCreationWarning( true );
+ printer.setGenerator( argv[0] );
+ printer.setOutputDirectory( baseDir );
+ printer.setSourceFile( args->url( 0 ).fileName() );
+
+ c.printFiles( printer );
+
+ kdDebug() << "Finished." << endl;
+}
diff --git a/kode/kxml_compiler/parser.cpp b/kode/kxml_compiler/parser.cpp
new file mode 100644
index 000000000..bc451ce0d
--- /dev/null
+++ b/kode/kxml_compiler/parser.cpp
@@ -0,0 +1,299 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "parser.h"
+
+#include <kode/code.h>
+#include <kode/printer.h>
+#include <kode/typedef.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qdom.h>
+#include <qregexp.h>
+#include <qmap.h>
+
+#include <iostream>
+
+Pattern::Pattern()
+ : optional( false ), zeroOrMore( false ), oneOrMore( false ),
+ choice( false )
+{
+}
+
+bool Pattern::isEmpty()
+{
+ return !optional && !zeroOrMore && !oneOrMore && !choice;
+}
+
+QString Pattern::asString()
+{
+ if ( isEmpty() ) return "";
+ QString str = "( ";
+ if ( optional ) str += "optional ";
+ if ( zeroOrMore ) str += "zeroOrMore ";
+ if ( oneOrMore ) str += "oneOrMore ";
+ if ( choice ) str += "choice ";
+ str += ")";
+ return str;
+}
+
+void Pattern::merge( Pattern p )
+{
+ if ( p.optional ) optional = true;
+ if ( p.zeroOrMore ) zeroOrMore = true;
+ if ( p.oneOrMore ) oneOrMore = true;
+ if ( p.choice ) choice = true;
+}
+
+Element::Element()
+ : hasText( false ), isEmpty( false )
+{
+}
+
+Parser::Parser()
+{
+}
+
+Element *Parser::parse( const QDomElement &docElement )
+{
+ Element *start = 0;
+
+ QDomNode n1;
+ for( n1 = docElement.firstChild(); !n1.isNull(); n1 = n1.nextSibling() ) {
+ QDomElement e1 = n1.toElement();
+ kdDebug() << "TOP LEVEL element " << e1.tagName() << endl;
+ if ( e1.tagName() == "define" ) {
+ Element *d = new Element;
+ d->name = e1.attribute( "name" );
+ parseElement( e1, d, Pattern() );
+ Element::List definitions;
+ QMap<QString,Element::List >::ConstIterator it;
+ it = mDefinitionMap.find( d->name );
+ if ( it != mDefinitionMap.end() ) definitions = *it;
+ definitions.append( d );
+ mDefinitionMap.replace( d->name, definitions );
+ } else if ( e1.tagName() == "start" ) {
+ start = new Element;
+ parseElement( e1, start, Pattern() );
+ } else {
+ kdDebug() << "parseGrammar: Unrecognized tag: " << e1.tagName() << endl;
+ }
+ }
+
+ return start;
+}
+
+Reference *Parser::parseReference( const QDomElement &referenceElement )
+{
+ Reference *r = new Reference;
+ r->name = referenceElement.attribute( "name" );
+ return r;
+}
+
+bool Parser::parseAttribute( const QDomElement &attributeElement,
+ Attribute *a )
+{
+ a->name = attributeElement.attribute( "name" );
+
+ return true;
+}
+
+bool Parser::parseElement( const QDomElement &elementElement, Element *e,
+ Pattern pattern )
+{
+ kdDebug() << "parseElement " << e->name << endl;
+
+ QDomNode n1;
+ for( n1 = elementElement.firstChild(); !n1.isNull(); n1 = n1.nextSibling() ) {
+ QDomElement e1 = n1.toElement();
+ if ( e1.tagName() == "element" ) {
+ Element *element = new Element;
+ element->name = e1.attribute( "name" );
+ element->pattern = pattern;
+ parseElement( e1, element, Pattern() );
+ e->elements.append( element );
+ } else if ( e1.tagName() == "attribute" ) {
+ Attribute *a = new Attribute;
+ a->name = e1.attribute( "name" );
+ a->pattern = pattern;
+ kdDebug() << "ATTRIBUTE: " << a->name << " " << a->pattern.asString()
+ << endl;
+ parseAttribute( e1, a );
+ e->attributes.append( a );
+ } else if ( e1.tagName() == "ref" ) {
+ Reference *r = parseReference( e1 );
+ r->pattern = pattern;
+ e->references.append( r );
+ } else if ( e1.tagName() == "text" ) {
+ e->hasText = true;
+ } else if ( e1.tagName() == "empty" ) {
+ e->isEmpty = true;
+ } else {
+ Pattern p = pattern;
+ if ( e1.tagName() == "optional" ) p.optional = true;
+ else if ( e1.tagName() == "zeroOrMore" ) p.zeroOrMore = true;
+ else if ( e1.tagName() == "oneOrMore" ) p.oneOrMore = true;
+ else if ( e1.tagName() == "choice" ) p.choice = true;
+ else {
+ kdDebug() << "Unsupported pattern '" << e1.tagName() << "'" << endl;
+ }
+ parseElement( e1, e, p );
+ }
+ }
+
+ return true;
+}
+
+void Parser::substituteReferences( Element *s )
+{
+ kdDebug() << "substituteReferences for '" << s->name << "'" << endl;
+ Reference::List::Iterator it = s->references.begin();
+ while( it != s->references.end() ) {
+ Reference *r = *it;
+ kdDebug() << "REF " << r->name << endl;
+ if ( r->name == s->name ) {
+ kdDebug() << "Don't resolve self reference" << endl;
+ return;
+ }
+ if ( r->substituted ) {
+ kdDebug() << "Already substituted." << endl;
+ ++it;
+ continue;
+ } else {
+ r->substituted = true;
+ }
+ QMap<QString,Element::List >::ConstIterator it1;
+ it1 = mDefinitionMap.find( r->name );
+ if ( it1 != mDefinitionMap.end() ) {
+ Element::List elements = *it1;
+ Element::List::ConstIterator it4;
+ for( it4 = elements.begin(); it4 != elements.end(); ++it4 ) {
+ Element *d = *it4;
+ substituteReferences( d );
+ Element::List::ConstIterator it2;
+ for( it2 = d->elements.begin(); it2 != d->elements.end(); ++it2 ) {
+ Element *e = *it2;
+ e->pattern.merge( r->pattern );
+ substituteReferences( e );
+ s->elements.append( e );
+ }
+ Attribute::List::ConstIterator it3;
+ for( it3 = d->attributes.begin(); it3 != d->attributes.end();
+ ++it3 ) {
+ Attribute *a = *it3;
+ a->pattern.merge( r->pattern );
+ s->attributes.append( a );
+ }
+ }
+ it = s->references.erase( it );
+ } else {
+ kdDebug() << "Reference not found" << endl;
+ ++it;
+ }
+ }
+}
+
+void Parser::doIndent( int cols )
+{
+ for( int i = 0; i < cols; ++i ) std::cout << " ";
+}
+
+void Parser::dumpPattern( Pattern pattern )
+{
+ std::cout << pattern.asString().utf8();
+}
+
+void Parser::dumpReferences( const Reference::List &references, int indent )
+{
+ Reference::List::ConstIterator it;
+ for( it = references.begin(); it != references.end(); ++it ) {
+ Reference *r = *it;
+ doIndent( indent );
+ std::cout << "REFERENCE " << r->name.utf8();
+ dumpPattern( r->pattern );
+ std::cout << std::endl;
+ }
+}
+
+void Parser::dumpAttributes( const Attribute::List &attributes, int indent )
+{
+ Attribute::List::ConstIterator it;
+ for( it = attributes.begin(); it != attributes.end(); ++it ) {
+ Attribute *a = *it;
+ doIndent( indent );
+ std::cout << "ATTRIBUTE " << a->name.utf8();
+ dumpPattern( a->pattern );
+ std::cout << std::endl;
+ }
+}
+
+void Parser::dumpElements( const Element::List &elements, int indent )
+{
+ Element::List::ConstIterator it;
+ for( it = elements.begin(); it != elements.end(); ++it ) {
+ Element *e = *it;
+ dumpElement( e, indent );
+ }
+}
+
+void Parser::dumpElement( Element *e, int indent )
+{
+ doIndent( indent );
+ std::cout << "ELEMENT " << e->name.utf8();
+ dumpPattern( e->pattern );
+ std::cout << std::endl;
+
+ if ( e->hasText ) {
+ doIndent( indent + 2 );
+ std::cout << "TEXT" << std::endl;
+ }
+
+ dumpAttributes( e->attributes, indent + 2 );
+ dumpElements( e->elements, indent + 2 );
+ dumpReferences( e->references, indent + 2 );
+}
+
+void Parser::dumpTree( Element *s )
+{
+ std::cout << "START " << s->name.utf8() << std::endl;
+ dumpElements( s->elements, 2 );
+ dumpReferences( s->references, 2 );
+}
+
+void Parser::dumpDefinitionMap()
+{
+ std::cout << "DEFINITION MAP" << std::endl;
+ QMap<QString,Element::List >::ConstIterator it;
+ for( it = mDefinitionMap.begin(); it != mDefinitionMap.end(); ++it ) {
+ dumpElements( *it, 2 );
+ }
+}
diff --git a/kode/kxml_compiler/parser.h b/kode/kxml_compiler/parser.h
new file mode 100644
index 000000000..b9ff542c0
--- /dev/null
+++ b/kode/kxml_compiler/parser.h
@@ -0,0 +1,134 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef PARSER_H
+#define PARSER_H
+
+#include <kode/code.h>
+#include <kode/printer.h>
+#include <kode/typedef.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qdom.h>
+#include <qregexp.h>
+#include <qmap.h>
+
+#include <iostream>
+
+class Pattern
+{
+ public:
+ Pattern();
+
+ bool isEmpty();
+
+ QString asString();
+
+ void merge( Pattern p );
+
+ bool optional;
+ bool zeroOrMore;
+ bool oneOrMore;
+ bool choice;
+};
+
+class Reference
+{
+ public:
+ typedef QValueList<Reference *> List;
+
+ Reference() : substituted( false ) {}
+
+ QString name;
+ Pattern pattern;
+
+ bool substituted;
+};
+
+class Attribute
+{
+ public:
+ typedef QValueList<Attribute *> List;
+
+ QString name;
+ QValueList<QString> choices;
+ QString defaultValue;
+ Pattern pattern;
+};
+
+class Element
+{
+ public:
+ typedef QValueList<Element *> List;
+
+ Element();
+
+ QString name;
+ Element::List elements;
+ Attribute::List attributes;
+ Reference::List references;
+ Pattern pattern;
+ bool hasText;
+ bool isEmpty;
+};
+
+class Parser
+{
+ public:
+ Parser();
+
+ Element *parse( const QDomElement &docElement );
+
+ Reference *parseReference( const QDomElement &referenceElement );
+ bool parseAttribute( const QDomElement &attributeElement,
+ Attribute *a );
+ bool parseElement( const QDomElement &elementElement, Element *e,
+ Pattern pattern );
+
+ void substituteReferences( Element *s );
+
+ void doIndent( int cols );
+
+ void dumpPattern( Pattern pattern );
+ void dumpReferences( const Reference::List &references,
+ int indent );
+ void dumpAttributes( const Attribute::List &attributes,
+ int indent );
+ void dumpElements( const Element::List &elements, int indent );
+ void dumpElement( Element *element, int indent );
+ void dumpTree( Element *s );
+ void dumpDefinitionMap();
+
+ private:
+ QMap<QString,Element::List> mDefinitionMap;
+};
+
+#endif
diff --git a/kode/license.cpp b/kode/license.cpp
new file mode 100644
index 000000000..1e251eaf3
--- /dev/null
+++ b/kode/license.cpp
@@ -0,0 +1,93 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "license.h"
+
+#include <kdebug.h>
+
+using namespace KODE;
+
+License::License()
+ : mType( GPL ), mQtException( true )
+{
+}
+
+License::License( Type type )
+ : mType( type ), mQtException( true )
+{
+}
+
+void License::setQtException( bool v )
+{
+ mQtException = v;
+}
+
+QString License::text()
+{
+ QString txt;
+
+ switch ( mType ) {
+ case GPL:
+ txt +=
+"This program is free software; you can redistribute it and/or modify\n"
+"it under the terms of the GNU General Public License as published by\n"
+"the Free Software Foundation; either version 2 of the License, or\n"
+"(at your option) any later version.\n"
+"\n"
+"This program is distributed in the hope that it will be useful,\n"
+"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+"GNU General Public License for more details.\n"
+"\n"
+"You should have received a copy of the GNU General Public License\n"
+"along with this program; if not, write to the Free Software\n"
+"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\n" "USA.\n";
+ if ( mQtException ) {
+ txt += "\n";
+ txt +=
+"As a special exception, permission is given to link this program\n"
+"with any edition of Qt, and distribute the resulting executable,\n"
+"without including the source code for Qt in the source distribution.\n";
+ }
+ break;
+ case LGPL:
+ txt +=
+"This library is free software; you can redistribute it and/or\n"
+"modify it under the terms of the GNU Library General Public\n"
+"License as published by the Free Software Foundation; either\n"
+"version 2 of the License, or (at your option) any later version.\n"
+"\n"
+"This library is distributed in the hope that it will be useful,\n"
+"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
+"Library General Public License for more details.\n"
+"\n"
+"You should have received a copy of the GNU Library General Public License\n"
+"along with this library; see the file COPYING.LIB. If not, write to\n"
+"the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n"
+"Boston, MA 02110-1301, USA.\n";
+ break;
+ default:
+ break;
+ }
+
+ return txt;
+}
diff --git a/kode/license.h b/kode/license.h
new file mode 100644
index 000000000..0d413f08d
--- /dev/null
+++ b/kode/license.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_LICENSE_H
+#define KODE_LICENSE_H
+
+#include <qstring.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT License
+{
+ public:
+ enum Type { GPL, LGPL };
+
+ License();
+ License( Type );
+
+ void setQtException( bool );
+
+ QString text();
+
+ private:
+ Type mType;
+
+ bool mQtException;
+};
+
+}
+
+#endif
diff --git a/kode/membervariable.cpp b/kode/membervariable.cpp
new file mode 100644
index 000000000..e497529eb
--- /dev/null
+++ b/kode/membervariable.cpp
@@ -0,0 +1,51 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "membervariable.h"
+
+#include <kdebug.h>
+
+using namespace KODE;
+
+MemberVariable::MemberVariable()
+ : Variable()
+{
+}
+
+MemberVariable::MemberVariable( const QString &name, const QString &type,
+ bool isStatic )
+ : Variable( name, type, isStatic )
+{
+ QString n;
+
+ if ( name.isEmpty() ) {
+ n = "mUndefined";
+ } else if ( name.length() >= 2 && name[ 0 ] == "m" &&
+ ( name[ 1 ].upper() == name[ 1 ] ) ) {
+ n = name;
+ } else {
+ n = "m";
+ n += name[ 0 ].upper();
+ n += name.mid( 1 );
+ }
+
+ setName( n );
+}
diff --git a/kode/membervariable.h b/kode/membervariable.h
new file mode 100644
index 000000000..e864f69ab
--- /dev/null
+++ b/kode/membervariable.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_MEMBERVARIABLE_H
+#define KODE_MEMBERVARIABLE_H
+
+#include "variable.h"
+
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT MemberVariable : public Variable
+{
+ public:
+ typedef QValueList<MemberVariable> List;
+
+ MemberVariable();
+ MemberVariable( const QString &name, const QString &type,
+ bool isStatic = false );
+};
+
+}
+
+#endif
diff --git a/kode/printer.cpp b/kode/printer.cpp
new file mode 100644
index 000000000..2a5cba2fc
--- /dev/null
+++ b/kode/printer.cpp
@@ -0,0 +1,543 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "printer.h"
+
+#include <kdebug.h>
+#include <ksavefile.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+using namespace KODE;
+
+Printer::Printer()
+ : mCreationWarning( false ), mGenerator( "libkode" )
+{
+}
+
+Printer::Printer( const Style &style )
+ : mStyle( style ), mCreationWarning( false ), mGenerator( "libkode" )
+{
+}
+
+void Printer::setCreationWarning( bool v )
+{
+ mCreationWarning = v;
+}
+
+void Printer::setGenerator( const QString &g )
+{
+ mGenerator = g;
+}
+
+void Printer::setOutputDirectory( const QString &o )
+{
+ mOutputDirectory = o;
+}
+
+void Printer::setSourceFile( const QString &s )
+{
+ mSourceFile = s;
+}
+
+QString Printer::functionSignature( const Function &f,
+ const QString &className,
+ bool includeClassQualifier )
+{
+ QString s;
+
+ if ( f.isStatic() && !includeClassQualifier ) {
+ s += "static ";
+ }
+
+ QString ret = f.returnType();
+ if ( !ret.isEmpty() ) {
+ s += ret;
+ if ( ret.right( 1 ) != "*" && ret.right( 1 ) != "&" ) {
+ s += " ";
+ }
+ }
+ if ( includeClassQualifier ) {
+ s += mStyle.className( className ) + "::";
+ }
+ if ( className == f.name() ) {
+ // Constructor
+ s += mStyle.className( f.name() );
+ } else {
+ s += f.name();
+ }
+ s += "(";
+ if ( !f.arguments().isEmpty() ) {
+ s += " " + f.arguments().join( ", " ) + " ";
+ }
+ s += ")";
+ if ( f.isConst() ) s += " const";
+
+ return s;
+}
+
+QString Printer::creationWarning()
+{
+ // Create warning about generated file
+ QString str = "// This file is generated by " + mGenerator;
+ if ( !mSourceFile.isEmpty() ) {
+ str += " from " + mSourceFile;
+ }
+ str += ".\n";
+
+ str += "// All changes you do to this file will be lost.";
+
+ return str;
+}
+
+QString Printer::licenseHeader( const File &file )
+{
+ Code code;
+ code += "/*";
+ code.setIndent( 4 );
+
+ code += "This file is part of " + file.project() + ".";
+ code.newLine();
+
+ QStringList copyrights = file.copyrightStrings();
+ if ( !copyrights.isEmpty() ) {
+ code.addBlock( copyrights.join( "\n" ) );
+ code.newLine();
+ }
+
+ code.addBlock( file.license().text() );
+
+ code.setIndent( 0 );
+ code += "*/";
+
+ return code.text();
+}
+
+Code Printer::functionHeaders( const Function::List &functions,
+ const QString &className,
+ int access )
+{
+ bool needNewLine = false;
+ bool hasAccess = false;
+
+ Code code;
+
+ Function::List::ConstIterator it;
+ for( it = functions.begin(); it != functions.end(); ++it ) {
+ Function f = *it;
+ if ( f.access() == access ) {
+ if ( !hasAccess ) {
+ code += f.accessAsString() + ":";
+ hasAccess = true;
+ }
+ code.indent();
+ if ( !(*it).docs().isEmpty() ) {
+ code += "/**";
+ code.indent();
+ code.addFormattedText( (*it).docs() );
+ code.unindent();
+ code += "*/";
+ }
+ code += functionSignature( *it, className ) + ";";
+ code.unindent();
+ needNewLine = true;
+ }
+ }
+ if ( needNewLine ) code.newLine();
+
+ return code;
+}
+
+QString Printer::classHeader( const Class &c )
+{
+ Code code;
+
+ if ( !c.docs().isEmpty() ) {
+ code += "/**";
+ code.indent();
+ code.addFormattedText( c.docs() );
+ code.unindent();
+ code += "*/";
+ }
+
+ QString txt = "class " + mStyle.className( c.name() );
+
+ Class::List baseClasses = c.baseClasses();
+ if ( !baseClasses.isEmpty() ) {
+ txt += " : ";
+ Class::List::ConstIterator it;
+ for( it = baseClasses.begin(); it != baseClasses.end(); ++it ) {
+ Class bc = *it;
+
+ if ( it != baseClasses.begin() ) txt +=", ";
+ txt += "public ";
+ if ( !bc.nameSpace().isEmpty() ) txt += bc.nameSpace() + "::";
+ txt += bc.name();
+ }
+ }
+ code += txt;
+
+ code += "{";
+ code.indent();
+
+ if ( c.isQObject() ) {
+ code += "Q_OBJECT";
+ code.newLine();
+ }
+
+ Function::List functions = c.functions();
+
+ Typedef::List typedefs = c.typedefs();
+ if ( typedefs.count() > 0 ) {
+ code += "public:";
+ code.indent();
+ Typedef::List::ConstIterator it;
+ for( it = typedefs.begin(); it != typedefs.end(); ++it ) {
+ code += (*it).declaration();
+ }
+ code.unindent();
+ code.newLine();
+ }
+
+ Enum::List enums = c.enums();
+ if ( enums.count() > 0 ) {
+ code += "public:";
+ code.indent();
+ Enum::List::ConstIterator it;
+ for( it = enums.begin(); it != enums.end(); ++it ) {
+ code += (*it).declaration();
+ }
+ code.unindent();
+ code.newLine();
+ }
+
+ code.addBlock( functionHeaders( functions, c.name(), Function::Public ) );
+ code.addBlock( functionHeaders( functions, c.name(), Function::Public | Function::Slot ) );
+ code.addBlock( functionHeaders( functions, c.name(), Function::Signal ) );
+ code.addBlock( functionHeaders( functions, c.name(), Function::Protected ) );
+ code.addBlock( functionHeaders( functions, c.name(), Function::Protected | Function::Slot ) );
+ code.addBlock( functionHeaders( functions, c.name(), Function::Private ) );
+ code.addBlock( functionHeaders( functions, c.name(), Function::Private | Function::Slot ) );
+
+ if ( !c.memberVariables().isEmpty() ) {
+ Function::List::ConstIterator it;
+ for( it = functions.begin(); it != functions.end(); ++it ) {
+ if ( (*it).access() == Function::Private ) break;
+ }
+ if ( it == functions.end() ) code += "private:";
+
+ code.indent();
+
+ MemberVariable::List variables = c.memberVariables();
+ MemberVariable::List::ConstIterator it2;
+ for( it2 = variables.begin(); it2 != variables.end(); ++it2 ) {
+ MemberVariable v = *it2;
+
+ QString decl;
+ if ( v.isStatic() ) decl += "static ";
+ decl += v.type();
+ if ( v.type().right( 1 ) != "*" && v.type().right( 1 ) != "&" ) {
+ decl += " ";
+ }
+ decl += v.name() + ";";
+
+ code += decl;
+ }
+ }
+
+ code.setIndent( 0 );
+ code += "};";
+
+ return code.text();
+}
+
+QString Printer::classImplementation( const Class &c )
+{
+ Code code;
+
+ bool needNewLine = false;
+
+ MemberVariable::List vars = c.memberVariables();
+ MemberVariable::List::ConstIterator itV;
+ for( itV = vars.begin(); itV != vars.end(); ++itV ) {
+ MemberVariable v = *itV;
+ if ( !v.isStatic() ) continue;
+ code += v.type() + c.name() + "::" + v.name() + " = " + v.initializer() +
+ ";";
+ needNewLine = true;
+ }
+ if ( needNewLine ) code.newLine();
+
+ Function::List functions = c.functions();
+ Function::List::ConstIterator it;
+ for( it = functions.begin(); it != functions.end(); ++it ) {
+ Function f = *it;
+
+ // Omit signals
+ if ( f.access() == Function::Signal )
+ continue;
+
+ code += functionSignature( f, c.name(), true );
+
+ if ( !f.initializers().isEmpty() ) {
+ code += ": " + f.initializers().join( ", " );
+ }
+
+ code += "{";
+ code.addBlock( f.body(), 2 );
+ code += "}";
+ code += "";
+ }
+
+ if ( c.isQObject() ) {
+ code.newLine();
+ code += "#include \"" + c.name().lower() + ".moc\"";
+ }
+
+ return code.text();
+}
+
+void Printer::printHeader( const File &f )
+{
+ Code out;
+
+ if ( mCreationWarning ) out += creationWarning();
+
+ out.addBlock( licenseHeader( f ) );
+
+ // Create include guard
+ QString className = f.filename();
+ className.replace( "-", "_" );
+
+ QString includeGuard;
+ if ( !f.nameSpace().isEmpty() ) includeGuard += f.nameSpace().upper() + "_";
+ includeGuard += className.upper() + "_H";
+
+ out += "#ifndef " + includeGuard;
+ out += "#define " + includeGuard;
+
+ out.newLine();
+
+
+ // Create includes
+ QStringList processed;
+ Class::List classes = f.classes();
+ Class::List::ConstIterator it;
+ for( it = classes.begin(); it != classes.end(); ++it ) {
+ QStringList includes = (*it).headerIncludes();
+ QStringList::ConstIterator it2;
+ for( it2 = includes.begin(); it2 != includes.end(); ++it2 ) {
+ if ( processed.find( *it2 ) == processed.end() ) {
+ out += "#include <" + *it2 + ">";
+ processed.append( *it2 );
+ }
+ }
+ }
+ if ( !processed.isEmpty() ) out.newLine();
+
+
+ // Create forward declarations
+ processed.clear();
+ for( it = classes.begin(); it != classes.end(); ++it ) {
+ QStringList decls = (*it).forwardDeclarations();
+ QStringList::ConstIterator it2;
+ for( it2 = decls.begin(); it2 != decls.end(); ++it2 ) {
+ if ( processed.find( *it2 ) == processed.end() ) {
+ out += "class " + *it2 + ";";
+ processed.append( *it2 );
+ }
+ }
+ }
+ if ( !processed.isEmpty() ) out.newLine();
+
+
+ if ( !f.nameSpace().isEmpty() ) {
+ out += "namespace " + f.nameSpace() + " {";
+ out.newLine();
+ }
+
+ // Create content
+ for( it = classes.begin(); it != classes.end(); ++it ) {
+ out.addBlock( classHeader( *it ) );
+ out.newLine();
+ }
+
+ if ( !f.nameSpace().isEmpty() ) {
+ out += "}";
+ out.newLine();
+ }
+
+ // Finish file
+ out += "#endif";
+
+
+ // Print to file
+ QString filename = f.filename() + ".h";
+
+ if ( !mOutputDirectory.isEmpty() ) filename.prepend( mOutputDirectory + "/" );
+
+ KSaveFile::backupFile( filename, QString::null, ".backup" );
+
+ QFile header( filename );
+ if ( !header.open( IO_WriteOnly ) ) {
+ kdError() << "Can't open '" << filename << "' for writing." << endl;
+ return;
+ }
+
+ QTextStream h( &header );
+
+ h << out.text();
+
+ header.close();
+}
+
+void Printer::printImplementation( const File &f, bool createHeaderInclude )
+{
+ Code out;
+
+ if ( mCreationWarning ) out += creationWarning();
+
+ out.addBlock( licenseHeader( f ) );
+
+ out.newLine();
+
+ // Create includes
+ if ( createHeaderInclude ) {
+ out += "#include \"" + f.filename() + ".h\"";
+ out.newLine();
+ }
+
+ QStringList includes = f.includes();
+ QStringList::ConstIterator it2;
+ for( it2 = includes.begin(); it2 != includes.end(); ++it2 ) {
+ out += "#include <" + *it2 + ">";
+ }
+ if ( !includes.isEmpty() ) out.newLine();
+
+ // Create class includes
+ QStringList processed;
+ Class::List classes = f.classes();
+ Class::List::ConstIterator it;
+ for( it = classes.begin(); it != classes.end(); ++it ) {
+ QStringList includes = (*it).includes();
+ QStringList::ConstIterator it2;
+ for( it2 = includes.begin(); it2 != includes.end(); ++it2 ) {
+ if ( processed.find( *it2 ) == processed.end() ) {
+ out += "#include <" + *it2 + ">";
+ processed.append( *it2 );
+ }
+ }
+ }
+ if ( !processed.isEmpty() ) out.newLine();
+
+ if ( !f.nameSpace().isEmpty() ) {
+ out += "using namespace " + f.nameSpace() + ";";
+ out.newLine();
+ }
+
+ // 'extern "C"' declarations
+ QStringList externCDeclarations = f.externCDeclarations();
+ if ( !externCDeclarations.isEmpty() ) {
+ out += "extern \"C\" {";
+ QStringList::ConstIterator it;
+ for( it = externCDeclarations.begin(); it != externCDeclarations.end();
+ ++it ) {
+ out += *it + ";";
+ }
+ out += "}";
+ out.newLine();
+ }
+
+ // File variables
+ Variable::List vars = f.fileVariables();
+ Variable::List::ConstIterator itV;
+ for( itV = vars.begin(); itV != vars.end(); ++itV ) {
+ Variable v = *itV;
+ QString str;
+ if ( v.isStatic() ) str += "static ";
+ str += v.type() + " " + v.name() + ";";
+ out += str;
+ }
+ if ( !vars.isEmpty() ) out.newLine();
+
+ // File code
+ if ( !f.fileCode().isEmpty() ) {
+ out += f.fileCode();
+ out.newLine();
+ }
+
+ // File functions
+ Function::List funcs = f.fileFunctions();
+ Function::List::ConstIterator itF;
+ for( itF = funcs.begin(); itF != funcs.end(); ++itF ) {
+ Function f = *itF;
+ out += functionSignature( f );
+ out += "{";
+ out.addBlock( f.body(), 2 );
+ out += "}";
+ out.newLine();
+ }
+
+ // Classes
+ for( it = classes.begin(); it != classes.end(); ++it ) {
+ QString str = classImplementation( *it );
+ if ( !str.isEmpty() ) out += classImplementation( *it );
+ }
+
+ // Print to file
+ QString filename = f.filename() + ".cpp";
+
+ if ( !mOutputDirectory.isEmpty() ) filename.prepend( mOutputDirectory + "/" );
+
+ KSaveFile::backupFile( filename, QString::null, ".backup" );
+
+ QFile implementation( filename );
+ if ( !implementation.open( IO_WriteOnly ) ) {
+ kdError() << "Can't open '" << filename << "' for writing." << endl;
+ return;
+ }
+
+ QTextStream h( &implementation );
+
+ h << out.text();
+
+ implementation.close();
+}
+
+void Printer::printAutoMakefile( const AutoMakefile &am )
+{
+ QString filename = "Makefile.am";
+
+ if ( !mOutputDirectory.isEmpty() ) filename.prepend( mOutputDirectory + "/" );
+
+ KSaveFile::backupFile( filename, QString::null, ".backup" );
+
+ QFile file( filename );
+ if ( !file.open( IO_WriteOnly ) ) {
+ kdError() << "Can't open '" << filename << "' for writing." << endl;
+ return;
+ }
+
+ QTextStream ts( &file );
+
+ ts << am.text();
+}
diff --git a/kode/printer.h b/kode/printer.h
new file mode 100644
index 000000000..169884571
--- /dev/null
+++ b/kode/printer.h
@@ -0,0 +1,75 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_PRINTER_H
+#define KODE_PRINTER_H
+
+#include "code.h"
+#include "file.h"
+#include "style.h"
+#include "automakefile.h"
+
+#include <kdepimmacros.h>
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qstringlist.h>
+
+namespace KODE {
+
+class KDE_EXPORT Printer
+{
+ public:
+ Printer();
+ Printer( const Style & );
+
+ void setCreationWarning( bool );
+ void setGenerator( const QString & );
+ void setOutputDirectory( const QString & );
+ void setSourceFile( const QString & );
+
+ void printHeader( const File & );
+ void printImplementation( const File &, bool createHeaderInclude = true );
+ void printAutoMakefile( const AutoMakefile & );
+
+ QString functionSignature( const Function &f,
+ const QString &className = QString::null,
+ bool includeClassQualifier = false );
+
+ protected:
+ QString creationWarning();
+ QString licenseHeader( const File & );
+ QString classHeader( const Class & );
+ QString classImplementation( const Class & );
+ Code functionHeaders( const Function::List &functions,
+ const QString &className,
+ int access );
+
+ private:
+ Style mStyle;
+
+ bool mCreationWarning;
+ QString mGenerator;
+ QString mOutputDirectory;
+ QString mSourceFile;
+};
+
+}
+
+#endif
diff --git a/kode/statemachine.cpp b/kode/statemachine.cpp
new file mode 100644
index 000000000..fe90d5d6b
--- /dev/null
+++ b/kode/statemachine.cpp
@@ -0,0 +1,84 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "statemachine.h"
+
+using namespace KODE;
+
+StateMachine::StateMachine()
+{
+}
+
+
+void StateMachine::setState( const QString &state, const Code &code )
+{
+ mStateMap.insert( state, code );
+
+ if ( mInitialState.isEmpty() ) mInitialState = state;
+}
+
+void StateMachine::setInitialState( const QString &state )
+{
+ mInitialState = state;
+}
+
+Code StateMachine::stateDefinition()
+{
+ Code code;
+
+ QStringList states;
+ QMap<QString,Code>::ConstIterator it;
+ for ( it = mStateMap.begin(); it != mStateMap.end(); ++it ) {
+ states.append( it.key() );
+ }
+
+ code += "enum State { " + states.join( ", " ) + " };";
+ code += "State state = " + mInitialState + ";";
+
+ return code;
+}
+
+Code StateMachine::transitionLogic()
+{
+ Code code;
+
+ code += "switch( state ) {";
+ code.indent();
+
+ QMap<QString,Code>::ConstIterator it;
+ for ( it = mStateMap.begin(); it != mStateMap.end(); ++it ) {
+ code += "case " + it.key() + ":";
+ code.indent();
+ code.addBlock( it.data() );
+ code += "break;";
+ code.unindent();
+ }
+
+ code += "default:";
+ code.indent();
+ code += "break;";
+ code.unindent();
+
+ code.unindent();
+ code += "}";
+
+ return code;
+}
diff --git a/kode/statemachine.h b/kode/statemachine.h
new file mode 100644
index 000000000..0adcd5548
--- /dev/null
+++ b/kode/statemachine.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_STATEMACHINE_H
+#define KODE_STATEMACHINE_H
+
+#include "code.h"
+
+#include <qstring.h>
+#include <qmap.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT StateMachine
+{
+ public:
+ StateMachine();
+
+ void setState( const QString &state, const Code &code );
+
+ void setInitialState( const QString &state );
+
+ Code stateDefinition();
+ Code transitionLogic();
+
+ private:
+ QMap<QString,Code> mStateMap;
+
+ QString mInitialState;
+};
+
+}
+
+#endif
diff --git a/kode/style.cpp b/kode/style.cpp
new file mode 100644
index 000000000..c7d20f4ca
--- /dev/null
+++ b/kode/style.cpp
@@ -0,0 +1,54 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "style.h"
+
+#include <kdebug.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+using namespace KODE;
+
+Style::Style()
+{
+}
+
+Style::~Style()
+{
+}
+
+QString Style::className( const QString &str )
+{
+ return upperFirst( str );
+}
+
+QString Style::upperFirst( const QString &str )
+{
+ if ( str.isEmpty() ) return str;
+ return str[ 0 ].upper() + str.mid( 1 );
+}
+
+QString Style::lowerFirst( const QString &str )
+{
+ if ( str.isEmpty() ) return str;
+ return str[ 0 ].lower() + str.mid( 1 );
+}
diff --git a/kode/style.h b/kode/style.h
new file mode 100644
index 000000000..f88c107b4
--- /dev/null
+++ b/kode/style.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_STYLE_H
+#define KODE_STYLE_H
+
+#include "license.h"
+
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qstringlist.h>
+
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT Style
+{
+ public:
+ Style();
+ virtual ~Style();
+
+ virtual QString className( const QString &str );
+
+ static QString upperFirst( const QString &str );
+ static QString lowerFirst( const QString &str );
+};
+
+}
+
+#endif
diff --git a/kode/typedef.cpp b/kode/typedef.cpp
new file mode 100644
index 000000000..10b2df46b
--- /dev/null
+++ b/kode/typedef.cpp
@@ -0,0 +1,38 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "typedef.h"
+
+using namespace KODE;
+
+Typedef::Typedef()
+{
+}
+
+Typedef::Typedef( const QString &type, const QString &alias )
+ : mType( type ), mAlias( alias )
+{
+}
+
+QString Typedef::declaration() const
+{
+ return "typedef " + mType + " " + mAlias + ";";
+}
diff --git a/kode/typedef.h b/kode/typedef.h
new file mode 100644
index 000000000..59f129c9d
--- /dev/null
+++ b/kode/typedef.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of KDE.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_TYPEDEF_H
+#define KODE_TYPEDEF_H
+
+#include <qvaluelist.h>
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT Typedef
+{
+ public:
+ typedef QValueList<Typedef> List;
+
+ Typedef();
+ Typedef( const QString &type, const QString &alias );
+
+ QString declaration() const;
+
+ private:
+ QString mType;
+ QString mAlias;
+};
+
+}
+
+#endif
diff --git a/kode/variable.cpp b/kode/variable.cpp
new file mode 100644
index 000000000..f56b351e0
--- /dev/null
+++ b/kode/variable.cpp
@@ -0,0 +1,63 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "membervariable.h"
+
+#include <kdebug.h>
+
+using namespace KODE;
+
+Variable::Variable()
+ : mIsStatic( false )
+{
+}
+
+Variable::Variable( const QString &name, const QString &type, bool isStatic )
+ : mIsStatic( isStatic )
+{
+ mType = type;
+
+ if ( name.isEmpty() ) {
+ mName = "mUndefined";
+ } else {
+ mName = name;
+ }
+}
+
+void Variable::setName( const QString &n )
+{
+ mName = n;
+}
+
+void Variable::setType( const QString &t )
+{
+ mType = t;
+}
+
+void Variable::setStatic( bool s )
+{
+ mIsStatic = s;
+}
+
+void Variable::setInitializer( const QString &i )
+{
+ mInitializer = i;
+}
diff --git a/kode/variable.h b/kode/variable.h
new file mode 100644
index 000000000..21c315c19
--- /dev/null
+++ b/kode/variable.h
@@ -0,0 +1,60 @@
+/*
+ This file is part of kdepim.
+
+ Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KODE_VARIABLE_H
+#define KODE_VARIABLE_H
+
+#include <qvaluelist.h>
+#include <qstring.h>
+
+#include <kdepimmacros.h>
+
+namespace KODE {
+
+class KDE_EXPORT Variable
+{
+ public:
+ typedef QValueList<Variable> List;
+
+ Variable();
+ Variable( const QString &name, const QString &type, bool isStatic = false );
+
+ void setType( const QString & );
+ QString type() const { return mType; }
+
+ void setName( const QString & );
+ QString name() const { return mName; }
+
+ void setStatic( bool );
+ bool isStatic() const { return mIsStatic; }
+
+ void setInitializer( const QString & );
+ QString initializer() const { return mInitializer; }
+
+ private:
+ QString mType;
+ QString mName;
+ bool mIsStatic;
+ QString mInitializer;
+};
+
+}
+
+#endif