wsdlpull
1.23
|
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/wsdlpull_export.h" 00024 #include "xmlpull/XmlPullParser.h" 00025 #include "xmlpull/XmlPullParserException.h" 00026 #include "schemaparser/SchemaParser.h" 00027 00028 #include "wsdlparser/PortType.h" 00029 #include "wsdlparser/Message.h" 00030 #include "wsdlparser/Operation.h" 00031 #include "wsdlparser/Binding.h" 00032 #include "wsdlparser/Service.h" 00033 #include "wsdlparser/WsdlExtension.h" 00034 00035 00036 00037 namespace WsdlPull{ 00038 00039 const std::string wsdlUri="http://schemas.xmlsoap.org/wsdl/"; 00040 00041 class Soap; 00042 //Wsdl pull parser 00043 class WSDLPULL_EXPORT WsdlParser 00044 { 00045 public: 00055 WsdlParser(std::istream & in = std::cin, std::ostream & out = std::cout, 00056 const std::string & schemaPath = ""); 00057 WsdlParser(const std::string& Uri,std::ostream & out = std::cout, 00058 const std::string & schemaPath = ""); 00059 ~WsdlParser(); 00061 00066 void setSchemaPath(const std::string & schemaPath); 00067 00076 int getNextElement(); 00077 00083 int getEventType(); 00084 00086 00089 //NOTE:The caller must *NOT* free the pointers returned by the getter apis 00090 //This is true for all apis except whenever the api returns a pointer to 00091 //a list of elements which is not one of the root wsdl elements , 00092 //such as getOperations(port type) which is the only exception 00097 std::string getNamespace(void); 00098 00103 std::string getName(); 00104 00110 const std::string* getDocumentation(); 00111 00118 const Binding *getBinding(); 00119 00126 const Binding *getBinding(const Qname & q); 00127 00133 bool getBindings(Binding::cBindingIterator & begin, 00134 Binding::cBindingIterator & end)const; 00135 00142 const Service *getService(); 00143 00150 typedef std::list<Service*>::iterator ServiceIterator; 00151 const Service *getService(const Qname & q); 00152 void getServices(ServiceIterator &from, ServiceIterator &to); 00153 00160 const PortType *getPortType(); 00161 00168 const PortType *getPortType(const Qname & q); 00169 00175 bool getPortTypes(PortType::cPortTypeIterator& begin, 00176 PortType::cPortTypeIterator& end)const; 00177 00185 bool getOperations(const Qname & portType, 00186 Operation::cOpIterator& begin, 00187 Operation::cOpIterator& end); 00188 00196 const Operation *getOperation(const Qname & portType, 00197 const Qname & q); 00198 00205 const Message *getMessage(); 00206 00213 const Message *getMessage(const Qname & q); 00214 00220 std::list < const Message *>& getMessages(); 00221 00230 void getSchemaParsers(std::vector<SchemaParser* >::iterator & from, 00231 std::vector<SchemaParser* >::iterator & to) ; 00232 00238 int getNumSchemas() const; 00239 00246 const SchemaParser *getSchemaParser(std::string targetNamespace) const; 00247 00248 00252 bool status()const; 00253 std::string wsdlPath()const; 00254 std::ostream & logger(); 00255 std::string &getWsdlFileName() { 00256 return wsdlFileName; 00257 } 00258 00259 static bool useLocalSchema_;//if false fetch the schemas from the web 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 extensibility 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 00338 private: 00339 /* 00340 * private methods for parsing 00341 */ 00342 int peek(bool lookahead = true); 00343 int next(); 00344 void error(std::string s,int level=0); 00345 std::string getNamespace(std::string prefix); 00346 Element * getElement(const Qname &); 00347 int getTypeId(const Qname &); 00348 int getSchema(const Qname & name,bool type = true); 00349 std::string* parseDoc(); 00350 void parseDefinitions(); 00351 void parseMessage(); 00352 void parseAnnotation(); 00353 void parseImport(); 00354 PortType *parsePortType(); 00355 Operation *parseOperation(PortType* p); 00356 void processMessageExtensibility(Operation * op, 00357 WsdlPull::MessageType mtype); 00358 void parseTypes(); 00359 void parseBinding(); 00360 void parseService(); 00361 int handleExtensibilityAttributes(std::string prefix, std::string name); 00362 int handleExtensibilityElement(int); 00363 void putMessage(Message * m); 00364 void putPortType(PortType * pt); 00365 void putBinding(Binding * bn); 00366 void initialize(bool); 00367 bool errorOccured_; 00368 XmlPullParser* openSchemaFile(const std::string& path); 00369 const Message *pgetMessage(const Qname& q); 00370 std::string name_, tnsPrefix_, tnsUri_; 00371 std::vector<SchemaParser*> schemaParser_; 00372 00373 typedef struct 00374 { 00375 WsdlExtension *we; 00376 SchemaParser *spe; 00377 } ExtensionInfo; 00378 std::list < const Message *> messages_; 00379 std::vector<ExtensionInfo> wsdlExtensions_; 00380 std::list < PortType *>porttypes_; 00381 std::list < Binding *>bindings_; 00382 std::list < Service*> services_; 00383 00384 class Imports 00385 { 00386 public: 00387 Imports(std::string,std::string); 00388 std::string ns, loc; 00389 }; 00390 std::vector<Imports> imports_; 00391 std::list < std::string *> docs_list_; 00392 std::ostream & ostr; 00393 std::istream & istr; 00394 int state_; 00395 int element_; //the last Wsdl element parsed 00396 std::string* Doc_; 00397 XmlPullParser * xParser_; 00398 std::ifstream xmlStream; 00399 std::string wsdlFileName; 00400 Soap * soap_,*soap2_; 00401 const int MAX_EXT_XML; 00402 std::string schemaPath_; // Path to schemas, used by parser during parsing. 00403 std::string uri_; //The uri to use to resolve imports.1 level up the location of the wsdl file 00404 }; 00405 00406 00407 inline 00408 WsdlParser::Imports::Imports(std::string nameSpace,std::string location) 00409 :ns(nameSpace), 00410 loc(location) 00411 { 00412 } 00413 00414 00415 inline 00416 std::string 00417 WsdlParser::getNamespace(std::string prefix) 00418 { 00419 return xParser_->getNamespace(prefix); 00420 } 00421 00422 00423 //public APIs 00424 inline 00425 int 00426 WsdlParser::getNextElement() 00427 { 00428 next(); 00429 return element_; 00430 } 00431 00432 inline 00433 const std::string* 00434 WsdlParser::getDocumentation() 00435 { 00436 return (const std::string*) Doc_; 00437 } 00438 00439 inline 00440 std::string 00441 WsdlParser::getNamespace(void) 00442 { 00443 return tnsUri_; 00444 } 00445 00446 inline 00447 std::string 00448 WsdlParser::getName() 00449 { 00450 return name_; 00451 } 00452 00453 00454 00455 inline 00456 int 00457 WsdlParser::getEventType() 00458 { 00459 return element_; 00460 } 00461 00462 00463 inline 00464 std::list < const Message *>& 00465 WsdlParser::getMessages() 00466 { 00467 return messages_; 00468 } 00469 00470 //This is deprecated 00471 //the ids 0 and 1 are return the schema parsers used to internally parse the soap schema. 00472 //Ideally you should use getSchemaParser(std::string).If you want to iterate over all the schema parsers 00473 //use getSchemaParsers 00474 inline 00475 const SchemaParser * 00476 WsdlParser::getSchemaParser(int schemaId) const 00477 { 00478 return (const SchemaParser *) schemaParser_[schemaId]; 00479 } 00480 00481 inline 00482 std::string 00483 WsdlParser::wsdlPath()const 00484 { 00485 return wsdlFileName ; 00486 } 00487 inline 00488 bool 00489 WsdlParser::status()const 00490 { 00491 return !errorOccured_; 00492 } 00493 00494 inline 00495 std::ostream& 00496 WsdlParser::logger() 00497 { 00498 return ostr; 00499 } 00500 } 00501 /* */ 00502 #endif /* */