1 /* 2 * wsdlpull - A C++ parser for WSDL (Web services description language) 3 * Copyright (C) 2005-2007 Vivek Krishna 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * 19 * 20 */ 21 #ifndef _SCHEMAVALIDATORH 22 #define _SCHEMAVALIDATORH 23 24 #include "xmlpull/wsdlpull_export.h" 25 #include "xmlpull/XmlSerializer.h" 26 #include "schemaparser/SchemaParser.h" 27 #include "schemaparser/SchemaParserException.h" 28 #include "schemaparser/TypeContainer.h" 29 30 31 namespace Schema { 32 33 //class for validating a schema instance 34 class WSDLPULL_EXPORT SchemaValidator 35 { 36 public: 37 /** @name Constructors and Destructors */ 38 //@{ 39 /** 40 * The constructor for SchemaValidator 41 * @param pointer to the schema parser instance for the schema 42 * @param output stream to write generated instances 43 */ 44 SchemaValidator(const SchemaParser * sp, 45 std::ostream & os = std::cout); 46 ~SchemaValidator(); 47 48 //@} 49 50 /** @name methods for validating schema instance*/ 51 //@{ 52 /** 53 * @name validate 54 * @brief This is the main function to validate any type with its instance 55 * @param XmlPullParser instance of the xml stream containing the 56 * instance of the schema type 57 * @param pointer to the type whose instance must be validated 58 * @param type container to be used (can be null) 59 * @return type container containing an instance of the schema type 60 */ 61 62 TypeContainer *validate(XmlPullParser * xpp, int typeId, 63 TypeContainer * ipTc = 0); 64 65 TypeContainer *validate(const std::string & val , int typeId, 66 TypeContainer * ipTc = 0, XmlPullParser * xpp = 0); //for simple types 67 TypeContainer * validate(void* value ,int typeId, 68 TypeContainer * ipTc = 0, XmlPullParser * xpp = 0); 69 //@} 70 71 /** @name methods for generating a schema instance*/ 72 //@{ 73 /** 74 * @name instance 75 * @brief This method generates instance of a type 76 * @param The tag name of the root element 77 * @param type id of the element 78 79 */ 80 bool instance(const std::string& tag, 81 Schema::Type type_id); 82 83 //@} 84 85 private: 86 87 TypeContainer* validateContentModel(XmlPullParser * xpp, 88 ContentModel* cm, 89 TypeContainer * ipTc, 90 const std::string & elemName, 91 bool nested=false, 92 TypeContainer* btCnt=0);//base contentModel 93 94 void extractSimpleType(const std::string & val, int basetype, 95 TypeContainer * ipTc, const SimpleType * st, 96 XmlPullParser * xpp); 97 bool validateListOrUnion(const SimpleType* st, 98 const std::string &val, XmlPullParser * xpp); 99 100 bool findElement(ContentModel::ContentsIterator start, 101 ContentModel::ContentsIterator end, 102 std::string name, 103 ContentModel::ContentsIterator & found); 104 bool checkAttributeOccurence(const ComplexType* ct ,XmlPullParser* xpp); 105 void instanceCM(ContentModel *cm); 106 void error(const std::string & , XmlPullParser* xpp=0); 107 bool instance1(const std::string& tag, Schema::Type type_id); 108 109 XmlSerializer * xmlStream_ ; 110 std::ostream &ostr_; 111 const SchemaParser *sParser_; 112 113 }; 114 } 115 #endif 116