activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1312046 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands: BrokerError.cpp BrokerError.h
Date Tue, 10 Apr 2012 23:39:45 GMT
Author: tabish
Date: Tue Apr 10 23:39:44 2012
New Revision: 1312046

URL: http://svn.apache.org/viewvc?rev=1312046&view=rev
Log:
Add a factory method to create real Exception objects.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp?rev=1312046&r1=1312045&r2=1312046&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp Tue
Apr 10 23:39:44 2012
@@ -23,6 +23,7 @@ using namespace std;
 using namespace activemq;
 using namespace activemq::exceptions;
 using namespace activemq::commands;
+using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -37,22 +38,28 @@ BrokerError::~BrokerError() {
 ////////////////////////////////////////////////////////////////////////////////
 void BrokerError::copyDataStructure( const DataStructure* src ) {
 
-    const BrokerError* srcErr = dynamic_cast<const BrokerError*>( src );
+    const BrokerError* srcErr = dynamic_cast<const BrokerError*> (src);
 
-    if( srcErr == NULL || src == NULL ) {
-        throw decaf::lang::exceptions::NullPointerException(
-            __FILE__, __LINE__,
-            "BrokerError::copyCommand - src is NULL or invalid" );
+    if (srcErr == NULL || src == NULL) {
+        throw NullPointerException(__FILE__, __LINE__, "BrokerError::copyCommand - src is
NULL or invalid");
     }
 
-    this->setMessage( srcErr->getMessage() );
-    this->setExceptionClass( srcErr->getExceptionClass() );
-    this->setStackTraceElements( srcErr->getStackTraceElements() );
-    this->setCause( srcErr->getCause() );
+    this->setMessage(srcErr->getMessage());
+    this->setExceptionClass(srcErr->getExceptionClass());
+    this->setStackTraceElements(srcErr->getStackTraceElements());
+    this->setCause(srcErr->getCause());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-decaf::lang::Pointer<commands::Command> BrokerError::visit( activemq::state::CommandVisitor*
visitor ) {
+Pointer<commands::Command> BrokerError::visit( activemq::state::CommandVisitor* visitor
) {
+    return visitor->processBrokerError(this);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::lang::Exception BrokerError::createExceptionObject() {
 
-    return visitor->processBrokerError( this );
+    // TODO Would be nice to actually create an exception matching the broker reported
+    // type as well as preserving the supplied stack trace and possible embedded cause.
+    Exception theCause(__FILE__, __LINE__, this->getMessage().c_str());
+    return theCause;
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h?rev=1312046&r1=1312045&r2=1312046&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h Tue
Apr 10 23:39:44 2012
@@ -20,18 +20,19 @@
 
 #include <activemq/util/Config.h>
 #include <activemq/commands/BaseCommand.h>
-#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/Exception.h>
 #include <decaf/lang/Pointer.h>
 
 #include <string>
 #include <vector>
 
-namespace activemq{
-namespace commands{
+namespace activemq {
+namespace commands {
 
     /**
-     * This class represents an Exception sent from the Broker.  The Broker
-     * sends java Throwables, so we must mimic its structure here.
+     * This class represents an Exception sent from the Broker.  The Broker sends a java
+     * Throwable structure, so we must mimic its structure here.  We provide a means in this
+     * class to create a Decaf Exception that represents the error from the broker.
      */
     class AMQCPP_API BrokerError : public BaseCommand {
     public:
@@ -73,7 +74,6 @@ namespace commands{
          * @returns new copy of this object.
          */
         virtual BrokerError* cloneDataStructure() const {
-
             BrokerError* error = new BrokerError();
             error->copyDataStructure( this );
             return error;
@@ -84,7 +84,7 @@ namespace commands{
          * members, overwriting any existing data.
          * @return src - Source Object
          */
-        virtual void copyDataStructure( const DataStructure* src );
+        virtual void copyDataStructure(const DataStructure* src);
 
         /**
          * Allows a Visitor to visit this command and return a response to the
@@ -93,8 +93,7 @@ namespace commands{
          *
          * @return a Response to the visitor being called or NULL if no response.
          */
-        virtual decaf::lang::Pointer<commands::Command> visit(
-            activemq::state::CommandVisitor* visitor );
+        virtual decaf::lang::Pointer<commands::Command> visit(activemq::state::CommandVisitor*
visitor);
 
         /**
          * Gets the string holding the error message
@@ -108,7 +107,7 @@ namespace commands{
          * Sets the string that contains the error Message
          * @param message - String Error Message
          */
-        virtual void setMessage( const std::string& message ) {
+        virtual void setMessage(const std::string& message) {
             this->message = message;
         }
 
@@ -124,7 +123,7 @@ namespace commands{
          * Sets the string that contains the Exception Class name
          * @param exceptionClass - String Exception Class name
          */
-        virtual void setExceptionClass( const std::string& exceptionClass ) {
+        virtual void setExceptionClass(const std::string& exceptionClass) {
             this->exceptionClass = exceptionClass;
         }
 
@@ -140,7 +139,7 @@ namespace commands{
          * Sets the Broker Error that caused this exception
          * @param cause - Broker Error
          */
-        virtual void setCause( const decaf::lang::Pointer<BrokerError>& cause )
{
+        virtual void setCause(const decaf::lang::Pointer<BrokerError>& cause) {
             this->cause = cause;
         }
 
@@ -148,7 +147,7 @@ namespace commands{
          * Gets the Stack Trace Elements for the Exception
          * @returns Stack Trace Elements
          */
-        virtual const std::vector< decaf::lang::Pointer<StackTraceElement> >&
getStackTraceElements() const {
+        virtual const std::vector<decaf::lang::Pointer<StackTraceElement> >&
getStackTraceElements() const {
             return stackTraceElements;
         }
 
@@ -156,10 +155,17 @@ namespace commands{
          * Sets the Stack Trace Elements for this Exception
          * @param stackTraceElements - Stack Trace Elements
          */
-        virtual void setStackTraceElements( const std::vector< decaf::lang::Pointer<StackTraceElement>
>& stackTraceElements ) {
+        virtual void setStackTraceElements(const std::vector<decaf::lang::Pointer<StackTraceElement>
>& stackTraceElements) {
             this->stackTraceElements = stackTraceElements;
         }
 
+        /**
+         * Creates and returns a Decaf Exception object that contains the error data from
the Broker.
+         *
+         * @return a new instance of a Decaf Exception
+         */
+        decaf::lang::Exception createExceptionObject();
+
     };
 
 }}



Mime
View raw message