dbertoni 00/12/06 15:42:37
Modified: c/src/XercesParserLiaison XercesDocumentBridge.cpp
XercesDocumentBridge.hpp XercesParserLiaison.cpp
XercesParserLiaison.hpp
Added: c/src/XercesParserLiaison
XercesLiaisonXalanDOMStringPool.cpp
XercesLiaisonXalanDOMStringPool.hpp
Log:
Made XercesDocumentBridge thread-safe again.
Revision Changes Path
1.14 +8 -14
xml-xalan/c/src/XercesParserLiaison/XercesDocumentBridge.cpp
Index: XercesDocumentBridge.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDocumentBridge.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XercesDocumentBridge.cpp 2000/11/02 01:46:43 1.13
+++ XercesDocumentBridge.cpp 2000/12/06 23:42:35 1.14
@@ -93,6 +93,7 @@
#include "XercesElementBridge.hpp"
#include "XercesEntityBridge.hpp"
#include "XercesEntityReferenceBridge.hpp"
+#include "XercesLiaisonXalanDOMStringPool.hpp"
#include "XercesNodeListBridge.hpp"
#include "XercesNotationBridge.hpp"
#include "XercesProcessingInstructionBridge.hpp"
@@ -102,6 +103,7 @@
XercesDocumentBridge::XercesDocumentBridge(
const DOM_Document& theXercesDocument,
+ bool threadSafe,
bool buildBridge) :
XalanDocument(),
m_xercesDocument(theXercesDocument),
@@ -110,16 +112,16 @@
m_navigator),
m_nodeMap(),
m_domImplementation(new
XercesDOMImplementationBridge(theXercesDocument.getImplementation())),
- m_navigators(1, XercesBridgeNavigator(this, !buildBridge)),
+ m_navigators(1, XercesBridgeNavigator(this, threadSafe == true ? false
: !buildBridge)),
m_navigator(m_navigators.front()),
m_nodes(),
m_doctype(0),
- m_mappingMode(!buildBridge),
+ m_mappingMode(threadSafe == true ? false : !buildBridge),
m_indexValid(false),
m_elementAllocator(25),
m_textAllocator(25),
m_attributeAllocator(25),
- m_stringPool()
+ m_stringPool(threadSafe == true ? new XercesLiaisonXalanDOMStringPool :
new XalanDOMStringPool)
{
#if !defined(XALAN_NO_NAMESPACES)
using std::make_pair;
@@ -1760,21 +1762,13 @@
const XalanDOMString&
XercesDocumentBridge::getPooledString(const XalanDOMString&
theString) const
{
-#if defined(XALAN_NO_MUTABLE)
- return ((XercesDocumentBridge*)this)->m_stringPool.get(theString);
-#else
- return m_stringPool.get(theString);
-#endif
+ return m_stringPool->get(theString);
}
const XalanDOMString&
-XercesDocumentBridge:: getPooledString(const XalanDOMChar*
theString) const
+XercesDocumentBridge::getPooledString(const XalanDOMChar*
theString) const
{
-#if defined(XALAN_NO_MUTABLE)
- return ((XercesDocumentBridge*)this)->m_stringPool.get(theString);
-#else
- return m_stringPool.get(theString);
-#endif
+ return m_stringPool->get(theString);
}
1.12 +5 -5
xml-xalan/c/src/XercesParserLiaison/XercesDocumentBridge.hpp
Index: XercesDocumentBridge.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesDocumentBridge.hpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XercesDocumentBridge.hpp 2000/11/02 01:46:43 1.11
+++ XercesDocumentBridge.hpp 2000/12/06 23:42:36 1.12
@@ -79,6 +79,7 @@
#if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
#include <XalanDOM/XalanDOMImplementation.hpp>
+#include <PlatformSupport/XalanDOMStringPool.hpp>
#endif
@@ -87,10 +88,6 @@
-#include <PlatformSupport/XalanDOMStringPool.hpp>
-
-
-
#include <DOMSupport/TreeWalker.hpp>
@@ -105,6 +102,7 @@
+class XalanDOMStringPool;
class XercesAttrBridge;
class XercesCommentBridge;
class XercesCDATASectionBridge;
@@ -136,11 +134,13 @@
* an unbuilt node at the same time.
*
* @param theXercesDocument The Xerces document to bridge
+ * @param threadSafe If true, the tree can safely be shared amongst
multiple threads. (Also implies buildBridge == true)
* @param buildBridge If true, all of the bridge nodes will be built
during construction.
*
*/
XercesDocumentBridge(
const DOM_Document& theXercesDocument,
+ bool threadSafe =
true,
bool buildBridge =
true);
virtual
@@ -588,7 +588,7 @@
mutable XercesAttributeBridgeAllocator m_attributeAllocator;
- mutable XalanDOMStringPool m_stringPool;
+ XalanAutoPtr<XalanDOMStringPool> m_stringPool;
};
1.23 +8 -5
xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.cpp
Index: XercesParserLiaison.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XercesParserLiaison.cpp 2000/11/30 20:39:04 1.22
+++ XercesParserLiaison.cpp 2000/12/06 23:42:36 1.23
@@ -121,7 +121,9 @@
m_exitOnFirstFatalError(true),
m_entityResolver(0),
m_errorHandler(this),
- m_documentMap()
+ m_documentMap(),
+ m_buildBridge(true),
+ m_threadSafe(true)
{
}
@@ -192,7 +194,7 @@
if (theXercesDocument.isNull() == false)
{
- theNewDocument = createDocument(theXercesDocument, true);
+ theNewDocument = createDocument(theXercesDocument,
m_threadSafe, m_buildBridge);
m_documentMap[theNewDocument] = theNewDocument;
}
@@ -208,7 +210,7 @@
const DOM_Document theXercesDocument =
DOM_Document::createDocument();
- return createDocument(theXercesDocument, false);
+ return createDocument(theXercesDocument, false, false);
}
@@ -416,7 +418,7 @@
XalanDocument*
XercesParserLiaison::createDocument(const DOM_Document&
theXercesDocument)
{
- return createDocument(theXercesDocument, false);
+ return createDocument(theXercesDocument, false, false);
}
@@ -614,10 +616,11 @@
XercesDocumentBridge*
XercesParserLiaison::createDocument(
const DOM_Document& theXercesDocument,
+ bool threadSafe,
bool buildBridge)
{
XercesDocumentBridge* const theNewDocument =
- new XercesDocumentBridge(theXercesDocument, buildBridge);
+ new XercesDocumentBridge(theXercesDocument, threadSafe,
buildBridge);
m_documentMap[theNewDocument] = theNewDocument;
1.17 +74 -0
xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.hpp
Index: XercesParserLiaison.hpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XercesParserLiaison.hpp 2000/11/02 01:46:44 1.16
+++ XercesParserLiaison.hpp 2000/12/06 23:42:36 1.17
@@ -124,9 +124,11 @@
DocumentHandler& handler,
const XalanDOMString& identifier = XalanDOMString());
+ // Create a non-thread safe document, with no synchronization and no
bridge...
virtual XalanDocument*
createDocument();
+ // Create a non-thread safe document, with no synchronization and no
bridge...
virtual XalanDocument*
getDOMFactory();
@@ -384,6 +386,72 @@
XercesDocumentBridge*>
DocumentMapType;
#endif
+ /**
+ * This functions returns the state of the liaison's build-bridge-nodes
flag.
+ *
+ * @return true, if the bridge nodes are automatically built, false
otherwise.
+ */
+ bool
+ getBuildBridgeNodes() const
+
+ {
+ return m_buildBridge;
+ }
+
+ /**
+ * This functions sets the state of the liaison's build-bridge-nodes
flag.
+ * This flag must be set for the document to be thread safe. It can
also be
+ * set to true to increase performance. If this flag is set to false,
then
+ * the thread-safe flag will also be set to false.
+ *
+ * @param newState The new state for the flag.
+ *
+ */
+ void
+ setBuildBridgeNodes(bool newState)
+ {
+ m_buildBridge = newState;
+
+ if (newState == false)
+ {
+ m_threadSafe = false;
+ }
+ }
+
+ /**
+ * This functions returns the state of the liaison's thread-safe flag.
+ * If true, documents created will be safe when data is read.
+ * Note -- modifications are _never_ synchronized.
+ *
+ * @return true, if the new documents will be thread safe, false
otherwise.
+ */
+ bool
+ getThreadSafe() const
+
+ {
+ return m_threadSafe;
+ }
+
+ /**
+ * This functions sets the state of the liaison's thread-safe flag.
+ * This flag must be set for the document to be thread safe. If this
+ * flag is set to true, then the build-bridge-nodes flag will also be
+ * set to true.
+ *
+ * @param newState The new state for the flag.
+ *
+ */
+ void
+ setThreadSafe(bool newState)
+ {
+ m_threadSafe = newState;
+
+ if (m_threadSafe == true)
+ {
+ m_buildBridge = true;
+ }
+ }
+
protected:
virtual DOMParser*
@@ -396,12 +464,14 @@
* Create a XalanDocument proxy for an existing Xerces document.
*
* @param theXercesDocument The Xerces document.
+ * @param threadSafe If true, read access to the tree will be
thread-safe (implies buildBridge == true).
* @param buildBridge If true, the entire bridge structure is built.
* @return a pointer to a new XercesDocumentBridge instance.
*/
virtual XercesDocumentBridge*
createDocument(
const DOM_Document& theXercesDocument,
+ bool threadSafe,
bool buildBridge);
private:
@@ -428,6 +498,10 @@
ErrorHandler* m_errorHandler;
DocumentMapType m_documentMap;
+
+ bool m_buildBridge;
+
+ bool m_threadSafe;
};
1.1
xml-xalan/c/src/XercesParserLiaison/XercesLiaisonXalanDOMStringPool.cpp
Index: XercesLiaisonXalanDOMStringPool.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// Class header file...
#include "XercesLiaisonXalanDOMStringPool.hpp"
XercesLiaisonXalanDOMStringPool::XercesLiaisonXalanDOMStringPool() :
XalanDOMStringPool(),
m_mutex()
{
}
XercesLiaisonXalanDOMStringPool::~XercesLiaisonXalanDOMStringPool()
{
}
void
XercesLiaisonXalanDOMStringPool::clear()
{
XMLMutexLock theLock(&m_mutex);
BaseClassType::clear();
}
XercesLiaisonXalanDOMStringPool::size_type
XercesLiaisonXalanDOMStringPool::size() const
{
#if defined(XALAN_NO_MUTABLE)
XMLMutexLock
theLock(&((XercesLiaisonXalanDOMStringPool*)this)->m_mutex);
#else
XMLMutexLock theLock(&m_mutex);
#endif
return BaseClassType::size();
}
const XalanDOMString&
XercesLiaisonXalanDOMStringPool::get(const XalanDOMString& theString)
{
XMLMutexLock theLock(&m_mutex);
return BaseClassType::get(theString);
}
const XalanDOMString&
XercesLiaisonXalanDOMStringPool::get(
const XalanDOMChar* theString,
unsigned int theLength)
{
XMLMutexLock theLock(&m_mutex);
return BaseClassType::get(theString, theLength);
}
1.1
xml-xalan/c/src/XercesParserLiaison/XercesLiaisonXalanDOMStringPool.hpp
Index: XercesLiaisonXalanDOMStringPool.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#if !defined(XERCESLIAISONXALANDOMSTRINGPOOL_HEADER_GUARD_1357924680)
#define XERCESLIAISONXALANDOMSTRINGPOOL_HEADER_GUARD_1357924680
// Base include file. Must be first.
#include <XercesParserLiaison/XercesParserLiaisonDefinitions.hpp>
#include <PlatformSupport/XalanDOMStringPool.hpp>
#include <util/Mutexes.hpp>
// A version of XalanDOMStringPool which is synchronized using a Xerces Mutex.
class XALAN_XERCESPARSERLIAISON_EXPORT XercesLiaisonXalanDOMStringPool :
public XalanDOMStringPool
{
public:
typedef XalanDOMStringPool BaseClassType;
explicit
XercesLiaisonXalanDOMStringPool();
virtual
~XercesLiaisonXalanDOMStringPool();
// These are inherited from XalanDOMStringPool...
virtual void
clear();
virtual size_type
size() const;
virtual const XalanDOMString&
get(const XalanDOMString& theString);
virtual const XalanDOMString&
get(
const XalanDOMChar* theString,
unsigned int theLength =
unsigned(-1));
private:
// Not implemented, for now...
XercesLiaisonXalanDOMStringPool(const XercesLiaisonXalanDOMStringPool&);
XercesLiaisonXalanDOMStringPool&
operator=(const XercesLiaisonXalanDOMStringPool&);
bool
operator==(const XercesLiaisonXalanDOMStringPool&) const;
// Data members...
mutable XMLMutex m_mutex;
};
#endif //
!defined(XERCESLIAISONXALANDOMSTRINGPOOL_HEADER_GUARD_1357924680)