source: NonGTP/Xerces/xerces/include/xercesc/internal/XMLGrammarPoolImpl.hpp @ 358

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

xerces added

Line 
1/*
2 * Copyright 1999-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 * $Log: XMLGrammarPoolImpl.hpp,v $
19 * Revision 1.17  2004/09/29 19:27:07  cargilld
20 * Fix for Jira-1217: fixing problems with getXSModel.
21 *
22 * Revision 1.16  2004/09/08 13:56:14  peiyongz
23 * Apache License Version 2.0
24 *
25 * Revision 1.15  2004/04/07 14:13:42  peiyongz
26 * systemId (to replace rootElemName) as DTDGrammar Key
27 *
28 * Revision 1.14  2003/12/19 23:02:43  cargilld
29 * Fix compiler messages on OS390.
30 *
31 * Revision 1.13  2003/11/21 22:38:50  neilg
32 * Enable grammar pools and grammar resolvers to manufacture
33 * XSModels.  This also cleans up handling in the
34 * parser classes by eliminating the need to tell
35 * the grammar pool that schema compoments need to be produced.
36 * Thanks to David Cargill.
37 *
38 * Revision 1.12  2003/11/14 22:34:20  neilg
39 * removed methods made unnecessary by new XSModel implementation design; thanks to David Cargill
40 *
41 * Revision 1.11  2003/11/06 21:53:52  neilg
42 * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted.  Also fix some documentation errors.
43 *
44 * Revision 1.10  2003/11/06 15:30:06  neilg
45 * first part of PSVI/schema component model implementation, thanks to David Cargill.  This covers setting the PSVIHandler on parser objects, as well as implementing XSNotation, XSSimpleTypeDefinition, XSIDCDefinition, and most of XSWildcard, XSComplexTypeDefinition, XSElementDeclaration, XSAttributeDeclaration and XSAttributeUse.
46 *
47 * Revision 1.9  2003/11/05 18:19:45  peiyongz
48 * Documentation update
49 *
50 * Revision 1.8  2003/10/29 16:16:08  peiyongz
51 * GrammarPool' serialization/deserialization support
52 *
53 * Revision 1.7  2003/10/10 18:36:41  neilg
54 * update XMLGrammarPool default implementation to reflect recent modifications to the base interface.
55 *
56 * Revision 1.6  2003/10/09 13:54:25  neilg
57 * modify grammar pool implementation to that, once locked, a thread-safe StringPool is used
58 *
59 * Revision 1.5  2003/09/16 18:30:54  neilg
60 * make Grammar pool be responsible for creating and owning URI string pools.  This is one more step towards having grammars be independent of the parsers involved in their creation
61 *
62 * Revision 1.4  2003/09/02 08:59:02  gareth
63 * Added API to get enumerator of grammars.
64 *
65 * Revision 1.3  2003/07/31 17:05:03  peiyongz
66 * Grammar embed Grammar Description
67 * using getGrammar(URI)
68 * update GrammarDescription info
69 *
70 * Revision 1.2  2003/06/23 21:06:21  peiyongz
71 * to solve unresolved symbol on Solaris
72 *
73 * Revision 1.1  2003/06/20 18:38:39  peiyongz
74 * Stateless Grammar Pool :: Part I
75 *
76 * $Id: XMLGrammarPoolImpl.hpp,v 1.17 2004/09/29 19:27:07 cargilld Exp $
77 *
78 */
79
80#if !defined(XMLGrammarPoolImplIMPL_HPP)
81#define XMLGrammarPoolImplIMPL_HPP
82
83#include <xercesc/framework/XMLGrammarPool.hpp>
84
85XERCES_CPP_NAMESPACE_BEGIN
86
87class XMLSynchronizedStringPool;
88
89class XMLUTIL_EXPORT XMLGrammarPoolImpl : public XMLGrammarPool
90{
91public :
92    // -----------------------------------------------------------------------
93    /** @name constructor and destructor */
94    // -----------------------------------------------------------------------
95    //@{
96
97    XMLGrammarPoolImpl(MemoryManager* const memMgr);
98
99    ~XMLGrammarPoolImpl();
100    //@}
101
102    // -----------------------------------------------------------------------
103    /** @name Implementation of Grammar Pool Interface */
104    // -----------------------------------------------------------------------
105    //@{
106   
107    /**
108      * cacheGrammar
109      *
110      * Provide the grammar pool with an opportunity
111      * to cache the given grammar.  If the pool does not choose to do so,
112      * it should return false; otherwise, it should return true, so that
113      * the caller knows whether the grammar has been adopted.
114      *
115      * @param gramToCache: the Grammar to be cached in the grammar pool
116      * @return true if the grammar pool has elected to cache the grammar (in which case
117      * it is assumed to have adopted it); false if it does not cache it
118          *
119      */
120    virtual bool           cacheGrammar(Grammar* const               gramToCache);
121   
122
123    /**
124      * retrieveGrammar
125      *
126      * @param gramDesc: the Grammar Description used to search for grammar
127          *                  cached in the grammar pool
128          *
129      */
130    virtual Grammar*       retrieveGrammar(XMLGrammarDescription* const gramDesc);
131   
132       
133    /**
134      * orphanGrammar
135      *
136          * grammar removed from the grammar pool and owned by the caller
137      *
138      * @param nameSpaceKey: Key used to search for grammar in the grammar pool
139          *
140      */
141    virtual Grammar*       orphanGrammar(const XMLCh* const nameSpaceKey); 
142
143
144    /**
145     * Get an enumeration of the cached Grammars in the Grammar pool
146     *
147     * @return enumeration of the cached Grammars in Grammar pool
148     */
149    virtual RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const;
150
151    /**
152      * clear
153      *
154          * all grammars are removed from the grammar pool and deleted.
155      * @return true if the grammar pool was cleared. false if it did not.
156      */
157    virtual bool           clear();
158       
159    /**
160      * lockPool
161      *
162          * When this method is called by the application, the
163      * grammar pool should stop adding new grammars to the cache.
164      */
165    virtual void           lockPool();
166   
167    /**
168      * unlockPool
169      *
170          * After this method has been called, the grammar pool implementation
171      * should return to its default behaviour when cacheGrammars(...) is called.
172      *
173      * For PSVI support any previous XSModel that was produced will be deleted.
174      */
175    virtual void           unlockPool();
176
177    //@}
178
179    // -----------------------------------------------------------------------
180    /** @name  Implementation of Factory interface */
181    // -----------------------------------------------------------------------
182    //@{
183
184    /**
185      * createDTDGrammar
186      *
187      */
188    virtual DTDGrammar*            createDTDGrammar();
189
190    /**
191      * createSchemaGrammar
192      *
193      */
194    virtual SchemaGrammar*         createSchemaGrammar();
195                   
196    /**
197      * createDTDDescription
198      *
199      */       
200    virtual XMLDTDDescription*     createDTDDescription(const XMLCh* const systemId);
201    /**
202      * createSchemaDescription
203      *
204      */               
205    virtual XMLSchemaDescription*  createSchemaDescription(const XMLCh* const targetNamespace);
206    //@}
207       
208    // -----------------------------------------------------------------------
209    /** @name  schema component model support */
210    // -----------------------------------------------------------------------                                                       
211    //@{
212
213    /***
214      * Return an XSModel derived from the components of all SchemaGrammars
215      * in the grammar pool.  If the pool is locked, this should
216      * be a thread-safe operation.  It should return null if and only if
217      * the pool is empty.
218      *
219      * Calling getXSModel() on an unlocked grammar pool may result in the
220      * creation of a new XSModel with the old XSModel being deleted.  The
221      * function will return a different address for the XSModel if it has
222      * changed.
223      *
224      * In this implementation, when the pool is not locked a new XSModel will be
225      * computed each this time the pool is called if the pool has changed (and the
226      * previous one will be destroyed at that time).  When the lockPool()
227      * method is called, an XSModel will be generated and returned whenever this method is called
228      * while the pool is in the locked state.  This will be destroyed if the unlockPool()
229      * operation is called.  The XSModel will not be serialized,
230      * but will be recreated if a deserialized pool is in the
231      * locked state.
232      *
233      * @deprecated (shouldn't use address to determine if XSModel changed)
234      */
235    virtual XSModel *getXSModel();
236
237    /***
238      * Return an XSModel derived from the components of all SchemaGrammars
239      * in the grammar pool.  If the pool is locked, this should
240      * be a thread-safe operation. 
241      *
242      * NOTE: The function should NEVER return NULL.  If there are no grammars in
243      *       the pool it should return an XSModel containing the Schema for Schema.
244      *
245      * Calling getXSModel() on an unlocked grammar pool may result in the
246      * creation of a new XSModel with the old XSModel being deleted.
247      * The bool parameter will indicate if the XSModel was changed.
248      * 
249      * In this implementation, when the pool is not locked a new XSModel will be
250      * computed each this time the pool is called if the pool has changed (and the
251      * previous one will be destroyed at that time).  When the lockPool()
252      * method is called, an XSModel will be generated and returned whenever this method is called
253      * while the pool is in the locked state.  This will be destroyed if the unlockPool()
254      * operation is called.  The XSModel will not be serialized,
255      * but will be recreated if a deserialized pool is in the
256      * locked state.
257      *     
258      */
259    virtual XSModel *getXSModel(bool& XSModelWasChanged);
260
261    // @}
262    // -----------------------------------------------------------------------
263    /** @name  Getter */
264    // -----------------------------------------------------------------------                                                       
265    //@{
266
267    /**
268      * Return an XMLStringPool for use by validation routines. 
269      * Implementations should not create a string pool on each call to this
270      * method, but should maintain one string pool for all grammars
271      * for which this pool is responsible.
272      */
273    virtual XMLStringPool *getURIStringPool();
274
275    // @}
276
277    // -----------------------------------------------------------------------
278    // serialization and deserialization support
279    // -----------------------------------------------------------------------
280
281    /***
282      *
283      * Multiple serializations
284      *
285      *    For multiple serializations, if the same file name is given, then the
286      *    last result will be in the file (overwriting mode), if different file
287      *    names are given, then there are multiple data stores for each serialization.
288      *
289      * Multiple deserializations
290      *
291      *    Not supported
292      *
293      * Versioning
294      *
295      *    Only binary data serialized with the current XercesC Version and
296      *    SerializationLevel is supported.
297      *
298      * Clean up
299      *
300      *    In the event of an exception thrown due to a corrupted data store during
301      *    deserialization, this implementation may not be able to clean up all resources
302      *    allocated, and therefore it is the client application's responsibility to
303      *    clean up those unreleased resources.
304      *
305      * Coupling of Grammars and StringPool
306      *
307      *    This implementation assumes that StringPool shall always be
308      *    serialized/deserialized together with the grammars. In the case that such a
309      *    coupling is not desired, client application can modify this behaviour by
310      *    either derivate from this imlementation and overwrite the serializeGrammars()
311      *    and/or deserializeGrammars() to decouple grammars and string pool, or
312      *    Once deserializeGrammars() is done, insert another StringPool through
313      *    setStringPool().
314      *
315      *    Client application shall be aware of the unpredicatable/undefined consequence
316      *    of this decoupling.
317      */
318
319    virtual void     serializeGrammars(BinOutputStream* const);
320    virtual void     deserializeGrammars(BinInputStream* const);
321
322    friend class XObjectComparator;
323    friend class XTemplateComparator;
324
325private:
326
327    virtual void    createXSModel();
328    // -----------------------------------------------------------------------
329    /** name  Unimplemented copy constructor and operator= */
330    // -----------------------------------------------------------------------
331    //@{
332    XMLGrammarPoolImpl(const XMLGrammarPoolImpl& );
333    XMLGrammarPoolImpl& operator=(const XMLGrammarPoolImpl& );
334    //@}
335
336    // -----------------------------------------------------------------------
337    //
338    // fGrammarRegistry:
339    //
340        //    container
341    // fStringPool
342    //    grammars need a string pool for URI -> int mappings
343    // fSynchronizedStringPool
344    //      When the grammar pool is locked, provide a string pool
345    //      that can be updated in a thread-safe manner.
346    // fLocked
347    //      whether the pool has been locked
348    //
349    // -----------------------------------------------------------------------
350    RefHashTableOf<Grammar>*            fGrammarRegistry;
351    XMLStringPool*                      fStringPool;
352    XMLSynchronizedStringPool*          fSynchronizedStringPool;
353    XSModel*                            fXSModel;
354    bool                                fLocked;
355    bool                                fXSModelIsValid;
356};
357
358XERCES_CPP_NAMESPACE_END
359
360#endif
Note: See TracBrowser for help on using the repository browser.