source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/internal/XMLGrammarPoolImpl.hpp @ 2674

Revision 2674, 11.0 KB checked in by mattausch, 16 years ago (diff)
Line 
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: XMLGrammarPoolImpl.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#if !defined(XMLGrammarPoolImplIMPL_HPP)
23#define XMLGrammarPoolImplIMPL_HPP
24
25#include <xercesc/framework/XMLGrammarPool.hpp>
26
27XERCES_CPP_NAMESPACE_BEGIN
28
29class XMLSynchronizedStringPool;
30
31class XMLUTIL_EXPORT XMLGrammarPoolImpl : public XMLGrammarPool
32{
33public :
34    // -----------------------------------------------------------------------
35    /** @name constructor and destructor */
36    // -----------------------------------------------------------------------
37    //@{
38
39    XMLGrammarPoolImpl(MemoryManager* const memMgr);
40
41    ~XMLGrammarPoolImpl();
42    //@}
43
44    // -----------------------------------------------------------------------
45    /** @name Implementation of Grammar Pool Interface */
46    // -----------------------------------------------------------------------
47    //@{
48   
49    /**
50      * cacheGrammar
51      *
52      * Provide the grammar pool with an opportunity
53      * to cache the given grammar.  If the pool does not choose to do so,
54      * it should return false; otherwise, it should return true, so that
55      * the caller knows whether the grammar has been adopted.
56      *
57      * @param gramToCache: the Grammar to be cached in the grammar pool
58      * @return true if the grammar pool has elected to cache the grammar (in which case
59      * it is assumed to have adopted it); false if it does not cache it
60          *
61      */
62    virtual bool           cacheGrammar(Grammar* const               gramToCache);
63   
64
65    /**
66      * retrieveGrammar
67      *
68      * @param gramDesc: the Grammar Description used to search for grammar
69          *                  cached in the grammar pool
70          *
71      */
72    virtual Grammar*       retrieveGrammar(XMLGrammarDescription* const gramDesc);
73   
74       
75    /**
76      * orphanGrammar
77      *
78          * grammar removed from the grammar pool and owned by the caller
79      *
80      * @param nameSpaceKey: Key used to search for grammar in the grammar pool
81          *
82      */
83    virtual Grammar*       orphanGrammar(const XMLCh* const nameSpaceKey); 
84
85
86    /**
87     * Get an enumeration of the cached Grammars in the Grammar pool
88     *
89     * @return enumeration of the cached Grammars in Grammar pool
90     */
91    virtual RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const;
92
93    /**
94      * clear
95      *
96          * all grammars are removed from the grammar pool and deleted.
97      * @return true if the grammar pool was cleared. false if it did not.
98      */
99    virtual bool           clear();
100       
101    /**
102      * lockPool
103      *
104          * When this method is called by the application, the
105      * grammar pool should stop adding new grammars to the cache.
106      */
107    virtual void           lockPool();
108   
109    /**
110      * unlockPool
111      *
112          * After this method has been called, the grammar pool implementation
113      * should return to its default behaviour when cacheGrammars(...) is called.
114      *
115      * For PSVI support any previous XSModel that was produced will be deleted.
116      */
117    virtual void           unlockPool();
118
119    //@}
120
121    // -----------------------------------------------------------------------
122    /** @name  Implementation of Factory interface */
123    // -----------------------------------------------------------------------
124    //@{
125
126    /**
127      * createDTDGrammar
128      *
129      */
130    virtual DTDGrammar*            createDTDGrammar();
131
132    /**
133      * createSchemaGrammar
134      *
135      */
136    virtual SchemaGrammar*         createSchemaGrammar();
137                   
138    /**
139      * createDTDDescription
140      *
141      */       
142    virtual XMLDTDDescription*     createDTDDescription(const XMLCh* const systemId);
143    /**
144      * createSchemaDescription
145      *
146      */               
147    virtual XMLSchemaDescription*  createSchemaDescription(const XMLCh* const targetNamespace);
148    //@}
149       
150    // -----------------------------------------------------------------------
151    /** @name  schema component model support */
152    // -----------------------------------------------------------------------                                                       
153    //@{
154
155    /***
156      * Return an XSModel derived from the components of all SchemaGrammars
157      * in the grammar pool.  If the pool is locked, this should
158      * be a thread-safe operation.  It should return null if and only if
159      * the pool is empty.
160      *
161      * Calling getXSModel() on an unlocked grammar pool may result in the
162      * creation of a new XSModel with the old XSModel being deleted.  The
163      * function will return a different address for the XSModel if it has
164      * changed.
165      *
166      * In this implementation, when the pool is not locked a new XSModel will be
167      * computed each this time the pool is called if the pool has changed (and the
168      * previous one will be destroyed at that time).  When the lockPool()
169      * method is called, an XSModel will be generated and returned whenever this method is called
170      * while the pool is in the locked state.  This will be destroyed if the unlockPool()
171      * operation is called.  The XSModel will not be serialized,
172      * but will be recreated if a deserialized pool is in the
173      * locked state.
174      *
175      * @deprecated (shouldn't use address to determine if XSModel changed)
176      */
177    virtual XSModel *getXSModel();
178
179    /***
180      * Return an XSModel derived from the components of all SchemaGrammars
181      * in the grammar pool.  If the pool is locked, this should
182      * be a thread-safe operation. 
183      *
184      * NOTE: The function should NEVER return NULL.  If there are no grammars in
185      *       the pool it should return an XSModel containing the Schema for Schema.
186      *
187      * Calling getXSModel() on an unlocked grammar pool may result in the
188      * creation of a new XSModel with the old XSModel being deleted.
189      * The bool parameter will indicate if the XSModel was changed.
190      * 
191      * In this implementation, when the pool is not locked a new XSModel will be
192      * computed each this time the pool is called if the pool has changed (and the
193      * previous one will be destroyed at that time).  When the lockPool()
194      * method is called, an XSModel will be generated and returned whenever this method is called
195      * while the pool is in the locked state.  This will be destroyed if the unlockPool()
196      * operation is called.  The XSModel will not be serialized,
197      * but will be recreated if a deserialized pool is in the
198      * locked state.
199      *     
200      */
201    virtual XSModel *getXSModel(bool& XSModelWasChanged);
202
203    // @}
204    // -----------------------------------------------------------------------
205    /** @name  Getter */
206    // -----------------------------------------------------------------------                                                       
207    //@{
208
209    /**
210      * Return an XMLStringPool for use by validation routines. 
211      * Implementations should not create a string pool on each call to this
212      * method, but should maintain one string pool for all grammars
213      * for which this pool is responsible.
214      */
215    virtual XMLStringPool *getURIStringPool();
216
217    // @}
218
219    // -----------------------------------------------------------------------
220    // serialization and deserialization support
221    // -----------------------------------------------------------------------
222
223    /***
224      *
225      * Multiple serializations
226      *
227      *    For multiple serializations, if the same file name is given, then the
228      *    last result will be in the file (overwriting mode), if different file
229      *    names are given, then there are multiple data stores for each serialization.
230      *
231      * Multiple deserializations
232      *
233      *    Not supported
234      *
235      * Versioning
236      *
237      *    Only binary data serialized with the current XercesC Version and
238      *    SerializationLevel is supported.
239      *
240      * Clean up
241      *
242      *    In the event of an exception thrown due to a corrupted data store during
243      *    deserialization, this implementation may not be able to clean up all resources
244      *    allocated, and therefore it is the client application's responsibility to
245      *    clean up those unreleased resources.
246      *
247      * Coupling of Grammars and StringPool
248      *
249      *    This implementation assumes that StringPool shall always be
250      *    serialized/deserialized together with the grammars. In the case that such a
251      *    coupling is not desired, client application can modify this behaviour by
252      *    either derivate from this imlementation and overwrite the serializeGrammars()
253      *    and/or deserializeGrammars() to decouple grammars and string pool, or
254      *    Once deserializeGrammars() is done, insert another StringPool through
255      *    setStringPool().
256      *
257      *    Client application shall be aware of the unpredicatable/undefined consequence
258      *    of this decoupling.
259      */
260
261    virtual void     serializeGrammars(BinOutputStream* const);
262    virtual void     deserializeGrammars(BinInputStream* const);
263
264private:
265
266    virtual void    createXSModel();
267
268    void
269    cleanUp();
270
271    // -----------------------------------------------------------------------
272    /** name  Unimplemented copy constructor and operator= */
273    // -----------------------------------------------------------------------
274    //@{
275    XMLGrammarPoolImpl(const XMLGrammarPoolImpl& );
276    XMLGrammarPoolImpl& operator=(const XMLGrammarPoolImpl& );
277    //@}
278
279    // -----------------------------------------------------------------------
280    //
281    // fGrammarRegistry:
282    //
283        //    container
284    // fStringPool
285    //    grammars need a string pool for URI -> int mappings
286    // fSynchronizedStringPool
287    //      When the grammar pool is locked, provide a string pool
288    //      that can be updated in a thread-safe manner.
289    // fLocked
290    //      whether the pool has been locked
291    //
292    // -----------------------------------------------------------------------
293    RefHashTableOf<Grammar>*            fGrammarRegistry;
294    XMLStringPool*                      fStringPool;
295    XMLSynchronizedStringPool*          fSynchronizedStringPool;
296    XSModel*                            fXSModel;
297    bool                                fLocked;
298    bool                                fXSModelIsValid;
299};
300
301XERCES_CPP_NAMESPACE_END
302
303#endif
Note: See TracBrowser for help on using the repository browser.