wsdlpull  1.23
SchemaParser.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  */
21 #ifndef _SCHEMAPARSERH
22 #define _SCHEMAPARSERH
23 
24 
26 #include "xmlpull/XmlPullParser.h"
28 #include "schemaparser/Schema.h"
30 #include "schemaparser/Group.h"
31 #include "schemaparser/Element.h"
37 
38 
39 namespace Schema {
40 
41 //class Schema Parser
43 {
44  public:
45 
50  typedef std::list<Element> ElementList;
51  typedef std::list<Attribute> AttributeList;
52  typedef std::list<Group> GroupList;
53  typedef std::list<AttributeGroup*> AttributeGroupList;
54  typedef std::list<Constraint*> ConstraintList;
55  typedef std::list<Qname> QNameList;
56  typedef std::list < const XSDType *> ConstTypeList;
57 
58  typedef struct
59  {
61  std::string ns;
62  } ImportedSchema ;
63 
65 
68 
78  SchemaParser(const std::string& Uri, std::string tns = "",
79  std::ostream & log = std::cout,const std::string & confPath="");
80 
90  SchemaParser(XmlPullParser * parser, std::string tns = "",
91  std::ostream & log = std::cout,const std::string & confPath="");
92 
93  ~SchemaParser();
94 
96 
103  bool parseSchemaTag();
104 
106 
109 
116  const XSDType *getType(const Qname & type, bool checkImports = true) ;
117 
122  const XSDType *getType(int id) const;
123 
129  const XSDType *getType(int id, std::string &nameSpace);
130 
136  ConstTypeList *getAllTypes() const;
137 
143  const Element *getElement(const Qname & element,bool checkImports=true) const;
144 
151  const ElementList& getElements() const;
152 
156  int getNumElements() const;
157 
163  Attribute *getAttribute(const Qname & attribute) ;
164 
171  const AttributeList& getAttributes()const;
172 
176  int getNumAttributes() const;
177 
178 
182  std::string getNamespace(void) const;
183 
187  int getNumTypes() const;
188 
189 
196  int getTypeId(const Qname &, bool create = false);
197 
203  bool isBasicType(int sType) const;
204 
227  int getBasicContentType(int typeId)const;
228 
234  Group* getGroup(const Qname& name);
235 
241  AttributeGroup* getAttributeGroup(const Qname& name);
242 
244 
251  bool isImported(const std::string & ns)const;
252  const SchemaParser* getImportedSchemaParser(const std::string & ns)const;
260  bool addImport(std::string ns, std::string location="");
266  bool addImport(SchemaParser* sp);
267  /*
268  * addImports .To add an array of schema parsers for imported schemas
269  * @param array of schema parsers
270  * @param number of schema parsers added
271  */
272  bool addImports(const std::vector<SchemaParser *>& schemaParsers); //to be removed soon
273 
275 
276 
284  bool finalize(void);
285 
292  void setWarningLevel(int l);
293  /*
294  * path to the directory where the config file for handling
295  * imports is located
296  */
297  void setSchemaPath(const std::string& s);
298 
299  /* Set the path to the uri from where references to imported schemas
300  * may be resolved. One level up the actual location.
301  * Example if you set uri as "tempuri.org" ,a reference to imported schema location "x.xsd"
302  * will be mapped to "tempuri.org/x.xsd"
303  */
304  void setUri(const std::string& u );
309  std::string getTypeName(Schema::Type t)const;
310  TypesTable *getTypesTable();
311  const SchemaParser *getImportedSchema(std::string &nameSpace);
312  std::vector<ImportedSchema> &getImportedSchemas();
313 
317  std::string getVersion()const;
318 
319  bool getElementQualified() const;
320  std::string getTnsPrefix( void) const;
321 
322 #ifdef LOGGING
323 
326  void print(std::ostream &) ;
327 #endif
328 
329 
330  private:
331  //This function parses global elements
332  Element parseElement(bool & fwdRef);
333  //This function parses global attributes
334  Attribute parseAttribute(bool & fwdRef);
335  void init();
336 
337  //This function parses <annotation> tag
338  void parseAnnotation();
339  ComplexType *parseComplexType();
340  SimpleType *parseSimpleType();
341 
342 
343  Element addAny(ContentModel* cm);
344  Group parseGroup(ContentModel* cm=0);
345  Constraint* parseConstraint(Schema::ConstraintType cstr);
346  AttributeGroup* parseAttributeGroup(ComplexType* cType=0);
347  Attribute addAnyAttribute(ComplexType * cType);
348 
349  void parseRestriction(SimpleType * st,ComplexType * ct=0);
350  void parseComplexContent(ComplexType * ct);
351  void parseSimpleContent(ComplexType * ct);
352 
353  void parseContent(ContentModel * cm);
354  bool parseImport(void);
355  bool parseInclude();
356  bool parseSchema(std::string tag="schema");
357  bool parseRedefine();
358  int checkImport(std::string nsp)const;
359  void copyImports(SchemaParser * sp);
360  void resolveForwardElementRefs();
361  void resolveForwardAttributeRefs();
362  bool& shouldResolve();
363  bool makeListFromSoapArray (ComplexType * ct);
364 
365  std::string fname_;
366  std::string tnsUri_;
367  std::string tnsPrefix_;
368  std::string version_;
369  XmlPullParser * xParser_;
370  bool elementQualified_;
371  bool attributeQualified_;
372  bool deleteXmlParser_;
373  bool resolveFwdRefs_;
374  TypesTable typesTable_;
375  std::ifstream xmlStream_;
376  ElementList lElems_;
377  AttributeList lAttributes_;
378  GroupList lGroups_;
379  AttributeGroupList lAttributeGroups_;
380  ConstraintList constraints_;
381  QNameList lForwardElemRefs_;
382  QNameList lForwardAttributeRefs_;
383 
384  std::vector<ImportedSchema> importedSchemas_;
385  void error(std::string, int level = 0);
386  int level_;//warning level
387  std::ostream & logFile_;
388  std::string confPath_;
389  std::string uri_; //The uri to use to resolve imports.1 level up the location of the schema file
390 };
391 
392 
393 inline
394 bool &
395 SchemaParser::shouldResolve()
396 {
397  return resolveFwdRefs_;
398 
399 }
400 
401 inline
404 {
405  return lElems_;
406 }
407 
408 inline
411 {
412  return lAttributes_;
413 }
414 
415 inline
416 void
418 {
419  level_ = l;
420 }
421 inline
422 bool
423 SchemaParser::isImported(const std::string & ns)const
424 {
425  return checkImport(ns) != -1;
426 }
427 inline
428 const SchemaParser*
429 SchemaParser::getImportedSchemaParser(const std::string & ns)const
430 {
431  int i= checkImport(ns);
432  if (i == -1 )
433  return 0;
434 
435  return importedSchemas_[i].sParser;
436 }
437 
438 inline
439 void
440 SchemaParser::setSchemaPath(const std::string& s)
441 {
442  confPath_ = s;
443 }
444 
445 inline
446 void
447 SchemaParser::setUri(const std::string& s)
448 {
449  uri_ = s;
450 }
451 
452 inline
453 TypesTable*
455 {
456  return &typesTable_;
457 }
458 
459 inline
460 std::vector<SchemaParser::ImportedSchema>&
462 {
463  return importedSchemas_;
464 }
465 
466 inline
467 std::string
469 {
470  return version_;
471 }
472 
473 inline
474 bool
476 {
477  return elementQualified_ ;
478 }
479 
480 inline
481 
482 std::string
484 {
485  return tnsPrefix_;
486 }
487 
488 }
489 #endif /* */
490 
491 
Schema::SchemaParser::ImportedSchema::sParser
SchemaParser * sParser
Definition: SchemaParser.h:60
Schema
Definition: Annotation.h:27
Schema::SchemaParser::GroupList
std::list< Group > GroupList
Definition: SchemaParser.h:52
TypesTable.h
Schema::TypesTable
Definition: TypesTable.h:35
Schema::Constraint
Definition: Constraint.h:33
Schema::SimpleType
Definition: SimpleType.h:53
Schema::SchemaParser::setUri
void setUri(const std::string &u)
Definition: SchemaParser.h:447
Schema::SchemaParser::getElements
const ElementList & getElements() const
Definition: SchemaParser.h:403
Schema::SchemaParser::AttributeList
std::list< Attribute > AttributeList
Definition: SchemaParser.h:51
Schema::SchemaParser::getTypesTable
TypesTable * getTypesTable()
Definition: SchemaParser.h:454
Group.h
Schema::SchemaParser::getImportedSchemas
std::vector< ImportedSchema > & getImportedSchemas()
Definition: SchemaParser.h:461
Constraint.h
Schema::Attribute
Definition: Attribute.h:27
Schema::ConstraintType
ConstraintType
Definition: Schema.h:51
Schema::XSDType
Definition: XSDType.h:37
Schema::SchemaParser
Definition: SchemaParser.h:42
Schema::SchemaParser::isImported
bool isImported(const std::string &ns) const
Definition: SchemaParser.h:423
Schema::SchemaParser::ElementList
std::list< Element > ElementList
Definition: SchemaParser.h:50
Schema::SchemaParser::AttributeGroupList
std::list< AttributeGroup * > AttributeGroupList
Definition: SchemaParser.h:53
Schema::ComplexType
Definition: ComplexType.h:34
Schema.h
Element.h
Schema::SchemaParser::ConstTypeList
std::list< const XSDType * > ConstTypeList
Definition: SchemaParser.h:56
Schema::SchemaParser::setWarningLevel
void setWarningLevel(int l)
Definition: SchemaParser.h:417
WSDLPULL_EXPORT
#define WSDLPULL_EXPORT
Definition: wsdlpull_export.h:33
AttributeGroup.h
Schema::Type
Type
Definition: Schema.h:59
Schema::SchemaParser::setSchemaPath
void setSchemaPath(const std::string &s)
Definition: SchemaParser.h:440
Schema::SchemaParser::getTnsPrefix
std::string getTnsPrefix(void) const
Definition: SchemaParser.h:483
ComplexType.h
XmlPullParser.h
wsdlpull_export.h
Schema::Group
Definition: Group.h:33
Schema::SchemaParser::ImportedSchema
Definition: SchemaParser.h:58
Schema::SchemaParser::getAttributes
const AttributeList & getAttributes() const
Definition: SchemaParser.h:410
Schema::SchemaParser::getImportedSchemaParser
const SchemaParser * getImportedSchemaParser(const std::string &ns) const
Definition: SchemaParser.h:429
XmlPullParser
Definition: XmlPullParser.h:46
Qname
Definition: Qname.h:30
XmlPullParserException.h
SchemaParserException.h
Schema::SchemaParser::ImportedSchema::ns
std::string ns
Definition: SchemaParser.h:61
Schema::AttributeGroup
Definition: AttributeGroup.h:33
Schema::Element
Definition: Element.h:30
Schema::SchemaParser::ConstraintList
std::list< Constraint * > ConstraintList
Definition: SchemaParser.h:54
Schema::ContentModel
Definition: ContentModel.h:36
Schema::SchemaParser::QNameList
std::list< Qname > QNameList
Definition: SchemaParser.h:55
SimpleType.h
Schema::SchemaParser::getElementQualified
bool getElementQualified() const
Definition: SchemaParser.h:475
Schema::SchemaParser::getVersion
std::string getVersion() const
Definition: SchemaParser.h:468