source: NonGTP/Xerces/xercesc/internal/XMLGrammarPoolImpl.hpp @ 188

Revision 188, 14.2 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 1999, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Log: XMLGrammarPoolImpl.hpp,v $
59 * Revision 1.14  2003/12/19 23:02:43  cargilld
60 * Fix compiler messages on OS390.
61 *
62 * Revision 1.13  2003/11/21 22:38:50  neilg
63 * Enable grammar pools and grammar resolvers to manufacture
64 * XSModels.  This also cleans up handling in the
65 * parser classes by eliminating the need to tell
66 * the grammar pool that schema compoments need to be produced.
67 * Thanks to David Cargill.
68 *
69 * Revision 1.12  2003/11/14 22:34:20  neilg
70 * removed methods made unnecessary by new XSModel implementation design; thanks to David Cargill
71 *
72 * Revision 1.11  2003/11/06 21:53:52  neilg
73 * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted.  Also fix some documentation errors.
74 *
75 * Revision 1.10  2003/11/06 15:30:06  neilg
76 * 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.
77 *
78 * Revision 1.9  2003/11/05 18:19:45  peiyongz
79 * Documentation update
80 *
81 * Revision 1.8  2003/10/29 16:16:08  peiyongz
82 * GrammarPool' serialization/deserialization support
83 *
84 * Revision 1.7  2003/10/10 18:36:41  neilg
85 * update XMLGrammarPool default implementation to reflect recent modifications to the base interface.
86 *
87 * Revision 1.6  2003/10/09 13:54:25  neilg
88 * modify grammar pool implementation to that, once locked, a thread-safe StringPool is used
89 *
90 * Revision 1.5  2003/09/16 18:30:54  neilg
91 * 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
92 *
93 * Revision 1.4  2003/09/02 08:59:02  gareth
94 * Added API to get enumerator of grammars.
95 *
96 * Revision 1.3  2003/07/31 17:05:03  peiyongz
97 * Grammar embed Grammar Description
98 * using getGrammar(URI)
99 * update GrammarDescription info
100 *
101 * Revision 1.2  2003/06/23 21:06:21  peiyongz
102 * to solve unresolved symbol on Solaris
103 *
104 * Revision 1.1  2003/06/20 18:38:39  peiyongz
105 * Stateless Grammar Pool :: Part I
106 *
107 * $Id: XMLGrammarPoolImpl.hpp,v 1.14 2003/12/19 23:02:43 cargilld Exp $
108 *
109 */
110
111#if !defined(XMLGrammarPoolImplIMPL_HPP)
112#define XMLGrammarPoolImplIMPL_HPP
113
114#include <xercesc/framework/XMLGrammarPool.hpp>
115
116XERCES_CPP_NAMESPACE_BEGIN
117
118class XMLSynchronizedStringPool;
119
120class XMLUTIL_EXPORT XMLGrammarPoolImpl : public XMLGrammarPool
121{
122public :
123    // -----------------------------------------------------------------------
124    /** @name constructor and destructor */
125    // -----------------------------------------------------------------------
126    //@{
127
128    XMLGrammarPoolImpl(MemoryManager* const memMgr);
129
130    ~XMLGrammarPoolImpl();
131    //@}
132
133    // -----------------------------------------------------------------------
134    /** @name Implementation of Grammar Pool Interface */
135    // -----------------------------------------------------------------------
136    //@{
137   
138    /**
139      * cacheGrammar
140      *
141      * Provide the grammar pool with an opportunity
142      * to cache the given grammar.  If the pool does not choose to do so,
143      * it should return false; otherwise, it should return true, so that
144      * the caller knows whether the grammar has been adopted.
145      *
146      * @param gramToCache: the Grammar to be cached in the grammar pool
147      * @return true if the grammar pool has elected to cache the grammar (in which case
148      * it is assumed to have adopted it); false if it does not cache it
149          *
150      */
151    virtual bool           cacheGrammar(Grammar* const               gramToCache);
152   
153
154    /**
155      * retrieveGrammar
156      *
157      * @param gramDesc: the Grammar Description used to search for grammar
158          *                  cached in the grammar pool
159          *
160      */
161    virtual Grammar*       retrieveGrammar(XMLGrammarDescription* const gramDesc);
162   
163       
164    /**
165      * orphanGrammar
166      *
167          * grammar removed from the grammar pool and owned by the caller
168      *
169      * @param nameSpaceKey: Key used to search for grammar in the grammar pool
170          *
171      */
172    virtual Grammar*       orphanGrammar(const XMLCh* const nameSpaceKey); 
173
174
175    /**
176     * Get an enumeration of the cached Grammars in the Grammar pool
177     *
178     * @return enumeration of the cached Grammars in Grammar pool
179     */
180    virtual RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const;
181
182    /**
183      * clear
184      *
185          * all grammars are removed from the grammar pool and deleted.
186      * @return true if the grammar pool was cleared. false if it did not.
187      */
188    virtual bool           clear();
189       
190    /**
191      * lockPool
192      *
193          * When this method is called by the application, the
194      * grammar pool should stop adding new grammars to the cache.
195      */
196    virtual void           lockPool();
197   
198    /**
199      * unlockPool
200      *
201          * After this method has been called, the grammar pool implementation
202      * should return to its default behaviour when cacheGrammars(...) is called.
203      *
204      * For PSVI support any previous XSModel that was produced will be deleted.
205      */
206    virtual void           unlockPool();
207
208    //@}
209
210    // -----------------------------------------------------------------------
211    /** @name  Implementation of Factory interface */
212    // -----------------------------------------------------------------------
213    //@{
214
215    /**
216      * createDTDGrammar
217      *
218      */
219    virtual DTDGrammar*            createDTDGrammar();
220
221    /**
222      * createSchemaGrammar
223      *
224      */
225    virtual SchemaGrammar*         createSchemaGrammar();
226                   
227    /**
228      * createDTDDescription
229      *
230      */       
231    virtual XMLDTDDescription*     createDTDDescription(const XMLCh* const rootName);
232    /**
233      * createSchemaDescription
234      *
235      */               
236    virtual XMLSchemaDescription*  createSchemaDescription(const XMLCh* const targetNamespace);
237    //@}
238       
239    // -----------------------------------------------------------------------
240    /** @name  schema component model support */
241    // -----------------------------------------------------------------------                                                       
242    //@{
243
244    /***
245      * Return an XSModel derived from the components of all SchemaGrammars
246      * in the grammar pool.  If the pool is locked, this should
247      * be a thread-safe operation.  It should return null if and only if
248      * the pool is empty.
249      *
250      * Calling getXSModel() on an unlocked grammar pool may result in the
251      * creation of a new XSModel with the old XSModel being deleted.  The
252      * function will return a different address for the XSModel if it has
253      * changed.
254      *
255      * In this implementation, when the pool is not locked a new XSModel will be
256      * computed each this time the pool is called if the pool has changed (and the
257      * previous one will be destroyed at that time).  When the lockPool()
258      * method is called, an XSModel will be generated and returned whenever this method is called
259      * while the pool is in the locked state.  This will be destroyed if the unlockPool()
260      * operation is called.  The XSModel will not be serialized,
261      * but will be recreated if a deserialized pool is in the
262      * locked state.
263      */
264    virtual XSModel *getXSModel();
265       
266    // @}
267    // -----------------------------------------------------------------------
268    /** @name  Getter */
269    // -----------------------------------------------------------------------                                                       
270    //@{
271
272    /**
273      * Return an XMLStringPool for use by validation routines. 
274      * Implementations should not create a string pool on each call to this
275      * method, but should maintain one string pool for all grammars
276      * for which this pool is responsible.
277      */
278    virtual XMLStringPool *getURIStringPool();
279
280    // @}
281
282    // -----------------------------------------------------------------------
283    // serialization and deserialization support
284    // -----------------------------------------------------------------------
285
286    /***
287      *
288      * Multiple serializations
289      *
290      *    For multiple serializations, if the same file name is given, then the
291      *    last result will be in the file (overwriting mode), if different file
292      *    names are given, then there are multiple data stores for each serialization.
293      *
294      * Multiple deserializations
295      *
296      *    Not supported
297      *
298      * Versioning
299      *
300      *    Only binary data serialized with the current XercesC Version and
301      *    SerializationLevel is supported.
302      *
303      * Clean up
304      *
305      *    In the event of an exception thrown due to a corrupted data store during
306      *    deserialization, this implementation may not be able to clean up all resources
307      *    allocated, and therefore it is the client application's responsibility to
308      *    clean up those unreleased resources.
309      *
310      * Coupling of Grammars and StringPool
311      *
312      *    This implementation assumes that StringPool shall always be
313      *    serialized/deserialized together with the grammars. In the case that such a
314      *    coupling is not desired, client application can modify this behaviour by
315      *    either derivate from this imlementation and overwrite the serializeGrammars()
316      *    and/or deserializeGrammars() to decouple grammars and string pool, or
317      *    Once deserializeGrammars() is done, insert another StringPool through
318      *    setStringPool().
319      *
320      *    Client application shall be aware of the unpredicatable/undefined consequence
321      *    of this decoupling.
322      */
323
324    virtual void     serializeGrammars(BinOutputStream* const);
325    virtual void     deserializeGrammars(BinInputStream* const);
326
327    friend class XObjectComparator;
328    friend class XTemplateComparator;
329
330private:
331
332    virtual void    createXSModel();
333    // -----------------------------------------------------------------------
334    /** name  Unimplemented copy constructor and operator= */
335    // -----------------------------------------------------------------------
336    //@{
337    XMLGrammarPoolImpl(const XMLGrammarPoolImpl& );
338    XMLGrammarPoolImpl& operator=(const XMLGrammarPoolImpl& );
339    //@}
340
341    // -----------------------------------------------------------------------
342    //
343    // fGrammarRegistry:
344    //
345        //    container
346    // fStringPool
347    //    grammars need a string pool for URI -> int mappings
348    // fSynchronizedStringPool
349    //      When the grammar pool is locked, provide a string pool
350    //      that can be updated in a thread-safe manner.
351    // fLocked
352    //      whether the pool has been locked
353    //
354    // -----------------------------------------------------------------------
355    RefHashTableOf<Grammar>*            fGrammarRegistry;
356    XMLStringPool*                      fStringPool;
357    XMLSynchronizedStringPool*          fSynchronizedStringPool;
358    XSModel*                            fXSModel;
359    bool                                fLocked;
360    bool                                fXSModelIsValid;
361};
362
363XERCES_CPP_NAMESPACE_END
364
365#endif
Note: See TracBrowser for help on using the repository browser.