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: GrammarResolver.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(GRAMMARRESOLVER_HPP) |
---|
23 | #define GRAMMARRESOLVER_HPP |
---|
24 | |
---|
25 | #include <xercesc/framework/XMLGrammarPool.hpp> |
---|
26 | #include <xercesc/util/RefHashTableOf.hpp> |
---|
27 | #include <xercesc/util/StringPool.hpp> |
---|
28 | #include <xercesc/validators/common/Grammar.hpp> |
---|
29 | |
---|
30 | XERCES_CPP_NAMESPACE_BEGIN |
---|
31 | |
---|
32 | class DatatypeValidator; |
---|
33 | class DatatypeValidatorFactory; |
---|
34 | class XMLGrammarDescription; |
---|
35 | |
---|
36 | /** |
---|
37 | * This class embodies the representation of a Grammar pool Resolver. |
---|
38 | * This class is called from the validator. |
---|
39 | * |
---|
40 | */ |
---|
41 | |
---|
42 | class VALIDATORS_EXPORT GrammarResolver : public XMemory |
---|
43 | { |
---|
44 | public: |
---|
45 | |
---|
46 | /** @name Constructor and Destructor */ |
---|
47 | //@{ |
---|
48 | /** |
---|
49 | * |
---|
50 | * Default Constructor |
---|
51 | */ |
---|
52 | GrammarResolver( |
---|
53 | XMLGrammarPool* const gramPool |
---|
54 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
55 | ); |
---|
56 | /** |
---|
57 | * Destructor |
---|
58 | */ |
---|
59 | ~GrammarResolver(); |
---|
60 | |
---|
61 | //@} |
---|
62 | |
---|
63 | /** @name Getter methods */ |
---|
64 | //@{ |
---|
65 | /** |
---|
66 | * Retrieve the DatatypeValidator |
---|
67 | * |
---|
68 | * @param uriStr the namespace URI |
---|
69 | * @param typeName the type name |
---|
70 | * @return the DatatypeValidator associated with namespace & type name |
---|
71 | */ |
---|
72 | DatatypeValidator* getDatatypeValidator(const XMLCh* const uriStr, |
---|
73 | const XMLCh* const typeName); |
---|
74 | |
---|
75 | /** |
---|
76 | * Retrieve the grammar that is associated with the specified namespace key |
---|
77 | * |
---|
78 | * @param gramDesc grammar description for the grammar |
---|
79 | * @return Grammar abstraction associated with the grammar description |
---|
80 | */ |
---|
81 | Grammar* getGrammar( XMLGrammarDescription* const gramDesc ) ; |
---|
82 | |
---|
83 | /** |
---|
84 | * Retrieve the grammar that is associated with the specified namespace key |
---|
85 | * |
---|
86 | * @param namespaceKey Namespace key into Grammar pool |
---|
87 | * @return Grammar abstraction associated with the NameSpace key. |
---|
88 | */ |
---|
89 | Grammar* getGrammar( const XMLCh* const namespaceKey ) ; |
---|
90 | |
---|
91 | /** |
---|
92 | * Get an enumeration of Grammar in the Grammar pool |
---|
93 | * |
---|
94 | * @return enumeration of Grammar in Grammar pool |
---|
95 | */ |
---|
96 | RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const; |
---|
97 | |
---|
98 | /** |
---|
99 | * Get an enumeration of the referenced Grammars |
---|
100 | * |
---|
101 | * @return enumeration of referenced Grammars |
---|
102 | */ |
---|
103 | RefHashTableOfEnumerator<Grammar> getReferencedGrammarEnumerator() const; |
---|
104 | |
---|
105 | /** |
---|
106 | * Get an enumeration of the cached Grammars in the Grammar pool |
---|
107 | * |
---|
108 | * @return enumeration of the cached Grammars in Grammar pool |
---|
109 | */ |
---|
110 | RefHashTableOfEnumerator<Grammar> getCachedGrammarEnumerator() const; |
---|
111 | |
---|
112 | /** |
---|
113 | * Get a string pool of schema grammar element/attribute names/prefixes |
---|
114 | * (used by TraverseSchema) |
---|
115 | * |
---|
116 | * @return a string pool of schema grammar element/attribute names/prefixes |
---|
117 | */ |
---|
118 | XMLStringPool* getStringPool(); |
---|
119 | |
---|
120 | /** |
---|
121 | * Is the specified Namespace key in Grammar pool? |
---|
122 | * |
---|
123 | * @param nameSpaceKey Namespace key |
---|
124 | * @return True if Namespace key association is in the Grammar pool. |
---|
125 | */ |
---|
126 | bool containsNameSpace( const XMLCh* const nameSpaceKey ); |
---|
127 | |
---|
128 | inline XMLGrammarPool* getGrammarPool() const; |
---|
129 | |
---|
130 | inline MemoryManager* getGrammarPoolMemoryManager() const; |
---|
131 | |
---|
132 | //@} |
---|
133 | |
---|
134 | /** @name Setter methods */ |
---|
135 | //@{ |
---|
136 | |
---|
137 | /** |
---|
138 | * Set the 'Grammar caching' flag |
---|
139 | */ |
---|
140 | void cacheGrammarFromParse(const bool newState); |
---|
141 | |
---|
142 | /** |
---|
143 | * Set the 'Use cached grammar' flag |
---|
144 | */ |
---|
145 | void useCachedGrammarInParse(const bool newState); |
---|
146 | |
---|
147 | //@} |
---|
148 | |
---|
149 | |
---|
150 | /** @name GrammarResolver methods */ |
---|
151 | //@{ |
---|
152 | /** |
---|
153 | * Add the Grammar with Namespace Key associated to the Grammar Pool. |
---|
154 | * The Grammar will be owned by the Grammar Pool. |
---|
155 | * |
---|
156 | * @param grammarToAdopt Grammar abstraction used by validator. |
---|
157 | */ |
---|
158 | void putGrammar(Grammar* const grammarToAdopt ); |
---|
159 | |
---|
160 | /** |
---|
161 | * Returns the Grammar with Namespace Key associated from the Grammar Pool |
---|
162 | * The Key entry is removed from the table (grammar is not deleted if |
---|
163 | * adopted - now owned by caller). |
---|
164 | * |
---|
165 | * @param nameSpaceKey Key to associate with Grammar abstraction |
---|
166 | */ |
---|
167 | Grammar* orphanGrammar(const XMLCh* const nameSpaceKey); |
---|
168 | |
---|
169 | /** |
---|
170 | * Cache the grammars in fGrammarBucket to fCachedGrammarRegistry. |
---|
171 | * If a grammar with the same key is already cached, an exception is |
---|
172 | * thrown and none of the grammars will be cached. |
---|
173 | */ |
---|
174 | void cacheGrammars(); |
---|
175 | |
---|
176 | /** |
---|
177 | * Reset internal Namespace/Grammar registry. |
---|
178 | */ |
---|
179 | void reset(); |
---|
180 | void resetCachedGrammar(); |
---|
181 | |
---|
182 | /** |
---|
183 | * Returns an XSModel, either from the GrammarPool or by creating one |
---|
184 | */ |
---|
185 | XSModel* getXSModel(); |
---|
186 | |
---|
187 | |
---|
188 | ValueVectorOf<SchemaGrammar*>* getGrammarsToAddToXSModel(); |
---|
189 | |
---|
190 | //@} |
---|
191 | |
---|
192 | private: |
---|
193 | // ----------------------------------------------------------------------- |
---|
194 | // Unimplemented constructors and operators |
---|
195 | // ----------------------------------------------------------------------- |
---|
196 | GrammarResolver(const GrammarResolver&); |
---|
197 | GrammarResolver& operator=(const GrammarResolver&); |
---|
198 | |
---|
199 | // ----------------------------------------------------------------------- |
---|
200 | // Private data members |
---|
201 | // |
---|
202 | // fStringPool The string pool used by TraverseSchema to store |
---|
203 | // element/attribute names and prefixes. |
---|
204 | // Always owned by Grammar pool implementation |
---|
205 | // |
---|
206 | // fGrammarBucket The parsed Grammar Pool, if no caching option. |
---|
207 | // |
---|
208 | // fGrammarFromPool Referenced Grammar Set, not owned |
---|
209 | // |
---|
210 | // fGrammarPool The Grammar Set either plugged or created. |
---|
211 | // |
---|
212 | // fDataTypeReg DatatypeValidatorFactory registery |
---|
213 | // |
---|
214 | // fMemoryManager Pluggable memory manager for dynamic memory |
---|
215 | // allocation/deallocation |
---|
216 | // ----------------------------------------------------------------------- |
---|
217 | bool fCacheGrammar; |
---|
218 | bool fUseCachedGrammar; |
---|
219 | bool fGrammarPoolFromExternalApplication; |
---|
220 | XMLStringPool* fStringPool; |
---|
221 | RefHashTableOf<Grammar>* fGrammarBucket; |
---|
222 | RefHashTableOf<Grammar>* fGrammarFromPool; |
---|
223 | DatatypeValidatorFactory* fDataTypeReg; |
---|
224 | MemoryManager* fMemoryManager; |
---|
225 | XMLGrammarPool* fGrammarPool; |
---|
226 | XSModel* fXSModel; |
---|
227 | XSModel* fGrammarPoolXSModel; |
---|
228 | ValueVectorOf<SchemaGrammar*>* fGrammarsToAddToXSModel; |
---|
229 | }; |
---|
230 | |
---|
231 | inline XMLStringPool* GrammarResolver::getStringPool() { |
---|
232 | |
---|
233 | return fStringPool; |
---|
234 | } |
---|
235 | |
---|
236 | |
---|
237 | inline void GrammarResolver::useCachedGrammarInParse(const bool aValue) |
---|
238 | { |
---|
239 | fUseCachedGrammar = aValue; |
---|
240 | } |
---|
241 | |
---|
242 | inline XMLGrammarPool* GrammarResolver::getGrammarPool() const |
---|
243 | { |
---|
244 | return fGrammarPool; |
---|
245 | } |
---|
246 | |
---|
247 | inline MemoryManager* GrammarResolver::getGrammarPoolMemoryManager() const |
---|
248 | { |
---|
249 | return fGrammarPool->getMemoryManager(); |
---|
250 | } |
---|
251 | |
---|
252 | inline ValueVectorOf<SchemaGrammar*>* GrammarResolver::getGrammarsToAddToXSModel() |
---|
253 | { |
---|
254 | return fGrammarsToAddToXSModel; |
---|
255 | } |
---|
256 | |
---|
257 | XERCES_CPP_NAMESPACE_END |
---|
258 | |
---|
259 | #endif |
---|