src/schemaparser/SchemaValidator.h

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 _SCHEMAVALIDATORH
00022 #define _SCHEMAVALIDATORH
00023 
00024 #include "xmlpull/wsdlpull_export.h"
00025 #include "xmlpull/XmlSerializer.h"
00026 #include "schemaparser/SchemaParser.h"
00027 #include "schemaparser/SchemaParserException.h"
00028 #include "schemaparser/TypeContainer.h"
00029 
00030 
00031 namespace Schema {
00032 
00033 //class for validating a schema instance
00034 class WSDLPULL_EXPORT SchemaValidator
00035 {
00036  public:
00037   /** @name Constructors and Destructors */
00038   //@{
00039   /**
00040    * The constructor for SchemaValidator
00041    * @param pointer to the schema parser instance for the schema
00042    * @param output stream to write generated instances
00043    */
00044   SchemaValidator(const SchemaParser * sp,
00045                   std::ostream & os = std::cout);
00046   ~SchemaValidator();
00047 
00048   //@}
00049 
00050   /** @name methods for validating schema instance*/
00051   //@{
00052   /**
00053    * @name validate 
00054    * @brief This is the main function to validate any type with its instance
00055    * @param  XmlPullParser instance of the xml stream containing the
00056    * instance of the schema type
00057    * @param pointer to the type whose instance must be validated
00058    * @param type container to be used (can be null)
00059    * @return type container containing an instance of the schema type
00060    */
00061   
00062   TypeContainer *validate(XmlPullParser * xpp, int typeId,
00063                           TypeContainer * ipTc = 0);
00064   
00065   TypeContainer *validate(const std::string & val , int typeId,
00066                           TypeContainer * ipTc = 0, XmlPullParser * xpp = 0); //for simple types
00067   TypeContainer * validate(void* value ,int typeId,
00068                            TypeContainer * ipTc = 0, XmlPullParser * xpp = 0);
00069   //@}
00070 
00071   /** @name methods for generating a schema instance*/
00072   //@{
00073   /**
00074    * @name instance
00075    * @brief This method generates instance of a type
00076    * @param The tag name of the root element
00077    * @param type id of the element
00078 
00079   */
00080   bool instance(const std::string& tag,
00081                 Schema::Type type_id);
00082 
00083   //@}
00084 
00085  private:
00086   
00087   TypeContainer* validateContentModel(XmlPullParser * xpp, 
00088                                       ContentModel* cm,
00089                                       TypeContainer * ipTc,
00090                                       const std::string & elemName,
00091                                       bool nested=false);
00092   
00093   void extractSimpleType(const std::string & val, int basetype,
00094                          TypeContainer * ipTc, const SimpleType * st,
00095                          XmlPullParser * xpp);
00096   bool    validateListOrUnion(const SimpleType* st,
00097                            const std::string &val, XmlPullParser * xpp);
00098 
00099   bool  findElement(ContentModel::ContentsIterator start, 
00100                     ContentModel::ContentsIterator end,
00101                     std::string name, 
00102                     ContentModel::ContentsIterator & found);
00103   bool checkAttributeOccurence(const ComplexType* ct ,XmlPullParser* xpp);
00104   void instanceCM(ContentModel *cm);
00105   void error(const std::string & , XmlPullParser* xpp=0);
00106   bool instance1(const std::string& tag,        Schema::Type type_id);
00107 
00108   XmlSerializer * xmlStream_ ;
00109   std::ostream &ostr_;
00110   const SchemaParser *sParser_;
00111 
00112 };
00113 }
00114 #endif

Generated on Sat May 3 16:28:59 2008 for wsdlpull by  doxygen 1.4.6