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 
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   //class Schema Parser
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); //to be removed soon
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     //This function parses global elements
00286     Element  parseElement(bool & fwdRef);
00287     //This function parses global attributes
00288     Attribute parseAttribute(bool & fwdRef);
00289 
00290     //This  function parses <annotation> tag
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_;//warning 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 

Generated on Mon Feb 6 23:02:42 2006 for wsdlpull by  doxygen 1.3.9.1