SchemaParser.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _SCHEMAPARSERH
00022 #define _SCHEMAPARSERH
00023
00024
00025 #include "xmlpull/wsdlpull_export.h"
00026 #include "xmlpull/XmlPullParser.h"
00027 #include "xmlpull/XmlPullParserException.h"
00028 #include "schemaparser/Schema.h"
00029 #include "schemaparser/SchemaParserException.h"
00030 #include "schemaparser/Group.h"
00031 #include "schemaparser/Element.h"
00032 #include "schemaparser/Constraint.h"
00033 #include "schemaparser/AttributeGroup.h"
00034 #include "schemaparser/ComplexType.h"
00035 #include "schemaparser/SimpleType.h"
00036 #include "schemaparser/TypesTable.h"
00037
00038
00039 namespace Schema {
00040
00041
00042 class WSDLPULL_EXPORT SchemaParser
00043 {
00044 public:
00045
00050 typedef std::list<Element> ElementList;
00051 typedef std::list<Attribute> AttributeList;
00052 typedef std::list<Group> GroupList;
00053 typedef std::list<AttributeGroup*> AttributeGroupList;
00054 typedef std::list<Constraint*> ConstraintList;
00055 typedef std::list<Qname> QNameList;
00056 typedef std::list < const XSDType *> ConstTypeList;
00057
00058 typedef struct
00059 {
00060 SchemaParser* sParser;
00061 std::string ns;
00062 } ImportedSchema ;
00063
00065
00068
00078 SchemaParser(const std::string& Uri, std::string tns = "",
00079 std::ostream & log = std::cout,const std::string & confPath="");
00080
00090 SchemaParser(XmlPullParser * parser, std::string tns = "",
00091 std::ostream & log = std::cout,const std::string & confPath="");
00092
00093 ~SchemaParser();
00094
00096
00103 bool parseSchemaTag();
00104
00106
00109
00116 const XSDType *getType(const Qname & type, bool checkImports = true) ;
00117
00122 const XSDType *getType(int id) const;
00123
00129 const XSDType *getType(int id, std::string &nameSpace);
00130
00136 ConstTypeList *getAllTypes() const;
00137
00143 const Element *getElement(const Qname & element,bool checkImports=true) const;
00144
00151 const ElementList& getElements() const;
00152
00156 int getNumElements() const;
00157
00163 Attribute *getAttribute(const Qname & attribute) ;
00164
00171 const AttributeList& getAttributes()const;
00172
00176 int getNumAttributes() const;
00177
00178
00182 std::string getNamespace(void) const;
00183
00187 int getNumTypes() const;
00188
00189
00196 int getTypeId(const Qname &, bool create = false);
00197
00203 bool isBasicType(int sType) const;
00204
00227 int getBasicContentType(int typeId)const;
00228
00234 Group* getGroup(const Qname& name);
00235
00241 AttributeGroup* getAttributeGroup(const Qname& name);
00242
00244
00251 bool isImported(const std::string & ns)const;
00252 const SchemaParser* getImportedSchemaParser(const std::string & ns)const;
00260 bool addImport(std::string ns, std::string location="");
00266 bool addImport(SchemaParser* sp);
00267
00268
00269
00270
00271
00272 bool addImports(const std::vector<SchemaParser *>& schemaParsers);
00273
00275
00276
00284 bool finalize(void);
00285
00292 void setWarningLevel(int l);
00293
00294
00295
00296
00297 void setSchemaPath(const std::string& s);
00298
00299
00300
00301
00302
00303
00304 void setUri(const std::string& u );
00309 std::string getTypeName(Schema::Type t)const;
00310 TypesTable *getTypesTable();
00311 const SchemaParser *getImportedSchema(std::string &nameSpace);
00312 std::vector<ImportedSchema> &getImportedSchemas();
00313
00317 std::string getVersion()const;
00318
00319 bool getElementQualified() const;
00320 std::string getTnsPrefix( void) const;
00321
00322 #ifdef LOGGING
00323
00326 void print(std::ostream &) ;
00327 #endif
00328
00329
00330 private:
00331
00332 Element parseElement(bool & fwdRef);
00333
00334 Attribute parseAttribute(bool & fwdRef);
00335 void init();
00336
00337
00338 void parseAnnotation();
00339 ComplexType *parseComplexType();
00340 SimpleType *parseSimpleType();
00341
00342
00343 Element addAny(ContentModel* cm);
00344 Group parseGroup(ContentModel* cm=0);
00345 Constraint* parseConstraint(Schema::ConstraintType cstr);
00346 AttributeGroup* parseAttributeGroup(ComplexType* cType=0);
00347 Attribute addAnyAttribute(ComplexType * cType);
00348
00349 void parseRestriction(SimpleType * st,ComplexType * ct=0);
00350 void parseComplexContent(ComplexType * ct);
00351 void parseSimpleContent(ComplexType * ct);
00352
00353 void parseContent(ContentModel * cm);
00354 bool parseImport(void);
00355 bool parseInclude();
00356 bool parseSchema(std::string tag="schema");
00357 bool parseRedefine();
00358 int checkImport(std::string nsp)const;
00359 void copyImports(SchemaParser * sp);
00360 void resolveForwardElementRefs();
00361 void resolveForwardAttributeRefs();
00362 bool& shouldResolve();
00363 bool makeListFromSoapArray (ComplexType * ct);
00364
00365 std::string fname_;
00366 std::string tnsUri_;
00367 std::string tnsPrefix_;
00368 std::string version_;
00369 XmlPullParser * xParser_;
00370 bool elementQualified_;
00371 bool attributeQualified_;
00372 bool deleteXmlParser_;
00373 bool resolveFwdRefs_;
00374 TypesTable typesTable_;
00375 std::ifstream xmlStream_;
00376 ElementList lElems_;
00377 AttributeList lAttributes_;
00378 GroupList lGroups_;
00379 AttributeGroupList lAttributeGroups_;
00380 ConstraintList constraints_;
00381 QNameList lForwardElemRefs_;
00382 QNameList lForwardAttributeRefs_;
00383
00384 std::vector<ImportedSchema> importedSchemas_;
00385 void error(std::string, int level = 0);
00386 int level_;
00387 std::ostream & logFile_;
00388 std::string confPath_;
00389 std::string uri_;
00390 };
00391
00392
00393 inline
00394 bool &
00395 SchemaParser::shouldResolve()
00396 {
00397 return resolveFwdRefs_;
00398
00399 }
00400
00401 inline
00402 const SchemaParser::ElementList&
00403 SchemaParser::getElements() const
00404 {
00405 return lElems_;
00406 }
00407
00408 inline
00409 const SchemaParser::AttributeList&
00410 SchemaParser::getAttributes() const
00411 {
00412 return lAttributes_;
00413 }
00414
00415 inline
00416 void
00417 SchemaParser::setWarningLevel(int l)
00418 {
00419 level_ = l;
00420 }
00421 inline
00422 bool
00423 SchemaParser::isImported(const std::string & ns)const
00424 {
00425 return checkImport(ns) != -1;
00426 }
00427 inline
00428 const SchemaParser*
00429 SchemaParser::getImportedSchemaParser(const std::string & ns)const
00430 {
00431 int i= checkImport(ns);
00432 if (i == -1 )
00433 return 0;
00434
00435 return importedSchemas_[i].sParser;
00436 }
00437
00438 inline
00439 void
00440 SchemaParser::setSchemaPath(const std::string& s)
00441 {
00442 confPath_ = s;
00443 }
00444
00445 inline
00446 void
00447 SchemaParser::setUri(const std::string& s)
00448 {
00449 uri_ = s;
00450 }
00451
00452 inline
00453 TypesTable*
00454 SchemaParser::getTypesTable()
00455 {
00456 return &typesTable_;
00457 }
00458
00459 inline
00460 std::vector<SchemaParser::ImportedSchema>&
00461 SchemaParser::getImportedSchemas()
00462 {
00463 return importedSchemas_;
00464 }
00465
00466 inline
00467 std::string
00468 SchemaParser::getVersion()const
00469 {
00470 return version_;
00471 }
00472
00473 inline
00474 bool
00475 SchemaParser::getElementQualified() const
00476 {
00477 return elementQualified_ ;
00478 }
00479
00480 inline
00481
00482 std::string
00483 SchemaParser::getTnsPrefix( void) const
00484 {
00485 return tnsPrefix_;
00486 }
00487
00488 }
00489 #endif
00490
00491