wsdlpull  1.23
WsdlParser.h
Go to the documentation of this file.
1 /*
2  * Wsdlpull - A C++ parser for WSDL (Web services description language)
3  * Copyright (C) 2005-2007 Vivek Krishna
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  */
20 #ifndef _WSDLPARSERH
21 #define _WSDLPARSERH
22 
24 #include "xmlpull/XmlPullParser.h"
27 
28 #include "wsdlparser/PortType.h"
29 #include "wsdlparser/Message.h"
30 #include "wsdlparser/Operation.h"
31 #include "wsdlparser/Binding.h"
32 #include "wsdlparser/Service.h"
34 
35 
36 
37 namespace WsdlPull{
38 
39  const std::string wsdlUri="http://schemas.xmlsoap.org/wsdl/";
40 
41 class Soap;
42 //Wsdl pull parser
44 {
45  public:
55  WsdlParser(std::istream & in = std::cin, std::ostream & out = std::cout,
56  const std::string & schemaPath = "");
57  WsdlParser(const std::string& Uri,std::ostream & out = std::cout,
58  const std::string & schemaPath = "");
59  ~WsdlParser();
61 
66  void setSchemaPath(const std::string & schemaPath);
67 
76  int getNextElement();
77 
83  int getEventType();
84 
86 
89  //NOTE:The caller must *NOT* free the pointers returned by the getter apis
90  //This is true for all apis except whenever the api returns a pointer to
91  //a list of elements which is not one of the root wsdl elements ,
92  //such as getOperations(port type) which is the only exception
97  std::string getNamespace(void);
98 
103  std::string getName();
104 
110  const std::string* getDocumentation();
111 
118  const Binding *getBinding();
119 
126  const Binding *getBinding(const Qname & q);
127 
133  bool getBindings(Binding::cBindingIterator & begin,
134  Binding::cBindingIterator & end)const;
135 
142  const Service *getService();
143 
150  typedef std::list<Service*>::iterator ServiceIterator;
151  const Service *getService(const Qname & q);
152  void getServices(ServiceIterator &from, ServiceIterator &to);
153 
160  const PortType *getPortType();
161 
168  const PortType *getPortType(const Qname & q);
169 
175  bool getPortTypes(PortType::cPortTypeIterator& begin,
176  PortType::cPortTypeIterator& end)const;
177 
185  bool getOperations(const Qname & portType,
186  Operation::cOpIterator& begin,
188 
196  const Operation *getOperation(const Qname & portType,
197  const Qname & q);
198 
205  const Message *getMessage();
206 
213  const Message *getMessage(const Qname & q);
214 
220  std::list < const Message *>& getMessages();
221 
230  void getSchemaParsers(std::vector<SchemaParser* >::iterator & from,
231  std::vector<SchemaParser* >::iterator & to) ;
232 
238  int getNumSchemas() const;
239 
246  const SchemaParser *getSchemaParser(std::string targetNamespace) const;
247 
248 
252  bool status()const;
253  std::string wsdlPath()const;
254  std::ostream & logger();
255  std::string &getWsdlFileName() {
256  return wsdlFileName;
257  }
258 
259  static bool useLocalSchema_;//if false fetch the schemas from the web
261 
262 
271  void addExtensibilityHandler(WsdlExtension * ext);
278  WsdlExtension * getExtensibilityHandler(const std::string & ns);
279  //return the extensibility handler for the given id.
280  //WsdlParser only stores ids for the extensibility elements.
281  WsdlExtension * getExtensibilityHandler(int extId);
283 
284 
291  bool setFeature (int feature_id);
293 
294 
298  enum
299  {
319  END
320  };
321 
322 #ifdef LOGGING
323  //for debugging
324  void print(std::ostream & out);
325 #endif
326 
327  //{@ Deprecated
334  const SchemaParser *getSchemaParser(int schemaId) const;
336 
337 
338  private:
339  /*
340  * private methods for parsing
341  */
342  int peek(bool lookahead = true);
343  int next();
344  void error(std::string s,int level=0);
345  std::string getNamespace(std::string prefix);
346  Element * getElement(const Qname &);
347  int getTypeId(const Qname &);
348  int getSchema(const Qname & name,bool type = true);
349  std::string* parseDoc();
350  void parseDefinitions();
351  void parseMessage();
352  void parseAnnotation();
353  void parseImport();
354  PortType *parsePortType();
355  Operation *parseOperation(PortType* p);
356  void processMessageExtensibility(Operation * op,
357  WsdlPull::MessageType mtype);
358  void parseTypes();
359  void parseBinding();
360  void parseService();
361  int handleExtensibilityAttributes(std::string prefix, std::string name);
362  int handleExtensibilityElement(int);
363  void putMessage(Message * m);
364  void putPortType(PortType * pt);
365  void putBinding(Binding * bn);
366  void initialize(bool);
367  bool errorOccured_;
368  XmlPullParser* openSchemaFile(const std::string& path);
369  const Message *pgetMessage(const Qname& q);
370  std::string name_, tnsPrefix_, tnsUri_;
371  std::vector<SchemaParser*> schemaParser_;
372 
373  typedef struct
374  {
375  WsdlExtension *we;
376  SchemaParser *spe;
377  } ExtensionInfo;
378  std::list < const Message *> messages_;
379  std::vector<ExtensionInfo> wsdlExtensions_;
380  std::list < PortType *>porttypes_;
381  std::list < Binding *>bindings_;
382  std::list < Service*> services_;
383 
384  class Imports
385  {
386  public:
387  Imports(std::string,std::string);
388  std::string ns, loc;
389  };
390  std::vector<Imports> imports_;
391  std::list < std::string *> docs_list_;
392  std::ostream & ostr;
393  std::istream & istr;
394  int state_;
395  int element_; //the last Wsdl element parsed
396  std::string* Doc_;
397  XmlPullParser * xParser_;
398  std::ifstream xmlStream;
399  std::string wsdlFileName;
400  Soap * soap_,*soap2_;
401  const int MAX_EXT_XML;
402  std::string schemaPath_; // Path to schemas, used by parser during parsing.
403  std::string uri_; //The uri to use to resolve imports.1 level up the location of the wsdl file
404 };
405 
406 
407 inline
408 WsdlParser::Imports::Imports(std::string nameSpace,std::string location)
409  :ns(nameSpace),
410  loc(location)
411 {
412 }
413 
414 
415 inline
416 std::string
417 WsdlParser::getNamespace(std::string prefix)
418 {
419  return xParser_->getNamespace(prefix);
420 }
421 
422 
423 //public APIs
424 inline
425 int
427 {
428  next();
429  return element_;
430 }
431 
432 inline
433 const std::string*
435 {
436  return (const std::string*) Doc_;
437 }
438 
439 inline
440 std::string
442 {
443  return tnsUri_;
444 }
445 
446 inline
447 std::string
449 {
450  return name_;
451 }
452 
453 
454 
455 inline
456 int
458 {
459  return element_;
460 }
461 
462 
463 inline
464 std::list < const Message *>&
466 {
467  return messages_;
468 }
469 
470 //This is deprecated
471 //the ids 0 and 1 are return the schema parsers used to internally parse the soap schema.
472 //Ideally you should use getSchemaParser(std::string).If you want to iterate over all the schema parsers
473 //use getSchemaParsers
474 inline
475 const SchemaParser *
476 WsdlParser::getSchemaParser(int schemaId) const
477 {
478  return (const SchemaParser *) schemaParser_[schemaId];
479 }
480 
481 inline
482 std::string
484 {
485  return wsdlFileName ;
486 }
487 inline
488 bool
490 {
491  return !errorOccured_;
492 }
493 
494 inline
495 std::ostream&
497 {
498  return ostr;
499 }
500 }
501 /* */
502 #endif /* */
std::string getName()
Definition: WsdlParser.h:448
const std::string * getDocumentation()
Definition: WsdlParser.h:434
std::list< PortType * >::const_iterator cPortTypeIterator
Definition: PortType.h:34
std::string wsdlPath() const
Definition: WsdlParser.h:483
std::ostream & logger()
Definition: WsdlParser.h:496
static bool useLocalSchema_
Definition: WsdlParser.h:259
std::string getNamespace(std::string prefix)
std::list< Service * >::iterator ServiceIterator
Definition: WsdlParser.h:150
Definition: Qname.h:30
std::list< const Message * > & getMessages()
Definition: WsdlParser.h:465
bool status() const
Definition: WsdlParser.h:489
#define WSDLPULL_EXPORT
const SchemaParser * getSchemaParser(std::string targetNamespace) const
Definition: WsdlParser.cpp:385
std::vector< Operation * >::const_iterator cOpIterator
Definition: Operation.h:57
const std::string wsdlUri
Definition: WsdlParser.h:39
std::string getNamespace(void)
Definition: WsdlParser.h:441
std::string & getWsdlFileName()
Definition: WsdlParser.h:255