Soap.h

Go to the documentation of this file.
00001 /* 
00002  * wsdlpull - A C++ parser  for WSDL  (Web services description language)
00003  * Copyright (C) 2005-2007 Vivek Krishna
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  *
00019  *
00020  */
00021 
00022 
00023 #ifndef _SOAPEXTH
00024 #define _SOAPEXTH
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 
00029 #include "wsdlparser/WsdlExtension.h"
00030 #include "wsdlparser/WsdlParser.h"
00031 #include "schemaparser/SchemaValidator.h"
00032 #include "xmlpull/wsdlpull_export.h"
00033 
00034 namespace WsdlPull {
00035 
00036 
00037 
00038 class WSDLPULL_EXPORT Soap:public WsdlExtension
00039 {
00040  public:
00041   
00042   static const std::string httpTransport;
00043   static const std::string httpBinding ;
00044   static const std::string soapEncUri11 ;
00045   static const std::string soapEnvUri11 ;
00046   static const std::string soapEncUri12 ;
00047   static const std::string soapEnvUri12 ;
00048   static const std::string soapBindingUri11;
00049   static const std::string soapBindingUri12 ;
00050 
00051   typedef enum  {
00052     SOAP11,
00053     SOAP12
00054   } SoapVersion;
00055 
00056   typedef enum
00057     {
00058       LITERAL,
00059       ENCODED
00060     } Encoding;
00061   
00062   typedef enum
00063     {
00064       RPC,
00065       DOC
00066     } Style;
00067 
00068   typedef enum
00069     {
00070       NONE,
00071       HTTP,
00072       SMTP
00073     } Transport;
00074 
00075   Soap(const std::string & schemaPath = "", SoapVersion a_soapVersion = SOAP11);
00076   virtual ~Soap();
00077 
00081   void setSchemaPath(const std::string & schemaPath);
00082 
00083   Transport getTransportMethod()const;
00084   Style getStyle()const;
00085   /*
00086     Returns the namespace URI of the wsdl
00087     extensibility elements that it can handle.
00088   */
00089   std::string getNamespace()const ;
00090   void setNamespacePrefix(std::string pre);
00091   std::string getNamespacePrefix()const;
00092   bool isNamespaceHandler(const std::string & ns)const;
00093   std::string getExtensibilitySchema(void)const;
00094   std::string getEncodingSchema(void)const ;
00095   std::string getEncodingUri(void) const;
00096   std::string getEnvelopeUri(void) const;
00097   void setSchemaParser(SchemaParser * spe);
00098 
00099   // parent is the Wsdl parent element type under which the extensibility element has come
00100   int handleElement(int parent, XmlPullParser *);
00101   //attName is the extensibility attribute
00102   int handleAttribute(int parent, std::string attName, XmlPullParser *);
00103   //returns a valid extensibilty element
00104   int getElementName(int id)const;
00105   int getElemAttribute(int id, int att_num);
00106   int getElemAttributeValue(int id, int att_num);
00107   //returns a valid extensibility attribute
00108   int getAttributeName(int id)const;
00109 
00110   //this is the start of all ids that must be used for elems/attributes in this namespace
00111   void setStartId(int id);
00112   int getStartId()const;
00113 
00114   void setWsdlParser(WsdlParser * wp);
00115   WsdlParser * wsdlParser()const;
00116   bool wasUsed()const;
00117 
00118   void serialize(std::ostream & out);
00119   void getSoapOperationInfo(int elemId, std::string & soapAction, Soap::Style& style);
00120   void getSoapBodyInfo(int elemId, std::string &ns, Soap::Encoding &use, std::string &encodingStyle);
00121   void getSoapHeaderInfo(int elemId, std::string &ns, int &partId, const Message* & m);
00122   bool  getServiceLocation(int elemId, std::string &location);
00123 
00124   SoapVersion getSoapVersion() const { return soapVersion_; }
00125   
00126   //TODO add more methods like this
00127   bool isSoapBody(int id);
00128   bool isSoapHeader(int id);
00129 
00130   /*
00131     Enums used in soap
00132   */
00133 
00134  private:
00135   void error(std::string);
00136   int processBinding(TypeContainer * t);
00137   int processOp(int, TypeContainer * t);
00138   int processBody(int, TypeContainer * t);
00139   int processHeader(int, TypeContainer * t);
00140   int processFault(int, TypeContainer * t);
00141   int processAddress(int parent, TypeContainer * t);
00142   std::string sNamespace, sNsPrefix, sTitle;
00143   int startId;
00144   SchemaParser *mySchemaParser;
00145   SchemaValidator *mySchemaValidator;
00146   WsdlParser *wParser_;
00147   
00148   typedef struct  
00149   {
00150     int typeId;
00151     int index;
00152   }IDTableIndex ;
00153 
00154   std::vector<IDTableIndex> idTable;
00155   int idCounter;
00156 
00157   typedef struct
00158   {
00159     int wsdlOpId;
00160     std::string soapAction;
00161     Style style;
00162   } SoapOperationBinding;
00163   std::vector<SoapOperationBinding> ops_;
00164 
00165   typedef struct
00166   {
00167     int messageId;
00168     Encoding use;
00169     std::string encodingStyle;
00170     std::string urn;
00171   } SoapMessageBinding;
00172   std::vector<SoapMessageBinding> body_;
00173   //  int nMsgs;
00174 
00175   typedef struct
00176   {
00177     std::string urn;
00178     int partId_;
00179     const Message* message_;
00180   }SoapHeaderBinding;
00181   std::vector<SoapHeaderBinding> header_;
00182   //  int nHeader;
00183 
00184   Transport transport_;
00185   Style style_;
00186   std::vector<std::string> location_;
00187   std::string schemaPath_;
00188 
00189   SoapVersion soapVersion_; //The SOAP version to use
00190 };
00191 
00192 inline 
00193 int
00194 Soap::getElementName(int id)const
00195 {
00196     if (id < startId || id > (startId + idCounter - 1))
00197         return 0;
00198     return idTable[id - startId].typeId;
00199 }
00200 
00201 
00202 inline
00203 int
00204 Soap::getAttributeName(int id)const
00205 {
00206     if (id < startId || id > (startId + idCounter - 1))
00207         return 0;
00208     return idTable[id - startId].typeId;
00209 }
00210 
00211 inline
00212 std::string
00213 Soap::getNamespace()const 
00214 {
00215   return sNamespace;
00216 }
00217 
00218 inline
00219 void
00220 Soap::setNamespacePrefix(std::string pre)
00221 {
00222   sNsPrefix = pre;
00223 }
00224 
00225 inline
00226 std::string
00227 Soap::getNamespacePrefix()const
00228 {
00229   return sNsPrefix;
00230 }
00231 
00232 inline
00233 bool
00234 Soap::isNamespaceHandler(const std::string & ns)const
00235 {
00236   return (ns == sNamespace);
00237 }
00238 
00239 inline
00240 void
00241 Soap::setSchemaParser(SchemaParser * spe)
00242 {
00243   mySchemaParser = spe;
00244   mySchemaValidator = new SchemaValidator(mySchemaParser);
00245 }
00246 
00247 inline
00248 void
00249 Soap::setStartId(int id)
00250 {
00251   startId = id;
00252 }
00253 
00254 inline
00255 int
00256 Soap:: getStartId()const
00257 {
00258   return startId;
00259 }
00260 
00261 inline
00262 void
00263 Soap::setWsdlParser(WsdlParser * wp)
00264 {
00265   wParser_ = wp;
00266 }
00267 
00268 inline
00269 bool
00270 Soap::wasUsed()const
00271 {
00272   return (wParser_ != 0);
00273 }
00274 
00275 inline
00276 Soap::Transport
00277 Soap::getTransportMethod()const
00278 {
00279   return transport_;
00280 }
00281 
00282 inline
00283 Soap::Style
00284 Soap::getStyle()const
00285 {
00286   return style_;
00287 }
00288 
00289 inline
00290 WsdlParser *
00291 Soap::wsdlParser()const
00292 {
00293   return wParser_;
00294 }
00295 
00296 }
00297 #endif                                            /*  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by  doxygen 1.6.2