source: NonGTP/Xerces/xerces/include/xercesc/validators/common/GrammarResolver.hpp @ 358

Revision 358, 7.9 KB checked in by bittner, 19 years ago (diff)

xerces added

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