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/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 //class Schema Parser
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    * addImports .To add an array of schema parsers for imported schemas
00260    * @param array of schema parsers
00261    * @param number of schema parsers added
00262    */
00263   bool addImports(const std::vector<SchemaParser *>& schemaParsers); //to be removed soon
00264 
00266 
00267 
00275   bool finalize(void);
00276 
00283   void setWarningLevel(unsigned char l);
00284   /*
00285    * path to the directory where the config file for handling 
00286    * imports is located
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   //This function parses global elements
00318   Element  parseElement(bool & fwdRef);
00319   //This function parses global attributes
00320   Attribute parseAttribute(bool & fwdRef);
00321   void init();
00322 
00323   //This  function parses <annotation> tag
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_;//warning 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 

Generated on Wed Apr 12 18:51:55 2006 for wsdlpull by  doxygen 1.3.9.1