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);
00249 const SchemaParser* getImportedSchemaParser(const std::string & ns);
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(unsigned char 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 #ifdef LOGGING
00312
00313
00314
00315 void print(std::ostream &) ;
00316 #endif
00317
00318
00319 private:
00320
00321 Element parseElement(bool & fwdRef);
00322
00323 Attribute parseAttribute(bool & fwdRef);
00324 void init();
00325
00326
00327 void parseAnnotation();
00328 ComplexType *parseComplexType();
00329 SimpleType *parseSimpleType();
00330
00331
00332 Element addAny(ContentModel* cm);
00333 Group parseGroup(ContentModel* cm=0);
00334 Constraint* parseConstraint(Schema::ConstraintType cstr);
00335 AttributeGroup* parseAttributeGroup(ComplexType* cType=0);
00336 Attribute addAnyAttribute(ComplexType * cType);
00337
00338 void parseRestriction(SimpleType * st,ComplexType * ct=0);
00339 void parseComplexContent(ComplexType * ct);
00340 void parseSimpleContent(ComplexType * ct);
00341
00342 void parseContent(ContentModel * cm);
00343 bool parseImport(void);
00344 bool parseInclude();
00345 bool parseSchema(std::string tag="schema");
00346 bool parseRedefine();
00347 int checkImport(std::string nsp);
00348 void copyImports(SchemaParser * sp);
00349 void resolveForwardElementRefs();
00350 void resolveForwardAttributeRefs();
00351 int addExternalElement(const std::string & name,const std::string & nspace,int localTypeId);
00352 bool& shouldResolve();
00353 bool makeListFromSoapArray (ComplexType * ct);
00354
00355 std::string fname_;
00356 std::string tnsUri_;
00357 std::string tnsPrefix_;
00358 XmlPullParser * xParser_;
00359 bool elementQualified_;
00360 bool attributeQualified_;
00361 bool deleteXmlParser_;
00362 bool resolveFwdRefs_;
00363 TypesTable typesTable_;
00364 std::ifstream xmlStream_;
00365 ElementList lElems_;
00366 AttributeList lAttributes_;
00367 GroupList lGroups_;
00368 AttributeGroupList lAttributeGroups_;
00369 ConstraintList constraints_;
00370 QNameList lForwardElemRefs_;
00371 QNameList lForwardAttributeRefs_;
00372
00373 std::vector<ImportedSchema> importedSchemas_;
00374 void error(std::string, int level = 0);
00375 unsigned char level_;
00376 std::ostream & logFile_;
00377 std::string confPath_;
00378 std::string uri_;
00379 };
00380
00381
00382 inline
00383 bool &
00384 SchemaParser::shouldResolve()
00385 {
00386 return resolveFwdRefs_;
00387
00388 }
00389
00390 inline
00391 const SchemaParser::ElementList&
00392 SchemaParser::getElements() const
00393 {
00394 return lElems_;
00395 }
00396
00397 inline
00398 const SchemaParser::AttributeList&
00399 SchemaParser::getAttributes() const
00400 {
00401 return lAttributes_;
00402 }
00403
00404 inline
00405 void
00406 SchemaParser::setWarningLevel(unsigned char l)
00407 {
00408 level_ = l;
00409 }
00410 inline
00411 bool
00412 SchemaParser::isImported(const std::string & ns)
00413 {
00414 return checkImport(ns) != -1;
00415 }
00416 inline
00417 const SchemaParser*
00418 SchemaParser::getImportedSchemaParser(const std::string & ns)
00419 {
00420 int i= checkImport(ns);
00421 if (i == -1 )
00422 return 0;
00423
00424 return importedSchemas_[i].sParser;
00425 }
00426
00427 inline
00428 void
00429 SchemaParser::setSchemaPath(const std::string& s)
00430 {
00431 confPath_ = s;
00432 }
00433
00434 inline
00435 void
00436 SchemaParser::setUri(const std::string& s)
00437 {
00438 uri_ = s;
00439 }
00440
00441 inline
00442 TypesTable*
00443 SchemaParser::getTypesTable()
00444 {
00445 return &typesTable_;
00446 }
00447
00448 inline
00449 std::vector<SchemaParser::ImportedSchema>&
00450 SchemaParser::getImportedSchemas()
00451 {
00452 return importedSchemas_;
00453 }
00454
00455 }
00456 #endif
00457
00458