src/wsdlparser/Soap.h

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 class WSDLPULL_EXPORT Soap:public WsdlExtension
00036 {
00037  public:
00038   
00039   static const std::string httpTransport;
00040   static const std::string httpBinding ;
00041   static const std::string soapEncUri ;
00042   static const std::string soapEnvUri ;
00043   static const std::string soapBindingUri ;
00044 
00045   typedef enum
00046     {
00047       LITERAL,
00048       ENCODED
00049     } Encoding;
00050   
00051   typedef enum
00052     {
00053       RPC,
00054       DOC
00055     } Style;
00056 
00057   typedef enum
00058     {
00059       NONE,
00060       HTTP,
00061       SMTP
00062     } Transport;
00063 
00064   Soap(const std::string & schemaPath = "");
00065   virtual ~Soap();
00066 
00067   /**
00068    * Set path to directory containing XML schemas.
00069    */
00070   void setSchemaPath(const std::string & schemaPath);
00071 
00072   Transport getTransportMethod()const;
00073   Style getStyle()const;
00074   /*
00075     Returns the namespace URI of the wsdl
00076     extensibility elements that it can handle.
00077   */
00078   std::string getNamespace()const ;
00079   void setNamespacePrefix(std::string pre);
00080   std::string getNamespacePrefix()const;
00081   bool isNamespaceHandler(const std::string & ns)const;
00082   std::string getExtensibilitySchema(void)const;
00083   std::string getEncodingSchema(void)const ;
00084   void setSchemaParser(SchemaParser * spe);
00085 
00086   // parent is the Wsdl parent element type under which the extensibility element has come
00087   int handleElement(int parent, XmlPullParser *);
00088   //attName is the extensibility attribute
00089   int handleAttribute(int parent, std::string attName, XmlPullParser *);
00090   //returns a valid extensibilty element
00091   int getElementName(int id)const;
00092   int getElemAttribute(int id, int att_num);
00093   int getElemAttributeValue(int id, int att_num);
00094   //returns a valid extensibility attribute
00095   int getAttributeName(int id)const;
00096 
00097   //this is the start of all ids that must be used for elems/attributes in this namespace
00098   void setStartId(int id);
00099   int getStartId()const;
00100 
00101   void setWsdlParser(WsdlParser * wp);
00102   WsdlParser * wsdlParser()const;
00103   bool wasUsed()const;
00104 
00105   void serialize(std::ostream & out);
00106   void getSoapOperationInfo(int elemId, std::string & soapAction, Soap::Style& style);
00107   void getSoapBodyInfo(int elemId, std::string &ns, Soap::Encoding &use, std::string &encodingStyle);
00108   void getSoapHeaderInfo(int elemId, std::string &ns, int &partId, const Message* & m);
00109   bool  getServiceLocation(int elemId, std::string &location);
00110   
00111   //TODO add more methods like this
00112   bool isSoapBody(int id);
00113   bool isSoapHeader(int id);
00114 
00115   /*
00116     Enums used in soap
00117   */
00118 
00119  private:
00120   void error(std::string);
00121   int processBinding(TypeContainer * t);
00122   int processOp(int, TypeContainer * t);
00123   int processBody(int, TypeContainer * t);
00124   int processHeader(int, TypeContainer * t);
00125   int processFault(int, TypeContainer * t);
00126   int processAddress(int parent, TypeContainer * t);
00127   std::string sNamespace, sNsPrefix, sTitle;
00128   int startId;
00129   SchemaParser *mySchemaParser;
00130   SchemaValidator *mySchemaValidator;
00131   WsdlParser *wParser_;
00132   
00133   typedef struct  
00134   {
00135     int typeId;
00136     int index;
00137   }IDTableIndex ;
00138 
00139   std::vector<IDTableIndex> idTable;
00140   int idCounter;
00141 
00142   typedef struct
00143   {
00144     int wsdlOpId;
00145     std::string soapAction;
00146     Style style;
00147   } SoapOperationBinding;
00148   std::vector<SoapOperationBinding> ops_;
00149 
00150   typedef struct
00151   {
00152     int messageId;
00153     Encoding use;
00154     std::string encodingStyle;
00155     std::string urn;
00156   } SoapMessageBinding;
00157   std::vector<SoapMessageBinding> body_;
00158   //  int nMsgs;
00159 
00160   typedef struct
00161   {
00162     std::string urn;
00163     int partId_;
00164     const Message* message_;
00165   }SoapHeaderBinding;
00166   std::vector<SoapHeaderBinding> header_;
00167   //  int nHeader;
00168 
00169   Transport transport_;
00170   Style style_;
00171   std::vector<std::string> location_;
00172   std::string schemaPath_;
00173 };
00174 
00175 inline 
00176 int
00177 Soap::getElementName(int id)const
00178 {
00179     if (id < startId || id > (startId + idCounter - 1))
00180         return 0;
00181     return idTable[id - startId].typeId;
00182 }
00183 
00184 
00185 inline
00186 int
00187 Soap::getAttributeName(int id)const
00188 {
00189     if (id < startId || id > (startId + idCounter - 1))
00190         return 0;
00191     return idTable[id - startId].typeId;
00192 }
00193 
00194 inline
00195 std::string
00196 Soap::getNamespace()const 
00197 {
00198   return sNamespace;
00199 }
00200 
00201 inline
00202 void
00203 Soap::setNamespacePrefix(std::string pre)
00204 {
00205   sNsPrefix = pre;
00206 }
00207 
00208 inline
00209 std::string
00210 Soap::getNamespacePrefix()const
00211 {
00212   return sNsPrefix;
00213 }
00214 
00215 inline
00216 bool
00217 Soap::isNamespaceHandler(const std::string & ns)const
00218 {
00219   return (ns == sNamespace);
00220 }
00221 
00222 inline
00223 void
00224 Soap::setSchemaParser(SchemaParser * spe)
00225 {
00226   mySchemaParser = spe;
00227   mySchemaValidator = new SchemaValidator(mySchemaParser);
00228 }
00229 
00230 inline
00231 void
00232 Soap::setStartId(int id)
00233 {
00234   startId = id;
00235 }
00236 
00237 inline
00238 int
00239 Soap:: getStartId()const
00240 {
00241   return startId;
00242 }
00243 
00244 inline
00245 void
00246 Soap::setWsdlParser(WsdlParser * wp)
00247 {
00248   wParser_ = wp;
00249 }
00250 
00251 inline
00252 bool
00253 Soap::wasUsed()const
00254 {
00255   return (wParser_ != 0);
00256 }
00257 
00258 inline
00259 Soap::Transport
00260 Soap::getTransportMethod()const
00261 {
00262   return transport_;
00263 }
00264 
00265 inline
00266 Soap::Style
00267 Soap::getStyle()const
00268 {
00269   return style_;
00270 }
00271 
00272 inline
00273 WsdlParser *
00274 Soap::wsdlParser()const
00275 {
00276   return wParser_;
00277 }
00278 
00279 }
00280 #endif                                            /*  */

Generated on Sat May 3 16:29:00 2008 for wsdlpull by  doxygen 1.4.6