peiyongz 2004/04/01 14:00:28
Modified: c/src/xercesc/dom DOMException.cpp DOMException.hpp
DOMRangeException.cpp DOMRangeException.hpp
Log:
DOMException to resolve message if not provided, (de)allocat memory for
message using MemoryManager provided/defaulted
Revision Changes Path
1.5 +43 -14 xml-xerces/c/src/xercesc/dom/DOMException.cpp
Index: DOMException.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/DOMException.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMException.cpp 29 Jan 2004 11:44:26 -0000 1.4
+++ DOMException.cpp 1 Apr 2004 22:00:27 -0000 1.5
@@ -58,33 +58,62 @@
* $Id$
*/
+#include <xercesc/dom/DOMImplementation.hpp>
+#include <xercesc/util/XMLString.hpp>
+#include <xercesc/framework/MemoryManager.hpp>
+
#include "DOMException.hpp"
XERCES_CPP_NAMESPACE_BEGIN
+// ---------------------------------------------------------------------------
+// Destructor and Constructor
+// ---------------------------------------------------------------------------
+DOMException::~DOMException()
+{
+ if (msg && fMsgOwned)
+ fMemoryManager->deallocate((void*)msg);
+}
DOMException::DOMException()
-: code((ExceptionCode) 0)
-, msg(0)
+:code((ExceptionCode) 0)
+,msg(0)
+,fMemoryManager(0)
+,fMsgOwned(false)
{
}
-
-DOMException::DOMException(short exCode, const XMLCh *message)
-: code ((ExceptionCode) exCode)
-, msg(message)
+DOMException::DOMException( short exCode
+ , const XMLCh* message
+ , MemoryManager* const memoryManager)
+:code((ExceptionCode) exCode)
+,msg(message)
+,fMemoryManager(memoryManager)
+,fMsgOwned(false)
{
-}
+ if (!message)
+ {
+ const unsigned int msgSize = 2047;
+ XMLCh errText[msgSize + 1];
+ fMsgOwned = true;
+
+ // load the text
+ msg = XMLString::replicate
+ (
+ DOMImplementation::loadDOMExceptionMsg(code, errText, msgSize) ?
errText : XMLUni::fgDefErrMsg
+ , fMemoryManager
+ );
-
-DOMException::DOMException(const DOMException &other)
-: code(other.code)
-, msg(other.msg)
-{
+ }
}
-DOMException::~DOMException()
+DOMException::DOMException(const DOMException &other)
+:code(other.code)
+,msg(0)
+,fMemoryManager(other.fMemoryManager)
+,fMsgOwned(other.fMsgOwned)
{
+ msg = other.fMsgOwned? XMLString::replicate(other.msg, other.fMemoryManager) :
other.msg;
}
XERCES_CPP_NAMESPACE_END
1.7 +37 -4 xml-xerces/c/src/xercesc/dom/DOMException.hpp
Index: DOMException.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/DOMException.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DOMException.hpp 29 Jan 2004 11:44:26 -0000 1.6
+++ DOMException.hpp 1 Apr 2004 22:00:27 -0000 1.7
@@ -62,6 +62,7 @@
*/
#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -85,6 +86,8 @@
* @since DOM Level 1
*/
+class MemoryManager;
+
class CDOM_EXPORT DOMException {
public:
// -----------------------------------------------------------------------
@@ -101,10 +104,15 @@
/**
* Constructor which takes an error code and a message.
*
- * @param code The error code which indicates the exception
- * @param message The string containing the error message
+ * @param code The error code which indicates the exception
+ * @param message The string containing the error message
+ * @param memoryManager The memory manager used to (de)allocate memory
*/
- DOMException(short code, const XMLCh *message);
+ DOMException(
+ short code
+ , const XMLCh* message
+ , MemoryManager* const memoryManager =
XMLPlatformUtils::fgMemoryManager
+ );
/**
* Copy constructor.
@@ -228,6 +236,11 @@
//@}
// -----------------------------------------------------------------------
+ // Getter
+ // -----------------------------------------------------------------------
+ inline const XMLCh* getMessage() const;
+
+ // -----------------------------------------------------------------------
// Class Types
// -----------------------------------------------------------------------
/** @name Public variables */
@@ -247,12 +260,32 @@
const XMLCh *msg;
//@}
+protected:
+
+ MemoryManager* fMemoryManager;
+
+private:
+
+ /**
+ * A boolean value.
+ * If the message is provided by the applications, it is not
+ * adopted.
+ * If the message is resolved by the DOM implementation, it is
+ * owned.
+ */
+ bool fMsgOwned;
+
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMException & operator = (const DOMException &);
};
+
+inline const XMLCh* DOMException::getMessage() const
+{
+ return msg;
+}
XERCES_CPP_NAMESPACE_END
1.5 +5 -3 xml-xerces/c/src/xercesc/dom/DOMRangeException.cpp
Index: DOMRangeException.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/DOMRangeException.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMRangeException.cpp 29 Jan 2004 11:44:26 -0000 1.4
+++ DOMRangeException.cpp 1 Apr 2004 22:00:27 -0000 1.5
@@ -70,8 +70,10 @@
}
-DOMRangeException::DOMRangeException(RangeExceptionCode exCode, const XMLCh*
message)
-: DOMException(exCode, message)
+DOMRangeException::DOMRangeException( RangeExceptionCode exCode
+ , const XMLCh* message
+ , MemoryManager* const memoryManager)
+: DOMException(exCode, message, memoryManager)
, code(exCode)
{
}
1.6 +8 -2 xml-xerces/c/src/xercesc/dom/DOMRangeException.hpp
Index: DOMRangeException.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/DOMRangeException.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DOMRangeException.hpp 29 Jan 2004 11:44:26 -0000 1.5
+++ DOMRangeException.hpp 1 Apr 2004 22:00:27 -0000 1.6
@@ -71,6 +71,7 @@
* <p>See also the <a
href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document
Object Model (DOM) Level 2 Traversal and Range Specification</a>.
* @since DOM Level 2
*/
+
class CDOM_EXPORT DOMRangeException : public DOMException {
public:
// -----------------------------------------------------------------------
@@ -114,8 +115,13 @@
*
* @param code The error code which indicates the exception
* @param message The string containing the error message
+ * @param memoryManager The memory manager used to (de)allocate memory
*/
- DOMRangeException(RangeExceptionCode code, const XMLCh* message);
+ DOMRangeException(
+ RangeExceptionCode code
+ , const XMLCh* message
+ , MemoryManager* const memoryManager
+ );
/**
* Copy constructor.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]