Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

WsdlParser.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 #ifndef _WSDLPARSERH
00021 #define _WSDLPARSERH
00022 
00023 #include <xmlpull/XmlPullParser.h>
00024 #include <xmlpull/XmlPullParserException.h>
00025 #include <schemaparser/SchemaParser.h>
00026 #include <wsdlparser/Wsdl.h>
00027 #include <wsdlparser/PortType.h>
00028 #include <wsdlparser/Message.h>
00029 #include <wsdlparser/Operation.h>
00030 #include <wsdlparser/Binding.h>
00031 #include <wsdlparser/WsdlExtension.h>
00032 
00033 const std::string wsdlUri="http://schemas.xmlsoap.org/wsdl/";
00034 class Soap;
00035 //Wsdl pull parser
00036 class WsdlParser
00037 {
00038  public:
00047   WsdlParser(istream & in = cin, ostream & out = cout);
00048   WsdlParser(const std::string& Uri,ostream & out = cout);
00049   ~WsdlParser();
00051 
00060   int getNextElement();
00061 
00067   int getEventType();
00068 
00070 
00073   //NOTE:The caller must *NOT* free the pointers returned by the getter apis
00074   //This is true for all apis except whenever the api returns a pointer to 
00075   //a list of elements which is not one  of the root wsdl elements ,
00076   //such as getOperations(port type) which is the only exception
00081   string getNamespace(void);
00082 
00087   string getName();
00088 
00094   const string*  getDocumentation();
00095 
00102   const Binding *getBinding();
00103 
00110   const Binding *getBinding(Qname & q);
00111 
00117   bool  getBindings(Binding::cBindingIterator & begin,
00118                     Binding::cBindingIterator & end)const;
00119 
00126   const PortType *getPortType();
00127 
00134   const PortType *getPortType(const Qname & q);
00135 
00141   bool getPortTypes(PortType::cPortTypeIterator& begin,
00142                     PortType::cPortTypeIterator& end)const;
00143 
00151   bool getOperations(const Qname & portType,
00152                      Operation::cOpIterator begin,
00153                      Operation::cOpIterator end);
00154 
00162   const Operation *getOperation(const Qname & portType, 
00163                                 const Qname & q);
00164 
00171   const Message *getMessage();
00172 
00179   const Message *getMessage(const Qname & q);
00180 
00186   list < const Message *>*getMessages();
00187 
00196   void
00197     WsdlParser::getSchemaParsers(std::vector<SchemaParser* >::iterator & from,
00198                                  std::vector<SchemaParser* >::iterator & to) ;
00199   
00205   int getNumSchemas() const;
00206 
00213   const SchemaParser *getSchemaParser(string targetNamespace) const;
00214 
00221   const SchemaParser *getSchemaParser(int schemaId) const;
00225   bool status()const;
00226   std::string wsdlPath()const;
00228 
00229   
00238   void addExtensibilityHandler(WsdlExtension * ext);
00245   WsdlExtension *  getExtensibilityHandler(const std::string & ns);
00246   WsdlExtension * getExtensibilityHandler(int extId);
00248 
00249  
00256   bool setFeature (int feature_id);
00258 
00259 
00263   enum
00264     {
00265       NONE ,
00266       START,
00267       DEFINITION,
00268       DOCUMENTATION,
00269       ANNOTATION,
00270       IMPORT,
00271       SCHEMA,
00272       TYPES,
00273       MESSAGE,
00274       PART,
00275       PORT_TYPE,
00276       OPERATION,
00277       INPUT,
00278       OUTPUT,
00279       FAULT,
00280       BINDING,
00281       EXTENSIBILITY,
00282       SERVICE,
00283       PORT,
00284       END
00285     };
00286 
00287 #ifdef LOGGING
00288   //for debugging
00289   void print(ostream & out);
00290 #endif
00291 
00292  private:
00293   /* 
00294    *  private methods for parsing
00295    */
00296   int peek(bool lookahead = true);
00297   int next();
00298   void error(string s,int level=0);
00299   string getNamespace(string prefix);
00300   Element * getElement(const Qname &);
00301   int getTypeId(const Qname &);
00302   int getSchema(const Qname & type);
00303   string* parseDoc();
00304   void parseDefinitions();
00305   void parseMessage();
00306   void parseAnnotation();
00307   void parseImport();
00308   PortType *parsePortType();
00309   Operation *parseOperation(PortType* p);
00310   void parseTypes();
00311   void parseBinding();
00312   void parseService();
00313   int handleExtensibilityAttributes(string prefix, string name);
00314   int handleExtensibilityElement(int);
00315   void putMessage(Message * m);
00316   void putPortType(PortType * pt);
00317   void putBinding(Binding * bn);
00318   void initialize(bool);
00319   bool errorOccured_;
00320   XmlPullParser* openSchemaFile(const std::string& path);
00321   const Message *pgetMessage(const Qname& q);
00322   std::string name_, tnsPrefix_, tnsUri_;
00323   std::vector<SchemaParser*> schemaParser_;
00324   std::list < const Message *> messages_list_;
00325   typedef struct
00326   {
00327     WsdlExtension *we;
00328     SchemaParser *spe;
00329   } ExtensionInfo;
00330   std::vector<ExtensionInfo> wsdlExtensions_;
00331   list < PortType *>porttypes_list_;
00332   list < Binding *>bindings_list_;
00333 
00334   class Imports
00335     {
00336     public:
00337       Imports(std::string,std::string);
00338       std::string ns, loc;
00339     };
00340   std::vector<Imports> imports_;
00341   list < string *> docs_list_;
00342   std::ostream & ostr;
00343   std::istream & istr;
00344   int state_;
00345   int element_;                            //the last Wsdl element parsed
00346   string* Doc_;
00347   XmlPullParser * xParser_;
00348   std::ifstream xmlStream;
00349   std::string wsdlFileName;
00350   Soap * soap_;
00351   const int MAX_EXT_XML;
00352 };
00353 
00354 inline
00355 WsdlParser::Imports::Imports(std::string nameSpace,std::string location)
00356   :ns(nameSpace),
00357      loc(location)
00358 {
00359 }
00360 
00361 
00362 inline
00363 std::string
00364 WsdlParser::getNamespace(string prefix)
00365 {
00366   return xParser_->getNamespace(prefix);
00367 }
00368 
00369 
00370 //public  APIs
00371 inline
00372 int  
00373 WsdlParser::getNextElement()
00374 {
00375   next();
00376   return element_;
00377 }
00378 
00379 inline
00380 const std::string*
00381 WsdlParser::getDocumentation() 
00382 {
00383   return  (const string*) Doc_;
00384 }
00385 
00386 inline
00387 std::string
00388 WsdlParser::getNamespace(void)
00389 {
00390   return tnsUri_;
00391 }
00392 
00393 inline
00394 std::string
00395 WsdlParser::getName()
00396 {
00397   return name_;
00398 }
00399 
00400 
00401 
00402 inline
00403 int
00404 WsdlParser::getEventType()
00405 {
00406   return element_;
00407 }
00408 
00409 
00410 inline
00411 list < const Message *>*
00412 WsdlParser::getMessages()
00413 {
00414   return &messages_list_;
00415 }
00416 
00417 inline
00418 int
00419 WsdlParser::getNumSchemas() const
00420 {
00421   return schemaParser_.size()-1;
00422 }
00423 
00424 inline
00425 const SchemaParser *
00426 WsdlParser::getSchemaParser(int schemaId) const
00427 {
00428   return (const SchemaParser *) schemaParser_[schemaId];
00429 }
00430 
00431 inline
00432 std::string
00433 WsdlParser::wsdlPath()const
00434 {
00435   return wsdlFileName           ;
00436 }
00437 inline
00438 bool
00439 WsdlParser::status()const
00440 {
00441  return !errorOccured_;
00442 }
00443 /*  */
00444 #endif                                            /*  */

Generated on Sun Oct 16 10:11:52 2005 for wsdlpull by  doxygen 1.3.9.1