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

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

Initial check-in of icXML 0.8 source files

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