[2674] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | * this work for additional information regarding copyright ownership. |
---|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | * (the "License"); you may not use this file except in compliance with |
---|
| 7 | * the License. You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | * See the License for the specific language governing permissions and |
---|
| 15 | * limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | * $Id: Grammar.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | #if !defined(GRAMMAR_HPP) |
---|
| 25 | #define GRAMMAR_HPP |
---|
| 26 | |
---|
| 27 | #include <limits.h> |
---|
| 28 | |
---|
| 29 | #include <xercesc/framework/XMLElementDecl.hpp> |
---|
| 30 | #include <xercesc/framework/XMLEntityDecl.hpp> |
---|
| 31 | #include <xercesc/framework/XMLNotationDecl.hpp> |
---|
| 32 | |
---|
| 33 | #include <xercesc/internal/XSerializable.hpp> |
---|
| 34 | |
---|
| 35 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 36 | |
---|
| 37 | class XMLGrammarDescription; |
---|
| 38 | |
---|
| 39 | // |
---|
| 40 | // This abstract class specifies the interface for a Grammar |
---|
| 41 | // |
---|
| 42 | |
---|
| 43 | class VALIDATORS_EXPORT Grammar : public XSerializable, public XMemory |
---|
| 44 | { |
---|
| 45 | public: |
---|
| 46 | |
---|
| 47 | // ----------------------------------------------------------------------- |
---|
| 48 | // Class Specific Types |
---|
| 49 | // |
---|
| 50 | // DTDGrammarType - Indicate this Grammar is built from a DTD. |
---|
| 51 | // SchemaGrammarType - Indicate this Grammar is built from a Schema. |
---|
| 52 | // |
---|
| 53 | // TOP_LEVEL_SCOPE - outermost scope level (i.e. global) of a declaration. |
---|
| 54 | // For DTD, all element decls and attribute decls always |
---|
| 55 | // have TOP_LEVEL_SCOPE. For schema, it may varies if |
---|
| 56 | // it is inside a complex type. |
---|
| 57 | // |
---|
| 58 | // UNKNOWN_SCOPE - unknown scope level. None of the decls should have this. |
---|
| 59 | // |
---|
| 60 | // ----------------------------------------------------------------------- |
---|
| 61 | enum GrammarType { |
---|
| 62 | DTDGrammarType |
---|
| 63 | , SchemaGrammarType |
---|
| 64 | , UnKnown |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | enum { |
---|
| 68 | // These are well-known values that must simply be larger |
---|
| 69 | // than any reasonable scope |
---|
| 70 | UNKNOWN_SCOPE = UINT_MAX - 0 |
---|
| 71 | , TOP_LEVEL_SCOPE = UINT_MAX - 1 |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | // ----------------------------------------------------------------------- |
---|
| 75 | // Constructors and Destructor |
---|
| 76 | // ----------------------------------------------------------------------- |
---|
| 77 | virtual ~Grammar(){}; |
---|
| 78 | |
---|
| 79 | // ----------------------------------------------------------------------- |
---|
| 80 | // Virtual Getter methods |
---|
| 81 | // ----------------------------------------------------------------------- |
---|
| 82 | virtual GrammarType getGrammarType() const =0; |
---|
| 83 | virtual const XMLCh* getTargetNamespace() const =0; |
---|
| 84 | virtual bool getValidated() const = 0; |
---|
| 85 | |
---|
| 86 | // Element Decl |
---|
| 87 | |
---|
| 88 | // this method should only be used while the grammar is being |
---|
| 89 | // constructed, not while it is being used |
---|
| 90 | // in a validation episode! |
---|
| 91 | virtual XMLElementDecl* findOrAddElemDecl |
---|
| 92 | ( |
---|
| 93 | const unsigned int uriId |
---|
| 94 | , const XMLCh* const baseName |
---|
| 95 | , const XMLCh* const prefixName |
---|
| 96 | , const XMLCh* const qName |
---|
| 97 | , unsigned int scope |
---|
| 98 | , bool& wasAdded |
---|
| 99 | ) = 0; |
---|
| 100 | |
---|
| 101 | virtual unsigned int getElemId |
---|
| 102 | ( |
---|
| 103 | const unsigned int uriId |
---|
| 104 | , const XMLCh* const baseName |
---|
| 105 | , const XMLCh* const qName |
---|
| 106 | , unsigned int scope |
---|
| 107 | ) const = 0; |
---|
| 108 | |
---|
| 109 | virtual const XMLElementDecl* getElemDecl |
---|
| 110 | ( |
---|
| 111 | const unsigned int uriId |
---|
| 112 | , const XMLCh* const baseName |
---|
| 113 | , const XMLCh* const qName |
---|
| 114 | , unsigned int scope |
---|
| 115 | ) const = 0; |
---|
| 116 | |
---|
| 117 | virtual XMLElementDecl* getElemDecl |
---|
| 118 | ( |
---|
| 119 | const unsigned int uriId |
---|
| 120 | , const XMLCh* const baseName |
---|
| 121 | , const XMLCh* const qName |
---|
| 122 | , unsigned int scope |
---|
| 123 | ) = 0; |
---|
| 124 | |
---|
| 125 | virtual const XMLElementDecl* getElemDecl |
---|
| 126 | ( |
---|
| 127 | const unsigned int elemId |
---|
| 128 | ) const = 0; |
---|
| 129 | |
---|
| 130 | virtual XMLElementDecl* getElemDecl |
---|
| 131 | ( |
---|
| 132 | const unsigned int elemId |
---|
| 133 | ) = 0; |
---|
| 134 | |
---|
| 135 | // Notation |
---|
| 136 | virtual const XMLNotationDecl* getNotationDecl |
---|
| 137 | ( |
---|
| 138 | const XMLCh* const notName |
---|
| 139 | ) const=0; |
---|
| 140 | |
---|
| 141 | virtual XMLNotationDecl* getNotationDecl |
---|
| 142 | ( |
---|
| 143 | const XMLCh* const notName |
---|
| 144 | )=0; |
---|
| 145 | |
---|
| 146 | // ----------------------------------------------------------------------- |
---|
| 147 | // Virtual Setter methods |
---|
| 148 | // ----------------------------------------------------------------------- |
---|
| 149 | virtual XMLElementDecl* putElemDecl |
---|
| 150 | ( |
---|
| 151 | const unsigned int uriId |
---|
| 152 | , const XMLCh* const baseName |
---|
| 153 | , const XMLCh* const prefixName |
---|
| 154 | , const XMLCh* const qName |
---|
| 155 | , unsigned int scope |
---|
| 156 | , const bool notDeclared = false |
---|
| 157 | ) = 0; |
---|
| 158 | |
---|
| 159 | virtual unsigned int putElemDecl |
---|
| 160 | ( |
---|
| 161 | XMLElementDecl* const elemDecl |
---|
| 162 | , const bool notDeclared = false |
---|
| 163 | ) = 0; |
---|
| 164 | |
---|
| 165 | virtual unsigned int putNotationDecl |
---|
| 166 | ( |
---|
| 167 | XMLNotationDecl* const notationDecl |
---|
| 168 | ) const=0; |
---|
| 169 | |
---|
| 170 | virtual void setValidated(const bool newState) = 0; |
---|
| 171 | |
---|
| 172 | // ----------------------------------------------------------------------- |
---|
| 173 | // Virtual methods |
---|
| 174 | // ----------------------------------------------------------------------- |
---|
| 175 | virtual void reset()=0; |
---|
| 176 | |
---|
| 177 | virtual void setGrammarDescription( XMLGrammarDescription*) = 0; |
---|
| 178 | virtual XMLGrammarDescription* getGrammarDescription() const = 0; |
---|
| 179 | |
---|
| 180 | /*** |
---|
| 181 | * Support for Serialization/De-serialization |
---|
| 182 | ***/ |
---|
| 183 | DECL_XSERIALIZABLE(Grammar) |
---|
| 184 | |
---|
| 185 | static void storeGrammar(XSerializeEngine& serEng |
---|
| 186 | , Grammar* const grammar); |
---|
| 187 | |
---|
| 188 | static Grammar* loadGrammar(XSerializeEngine& serEng); |
---|
| 189 | |
---|
| 190 | protected : |
---|
| 191 | // ----------------------------------------------------------------------- |
---|
| 192 | // Hidden constructors |
---|
| 193 | // ----------------------------------------------------------------------- |
---|
| 194 | Grammar(){}; |
---|
| 195 | |
---|
| 196 | private: |
---|
| 197 | // ----------------------------------------------------------------------- |
---|
| 198 | // Unimplemented constructors and operators |
---|
| 199 | // ----------------------------------------------------------------------- |
---|
| 200 | Grammar(const Grammar&); |
---|
| 201 | Grammar& operator=(const Grammar&); |
---|
| 202 | }; |
---|
| 203 | |
---|
| 204 | XERCES_CPP_NAMESPACE_END |
---|
| 205 | |
---|
| 206 | #endif |
---|