diff options
Diffstat (limited to 'kode/kwsdl')
123 files changed, 13033 insertions, 0 deletions
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 ¤tAction, 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 ¤tAction, 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 ¤tAction, 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 ¤tAction, 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 |