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
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
00064
00067
00074 SchemaParser(const std::string& Uri, std::string tns = "",
00075 std::ostream & log = std::cout,const std::string & confPath="");
00076
00083 SchemaParser(XmlPullParser * parser, std::string tns = "",
00084 std::ostream & log = std::cout,const std::string & confPath="");
00085
00086 ~SchemaParser();
00087
00089
00096 bool parseSchemaTag();
00097
00099
00102
00108 const XSDType *getType(const Qname & type) ;
00109
00114 const XSDType *getType(int id) const;
00115
00121 const XSDType *getType(int id, std::string &nameSpace);
00122
00128 ConstTypeList *getAllTypes() const;
00129
00134 const Element *getElement(const Qname & element) const;
00135
00142 const ElementList& getElements() const;
00143
00147 int getNumElements() const;
00148
00154 Attribute *getAttribute(const Qname & attribute) ;
00155
00162 const AttributeList& getAttributes()const;
00163
00167 int getNumAttributes() const;
00168
00169
00173 std::string getNamespace(void) const;
00174
00178 int getNumTypes() const;
00179
00180
00187 int getTypeId(const Qname &, bool create = false);
00188
00194 bool isBasicType(int sType) const;
00195
00218 int getBasicContentType(int typeId)const;
00219
00225 Group* getGroup(const Qname& name);
00226
00232 AttributeGroup* getAttributeGroup(const Qname& name);
00233
00235
00242 bool isImported(const std::string & ns);
00243 const SchemaParser* getImportedSchemaParser(const std::string & ns);
00251 bool addImport(std::string ns, std::string location="");
00257 bool addImport(SchemaParser* sp);
00258
00259
00260
00261
00262
00263 bool addImports(const std::vector<SchemaParser *>& schemaParsers);
00264
00266
00267
00275 bool finalize(void);
00276
00283 void setWarningLevel(unsigned char l);
00284
00285
00286
00287
00288 void setSchemaPath(const std::string& s);
00289
00294 std::string getTypeName(Schema::Type t)const;
00295
00296 TypesTable *getTypesTable()
00297 {
00298 return &typesTable_;
00299 }
00300
00301 const SchemaParser *getImportedSchema(std::string &nameSpace);
00302
00303 std::vector<ImportedSchema> &getImportedSchemas()
00304 {
00305 return importedSchemas_;
00306 }
00307
00308 #ifdef LOGGING
00309
00312 void print(std::ostream &) ;
00313 #endif
00314
00315
00316 private:
00317
00318 Element parseElement(bool & fwdRef);
00319
00320 Attribute parseAttribute(bool & fwdRef);
00321 void init();
00322
00323
00324 void parseAnnotation();
00325 ComplexType *parseComplexType();
00326 SimpleType *parseSimpleType();
00327
00328
00329 Element addAny(ContentModel* cm);
00330 Group parseGroup(ContentModel* cm=0);
00331 Constraint* parseConstraint(Schema::Constraints cstr);
00332 AttributeGroup* parseAttributeGroup(ComplexType* cType=0);
00333 Attribute addAnyAttribute(ComplexType * cType);
00334
00335 void parseRestriction(SimpleType * st,ComplexType * ct=0);
00336 void parseComplexContent(ComplexType * ct);
00337 void parseSimpleContent(ComplexType * ct);
00338
00339 void parseContent(ContentModel * cm);
00340 bool parseImport(void);
00341 bool parseInclude();
00342 bool parseSchema(std::string tag="schema");
00343 bool parseRedefine();
00344 int checkImport(std::string nsp);
00345 void copyImports(SchemaParser * sp);
00346 void resolveForwardElementRefs();
00347 void resolveForwardAttributeRefs();
00348 int addExternalElement(const std::string & name,const std::string & nspace,int localTypeId);
00349 bool& shouldResolve();
00350 bool makeListFromSoapArray (ComplexType * ct);
00351
00352 std::string fname_;
00353 std::string tnsUri_;
00354 std::string tnsPrefix_;
00355 XmlPullParser * xParser_;
00356 bool elementQualified_;
00357 bool attributeQualified_;
00358 bool deleteXmlParser_;
00359 bool resolveFwdRefs_;
00360 TypesTable typesTable_;
00361 std::ifstream xmlStream_;
00362 ElementList lElems_;
00363 AttributeList lAttributes_;
00364 GroupList lGroups_;
00365 AttributeGroupList lAttributeGroups_;
00366 ConstraintList constraints_;
00367 QNameList lForwardElemRefs_;
00368 QNameList lForwardAttributeRefs_;
00369
00370 std::vector<ImportedSchema> importedSchemas_;
00371 void error(std::string, int level = 0);
00372 unsigned char level_;
00373 std::ostream & logFile_;
00374 std::string confPath_;
00375 };
00376
00377
00378 inline
00379 bool &
00380 SchemaParser::shouldResolve()
00381 {
00382 return resolveFwdRefs_;
00383
00384 }
00385
00386 inline
00387 const SchemaParser::ElementList&
00388 SchemaParser::getElements() const
00389 {
00390 return lElems_;
00391 }
00392
00393 inline
00394 const SchemaParser::AttributeList&
00395 SchemaParser::getAttributes() const
00396 {
00397 return lAttributes_;
00398 }
00399
00400 inline
00401 void
00402 SchemaParser::setWarningLevel(unsigned char l)
00403 {
00404 level_ = l;
00405 }
00406 inline
00407 bool
00408 SchemaParser::isImported(const std::string & ns)
00409 {
00410 return checkImport(ns) != -1;
00411 }
00412 inline
00413 const SchemaParser*
00414 SchemaParser::getImportedSchemaParser(const std::string & ns)
00415 {
00416 int i= checkImport(ns);
00417 if (i == -1 )
00418 return 0;
00419
00420 return importedSchemas_[i].sParser;
00421 }
00422
00423 inline
00424 void
00425 SchemaParser::setSchemaPath(const std::string& s)
00426 {
00427 confPath_ = s;
00428 }
00429
00430 }
00431 #endif
00432
00433