cargilld 2004/09/29 12:27:07
Modified: c/src/xercesc/framework XMLGrammarPool.hpp
c/src/xercesc/internal XMLGrammarPoolImpl.cpp
XMLGrammarPoolImpl.hpp
c/src/xercesc/validators/common GrammarResolver.cpp
Log:
Fix for Jira-1217: fixing problems with getXSModel.
Revision Changes Path
1.14 +27 -1 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XMLGrammarPool.hpp 8 Sep 2004 13:55:59 -0000 1.13
+++ XMLGrammarPool.hpp 29 Sep 2004 19:27:07 -0000 1.14
@@ -16,6 +16,9 @@
/*
* $Log$
+ * Revision 1.14 2004/09/29 19:27:07 cargilld
+ * Fix for Jira-1217: fixing problems with getXSModel.
+ *
* Revision 1.13 2004/09/08 13:55:59 peiyongz
* Apache License Version 2.0
*
@@ -223,8 +226,31 @@
* creation of a new XSModel with the old XSModel being deleted. The
* function will return a different address for the XSModel if it has
* changed.
+ *
+ * @deprecated (shouldn't use address to determine if XSModel changed)
*/
virtual XSModel *getXSModel() = 0;
+
+ /***
+ * 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.
+ *
+ * NOTE: The function should NEVER return NULL. If there are no grammars in
+ * the pool it should return an XSModel containing the Schema for
Schema.
+ *
+ * Calling getXSModel() on an unlocked grammar pool may result in the
+ * creation of a new XSModel with the old XSModel being deleted.
+ * The bool parameter will indicate if the XSModel was changed.
+ *
+ * For source code compatibility, default implementation is to say
+ * XSModelWasChanged.
+ */
+ virtual XSModel *getXSModel(bool& XSModelWasChanged)
+ {
+ XSModelWasChanged = true;
+ return getXSModel();
+ }
// @}
1.23 +29 -28 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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XMLGrammarPoolImpl.cpp 10 Sep 2004 17:36:13 -0000 1.22
+++ XMLGrammarPoolImpl.cpp 29 Sep 2004 19:27:07 -0000 1.23
@@ -16,6 +16,9 @@
/*
* $Log$
+ * Revision 1.23 2004/09/29 19:27:07 cargilld
+ * Fix for Jira-1217: fixing problems with getXSModel.
+ *
* Revision 1.22 2004/09/10 17:36:13 cargilld
* Return bool as described in the interface for cacheGrammar instead of throwing
an exception. Fix from Dave Bertoni.
*
@@ -111,27 +114,8 @@
// private function used to update fXSModel
void XMLGrammarPoolImpl::createXSModel()
{
- RefHashTableOfEnumerator<Grammar> grammarEnum(fGrammarRegistry, false,
getMemoryManager());
- if (fXSModel)
- {
- // Need to guarantee that we return a different address...
- if (grammarEnum.hasMoreElements())
- {
- XSModel* xsModel = new (getMemoryManager()) XSModel(this,
getMemoryManager());
- delete fXSModel;
- fXSModel = xsModel;
- }
- else
- {
- // its empty...
- delete fXSModel;
- fXSModel = 0;
- }
- }
- else if (grammarEnum.hasMoreElements())
- {
- fXSModel = new (getMemoryManager()) XSModel(this, getMemoryManager());
- }
+ delete fXSModel;
+ fXSModel = new (getMemoryManager()) XSModel(this, getMemoryManager());
fXSModelIsValid = true;
}
@@ -178,8 +162,10 @@
fGrammarRegistry->put((void*) grammarKey, gramToCache);
- fXSModelIsValid = false;
-
+ if (fXSModelIsValid && gramToCache->getGrammarType() ==
Grammar::SchemaGrammarType)
+ {
+ fXSModelIsValid = false;
+ }
return true;
}
@@ -197,9 +183,13 @@
Grammar* XMLGrammarPoolImpl::orphanGrammar(const XMLCh* const nameSpaceKey)
{
if (!fLocked)
- {
- fXSModelIsValid = false;
- return fGrammarRegistry->orphanKey(nameSpaceKey);
+ {
+ Grammar* grammar = fGrammarRegistry->orphanKey(nameSpaceKey);
+ if (fXSModelIsValid && grammar && grammar->getGrammarType() ==
Grammar::SchemaGrammarType)
+ {
+ fXSModelIsValid = false;
+ }
+ return grammar;
}
return 0;
}
@@ -296,8 +286,19 @@
if (fXSModelIsValid)
return fXSModel;
-
+
createXSModel();
+ return fXSModel;
+}
+
+XSModel *XMLGrammarPoolImpl::getXSModel(bool& XSModelWasChanged)
+{
+ XSModelWasChanged = false;
+ if (fLocked || fXSModelIsValid)
+ return fXSModel;
+
+ createXSModel();
+ XSModelWasChanged = true;
return fXSModel;
}
1.17 +31 -2 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XMLGrammarPoolImpl.hpp 8 Sep 2004 13:56:14 -0000 1.16
+++ XMLGrammarPoolImpl.hpp 29 Sep 2004 19:27:07 -0000 1.17
@@ -16,6 +16,9 @@
/*
* $Log$
+ * Revision 1.17 2004/09/29 19:27:07 cargilld
+ * Fix for Jira-1217: fixing problems with getXSModel.
+ *
* Revision 1.16 2004/09/08 13:56:14 peiyongz
* Apache License Version 2.0
*
@@ -226,9 +229,35 @@
* operation is called. The XSModel will not be serialized,
* but will be recreated if a deserialized pool is in the
* locked state.
+ *
+ * @deprecated (shouldn't use address to determine if XSModel changed)
*/
virtual XSModel *getXSModel();
-
+
+ /***
+ * 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.
+ *
+ * NOTE: The function should NEVER return NULL. If there are no grammars in
+ * the pool it should return an XSModel containing the Schema for Schema.
+ *
+ * Calling getXSModel() on an unlocked grammar pool may result in the
+ * creation of a new XSModel with the old XSModel being deleted.
+ * The bool parameter will indicate if the XSModel was changed.
+ *
+ * In this implementation, when the pool is not locked a new XSModel will be
+ * computed each this time the pool is called if the pool has changed (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(bool& XSModelWasChanged);
+
// @}
// -----------------------------------------------------------------------
/** @name Getter */
1.29 +22 -17 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.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- GrammarResolver.cpp 8 Sep 2004 13:56:51 -0000 1.28
+++ GrammarResolver.cpp 29 Sep 2004 19:27:07 -0000 1.29
@@ -16,6 +16,9 @@
/*
* $Log$
+ * Revision 1.29 2004/09/29 19:27:07 cargilld
+ * Fix for Jira-1217: fixing problems with getXSModel.
+ *
* Revision 1.28 2004/09/08 13:56:51 peiyongz
* Apache License Version 2.0
*
@@ -457,21 +460,24 @@
// We know if the grammarpool changed thru caching, orphaning and erasing
// but NOT by other mechanisms such as lockPool() or unlockPool() so it
// is safest to always get it. The grammarPool XSModel will only be
- // regenerated if something changed and in that case it will have a new
- // address.
- xsModel = fGrammarPool->getXSModel();
- if (xsModel != fGrammarPoolXSModel)
+ // regenerated if something changed.
+ bool XSModelWasChanged;
+ // The grammarpool will always return an xsmodel, even if it is just
+ // the schema for schema xsmodel...
+ xsModel = fGrammarPool->getXSModel(XSModelWasChanged);
+ if (XSModelWasChanged)
{
// we know the grammarpool XSModel has changed or this is the
// first call to getXSModel
if (!fGrammarPoolXSModel && (fGrammarsToAddToXSModel->size() == 0) &&
!fXSModel)
- {
+ {
fGrammarPoolXSModel = xsModel;
return fGrammarPoolXSModel;
}
else
{
+ fGrammarPoolXSModel = xsModel;
// We had previously augmented the grammar pool XSModel
// with our our grammars or we would like to upate it now
// so we have to regenerate the XSModel
@@ -483,18 +489,15 @@
if (grammar.getGrammarType() == Grammar::SchemaGrammarType)
fGrammarsToAddToXSModel->addElement((SchemaGrammar*)&grammar);
}
- if (fXSModel)
- {
- xsModel = new (fMemoryManager) XSModel(fGrammarPoolXSModel,
this, fMemoryManager);
- delete fXSModel;
- fXSModel = xsModel;
- }
- else
- {
- fXSModel = new (fMemoryManager) XSModel(fGrammarPoolXSModel,
this, fMemoryManager);
- }
- fGrammarsToAddToXSModel->removeAllElements();
- return fXSModel;
+ delete fXSModel;
+ if (fGrammarsToAddToXSModel->size())
+ {
+ fXSModel = new (fMemoryManager) XSModel(fGrammarPoolXSModel,
this, fMemoryManager);
+ fGrammarsToAddToXSModel->removeAllElements();
+ return fXSModel;
+ }
+ fXSModel = 0;
+ return fGrammarPoolXSModel;
}
}
else {
@@ -523,6 +526,8 @@
{
return fGrammarPoolXSModel;
}
+ fXSModel = new (fMemoryManager) XSModel(0, this, fMemoryManager);
+ return fXSModel;
}
}
// Not Caching...
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]