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 "schemaparser/Schema.h"
00028 #include "schemaparser/SchemaParserException.h"
00029 #include "schemaparser/Group.h"
00030 #include "schemaparser/Element.h"
00031 #include "schemaparser/Constraint.h"
00032 #include "schemaparser/AttributeGroup.h"
00033 #include "schemaparser/ComplexType.h"
00034 #include "schemaparser/SimpleType.h"
00035 #include "schemaparser/TypesTable.h"
00036
00037
00038 namespace Schema {
00039
00040
00041 class WSDLPULL_EXPORT SchemaParser
00042 {
00043 public:
00044
00045
00046
00047
00048
00049 typedef std::list<Element> ElementList;
00050 typedef std::list<Attribute> AttributeList;
00051 typedef std::list<Group> GroupList;
00052 typedef std::list<AttributeGroup*> AttributeGroupList;
00053 typedef std::list<Constraint*> ConstraintList;
00054 typedef std::list<Qname> QNameList;
00055 typedef std::list < const XSDType *> ConstTypeList;
00056
00057 typedef struct
00058 {
00059 SchemaParser* sParser;
00060 std::string ns;
00061 } ImportedSchema ;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 SchemaParser(const std::string& Uri, std::string tns = "",
00078 std::ostream & log = std::cout,const std::string & confPath="");
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 SchemaParser(XmlPullParser * parser, std::string tns = "",
00090 std::ostream & log = std::cout,const std::string & confPath="");
00091
00092 ~SchemaParser();
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 bool parseSchemaTag();
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 const XSDType *getType(const Qname & type) ;
00115
00116
00117
00118
00119
00120 const XSDType *getType(int id) const;
00121
00122
00123
00124
00125
00126
00127 const XSDType *getType(int id, std::string &nameSpace);
00128
00129
00130
00131
00132
00133
00134 ConstTypeList *getAllTypes() const;
00135
00136
00137
00138
00139
00140 const Element *getElement(const Qname & element) const;
00141
00142
00143
00144
00145
00146
00147
00148 const ElementList& getElements() const;
00149
00150
00151
00152
00153 int getNumElements() const;
00154
00155
00156
00157
00158
00159
00160 Attribute *getAttribute(const Qname & attribute) ;
00161
00162
00163
00164
00165
00166
00167
00168 const AttributeList& getAttributes()const;
00169
00170
00171
00172
00173 int getNumAttributes() const;
00174
00175
00176
00177
00178
00179 std::string getNamespace(void) const;
00180
00181
00182
00183
00184 int getNumTypes() const;
00185
00186
00187
00188
00189
00190
00191
00192
00193 int getTypeId(const Qname &, bool create = false);
00194
00195
00196
00197
00198
00199
00200 bool isBasicType(int sType) const;
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 int getBasicContentType(int typeId)const;
00225
00226
00227
00228
00229
00230
00231 Group* getGroup(const Qname& name);
00232
00233
00234
00235
00236
00237
00238 AttributeGroup* getAttributeGroup(const Qname& name);
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 bool isImported(const std::string & ns)const;
00249 const SchemaParser* getImportedSchemaParser(const std::string & ns)const;
00250
00251
00252
00253
00254
00255
00256
00257 bool addImport(std::string ns, std::string location="");
00258
00259
00260
00261
00262
00263 bool addImport(SchemaParser* sp);
00264
00265
00266
00267
00268
00269 bool addImports(const std::vector<SchemaParser *>& schemaParsers);
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 bool finalize(void);
00282
00283
00284
00285
00286
00287
00288
00289 void setWarningLevel(int l);
00290
00291
00292
00293
00294 void setSchemaPath(const std::string& s);
00295
00296
00297
00298
00299
00300
00301 void setUri(const std::string& u );
00302
00303
00304
00305
00306 std::string getTypeName(Schema::Type t)const;
00307 TypesTable *getTypesTable();
00308 const SchemaParser *getImportedSchema(std::string &nameSpace);
00309 std::vector<ImportedSchema> &getImportedSchemas();
00310
00311
00312
00313
00314 std::string getVersion()const;
00315
00316 bool getElementQualified() const;
00317 std::string getTnsPrefix( void) const;
00318
00319 #ifdef LOGGING
00320
00321
00322
00323 void print(std::ostream &) ;
00324 #endif
00325
00326
00327 private:
00328
00329 Element parseElement(bool & fwdRef);
00330
00331 Attribute parseAttribute(bool & fwdRef);
00332 void init();
00333
00334
00335 void parseAnnotation();
00336 ComplexType *parseComplexType();
00337 SimpleType *parseSimpleType();
00338
00339
00340 Element addAny(ContentModel* cm);
00341 Group parseGroup(ContentModel* cm=0);
00342 Constraint* parseConstraint(Schema::ConstraintType cstr);
00343 AttributeGroup* parseAttributeGroup(ComplexType* cType=0);
00344 Attribute addAnyAttribute(ComplexType * cType);
00345
00346 void parseRestriction(SimpleType * st,ComplexType * ct=0);
00347 void parseComplexContent(ComplexType * ct);
00348 void parseSimpleContent(ComplexType * ct);
00349
00350 void parseContent(ContentModel * cm);
00351 bool parseImport(void);
00352 bool parseInclude();
00353 bool parseSchema(std::string tag="schema");
00354 bool parseRedefine();
00355 int checkImport(std::string nsp)const;
00356 void copyImports(SchemaParser * sp);
00357 void resolveForwardElementRefs();
00358 void resolveForwardAttributeRefs();
00359 bool& shouldResolve();
00360 bool makeListFromSoapArray (ComplexType * ct);
00361
00362 std::string fname_;
00363 std::string tnsUri_;
00364 std::string tnsPrefix_;
00365 std::string version_;
00366 XmlPullParser * xParser_;
00367 bool elementQualified_;
00368 bool attributeQualified_;
00369 bool deleteXmlParser_;
00370 bool resolveFwdRefs_;
00371 TypesTable typesTable_;
00372 std::ifstream xmlStream_;
00373 ElementList lElems_;
00374 AttributeList lAttributes_;
00375 GroupList lGroups_;
00376 AttributeGroupList lAttributeGroups_;
00377 ConstraintList constraints_;
00378 QNameList lForwardElemRefs_;
00379 QNameList lForwardAttributeRefs_;
00380
00381 std::vector<ImportedSchema> importedSchemas_;
00382 void error(std::string, int level = 0);
00383 int level_;
00384 std::ostream & logFile_;
00385 std::string confPath_;
00386 std::string uri_;
00387 };
00388
00389
00390 inline
00391 bool &
00392 SchemaParser::shouldResolve()
00393 {
00394 return resolveFwdRefs_;
00395
00396 }
00397
00398 inline
00399 const SchemaParser::ElementList&
00400 SchemaParser::getElements() const
00401 {
00402 return lElems_;
00403 }
00404
00405 inline
00406 const SchemaParser::AttributeList&
00407 SchemaParser::getAttributes() const
00408 {
00409 return lAttributes_;
00410 }
00411
00412 inline
00413 void
00414 SchemaParser::setWarningLevel(int l)
00415 {
00416 level_ = l;
00417 }
00418 inline
00419 bool
00420 SchemaParser::isImported(const std::string & ns)const
00421 {
00422 return checkImport(ns) != -1;
00423 }
00424 inline
00425 const SchemaParser*
00426 SchemaParser::getImportedSchemaParser(const std::string & ns)const
00427 {
00428 int i= checkImport(ns);
00429 if (i == -1 )
00430 return 0;
00431
00432 return importedSchemas_[i].sParser;
00433 }
00434
00435 inline
00436 void
00437 SchemaParser::setSchemaPath(const std::string& s)
00438 {
00439 confPath_ = s;
00440 }
00441
00442 inline
00443 void
00444 SchemaParser::setUri(const std::string& s)
00445 {
00446 uri_ = s;
00447 }
00448
00449 inline
00450 TypesTable*
00451 SchemaParser::getTypesTable()
00452 {
00453 return &typesTable_;
00454 }
00455
00456 inline
00457 std::vector<SchemaParser::ImportedSchema>&
00458 SchemaParser::getImportedSchemas()
00459 {
00460 return importedSchemas_;
00461 }
00462
00463 inline
00464 std::string
00465 SchemaParser::getVersion()const
00466 {
00467 return version_;
00468 }
00469
00470 inline
00471 bool
00472 SchemaParser::getElementQualified() const
00473 {
00474 return elementQualified_ ;
00475 }
00476
00477 inline
00478
00479 std::string
00480 SchemaParser::getTnsPrefix( void) const
00481 {
00482 return tnsPrefix_;
00483 }
00484
00485 }
00486 #endif
00487
00488