Coverage Report

Created: 2025-11-16 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xerces-c/src/xercesc/validators/common/GrammarResolver.hpp
Line
Count
Source
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 932889 2010-04-11 13:10:10Z borisk $
20
 */
21
22
#if !defined(XERCESC_INCLUDE_GUARD_GRAMMARRESOLVER_HPP)
23
#define XERCESC_INCLUDE_GUARD_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 DatatypeValidatorFactory used for built-in schema types
77
     *
78
     * @return the DatatypeValidator associated with namespace for XMLSchema
79
     */
80
    DatatypeValidatorFactory* getBuiltinDatatypeValidatorFactory();
81
82
    /**
83
     * Retrieve the grammar that is associated with the specified namespace key
84
     *
85
     * @param  gramDesc   grammar description for the grammar
86
     * @return Grammar abstraction associated with the grammar description
87
     */
88
    Grammar* getGrammar( XMLGrammarDescription* const gramDesc ) ;
89
90
    /**
91
     * Retrieve the grammar that is associated with the specified namespace key
92
     *
93
     * @param  namespaceKey   Namespace key into Grammar pool
94
     * @return Grammar abstraction associated with the NameSpace key.
95
     */
96
    Grammar* getGrammar( const XMLCh* const namespaceKey ) ;
97
98
    /**
99
     * Get an enumeration of Grammar in the Grammar pool
100
     *
101
     * @return enumeration of Grammar in Grammar pool
102
     */
103
    RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const;
104
105
    /**
106
     * Get an enumeration of the referenced Grammars 
107
     *
108
     * @return enumeration of referenced Grammars
109
     */
110
    RefHashTableOfEnumerator<Grammar> getReferencedGrammarEnumerator() const;
111
112
    /**
113
     * Get an enumeration of the cached Grammars in the Grammar pool
114
     *
115
     * @return enumeration of the cached Grammars in Grammar pool
116
     */
117
    RefHashTableOfEnumerator<Grammar> getCachedGrammarEnumerator() const;
118
119
    /**
120
     * Get a string pool of schema grammar element/attribute names/prefixes
121
     * (used by TraverseSchema)
122
     *
123
     * @return a string pool of schema grammar element/attribute names/prefixes
124
     */
125
    XMLStringPool* getStringPool();
126
127
    /**
128
     * Is the specified Namespace key in Grammar pool?
129
     *
130
     * @param  nameSpaceKey    Namespace key
131
     * @return True if Namespace key association is in the Grammar pool.
132
     */
133
    bool containsNameSpace( const XMLCh* const nameSpaceKey );
134
135
    inline XMLGrammarPool* getGrammarPool() const;
136
137
    inline MemoryManager* getGrammarPoolMemoryManager() const;
138
139
    //@}
140
141
    /** @name Setter methods */
142
    //@{
143
144
    /**
145
      * Set the 'Grammar caching' flag
146
      */
147
    void cacheGrammarFromParse(const bool newState);
148
149
    /**
150
      * Set the 'Use cached grammar' flag
151
      */
152
    void useCachedGrammarInParse(const bool newState);
153
154
    //@}
155
156
157
    /** @name GrammarResolver methods */
158
    //@{
159
    /**
160
     * Add the Grammar with Namespace Key associated to the Grammar Pool.
161
     * The Grammar will be owned by the Grammar Pool.
162
     *
163
     * @param  grammarToAdopt  Grammar abstraction used by validator.
164
     */
165
    void putGrammar(Grammar* const               grammarToAdopt );
166
167
    /**
168
     * Returns the Grammar with Namespace Key associated from the Grammar Pool
169
     * The Key entry is removed from the table (grammar is not deleted if
170
     * adopted - now owned by caller).
171
     *
172
     * @param  nameSpaceKey    Key to associate with Grammar abstraction
173
     */
174
    Grammar* orphanGrammar(const XMLCh* const nameSpaceKey);
175
176
    /**
177
     * Cache the grammars in fGrammarBucket to fCachedGrammarRegistry.
178
     * If a grammar with the same key is already cached, an exception is
179
     * thrown and none of the grammars will be cached.
180
     */
181
    void cacheGrammars();
182
183
    /**
184
     * Reset internal Namespace/Grammar registry.
185
     */
186
    void reset();
187
    void resetCachedGrammar();
188
189
    /**
190
     * Returns an XSModel, either from the GrammarPool or by creating one
191
     */
192
    XSModel*    getXSModel();
193
194
195
    ValueVectorOf<SchemaGrammar*>* getGrammarsToAddToXSModel();
196
197
    //@}
198
199
private:
200
    // -----------------------------------------------------------------------
201
    //  Unimplemented constructors and operators
202
    // -----------------------------------------------------------------------
203
    GrammarResolver(const GrammarResolver&);
204
    GrammarResolver& operator=(const GrammarResolver&);
205
206
    // -----------------------------------------------------------------------
207
    //  Private data members
208
    //
209
    //  fStringPool            The string pool used by TraverseSchema to store
210
    //                         element/attribute names and prefixes.
211
    //                         Always owned by Grammar pool implementation
212
    //
213
    //  fGrammarBucket         The parsed Grammar Pool, if no caching option.
214
    //
215
    //  fGrammarFromPool       Referenced Grammar Set, not owned
216
    //
217
    //  fGrammarPool           The Grammar Set either plugged or created. 
218
    //
219
    //  fDataTypeReg           DatatypeValidatorFactory registry
220
    //
221
    //  fMemoryManager         Pluggable memory manager for dynamic memory
222
    //                         allocation/deallocation
223
    // -----------------------------------------------------------------------
224
    bool                            fCacheGrammar;
225
    bool                            fUseCachedGrammar;
226
    bool                            fGrammarPoolFromExternalApplication;
227
    XMLStringPool*                  fStringPool;
228
    RefHashTableOf<Grammar>*        fGrammarBucket;
229
    RefHashTableOf<Grammar>*        fGrammarFromPool;
230
    DatatypeValidatorFactory*       fDataTypeReg;
231
    MemoryManager*                  fMemoryManager;
232
    XMLGrammarPool*                 fGrammarPool;
233
    XSModel*                        fXSModel;
234
    XSModel*                        fGrammarPoolXSModel;
235
    ValueVectorOf<SchemaGrammar*>*  fGrammarsToAddToXSModel;
236
};
237
238
18.8k
inline XMLStringPool* GrammarResolver::getStringPool() {
239
240
18.8k
    return fStringPool;
241
18.8k
}
242
243
244
inline void GrammarResolver::useCachedGrammarInParse(const bool aValue)
245
18.8k
{
246
18.8k
    fUseCachedGrammar = aValue;
247
18.8k
}
248
249
inline XMLGrammarPool* GrammarResolver::getGrammarPool() const
250
0
{
251
0
    return fGrammarPool;
252
0
}
253
254
inline MemoryManager* GrammarResolver::getGrammarPoolMemoryManager() const
255
18.8k
{
256
18.8k
    return fGrammarPool->getMemoryManager();
257
18.8k
}
258
259
inline ValueVectorOf<SchemaGrammar*>* GrammarResolver::getGrammarsToAddToXSModel()
260
0
{
261
0
    return fGrammarsToAddToXSModel;
262
0
}
263
264
inline DatatypeValidatorFactory* GrammarResolver::getBuiltinDatatypeValidatorFactory()
265
0
{
266
0
    return fDataTypeReg;
267
0
}
268
269
XERCES_CPP_NAMESPACE_END
270
271
#endif