source: NonGTP/Xerces/xerces/include/xercesc/framework/XMLGrammarPool.hpp @ 358

Revision 358, 13.8 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: XMLGrammarPool.hpp,v $
19 * Revision 1.14  2004/09/29 19:27:07  cargilld
20 * Fix for Jira-1217: fixing problems with getXSModel.
21 *
22 * Revision 1.13  2004/09/08 13:55:59  peiyongz
23 * Apache License Version 2.0
24 *
25 * Revision 1.12  2004/04/07 14:09:22  peiyongz
26 * systemId (to replace rootElemName) as DTDGrammar Key
27 *
28 * Revision 1.11  2003/11/25 15:10:44  jberry
29 * Eliminate some compiler warnings concerning comments inside of comments
30 *
31 * Revision 1.10  2003/11/21 22:34:45  neilg
32 * More schema component model implementation, thanks to David Cargill.
33 * In particular, this cleans up and completes the XSModel, XSNamespaceItem,
34 * XSAttributeDeclaration and XSAttributeGroup implementations.
35 *
36 * Revision 1.9  2003/11/06 21:53:52  neilg
37 * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted.  Also fix some documentation errors.
38 *
39 * Revision 1.8  2003/11/06 15:30:06  neilg
40 * 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.
41 *
42 * Revision 1.7  2003/11/05 18:19:09  peiyongz
43 * Documentation update
44 *
45 * Revision 1.6  2003/10/29 16:16:48  peiyongz
46 * GrammarPool' serialization/deserialization support
47 *
48 * Revision 1.5  2003/10/10 18:36:03  neilg
49 * update XMLGrammarPool interface to make expected behaviour of locked pools better specified, and to add the capability to generate XSModels
50 *
51 * Revision 1.4  2003/09/16 18:30:54  neilg
52 * 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
53 *
54 * Revision 1.3  2003/09/02 08:59:02  gareth
55 * Added API to get enumerator of grammars.
56 *
57 * Revision 1.2  2003/07/31 17:02:42  peiyongz
58 * Grammar embed GrammarDescription
59 *
60 * Revision 1.1  2003/06/20 18:37:39  peiyongz
61 * Stateless Grammar Pool :: Part I
62 *
63 * $Id: XMLGrammarPool.hpp,v 1.14 2004/09/29 19:27:07 cargilld Exp $
64 *
65 */
66
67#if !defined(XMLGRAMMARPOOL_HPP)
68#define XMLGRAMMARPOOL_HPP
69
70#include <xercesc/util/PlatformUtils.hpp>
71#include <xercesc/util/RefHashTableOf.hpp>
72#include <xercesc/util/XMemory.hpp>
73#include <xercesc/framework/psvi/XSModel.hpp>
74
75
76XERCES_CPP_NAMESPACE_BEGIN
77
78class Grammar;
79class XMLGrammarDescription;
80class DTDGrammar;
81class SchemaGrammar;
82class XMLDTDDescription;
83class XMLSchemaDescription;
84class XMLStringPool;
85class BinInputStream;
86class BinOutputStream;
87
88class XMLPARSER_EXPORT XMLGrammarPool : public XMemory
89{
90public :
91    // -----------------------------------------------------------------------
92    /** @name Virtual destructor for derived classes */
93    // -----------------------------------------------------------------------
94    //@{
95
96    /**
97      * virtual destructor
98      *
99      */
100    virtual ~XMLGrammarPool(){};
101    //@}
102
103    // -----------------------------------------------------------------------
104    /** @name The Grammar Pool Interface */
105    // -----------------------------------------------------------------------
106    //@{
107
108    /**
109      * cacheGrammar
110      *
111      * Provide the grammar pool with an opportunity
112      * to cache the given grammar.  If the pool does not choose to do so,
113      * it should return false; otherwise, it should return true, so that
114      * the caller knows whether the grammar has been adopted.
115      *
116      * @param gramToCache: the Grammar to be cached in the grammar pool
117      * @return true if the grammar pool has elected to cache the grammar (in which case
118      * it is assumed to have adopted it); false if it does not cache it
119          *
120      */
121    virtual bool           cacheGrammar(Grammar* const               gramToCache) = 0;
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) = 0;
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      * @return the grammar that was removed from the pool (0 if none)
140      */
141    virtual Grammar*       orphanGrammar(const XMLCh* const nameSpaceKey) = 0; 
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 = 0;
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() = 0;
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      * This should result in the grammar pool being sharable
165      * among parsers operating in different threads.
166      *
167      */
168    virtual void           lockPool() = 0;
169   
170    /**
171      * unlockPool
172      *
173          * After this method has been called, the grammar pool implementation
174      * should return to its default behaviour when cacheGrammars(...) is called.
175      * One effect, depending on the underlying implementation, is that the grammar pool
176      * may no longer be thread-safe (even on read operations).
177      *
178      * For PSVI support any previous XSModel that was produced will be deleted.
179      */
180    virtual void           unlockPool() = 0;
181
182    //@}
183
184    // -----------------------------------------------------------------------
185    /** @name  Factory interface */
186    // -----------------------------------------------------------------------
187    //@{
188
189    /**
190      * createDTDGrammar
191      *
192      */
193    virtual DTDGrammar*            createDTDGrammar() = 0;
194
195    /**
196      * createSchemaGrammar
197      *
198      */
199    virtual SchemaGrammar*         createSchemaGrammar() = 0;
200                   
201    /**
202      * createDTDDescription
203      *
204      */       
205    virtual XMLDTDDescription*     createDTDDescription(const XMLCh* const systemId) = 0;
206    /**
207      * createSchemaDescription
208      *
209      */               
210    virtual XMLSchemaDescription*  createSchemaDescription(const XMLCh* const targetNamespace) = 0;
211
212    //@}
213
214    // -----------------------------------------------------------------------
215    /** @name  schema component model support */
216    // -----------------------------------------------------------------------                                                       
217    //@{
218
219    /***
220      * Return an XSModel derived from the components of all SchemaGrammars
221      * in the grammar pool.  If the pool is locked, this should
222      * be a thread-safe operation.  It should return null if and only if
223      * the pool is empty.
224      *
225      * Calling getXSModel() on an unlocked grammar pool may result in the
226      * creation of a new XSModel with the old XSModel being deleted.  The
227      * function will return a different address for the XSModel if it has
228      * changed.
229      *
230      * @deprecated (shouldn't use address to determine if XSModel changed)
231      */
232    virtual XSModel *getXSModel() = 0;
233
234    /***
235      * Return an XSModel derived from the components of all SchemaGrammars
236      * in the grammar pool.  If the pool is locked, this should
237      * be a thread-safe operation.
238      *
239      * NOTE: The function should NEVER return NULL.  If there are no grammars in
240      *       the pool it should return an XSModel containing the Schema for Schema.     
241      *
242      * Calling getXSModel() on an unlocked grammar pool may result in the
243      * creation of a new XSModel with the old XSModel being deleted.
244      * The bool parameter will indicate if the XSModel was changed.
245      *     
246      * For source code compatibility, default implementation is to say
247      * XSModelWasChanged.
248      */
249    virtual XSModel *getXSModel(bool& XSModelWasChanged)
250    {
251        XSModelWasChanged = true;
252        return getXSModel();
253    }
254       
255    // @}
256
257    // -----------------------------------------------------------------------
258    /** @name  Getter */
259    // -----------------------------------------------------------------------                                                       
260    //@{
261
262    /**
263      * getMemoryManager
264      *
265      */   
266        inline MemoryManager* const    getMemoryManager()
267    {
268        return fMemMgr;
269    }
270
271    /**
272      * Return an XMLStringPool for use by validation routines. 
273      * Implementations should not create a string pool on each call to this
274      * method, but should maintain one string pool for all grammars
275      * for which this pool is responsible.
276      */
277    virtual XMLStringPool *getURIStringPool() = 0;
278    //@}
279
280    // -----------------------------------------------------------------------
281    /** serialization and deserialization support */
282    // -----------------------------------------------------------------------                                                       
283
284    /***
285      *
286      * 1. Context: Serialize/Deserialize All Grammars In One Session
287      *
288      *    Since it is common that a declaration in one grammar may reference
289      *    to definitions in other grammars, it is required to serialize those
290      *    related (or interdependent) grammars in to one persistent data store
291      *    in one serialization session (storing), and deserialize them from the
292      *    persistent data store in one deserialization session (loading) back
293      *    to the grammar pool.   
294      *
295      * 2. Multiple serializations
296      *
297      *    It is acceptable that client application requests more than one
298      *    grammar serialization on a particular grammar pool, to track the
299      *    different grammars cached, or for whatever reasons that client
300      *    application is interested in.
301      *
302      * 3. Multiple deserializations
303      *
304      *    Request for grammar deserialization either after the grammar pool has
305      *    its own cached grammars, or request for more than one grammar
306      *    deserialization, may cause undesired and unpredictable consequence
307      *    and therefore client application shall be aware that individual
308      *    implementationis may NOT support this.
309      *
310      *    However it is strongly recommended that the client application requests
311      *    no more than one grammar deserialization even a particular implementation
312      *    may allow multiple deserializations.
313      *
314      * 4. Locking
315      *
316      *    Both serialization and deserialization requires to lock the grammar pool
317      *    before operation and unlock after operation. In the case the grammar pool
318      *    is locked by a third party, the request for serialization/deserialization
319      *    will NOT be entertained.
320      *
321      * 5. Versioning
322      *
323      *    The Persistent data store has a version tag to be verified during
324      *    deserialization, thus a grammar pool may decide if it supports
325      *    a binary data created by a different release of Xerces.
326      *
327      * 6. Clean up
328      *
329      *    The client application shall be aware that in the event of an exception
330      *    thrown due to a corrupted data store during deserialization, implementation
331      *    may not be able to clean up all resources allocated, and therefore it is
332      *    client application's responsibility to clean up those unreleased resources.
333      *
334      *
335      */
336    virtual void     serializeGrammars(BinOutputStream* const)  = 0;
337    virtual void     deserializeGrammars(BinInputStream* const) = 0;       
338           
339protected :
340    // -----------------------------------------------------------------------
341    /**  Hidden Constructors */
342    // -----------------------------------------------------------------------
343    //@{
344    XMLGrammarPool(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager)
345    :fMemMgr(memMgr)
346    {
347    };
348    //@}
349
350private :
351    // -----------------------------------------------------------------------
352    /** name  Unimplemented copy constructor and operator= */
353    // -----------------------------------------------------------------------
354    //@{
355    XMLGrammarPool(const XMLGrammarPool& );
356    XMLGrammarPool& operator=(const XMLGrammarPool& );
357    //@}
358
359    // -----------------------------------------------------------------------
360    //
361    // fMemMgr: plugged-in (or defaulted-in) memory manager
362    //          not owned
363    //          no reset after initialization
364    //
365    // -----------------------------------------------------------------------
366   
367    MemoryManager* const  fMemMgr;
368
369};
370
371XERCES_CPP_NAMESPACE_END
372
373#endif
Note: See TracBrowser for help on using the repository browser.