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 
00027 #include "wsdlparser/PortType.h"
00028 #include "wsdlparser/Message.h"
00029 #include "wsdlparser/Operation.h"
00030 #include "wsdlparser/Binding.h"
00031 #include "wsdlparser/Service.h"
00032 #include "wsdlparser/WsdlExtension.h"
00033 
00034 #ifndef WSDLPULL_EXPORT
00035 #if (defined _MSC_VER) && (defined _MT)
00036 #define WSDLPULL_EXPORT __declspec (dllimport)
00037 #else
00038 #define WSDLPULL_EXPORT 
00039 #endif
00040 #endif
00041 
00042 namespace WsdlPull{
00043 
00044   const std::string wsdlUri="http://schemas.xmlsoap.org/wsdl/";
00045 
00046 
00047 class Soap;
00048 //Wsdl pull parser
00049 class WSDLPULL_EXPORT WsdlParser
00050 {
00051  public:
00061   WsdlParser(std::istream & in = std::cin, std::ostream & out = std::cout,
00062              const std::string & schemaPath = SCHEMADIR);
00063   WsdlParser(const std::string& Uri,std::ostream & out = std::cout,
00064              const std::string & schemaPath = SCHEMADIR);
00065   ~WsdlParser();
00067 
00072   void setSchemaPath(const std::string & schemaPath);
00073 
00082   int getNextElement();
00083 
00089   int getEventType();
00090 
00092 
00095   //NOTE:The caller must *NOT* free the pointers returned by the getter apis
00096   //This is true for all apis except whenever the api returns a pointer to 
00097   //a list of elements which is not one  of the root wsdl elements ,
00098   //such as getOperations(port type) which is the only exception
00103   std::string getNamespace(void);
00104 
00109   std::string getName();
00110 
00116   const std::string*  getDocumentation();
00117 
00124   const Binding *getBinding();
00125 
00132   const Binding *getBinding(const Qname & q);
00133 
00139   bool  getBindings(Binding::cBindingIterator & begin,
00140                     Binding::cBindingIterator & end)const;
00141 
00148   const Service *getService();
00149 
00156   const Service *getService(const Qname & q);
00157 
00164   const PortType *getPortType();
00165 
00172   const PortType *getPortType(const Qname & q);
00173 
00179   bool getPortTypes(PortType::cPortTypeIterator& begin,
00180                     PortType::cPortTypeIterator& end)const;
00181 
00189   bool getOperations(const Qname & portType,
00190                      Operation::cOpIterator begin,
00191                      Operation::cOpIterator end);
00192 
00200   const Operation *getOperation(const Qname & portType, 
00201                                 const Qname & q);
00202 
00209   const Message *getMessage();
00210 
00217   const Message *getMessage(const Qname & q);
00218 
00224   std::list < const Message *>& getMessages();
00225 
00234   void
00235     WsdlParser::getSchemaParsers(std::vector<SchemaParser* >::iterator & from,
00236                                  std::vector<SchemaParser* >::iterator & to) ;
00237   
00243   int getNumSchemas() const;
00244 
00251   const SchemaParser *getSchemaParser(std::string targetNamespace) const;
00252 
00253 
00257   bool status()const;
00258   std::string wsdlPath()const;
00259   std::ostream & logger();
00261 
00262   
00271   void addExtensibilityHandler(WsdlExtension * ext);
00278   WsdlExtension *  getExtensibilityHandler(const std::string & ns);
00279    //return the extensibility handler for the given id.
00280    //WsdlParser only stores ids for the extensibilit elements.
00281   WsdlExtension * getExtensibilityHandler(int extId);
00283 
00284  
00291   bool setFeature (int feature_id);
00293 
00294 
00298   enum
00299     {
00300       NONE ,
00301       START,
00302       DEFINITION,
00303       DOCUMENTATION,
00304       ANNOTATION,
00305       IMPORT,
00306       SCHEMA,
00307       TYPES,
00308       MESSAGE,
00309       PART,
00310       PORT_TYPE,
00311       OPERATION,
00312       INPUT,
00313       OUTPUT,
00314       FAULT,
00315       BINDING,
00316       EXTENSIBILITY,
00317       SERVICE,
00318       PORT,
00319       END
00320     };
00321 
00322 #ifdef LOGGING
00323   //for debugging
00324   void print(std::ostream & out);
00325 #endif
00326 
00327   //{@ Deprecated
00334   const SchemaParser *getSchemaParser(int schemaId) const;
00336 
00337  private:
00338   /* 
00339    *  private methods for parsing
00340    */
00341   int peek(bool lookahead = true);
00342   int next();
00343   void error(std::string s,int level=0);
00344   std::string getNamespace(std::string prefix);
00345   Element * getElement(const Qname &);
00346   int getTypeId(const Qname &);
00347   int getSchema(const Qname & type);
00348   std::string* parseDoc();
00349   void parseDefinitions();
00350   void parseMessage();
00351   void parseAnnotation();
00352   void parseImport();
00353   PortType *parsePortType();
00354   Operation *parseOperation(PortType* p);
00355   void parseTypes();
00356   void parseBinding();
00357   void parseService();
00358   int handleExtensibilityAttributes(std::string prefix, std::string name);
00359   int handleExtensibilityElement(int);
00360   void putMessage(Message * m);
00361   void putPortType(PortType * pt);
00362   void putBinding(Binding * bn);
00363   void initialize(bool);
00364   bool errorOccured_;
00365   XmlPullParser* openSchemaFile(const std::string& path);
00366   const Message *pgetMessage(const Qname& q);
00367   std::string name_, tnsPrefix_, tnsUri_;
00368   std::vector<SchemaParser*> schemaParser_;
00369 
00370   typedef struct
00371   {
00372     WsdlExtension *we;
00373     SchemaParser *spe;
00374   } ExtensionInfo;
00375   std::list < const Message *> messages_;
00376   std::vector<ExtensionInfo> wsdlExtensions_;
00377   std::list < PortType *>porttypes_;
00378   std::list < Binding *>bindings_;
00379   std::list < Service*> services_;
00380 
00381   class Imports
00382   {
00383   public:
00384     Imports(std::string,std::string);
00385     std::string ns, loc;
00386   };
00387   std::vector<Imports> imports_;
00388   std::list < std::string *> docs_list_;
00389   std::ostream & ostr;
00390   std::istream & istr;
00391   int state_;
00392   int element_;                            //the last Wsdl element parsed
00393   std::string* Doc_;
00394   XmlPullParser * xParser_;
00395   std::ifstream xmlStream;
00396   std::string wsdlFileName;
00397   Soap * soap_;
00398   const int MAX_EXT_XML;
00399   std::string schemaPath_; // Path to schemas, used by parser during parsing.
00400 };
00401 
00402 
00403 inline
00404 WsdlParser::Imports::Imports(std::string nameSpace,std::string location)
00405   :ns(nameSpace),
00406      loc(location)
00407 {
00408 }
00409 
00410 
00411 inline
00412 std::string
00413 WsdlParser::getNamespace(std::string prefix)
00414 {
00415   return xParser_->getNamespace(prefix);
00416 }
00417 
00418 
00419 //public  APIs
00420 inline
00421 int  
00422 WsdlParser::getNextElement()
00423 {
00424   next();
00425   return element_;
00426 }
00427 
00428 inline
00429 const std::string*
00430 WsdlParser::getDocumentation() 
00431 {
00432   return  (const std::string*) Doc_;
00433 }
00434 
00435 inline
00436 std::string
00437 WsdlParser::getNamespace(void)
00438 {
00439   return tnsUri_;
00440 }
00441 
00442 inline
00443 std::string
00444 WsdlParser::getName()
00445 {
00446   return name_;
00447 }
00448 
00449 
00450 
00451 inline
00452 int
00453 WsdlParser::getEventType()
00454 {
00455   return element_;
00456 }
00457 
00458 
00459 inline
00460 std::list < const Message *>&
00461 WsdlParser::getMessages()
00462 {
00463   return messages_;
00464 }
00465 
00466 //This is deprecated
00467 //the ids 0 and 1 are return the schema parsers used to internally parse the soap schema.
00468 //Ideally you should use getSchemaParser(std::string).If you want to iterate over all the schema parsers
00469 //use getSchemaParsers
00470 inline
00471 const SchemaParser *
00472 WsdlParser::getSchemaParser(int schemaId) const
00473 {
00474   return (const SchemaParser *) schemaParser_[schemaId];
00475 }
00476 
00477 inline
00478 std::string
00479 WsdlParser::wsdlPath()const
00480 {
00481   return wsdlFileName           ;
00482 }
00483 inline
00484 bool
00485 WsdlParser::status()const
00486 {
00487  return !errorOccured_;
00488 }
00489 
00490 inline
00491 std::ostream&
00492 WsdlParser::logger()
00493 {
00494   return ostr;
00495 }
00496 }
00497 /*  */
00498 #endif                                            /*  */

Generated on Mon Feb 6 23:02:42 2006 for wsdlpull by  doxygen 1.3.9.1