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 
00250   std::string getTypeName(Schema::Type t)const;
00251 #ifdef LOGGING
00252 
00255   void print(ostream &) ;
00256 #endif
00257 
00258 
00259  private:
00260   //This function parses global elements
00261   Element  parseElement(bool & fwdRef);
00262   //This function parses global attributes
00263   Attribute parseAttribute(bool & fwdRef);
00264 
00265   //This  function parses <annotation> tag
00266   void parseAnnotation();
00267   ComplexType *parseComplexType();
00268   SimpleType *parseSimpleType();
00269 
00270 
00271   Element addAny(ContentModel* cm);
00272   Group parseGroup(ContentModel* cm=0);
00273   Constraint* parseConstraint(Schema::Constraints cstr);
00274   AttributeGroup parseAttributeGroup(ComplexType* cType=0);
00275   Attribute addAnyAttribute(ComplexType * cType);
00276 
00277   void parseRestriction(SimpleType * st,ComplexType * ct=0);
00278   void parseComplexContent(ComplexType * ct);
00279   void parseSimpleContent(ComplexType * ct);
00280 
00281   void parseContent(ContentModel * cm);
00282   bool parseImport(void);
00283   bool parseInclude();
00284   bool parseSchema(std::string tag="schema");
00285   bool parseRedefine();
00286   int checkImport(string nsp);
00287   void resolveForwardElementRefs();
00288   void resolveForwardAttributeRefs();
00289   int  addExternalElement(const string & name,int localTypeId);
00290   bool& shouldResolve();
00291   bool makeListFromSoapArray (ComplexType * ct);
00292 
00293   std::map<std::string,std::string>
00294     SchemaParser::processAttributes(XmlPullParser* xpp);
00295 
00296   std::string tnsUri_;
00297   std::string tnsPrefix_;
00298   XmlPullParser * xParser_;
00299   bool elementQualified_;
00300   bool attributeQualified_;
00301   bool deleteXmlParser_;
00302   bool resolveFwdRefs_;
00303   
00304   TypesTable typesTable_;
00305   std::ifstream xmlStream_;
00306   std::list<Element> lElems_;
00307   std::list<Attribute> lAttributes_;
00308   std::list<Group> lGroups_;
00309   std::list<AttributeGroup> lAttributeGroups_;
00310   std::list<Constraint*> constraints_;
00311   std::list<Qname> lForwardElemRefs_;
00312   std::list<Qname> lForwardAttributeRefs_;
00313   
00314   typedef struct
00315   {
00316     SchemaParser* sParser;
00317     std::string ns;
00318   } ImportedSchema ;
00319   std::vector<ImportedSchema> importedSchemas_;  
00320   void error(string, int level = 0);
00321   unsigned char level_;//warning level
00322   std::ostream & logFile_;
00323 };
00324 
00325 
00326 inline
00327 bool &
00328 SchemaParser::shouldResolve()
00329 {
00330   return resolveFwdRefs_;
00331   
00332 }
00333 
00334 inline
00335 const list<Element> 
00336 SchemaParser::getElements() const
00337 {
00338   return lElems_;
00339 }
00340 
00341 inline
00342 const list<Attribute> 
00343 SchemaParser::getAttributes() const
00344 {
00345   return lAttributes_;
00346 }
00347 inline
00348 void
00349 SchemaParser::setWarningLevel(unsigned char l)
00350 {
00351   level_ = l;
00352 }
00353 
00354 #endif                                            /*  */
00355 
00356 

Generated on Sat Oct 29 13:08:56 2005 for wsdlpull by  doxygen 1.3.9.1