wsdlpull
1.23
|
00001 /* 00002 * wsdlpull - A C++ parser for WSDL (Web services description language) 00003 * Copyright (C) 2005-2007 Vivek Krishna 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public 00016 * License along with this library; if not, write to the Free 00017 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 * 00019 * 00020 */ 00021 #ifndef _SCHEMAPARSERH 00022 #define _SCHEMAPARSERH 00023 00024 00025 #include "xmlpull/wsdlpull_export.h" 00026 #include "xmlpull/XmlPullParser.h" 00027 #include "xmlpull/XmlPullParserException.h" 00028 #include "schemaparser/Schema.h" 00029 #include "schemaparser/SchemaParserException.h" 00030 #include "schemaparser/Group.h" 00031 #include "schemaparser/Element.h" 00032 #include "schemaparser/Constraint.h" 00033 #include "schemaparser/AttributeGroup.h" 00034 #include "schemaparser/ComplexType.h" 00035 #include "schemaparser/SimpleType.h" 00036 #include "schemaparser/TypesTable.h" 00037 00038 00039 namespace Schema { 00040 00041 //class Schema Parser 00042 class WSDLPULL_EXPORT SchemaParser 00043 { 00044 public: 00045 00050 typedef std::list<Element> ElementList; 00051 typedef std::list<Attribute> AttributeList; 00052 typedef std::list<Group> GroupList; 00053 typedef std::list<AttributeGroup*> AttributeGroupList; 00054 typedef std::list<Constraint*> ConstraintList; 00055 typedef std::list<Qname> QNameList; 00056 typedef std::list < const XSDType *> ConstTypeList; 00057 00058 typedef struct 00059 { 00060 SchemaParser* sParser; 00061 std::string ns; 00062 } ImportedSchema ; 00063 00065 00068 00078 SchemaParser(const std::string& Uri, std::string tns = "", 00079 std::ostream & log = std::cout,const std::string & confPath=""); 00080 00090 SchemaParser(XmlPullParser * parser, std::string tns = "", 00091 std::ostream & log = std::cout,const std::string & confPath=""); 00092 00093 ~SchemaParser(); 00094 00096 00103 bool parseSchemaTag(); 00104 00106 00109 00116 const XSDType *getType(const Qname & type, bool checkImports = true) ; 00117 00122 const XSDType *getType(int id) const; 00123 00129 const XSDType *getType(int id, std::string &nameSpace); 00130 00136 ConstTypeList *getAllTypes() const; 00137 00143 const Element *getElement(const Qname & element,bool checkImports=true) const; 00144 00151 const ElementList& getElements() const; 00152 00156 int getNumElements() const; 00157 00163 Attribute *getAttribute(const Qname & attribute) ; 00164 00171 const AttributeList& getAttributes()const; 00172 00176 int getNumAttributes() const; 00177 00178 00182 std::string getNamespace(void) const; 00183 00187 int getNumTypes() const; 00188 00189 00196 int getTypeId(const Qname &, bool create = false); 00197 00203 bool isBasicType(int sType) const; 00204 00227 int getBasicContentType(int typeId)const; 00228 00234 Group* getGroup(const Qname& name); 00235 00241 AttributeGroup* getAttributeGroup(const Qname& name); 00242 00244 00251 bool isImported(const std::string & ns)const; 00252 const SchemaParser* getImportedSchemaParser(const std::string & ns)const; 00260 bool addImport(std::string ns, std::string location=""); 00266 bool addImport(SchemaParser* sp); 00267 /* 00268 * addImports .To add an array of schema parsers for imported schemas 00269 * @param array of schema parsers 00270 * @param number of schema parsers added 00271 */ 00272 bool addImports(const std::vector<SchemaParser *>& schemaParsers); //to be removed soon 00273 00275 00276 00284 bool finalize(void); 00285 00292 void setWarningLevel(int l); 00293 /* 00294 * path to the directory where the config file for handling 00295 * imports is located 00296 */ 00297 void setSchemaPath(const std::string& s); 00298 00299 /* Set the path to the uri from where references to imported schemas 00300 * may be resolved. One level up the actual location. 00301 * Example if you set uri as "tempuri.org" ,a reference to imported schema location "x.xsd" 00302 * will be mapped to "tempuri.org/x.xsd" 00303 */ 00304 void setUri(const std::string& u ); 00309 std::string getTypeName(Schema::Type t)const; 00310 TypesTable *getTypesTable(); 00311 const SchemaParser *getImportedSchema(std::string &nameSpace); 00312 std::vector<ImportedSchema> &getImportedSchemas(); 00313 00317 std::string getVersion()const; 00318 00319 bool getElementQualified() const; 00320 std::string getTnsPrefix( void) const; 00321 00322 #ifdef LOGGING 00323 00326 void print(std::ostream &) ; 00327 #endif 00328 00329 00330 private: 00331 //This function parses global elements 00332 Element parseElement(bool & fwdRef); 00333 //This function parses global attributes 00334 Attribute parseAttribute(bool & fwdRef); 00335 void init(); 00336 00337 //This function parses <annotation> tag 00338 void parseAnnotation(); 00339 ComplexType *parseComplexType(); 00340 SimpleType *parseSimpleType(); 00341 00342 00343 Element addAny(ContentModel* cm); 00344 Group parseGroup(ContentModel* cm=0); 00345 Constraint* parseConstraint(Schema::ConstraintType cstr); 00346 AttributeGroup* parseAttributeGroup(ComplexType* cType=0); 00347 Attribute addAnyAttribute(ComplexType * cType); 00348 00349 void parseRestriction(SimpleType * st,ComplexType * ct=0); 00350 void parseComplexContent(ComplexType * ct); 00351 void parseSimpleContent(ComplexType * ct); 00352 00353 void parseContent(ContentModel * cm); 00354 bool parseImport(void); 00355 bool parseInclude(); 00356 bool parseSchema(std::string tag="schema"); 00357 bool parseRedefine(); 00358 int checkImport(std::string nsp)const; 00359 void copyImports(SchemaParser * sp); 00360 void resolveForwardElementRefs(); 00361 void resolveForwardAttributeRefs(); 00362 bool& shouldResolve(); 00363 bool makeListFromSoapArray (ComplexType * ct); 00364 00365 std::string fname_; 00366 std::string tnsUri_; 00367 std::string tnsPrefix_; 00368 std::string version_; 00369 XmlPullParser * xParser_; 00370 bool elementQualified_; 00371 bool attributeQualified_; 00372 bool deleteXmlParser_; 00373 bool resolveFwdRefs_; 00374 TypesTable typesTable_; 00375 std::ifstream xmlStream_; 00376 ElementList lElems_; 00377 AttributeList lAttributes_; 00378 GroupList lGroups_; 00379 AttributeGroupList lAttributeGroups_; 00380 ConstraintList constraints_; 00381 QNameList lForwardElemRefs_; 00382 QNameList lForwardAttributeRefs_; 00383 00384 std::vector<ImportedSchema> importedSchemas_; 00385 void error(std::string, int level = 0); 00386 int level_;//warning level 00387 std::ostream & logFile_; 00388 std::string confPath_; 00389 std::string uri_; //The uri to use to resolve imports.1 level up the location of the schema file 00390 }; 00391 00392 00393 inline 00394 bool & 00395 SchemaParser::shouldResolve() 00396 { 00397 return resolveFwdRefs_; 00398 00399 } 00400 00401 inline 00402 const SchemaParser::ElementList& 00403 SchemaParser::getElements() const 00404 { 00405 return lElems_; 00406 } 00407 00408 inline 00409 const SchemaParser::AttributeList& 00410 SchemaParser::getAttributes() const 00411 { 00412 return lAttributes_; 00413 } 00414 00415 inline 00416 void 00417 SchemaParser::setWarningLevel(int l) 00418 { 00419 level_ = l; 00420 } 00421 inline 00422 bool 00423 SchemaParser::isImported(const std::string & ns)const 00424 { 00425 return checkImport(ns) != -1; 00426 } 00427 inline 00428 const SchemaParser* 00429 SchemaParser::getImportedSchemaParser(const std::string & ns)const 00430 { 00431 int i= checkImport(ns); 00432 if (i == -1 ) 00433 return 0; 00434 00435 return importedSchemas_[i].sParser; 00436 } 00437 00438 inline 00439 void 00440 SchemaParser::setSchemaPath(const std::string& s) 00441 { 00442 confPath_ = s; 00443 } 00444 00445 inline 00446 void 00447 SchemaParser::setUri(const std::string& s) 00448 { 00449 uri_ = s; 00450 } 00451 00452 inline 00453 TypesTable* 00454 SchemaParser::getTypesTable() 00455 { 00456 return &typesTable_; 00457 } 00458 00459 inline 00460 std::vector<SchemaParser::ImportedSchema>& 00461 SchemaParser::getImportedSchemas() 00462 { 00463 return importedSchemas_; 00464 } 00465 00466 inline 00467 std::string 00468 SchemaParser::getVersion()const 00469 { 00470 return version_; 00471 } 00472 00473 inline 00474 bool 00475 SchemaParser::getElementQualified() const 00476 { 00477 return elementQualified_ ; 00478 } 00479 00480 inline 00481 00482 std::string 00483 SchemaParser::getTnsPrefix( void) const 00484 { 00485 return tnsPrefix_; 00486 } 00487 00488 } 00489 #endif /* */ 00490 00491