Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SchemaParser.h

Go to the documentation of this file.
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 #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 //class Schema Parser
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); //to be removed soon
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   //This function parses global elements
00255   Element  parseElement(bool & fwdRef);
00256   //This function parses global attributes
00257   Attribute parseAttribute(bool & fwdRef);
00258 
00259   //This  function parses <annotation> tag
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_;//warning 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 

Generated on Sun Oct 16 10:11:52 2005 for wsdlpull by  doxygen 1.3.9.1