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/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 #ifndef WSDLPULL_EXPORT
00037 #if (defined _MSC_VER) && (defined _MT)
00038 #define WSDLPULL_EXPORT __declspec (dllimport)
00039 #else
00040 #define WSDLPULL_EXPORT
00041 #endif
00042 #endif
00043
00044 namespace Schema {
00045
00046 class WSDLPULL_EXPORT SchemaParser
00047 {
00048 public:
00049
00054 typedef std::list<Element> ElementList;
00055 typedef std::list<Attribute> AttributeList;
00056 typedef std::list<Group> GroupList;
00057 typedef std::list<AttributeGroup*> AttributeGroupList;
00058 typedef std::list<Constraint*> ConstraintList;
00059 typedef std::list<Qname> QNameList;
00060 typedef std::list < const XSDType *> ConstTypeList;
00061
00063
00066
00073 SchemaParser(const std::string& Uri, std::string tns = "", std::ostream & log = std::cout);
00074
00081 SchemaParser(XmlPullParser * parser, std::string tns = "", std::ostream & log = std::cout);
00082
00083 ~SchemaParser();
00084
00086
00093 bool parseSchemaTag();
00094
00096
00099
00105 const XSDType *getType(const Qname & type) ;
00106
00111 const XSDType *getType(int id) const;
00112
00118 ConstTypeList *getAllTypes() const;
00119
00124 const Element *getElement(const Qname & element) const;
00125
00132 const ElementList& getElements() const;
00133
00137 int getNumElements() const;
00138
00144 Attribute *getAttribute(const Qname & attribute) ;
00145
00152 const AttributeList& getAttributes()const;
00153
00157 int getNumAttributes() const;
00158
00159
00163 std::string getNamespace(void) const;
00164
00168 int getNumTypes() const;
00169
00170
00177 int getTypeId(const Qname &, bool create = false);
00178
00184 bool isBasicType(int sType) const;
00185
00208 int getBasicContentType(int typeId)const;
00209
00215 Group* getGroup(const Qname& name);
00216
00222 AttributeGroup* getAttributeGroup(const Qname& name);
00223
00225
00233 bool addImports(const std::vector<SchemaParser *>& schemaParsers);
00241 bool addImport(std::string ns, std::string location="");
00247 bool addImport(SchemaParser* sp);
00248
00250
00251
00259 bool finalize(void);
00260
00267 void setWarningLevel(unsigned char l);
00268
00273 std::string getTypeName(Schema::Type t)const;
00274
00275
00276 #ifdef LOGGING
00277
00280 void print(std::ostream &) ;
00281 #endif
00282
00283
00284 private:
00285
00286 Element parseElement(bool & fwdRef);
00287
00288 Attribute parseAttribute(bool & fwdRef);
00289
00290
00291 void parseAnnotation();
00292 ComplexType *parseComplexType();
00293 SimpleType *parseSimpleType();
00294
00295
00296 Element addAny(ContentModel* cm);
00297 Group parseGroup(ContentModel* cm=0);
00298 Constraint* parseConstraint(Schema::Constraints cstr);
00299 AttributeGroup* parseAttributeGroup(ComplexType* cType=0);
00300 Attribute addAnyAttribute(ComplexType * cType);
00301
00302 void parseRestriction(SimpleType * st,ComplexType * ct=0);
00303 void parseComplexContent(ComplexType * ct);
00304 void parseSimpleContent(ComplexType * ct);
00305
00306 void parseContent(ContentModel * cm);
00307 bool parseImport(void);
00308 bool parseInclude();
00309 bool parseSchema(std::string tag="schema");
00310 bool parseRedefine();
00311 int checkImport(std::string nsp);
00312 void resolveForwardElementRefs();
00313 void resolveForwardAttributeRefs();
00314 int addExternalElement(const std::string & name,int localTypeId);
00315 bool& shouldResolve();
00316 bool makeListFromSoapArray (ComplexType * ct);
00317
00318 std::string tnsUri_;
00319 std::string tnsPrefix_;
00320 XmlPullParser * xParser_;
00321 bool elementQualified_;
00322 bool attributeQualified_;
00323 bool deleteXmlParser_;
00324 bool resolveFwdRefs_;
00325
00326 TypesTable typesTable_;
00327 std::ifstream xmlStream_;
00328 ElementList lElems_;
00329 AttributeList lAttributes_;
00330 GroupList lGroups_;
00331 AttributeGroupList lAttributeGroups_;
00332 ConstraintList constraints_;
00333 QNameList lForwardElemRefs_;
00334 QNameList lForwardAttributeRefs_;
00335
00336 typedef struct
00337 {
00338 SchemaParser* sParser;
00339 std::string ns;
00340 } ImportedSchema ;
00341 std::vector<ImportedSchema> importedSchemas_;
00342 void error(std::string, int level = 0);
00343 unsigned char level_;
00344 std::ostream & logFile_;
00345 };
00346
00347
00348 inline
00349 bool &
00350 SchemaParser::shouldResolve()
00351 {
00352 return resolveFwdRefs_;
00353
00354 }
00355
00356 inline
00357 const SchemaParser::ElementList&
00358 SchemaParser::getElements() const
00359 {
00360 return lElems_;
00361 }
00362
00363 inline
00364 const SchemaParser::AttributeList&
00365 SchemaParser::getAttributes() const
00366 {
00367 return lAttributes_;
00368 }
00369 inline
00370 void
00371 SchemaParser::setWarningLevel(unsigned char l)
00372 {
00373 level_ = l;
00374 }
00375 }
00376 #endif
00377
00378