source: icXML/icXML-devel/src/icxercesc/validators/common/GrammarResolver.hpp

Last change on this file was 3564, checked in by cameron, 6 years ago

Changes to icxercesc files

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