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 #include <map>
00025 #include <xmlpull/XmlPullParser.h>
00026 #include <schemaparser/Schema.h>
00027 #include <schemaparser/SchemaParserException.h>
00028 #include <schemaparser/Group.h>
00029 #include <schemaparser/Element.h>
00030 #include <schemaparser/Constraint.h>
00031 #include <schemaparser/AttributeGroup.h>
00032 #include <schemaparser/ComplexType.h>
00033 #include <schemaparser/SimpleType.h>
00034 #include <schemaparser/TypesTable.h>
00035
00036
00037
00038 class SchemaParser
00039 {
00040 public:
00043
00050 SchemaParser(const string& Uri, string tns = "", ostream & log = cout);
00051
00058 SchemaParser(XmlPullParser * parser, string tns = "", ostream & log = cout);
00059
00060 ~SchemaParser();
00061
00063
00070 bool parseSchemaTag();
00071
00073
00076
00082 const XSDType *getType(const Qname & type) ;
00083
00088 const XSDType *getType(int id) const;
00089
00095 list < const XSDType *>*getAllTypes() const;
00096
00101 const Element *getElement(const Qname & element) const;
00102
00109 const list<Element> getElements() const;
00110
00114 int getNumElements() const;
00115
00121 Attribute *getAttribute(const Qname & attribute) ;
00122
00129 const list<Attribute> getAttributes()const;
00130
00134 int getNumAttributes() const;
00135
00136
00140 string getNamespace(void) const;
00141
00145 int getNumTypes() const;
00146
00147
00154 int getTypeId(const Qname &, bool create = false);
00155
00161 bool isBasicType(int sType) const;
00162
00185 int getBasicContentType(int typeId)const;
00186
00192 Group* getGroup(const Qname& name);
00193
00199 AttributeGroup* getAttributeGroup(const Qname& name);
00200
00202
00210 bool addImports(const std::vector<SchemaParser *>& schemaParsers);
00218 bool addImport(string ns, string location="");
00224 bool addImport(SchemaParser* sp);
00225
00227
00228
00236 bool finalize(void);
00237
00244 void setWarningLevel(unsigned char l);
00245 #ifdef LOGGING
00246
00249 void print(ostream &) ;
00250 #endif
00251
00252
00253 private:
00254
00255 Element parseElement(bool & fwdRef);
00256
00257 Attribute parseAttribute(bool & fwdRef);
00258
00259
00260 void parseAnnotation();
00261 ComplexType *parseComplexType();
00262 SimpleType *parseSimpleType();
00263
00264
00265 Element addAny(ContentModel* cm);
00266 Group parseGroup(ContentModel* cm=0);
00267 Constraint* parseConstraint(Schema::Constraints cstr);
00268 AttributeGroup parseAttributeGroup(ComplexType* cType=0);
00269 Attribute addAnyAttribute(ComplexType * cType);
00270
00271 void parseRestriction(SimpleType * st,ComplexType * ct=0);
00272 void parseComplexContent(ComplexType * ct);
00273 void parseSimpleContent(ComplexType * ct);
00274
00275 void parseContent(ContentModel * cm);
00276 bool parseImport(void);
00277 bool parseInclude();
00278 bool parseSchema(std::string tag="schema");
00279 bool parseRedefine();
00280 int checkImport(string nsp);
00281 void resolveForwardElementRefs();
00282 void resolveForwardAttributeRefs();
00283 int addExternalElement(const string & name,int localTypeId);
00284 bool& shouldResolve();
00285
00286 std::map<std::string,std::string>
00287 SchemaParser::processAttributes(XmlPullParser* xpp);
00288
00289 std::string tnsUri_;
00290 std::string tnsPrefix_;
00291 XmlPullParser * xParser_;
00292 bool elementQualified_;
00293 bool attributeQualified_;
00294 bool deleteXmlParser_;
00295 bool resolveFwdRefs_;
00296
00297 TypesTable typesTable_;
00298 std::ifstream xmlStream_;
00299 std::list<Element> lElems_;
00300 std::list<Attribute> lAttributes_;
00301 std::list<Group> lGroups_;
00302 std::list<AttributeGroup> lAttributeGroups_;
00303 std::list<Constraint*> constraints_;
00304 std::list<Qname> lForwardElemRefs_;
00305 std::list<Qname> lForwardAttributeRefs_;
00306
00307 typedef struct
00308 {
00309 SchemaParser* sParser;
00310 std::string ns;
00311 } ImportedSchema ;
00312 std::vector<ImportedSchema> importedSchemas_;
00313 void error(string, int level = 0);
00314 unsigned char level_;
00315 std::ostream & logFile_;
00316 };
00317
00318
00319 inline
00320 bool &
00321 SchemaParser::shouldResolve()
00322 {
00323 return resolveFwdRefs_;
00324
00325 }
00326
00327 inline
00328 const list<Element>
00329 SchemaParser::getElements() const
00330 {
00331 return lElems_;
00332 }
00333
00334 inline
00335 const list<Attribute>
00336 SchemaParser::getAttributes() const
00337 {
00338 return lAttributes_;
00339 }
00340 inline
00341 void
00342 SchemaParser::setWarningLevel(unsigned char l)
00343 {
00344 level_ = l;
00345 }
00346
00347 #endif
00348
00349