neilg 2003/11/06 13:53:52 Modified: c/src/xercesc/framework XMLGrammarPool.hpp c/src/xercesc/internal XMLGrammarPoolImpl.cpp XMLGrammarPoolImpl.hpp c/src/xercesc/validators/common GrammarResolver.cpp Log: update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted. Also fix some documentation errors. Revision Changes Path 1.9 +20 -14 xml-xerces/c/src/xercesc/framework/XMLGrammarPool.hpp Index: XMLGrammarPool.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/XMLGrammarPool.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XMLGrammarPool.hpp 6 Nov 2003 15:30:06 -0000 1.8 +++ XMLGrammarPool.hpp 6 Nov 2003 21:53:52 -0000 1.9 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.9 2003/11/06 21:53:52 neilg + * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted. Also fix some documentation errors. + * * Revision 1.8 2003/11/06 15:30:06 neilg * 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. * @@ -128,10 +131,17 @@ /** * cacheGrammar * + * Provide the grammar pool with an opportunity + * to cache the given grammar. If the pool does not choose to do so, + * it should return false; otherwise, it should return true, so that + * the caller knows whether the grammar has been adopted. + * * @param gramToCache: the Grammar to be cached in the grammar pool + * @return true if the grammar pool has elected to cache the grammar (in which case + * it is assumed to have adopted it); false if it does not cache it * */ - virtual void cacheGrammar(Grammar* const gramToCache) = 0; + virtual bool cacheGrammar(Grammar* const gramToCache) = 0; /** * retrieveGrammar @@ -185,6 +195,8 @@ * * After this method has been called, the grammar pool implementation * should return to its default behaviour when cacheGrammars(...) is called. + * One effect, depending on the underlying implementation, is that the grammar pool + * may no longer be thread-safe (even on read operations). * */ virtual void unlockPool() = 0; @@ -234,18 +246,12 @@ //@{ /*** - * If the grammar pool has been locked, this method returns - * an XSModel corresponding to the schema components represented - * by the objects stored in the pool. If the pool has not been - * locked, this must return null. If the pool is unlocked at - * any point, the underlying XSModel will be destroyed; - * applications must take care that, if they wish to unlock - * a pool, no further access is made to the XSModel - * it produced. The pool's XSModel will not be serialized, - * but, if a locked pool is deserialized, its XSModel - * will be recreated. + * Return an XSModel derived from the components of all SchemaGrammars + * in the grammar pool. If the pool is locked, this should + * be a thread-safe operation. It should return null if and only if + * the pool is empty. */ - virtual XSModel *getXSModel() const = 0; + virtual XSModel *getXSModel() = 0; // @} 1.11 +13 -8 xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.cpp Index: XMLGrammarPoolImpl.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XMLGrammarPoolImpl.cpp 6 Nov 2003 15:30:06 -0000 1.10 +++ XMLGrammarPoolImpl.cpp 6 Nov 2003 21:53:52 -0000 1.11 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.11 2003/11/06 21:53:52 neilg + * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted. Also fix some documentation errors. + * * Revision 1.10 2003/11/06 15:30:06 neilg * 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. * @@ -135,10 +138,12 @@ // ----------------------------------------------------------------------- // Implementation of Grammar Pool Interface // ----------------------------------------------------------------------- -void XMLGrammarPoolImpl::cacheGrammar(Grammar* const gramToCache ) +bool XMLGrammarPoolImpl::cacheGrammar(Grammar* const gramToCache ) { + if(fLocked) + return false; if (!gramToCache ) - return; + return false; const XMLCh* grammarKey = gramToCache->getGrammarDescription()->getGrammarKey(); @@ -157,6 +162,7 @@ } updatePSVIvectorElemIds(fPSVIvectorElemDecls, (SchemaGrammar*) gramToCache); } + return true; } @@ -261,14 +267,13 @@ return new (getMemoryManager()) XMLSchemaDescriptionImpl(targetNamespace, getMemoryManager()); } -inline XSModel *XMLGrammarPoolImpl::getXSModel() const +XSModel *XMLGrammarPoolImpl::getXSModel() { - if(!fLocked) - return 0; - return fXSModel; + // REVISIT: implement along with XSModel implementation + return 0; } -inline XMLStringPool *XMLGrammarPoolImpl::getURIStringPool() +XMLStringPool *XMLGrammarPoolImpl::getURIStringPool() { if(fLocked) return fSynchronizedStringPool; 1.11 +26 -13 xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.hpp Index: XMLGrammarPoolImpl.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLGrammarPoolImpl.hpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XMLGrammarPoolImpl.hpp 6 Nov 2003 15:30:06 -0000 1.10 +++ XMLGrammarPoolImpl.hpp 6 Nov 2003 21:53:52 -0000 1.11 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.11 2003/11/06 21:53:52 neilg + * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted. Also fix some documentation errors. + * * Revision 1.10 2003/11/06 15:30:06 neilg * 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. * @@ -127,10 +130,17 @@ /** * cacheGrammar * + * Provide the grammar pool with an opportunity + * to cache the given grammar. If the pool does not choose to do so, + * it should return false; otherwise, it should return true, so that + * the caller knows whether the grammar has been adopted. + * * @param gramToCache: the Grammar to be cached in the grammar pool + * @return true if the grammar pool has elected to cache the grammar (in which case + * it is assumed to have adopted it); false if it does not cache it * */ - virtual void cacheGrammar(Grammar* const gramToCache); + virtual bool cacheGrammar(Grammar* const gramToCache); /** @@ -234,18 +244,21 @@ //@{ /*** - * If the grammar pool has been locked, this method returns - * an XSModel corresponding to the schema components represented - * by the objects stored in the pool. If the pool has not been - * locked, this must return null. If the pool is unlocked at - * any point, the underlying XSModel will be destroyed; - * applications must take care that, if they wish to unlock - * a pool, no further access is made to the XSModel - * it produced. The pool's XSModel will not be serialized, - * but, if a locked pool is deserialized, its XSModel - * will be recreated. + * Return an XSModel derived from the components of all SchemaGrammars + * in the grammar pool. If the pool is locked, this should + * be a thread-safe operation. It should return null if and only if + * the pool is empty. + * + * In this implementation, a new XSModel will be + * computed each this time the pool is called if the pool is not locked (and the + * previous one will be destroyed at that time). When the lockPool() + * method is called, an XSModel will be generated and returned whenever this method is called + * while the pool is in the locked state. This will be destroyed if the unlockPool() + * operation is called. The XSModel will not be serialized, + * but will be recreated if a deserialized pool is in the + * locked state. */ - virtual XSModel *getXSModel() const; + virtual XSModel *getXSModel(); // @} // ----------------------------------------------------------------------- 1.20 +15 -4 xml-xerces/c/src/xercesc/validators/common/GrammarResolver.cpp Index: GrammarResolver.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/common/GrammarResolver.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- GrammarResolver.cpp 16 Sep 2003 18:30:54 -0000 1.19 +++ GrammarResolver.cpp 6 Nov 2003 21:53:52 -0000 1.20 @@ -57,6 +57,9 @@ /* * $Log$ + * Revision 1.20 2003/11/06 21:53:52 neilg + * update grammar pool interface so that cacheGrammar(Grammar) can tell the caller whether the grammar was accepted. Also fix some documentation errors. + * * Revision 1.19 2003/09/16 18:30:54 neilg * 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 * @@ -329,7 +332,11 @@ */ if (fCacheGrammar) { - fGrammarPool->cacheGrammar(grammarToAdopt); + if(!fGrammarPool->cacheGrammar(grammarToAdopt)) + { + // grammar pool doesn't want it; we're stuck with looking after it + fGrammarBucket->put( (void*) grammarToAdopt->getGrammarDescription()->getGrammarKey(), grammarToAdopt ); + } } else { @@ -370,12 +377,16 @@ for (unsigned int i = 0; i < keyCount; i++) { XMLCh* grammarKey = keys.elementAt(i); - Grammar* grammar = fGrammarBucket->orphanKey(grammarKey); /*** * It is up to the GrammarPool implementation to handle duplicated grammar */ - fGrammarPool->cacheGrammar(grammar); + Grammar* grammar = fGrammarBucket->get(grammarKey); + if(fGrammarPool->cacheGrammar(grammar)) + { + // only orphan grammar is grammar pool accepts + fGrammarBucket->orphanKey(grammarKey); + } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]