You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/08/15 16:24:43 UTC

svn commit: r566185 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net: URI.cpp URISyntaxException.h

Author: tabish
Date: Wed Aug 15 07:24:42 2007
New Revision: 566185

URL: http://svn.apache.org/viewvc?view=rev&rev=566185
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Adding start of URI class

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URISyntaxException.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp?view=diff&rev=566185&r1=566184&r2=566185
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp Wed Aug 15 07:24:42 2007
@@ -84,9 +84,8 @@
     if( scheme != "" && path.length() > 0 && path.at(0) != '/') {
 
         throw URISyntaxException(
-            __FILE__, __LINE__,
-            "URI::URI - Path string: %s starts with invalid char '/'",
-            path.c_str() );
+            __FILE__, __LINE__, path,
+            "URI::URI - Path string: %s starts with invalid char '/'" );
     }
 
     std::string uri = "";
@@ -164,9 +163,8 @@
 
     if( scheme != "" && path.length() > 0 && path.at(0) != '/' ) {
          throw URISyntaxException(
-            __FILE__, __LINE__,
-            "URI::URI - Path String %s must start with a '/'",
-            path.c_str() );
+            __FILE__, __LINE__, path,
+            "URI::URI - Path String %s must start with a '/'" );
      }
 
      std::string uri = "";
@@ -207,10 +205,35 @@
 
     if( result != APR_SUCCESS ) {
         throw URISyntaxException(
-            __FILE__, __LINE__,
-            "URI::praseURI - URI String %s invalid.",
-            uri.c_str() );
+            __FILE__, __LINE__, uri,
+            "URI::praseURI - URI String %s invalid." );
     }
+
+    std::cout << "\n";
+    std::cout << "Original URI String: " << uri << std::endl;
+    std::cout << "\n";
+    std::cout << "Scheme: "
+              << ( this->uri.scheme ? this->uri.scheme : "" ) << std::endl;
+    std::cout << "Host: "
+              << ( this->uri.hostinfo ? this->uri.hostinfo : "" ) << std::endl;
+    std::cout << "User: "
+              << ( this->uri.user ? this->uri.user : "" ) << std::endl;
+    std::cout << "Passwrod: "
+              << ( this->uri.password ? this->uri.password : "" ) << std::endl;
+    std::cout << "Host Name: "
+              << ( this->uri.hostname ? this->uri.hostname : "" ) << std::endl;
+    std::cout << "Port Str: "
+              << ( this->uri.port_str ? this->uri.port_str : "" ) << std::endl;
+    std::cout << "Path: "
+              << ( this->uri.path ? this->uri.path : "" ) << std::endl;
+    std::cout << "Query: "
+              << ( this->uri.query ? this->uri.query : "" ) << std::endl;
+    std::cout << "Fragment: "
+              << ( this->uri.fragment ? this->uri.fragment : "" ) << std::endl;
+    std::cout << "Port: " << this->uri.port << std::endl;
+    std::cout << "Is Initialized: " << this->uri.is_initialized << std::endl;
+    std::cout << "DNS Looked Up: " << this->uri.dns_looked_up << std::endl;
+    std::cout << "DNS Resolved: " << this->uri.dns_resolved << std::endl;
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URISyntaxException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URISyntaxException.h?view=diff&rev=566185&r1=566184&r2=566185
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URISyntaxException.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URISyntaxException.h Wed Aug 15 07:24:42 2007
@@ -25,48 +25,92 @@
 namespace net{
 
     class DECAF_API URISyntaxException : public lang::Exception {
+    private:
+
+        std::string reason;
+        std::string input;
+        int index;
+
     public:
 
         /**
          * Default Constructor
          */
-        URISyntaxException() throw() {}
+        URISyntaxException() throw() {
+            this->reason = "";
+            this->input = "";
+            this->index = -1;
+        }
 
         /**
          * Conversion Constructor from some other Exception
          * @param An exception that should become this type of Exception
          */
-        URISyntaxException( const Exception& ex ) throw()
-        : Exception()
-        {
+        URISyntaxException( const Exception& ex ) throw() : Exception() {
+
             *(Exception*)this = ex;
+            this->reason = "";
+            this->input = "";
+            this->index = -1;
         }
 
         /**
          * Copy Constructor
          */
-        URISyntaxException( const URISyntaxException& ex ) throw()
-        : Exception()
-        {
+        URISyntaxException( const URISyntaxException& ex ) throw() : Exception() {
+
             *(Exception*)this = ex;
+            this->reason = ex.getReason();
+            this->input = ex.getInput();
+            this->index = ex.getIndex();
         }
 
         /**
          * Constructor - Initializes the file name and line number where
-         * this message occured.  Sets the message to report, using an
-         * optional list of arguments to parse into the message
+         * this message occured.  Sets the input string that caused the error
+         * and the reason for the error.
          * @param file name where exception occurs
          * @param line number where the exception occurred.
-         * @param message to report
+         * @param input uri string
+         * @param reason string for the failure.
          * @param list of primitives that are formatted into the message
          */
         URISyntaxException( const char* file, const int lineNumber,
-                            const char* msg, ... ) throw ()
-        : Exception()
-        {
-            va_list vargs ;
-            va_start( vargs, msg );
-            buildMessage( msg, vargs );
+                            const std::string& input,
+                            const std::string& reason ) throw () : Exception() {
+
+            this->reason = reason;
+            this->input = input;
+            this->index = -1;
+
+            const char * message = "Input: %s, Reason it failed: %s";
+            this->setMessage( message, input.c_str(), reason.c_str() );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the input string that caused the error
+         * and the reason for the error.
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param input uri string
+         * @param reason string for the failure.
+         * @param index in the uri string where the error occured.
+         */
+        URISyntaxException( const char* file, const int lineNumber,
+                            const std::string& input,
+                            const std::string& reason,
+                            int index ) throw () : Exception() {
+
+            this->reason = reason;
+            this->input = input;
+            this->index = index;
+
+            const char * message = "Input: %s, Index %d resulted in this error: %s";
+            this->setMessage( message, input.c_str(), index, reason.c_str() );
 
             // Set the first mark for this exception.
             setMark( file, lineNumber );
@@ -85,6 +129,27 @@
          * Destructor
          */
         virtual ~URISyntaxException() throw() {}
+
+        /**
+         * @returns the Input string that cause this exception or ""
+         */
+        std::string getInput() const {
+            return input;
+        }
+
+        /**
+         * @returns the Reason given for this failure, or ""
+         */
+        std::string getReason() const {
+            return reason;
+        }
+
+        /**
+         * @returns the index in the input string where the error occured or -1
+         */
+        int getIndex() const {
+            return index;
+        }
 
     };