1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | *
|
---|
5 | * Copyright (c) 2001 The Apache Software Foundation. All rights
|
---|
6 | * reserved.
|
---|
7 | *
|
---|
8 | * Redistribution and use in source and binary forms, with or without
|
---|
9 | * modification, are permitted provided that the following conditions
|
---|
10 | * are met:
|
---|
11 | *
|
---|
12 | * 1. Redistributions of source code must retain the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer.
|
---|
14 | *
|
---|
15 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
16 | * notice, this list of conditions and the following disclaimer in
|
---|
17 | * the documentation and/or other materials provided with the
|
---|
18 | * distribution.
|
---|
19 | *
|
---|
20 | * 3. The end-user documentation included with the redistribution,
|
---|
21 | * if any, must include the following acknowledgment:
|
---|
22 | * "This product includes software developed by the
|
---|
23 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
24 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
25 | * if and wherever such third-party acknowledgments normally appear.
|
---|
26 | *
|
---|
27 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
28 | * not be used to endorse or promote products derived from this
|
---|
29 | * software without prior written permission. For written
|
---|
30 | * permission, please contact apache@apache.org.
|
---|
31 | *
|
---|
32 | * 5. Products derived from this software may not be called "Apache",
|
---|
33 | * nor may "Apache" appear in their name, without prior written
|
---|
34 | * permission of the Apache Software Foundation.
|
---|
35 | *
|
---|
36 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
37 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
38 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
39 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
42 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
43 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
44 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
45 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
46 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
47 | * SUCH DAMAGE.
|
---|
48 | * ====================================================================
|
---|
49 | *
|
---|
50 | * This software consists of voluntary contributions made by many
|
---|
51 | * individuals on behalf of the Apache Software Foundation and was
|
---|
52 | * originally based on software copyright (c) 2001, International
|
---|
53 | * Business Machines, Inc., http://www.apache.org. For more
|
---|
54 | * information on the Apache Software Foundation, please see
|
---|
55 | * <http://www.apache.org/>.
|
---|
56 | */
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * $Id: GrammarResolver.hpp,v 1.18 2004/01/29 11:51:21 cargilld Exp $
|
---|
60 | */
|
---|
61 |
|
---|
62 | #if !defined(GRAMMARRESOLVER_HPP)
|
---|
63 | #define GRAMMARRESOLVER_HPP
|
---|
64 |
|
---|
65 | #include <xercesc/framework/XMLGrammarPool.hpp>
|
---|
66 | #include <xercesc/util/RefHashTableOf.hpp>
|
---|
67 | #include <xercesc/util/StringPool.hpp>
|
---|
68 | #include <xercesc/validators/common/Grammar.hpp>
|
---|
69 |
|
---|
70 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
71 |
|
---|
72 | class DatatypeValidator;
|
---|
73 | class DatatypeValidatorFactory;
|
---|
74 | class XMLGrammarDescription;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * This class embodies the representation of a Grammar pool Resolver.
|
---|
78 | * This class is called from the validator.
|
---|
79 | *
|
---|
80 | */
|
---|
81 |
|
---|
82 | class VALIDATORS_EXPORT GrammarResolver : public XMemory
|
---|
83 | {
|
---|
84 | public:
|
---|
85 |
|
---|
86 | /** @name Constructor and Destructor */
|
---|
87 | //@{
|
---|
88 | /**
|
---|
89 | *
|
---|
90 | * Default Constructor
|
---|
91 | */
|
---|
92 | GrammarResolver(
|
---|
93 | XMLGrammarPool* const gramPool
|
---|
94 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
95 | );
|
---|
96 | /**
|
---|
97 | * Destructor
|
---|
98 | */
|
---|
99 | ~GrammarResolver();
|
---|
100 |
|
---|
101 | //@}
|
---|
102 |
|
---|
103 | /** @name Getter methods */
|
---|
104 | //@{
|
---|
105 | /**
|
---|
106 | * Retrieve the DatatypeValidator
|
---|
107 | *
|
---|
108 | * @param uriStr the namespace URI
|
---|
109 | * @param typeName the type name
|
---|
110 | * @return the DatatypeValidator associated with namespace & type name
|
---|
111 | */
|
---|
112 | DatatypeValidator* getDatatypeValidator(const XMLCh* const uriStr,
|
---|
113 | const XMLCh* const typeName);
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Retrieve the grammar that is associated with the specified namespace key
|
---|
117 | *
|
---|
118 | * @param gramDesc grammar description for the grammar
|
---|
119 | * @return Grammar abstraction associated with the grammar description
|
---|
120 | */
|
---|
121 | Grammar* getGrammar( XMLGrammarDescription* const gramDesc ) ;
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Retrieve the grammar that is associated with the specified namespace key
|
---|
125 | *
|
---|
126 | * @param namespaceKey Namespace key into Grammar pool
|
---|
127 | * @return Grammar abstraction associated with the NameSpace key.
|
---|
128 | */
|
---|
129 | Grammar* getGrammar( const XMLCh* const namespaceKey ) ;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Get an enumeration of Grammar in the Grammar pool
|
---|
133 | *
|
---|
134 | * @return enumeration of Grammar in Grammar pool
|
---|
135 | */
|
---|
136 | RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const;
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Get an enumeration of the referenced Grammars
|
---|
140 | *
|
---|
141 | * @return enumeration of referenced Grammars
|
---|
142 | */
|
---|
143 | RefHashTableOfEnumerator<Grammar> getReferencedGrammarEnumerator() const;
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Get an enumeration of the cached Grammars in the Grammar pool
|
---|
147 | *
|
---|
148 | * @return enumeration of the cached Grammars in Grammar pool
|
---|
149 | */
|
---|
150 | RefHashTableOfEnumerator<Grammar> getCachedGrammarEnumerator() const;
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Get a string pool of schema grammar element/attribute names/prefixes
|
---|
154 | * (used by TraverseSchema)
|
---|
155 | *
|
---|
156 | * @return a string pool of schema grammar element/attribute names/prefixes
|
---|
157 | */
|
---|
158 | XMLStringPool* getStringPool();
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Is the specified Namespace key in Grammar pool?
|
---|
162 | *
|
---|
163 | * @param nameSpaceKey Namespace key
|
---|
164 | * @return True if Namespace key association is in the Grammar pool.
|
---|
165 | */
|
---|
166 | bool containsNameSpace( const XMLCh* const nameSpaceKey );
|
---|
167 |
|
---|
168 | inline XMLGrammarPool* const getGrammarPool() const;
|
---|
169 |
|
---|
170 | inline MemoryManager* const getGrammarPoolMemoryManager() const;
|
---|
171 |
|
---|
172 | //@}
|
---|
173 |
|
---|
174 | /** @name Setter methods */
|
---|
175 | //@{
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Set the 'Grammar caching' flag
|
---|
179 | */
|
---|
180 | void cacheGrammarFromParse(const bool newState);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Set the 'Use cached grammar' flag
|
---|
184 | */
|
---|
185 | void useCachedGrammarInParse(const bool newState);
|
---|
186 |
|
---|
187 | //@}
|
---|
188 |
|
---|
189 |
|
---|
190 | /** @name GrammarResolver methods */
|
---|
191 | //@{
|
---|
192 | /**
|
---|
193 | * Add the Grammar with Namespace Key associated to the Grammar Pool.
|
---|
194 | * The Grammar will be owned by the Grammar Pool.
|
---|
195 | *
|
---|
196 | * @param grammarToAdopt Grammar abstraction used by validator.
|
---|
197 | */
|
---|
198 | void putGrammar(Grammar* const grammarToAdopt );
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Returns the Grammar with Namespace Key associated from the Grammar Pool
|
---|
202 | * The Key entry is removed from the table (grammar is not deleted if
|
---|
203 | * adopted - now owned by caller).
|
---|
204 | *
|
---|
205 | * @param nameSpaceKey Key to associate with Grammar abstraction
|
---|
206 | */
|
---|
207 | Grammar* orphanGrammar(const XMLCh* const nameSpaceKey);
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Cache the grammars in fGrammarBucket to fCachedGrammarRegistry.
|
---|
211 | * If a grammar with the same key is already cached, an exception is
|
---|
212 | * thrown and none of the grammars will be cached.
|
---|
213 | */
|
---|
214 | void cacheGrammars();
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Reset internal Namespace/Grammar registry.
|
---|
218 | */
|
---|
219 | void reset();
|
---|
220 | void resetCachedGrammar();
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Returns an XSModel, either from the GrammarPool or by creating one
|
---|
224 | */
|
---|
225 | XSModel* getXSModel();
|
---|
226 |
|
---|
227 |
|
---|
228 | ValueVectorOf<SchemaGrammar*>* getGrammarsToAddToXSModel();
|
---|
229 |
|
---|
230 | //@}
|
---|
231 |
|
---|
232 | private:
|
---|
233 | // -----------------------------------------------------------------------
|
---|
234 | // Unimplemented constructors and operators
|
---|
235 | // -----------------------------------------------------------------------
|
---|
236 | GrammarResolver(const GrammarResolver&);
|
---|
237 | GrammarResolver& operator=(const GrammarResolver&);
|
---|
238 |
|
---|
239 | // -----------------------------------------------------------------------
|
---|
240 | // Private data members
|
---|
241 | //
|
---|
242 | // fStringPool The string pool used by TraverseSchema to store
|
---|
243 | // element/attribute names and prefixes.
|
---|
244 | // Always owned by Grammar pool implementation
|
---|
245 | //
|
---|
246 | // fGrammarBucket The parsed Grammar Pool, if no caching option.
|
---|
247 | //
|
---|
248 | // fGrammarFromPool Referenced Grammar Set, not owned
|
---|
249 | //
|
---|
250 | // fGrammarPool The Grammar Set either plugged or created.
|
---|
251 | //
|
---|
252 | // fDataTypeReg DatatypeValidatorFactory registery
|
---|
253 | //
|
---|
254 | // fMemoryManager Pluggable memory manager for dynamic memory
|
---|
255 | // allocation/deallocation
|
---|
256 | // -----------------------------------------------------------------------
|
---|
257 | bool fCacheGrammar;
|
---|
258 | bool fUseCachedGrammar;
|
---|
259 | bool fGrammarPoolFromExternalApplication;
|
---|
260 | XMLStringPool* fStringPool;
|
---|
261 | RefHashTableOf<Grammar>* fGrammarBucket;
|
---|
262 | RefHashTableOf<Grammar>* fGrammarFromPool;
|
---|
263 | DatatypeValidatorFactory* fDataTypeReg;
|
---|
264 | MemoryManager* fMemoryManager;
|
---|
265 | XMLGrammarPool* fGrammarPool;
|
---|
266 | XSModel* fXSModel;
|
---|
267 | XSModel* fGrammarPoolXSModel;
|
---|
268 | ValueVectorOf<SchemaGrammar*>* fGrammarsToAddToXSModel;
|
---|
269 | };
|
---|
270 |
|
---|
271 | inline XMLStringPool* GrammarResolver::getStringPool() {
|
---|
272 |
|
---|
273 | return fStringPool;
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | inline void GrammarResolver::useCachedGrammarInParse(const bool aValue)
|
---|
278 | {
|
---|
279 | fUseCachedGrammar = aValue;
|
---|
280 | }
|
---|
281 |
|
---|
282 | inline XMLGrammarPool* const GrammarResolver::getGrammarPool() const
|
---|
283 | {
|
---|
284 | return fGrammarPool;
|
---|
285 | }
|
---|
286 |
|
---|
287 | inline MemoryManager* const GrammarResolver::getGrammarPoolMemoryManager() const
|
---|
288 | {
|
---|
289 | return fGrammarPool->getMemoryManager();
|
---|
290 | }
|
---|
291 |
|
---|
292 | inline ValueVectorOf<SchemaGrammar*>* GrammarResolver::getGrammarsToAddToXSModel()
|
---|
293 | {
|
---|
294 | return fGrammarsToAddToXSModel;
|
---|
295 | }
|
---|
296 |
|
---|
297 | XERCES_CPP_NAMESPACE_END
|
---|
298 |
|
---|
299 | #endif
|
---|