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/03/19 20:39:41 UTC

svn commit: r520060 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/connector/stomp/ main/activemq/core/ test/ test/activemq/connector/stomp/ test/activemq/core/

Author: tabish
Date: Mon Mar 19 12:39:40 2007
New Revision: 520060

URL: http://svn.apache.org/viewvc?view=rev&rev=520060
Log:
Removing ActiveMQDestination and moving its functionality back into StompDestination as that's the only place its used.

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.h   (with props)
Removed:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQDestination.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQDestinationTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQDestinationTest.h
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompDestination.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?view=diff&rev=520060&r1=520059&r2=520060
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Mon Mar 19 12:39:40 2007
@@ -94,7 +94,6 @@
     activemq/core/ActiveMQProducer.h \
     activemq/core/ActiveMQMessage.h \
     activemq/core/ActiveMQConnectionData.h \
-    activemq/core/ActiveMQDestination.h \
     activemq/core/ActiveMQConnection.h \
     activemq/core/ActiveMQTransaction.h \
     activemq/core/ActiveMQConnectionFactory.h \

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompDestination.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompDestination.h?view=diff&rev=520060&r1=520059&r2=520060
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompDestination.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompDestination.h Mon Mar 19 12:39:40 2007
@@ -20,7 +20,11 @@
 
 #include <string>
 
-#include <activemq/core/ActiveMQDestination.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/util/StringTokenizer.h>
+#include <activemq/exceptions/IllegalArgumentException.h>
+
+#include <cms/Destination.h>
 
 namespace activemq{
 namespace connector{
@@ -28,29 +32,89 @@
 
     /**
      * Templatized Destination Class that bundles all the common aspects
-     * of a Stomp Destination into one class.  The template arguement is 
+     * of a Stomp Destination into one class.  The template arguement is
      * one of Topic, Queue, TemporaryTopic, or TemporaryQueue.
      */
     template <typename T>
-    class StompDestination : public core::ActiveMQDestination<T>
+    class StompDestination : public T
     {
+    private:
+
+        // Params that are optional on the destination
+        util::SimpleProperties properties;
+
+        // Destination type
+        cms::Destination::DestinationType destType;
+
+        // Name of the Destination
+        std::string name;
+
     public:
 
         /**
          * Copy Consturctor
          * @param source CMS Dest to Copy, must be a compatible type
          */
-    	StompDestination( const cms::Destination* source ) :
-            core::ActiveMQDestination<T>( source ) {}
-        
+        StompDestination( const cms::Destination* source ) {
+            this->copy( *source );
+        }
+
         /**
          * Custom Constructor
-         * @param name string destination name plus any params
+         * @param dest string destination name plus any params
          * @param type the type of destination this represents.
          */
-    	StompDestination( const std::string& name,
-                          cms::Destination::DestinationType type ) :
-            core::ActiveMQDestination<T>( name, type ){}
+        StompDestination( const std::string& dest,
+                          cms::Destination::DestinationType destType ) {
+            try
+            {
+                util::StringTokenizer tokenizer(dest, "?&");
+                std::vector<std::string> tokens;
+
+                // Set the type, we know that much anyway
+                this->destType = destType;
+
+                // Require that there at least one token, the dest
+                if( tokenizer.countTokens() < 1 )
+                {
+                    throw exceptions::IllegalArgumentException(
+                        __FILE__, __LINE__,
+                        ( std::string(
+                            "ActiveMQDestination::ActiveMQDestination - "
+                            "Marlformed Dest: " ) + dest ).c_str() );
+                }
+
+                // Grab the name, that's always first.
+                this->name = tokenizer.nextToken();
+
+                // Now get all the optional parameters and store them as properties
+                int count = tokenizer.toArray( tokens );
+
+                for( int i = 0; i < count; ++i )
+                {
+                    tokenizer.reset( tokens[i], "=" );
+
+                    if( tokenizer.countTokens() != 2 )
+                    {
+                        throw exceptions::IllegalArgumentException(
+                            __FILE__, __LINE__,
+                            ( std::string(
+                                "ActiveMQDestination::ActiveMQDestination - "
+                                "Marlformed Parameter = ") + tokens[i] ).c_str() );
+                    }
+
+                    // Get the out in the right order
+                    std::string key   = tokenizer.nextToken();
+                    std::string value = tokenizer.nextToken();
+
+                    // Store this param as a property
+                    properties.setProperty( key, value );
+                }
+            }
+            AMQ_CATCH_RETHROW( exceptions::IllegalArgumentException )
+            AMQ_CATCH_EXCEPTION_CONVERT( exceptions::ActiveMQException, exceptions::IllegalArgumentException )
+            AMQ_CATCHALL_THROW( exceptions::IllegalArgumentException )
+        }
 
         virtual ~StompDestination() {}
 
@@ -60,11 +124,85 @@
          * @return name in a format that is used by the broker
          */
         virtual std::string toProviderString() const {
-            return getPrefix() + core::ActiveMQDestination<T>::getName();
+            return getPrefix() + getName();
+        }
+
+        /**
+         * Get the properties of this Destination, these are the optional
+         * params that can be specified on a destination name i.e/
+         * TEST.QUEUE?consumer.dispatchAsync=false&consumer.prefetchSize=10
+         * @returns const reference to a properties object
+         */
+        virtual const util::Properties& getProperties() const {
+            return properties;
+        }
+
+        /**
+         * Copy the contents of the given properties object to this
+         * objects Properties object.  Existing values are erased.
+         * @param properties the Properties to copy to this object.
+         */
+        virtual void setProperties( const util::Properties& properties ){
+            this->properties.copy( &properties );
+        }
+
+        /**
+         * Gets the Destination Name minus any optional params that can
+         * be appended to the destination with an ?
+         * @returns destination name minus params
+         */
+        virtual const std::string& getName() const {
+            return name;
+        }
+
+        /**
+         * Sets the Destination Name minus any optional params that can
+         * be appended to the destination with an ?
+         * @param name destination name minus params
+         */
+        virtual void setName( const std::string& name ) {
+            this->name = name;
+        }
+
+        /**
+         * Retrieve the Destination Type for this Destination
+         * @return The Destination Type
+         */
+        virtual cms::Destination::DestinationType getDestinationType() const {
+            return destType;
+        }
+
+        /**
+         * Set the Destination Type for this Destination
+         * @param destType The Destination Type
+         */
+        virtual void setDestinationType( cms::Destination::DestinationType destType ) {
+            this->destType = destType;
+        }
+
+        /**
+         * Copies the contents of the given Destinastion object to this one.
+         * @param source The source Destination object.
+         */
+        virtual void copy( const cms::Destination& source ) {
+
+            try
+            {
+                // This will throw an Bad Cast Exception if the destination
+                // isn't a compatible type
+                const StompDestination<T>& destination =
+                    dynamic_cast< const StompDestination<T>& >( source );
+
+                this->name = destination.getName();
+                this->destType = destination.getDestinationType();
+
+                this->properties.copy( &destination.getProperties() );
+            }
+            AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
         }
 
     protected:
-    
+
         /**
          * Retrieves the proper Stomp Prefix for the specified type
          * of Destination

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?view=diff&rev=520060&r1=520059&r2=520060
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Mon Mar 19 12:39:40 2007
@@ -64,7 +64,6 @@
   activemq/connector/openwire/commands/BrokerInfoTest.cpp \
   activemq/core/ActiveMQConnectionFactoryTest.cpp \
   activemq/core/ActiveMQConnectionTest.cpp \
-  activemq/core/ActiveMQDestinationTest.cpp \
   activemq/core/ActiveMQSessionTest.cpp \
   activemq/exceptions/ActiveMQExceptionTest.cpp \
   activemq/io/BufferedInputStreamTest.cpp \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.cpp?view=auto&rev=520060
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.cpp Mon Mar 19 12:39:40 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "StompDestinationTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::core::StompDestinationTest );
+
+///////////////////////////////////////////////////////////////////////////////
+void StompDestinationTest::test()
+{
+    MyDestination dest( "test" );
+
+    CPPUNIT_ASSERT( dest.getTopicName() == "test" );
+
+    MyDestination dest1( "test1?value1=1&value2=2" );
+
+    CPPUNIT_ASSERT( dest1.getTopicName() == "test1" );
+    CPPUNIT_ASSERT( dest1.getProperties().hasProperty( "value1" ) == true );
+    CPPUNIT_ASSERT( dest1.getProperties().hasProperty( "value2" ) == true );
+    CPPUNIT_ASSERT( dest1.getProperties().hasProperty( "value3" ) != true );
+
+    std::string value1 = dest1.getProperties().getProperty( "value1" );
+    std::string value2 = dest1.getProperties().getProperty( "value2" );
+
+    CPPUNIT_ASSERT( value1 == "1" );
+    CPPUNIT_ASSERT( value2 == "2" );
+
+    MyDestination* dest2 =
+        dynamic_cast< MyDestination* >( dest1.clone() );
+
+    CPPUNIT_ASSERT( dest2 != NULL );
+
+    CPPUNIT_ASSERT( dest2->getTopicName() == "test1" );
+    CPPUNIT_ASSERT( dest2->getProperties().hasProperty( "value1" ) == true );
+    CPPUNIT_ASSERT( dest2->getProperties().hasProperty( "value2" ) == true );
+    CPPUNIT_ASSERT( dest2->getProperties().hasProperty( "value3" ) != true );
+
+    value1 = dest2->getProperties().getProperty( "value1" );
+    value2 = dest2->getProperties().getProperty( "value2" );
+
+    CPPUNIT_ASSERT( value1 == "1" );
+    CPPUNIT_ASSERT( value2 == "2" );
+
+    delete dest2;
+
+    MyDestination dest3("dummy");
+    dest3.copy( dest1 );
+
+    CPPUNIT_ASSERT( dest3.getTopicName() == "test1" );
+    CPPUNIT_ASSERT( dest3.getProperties().hasProperty( "value1" ) == true );
+    CPPUNIT_ASSERT( dest3.getProperties().hasProperty( "value2" ) == true );
+    CPPUNIT_ASSERT( dest3.getProperties().hasProperty( "value3" ) != true );
+
+    value1 = dest3.getProperties().getProperty( "value1" );
+    value2 = dest3.getProperties().getProperty( "value2" );
+
+    CPPUNIT_ASSERT( value1 == "1" );
+    CPPUNIT_ASSERT( value2 == "2" );
+
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.h?view=auto&rev=520060
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.h Mon Mar 19 12:39:40 2007
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPDESTINATIONTEST_H_
+#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPDESTINATIONTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/connector/stomp/StompDestination.h>
+#include <cms/Topic.h>
+
+namespace activemq{
+namespace core{
+
+    class StompDestinationTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( StompDestinationTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        class MyDestination : public StompDestinationTest< cms::Topic >
+        {
+        public:
+
+            MyDestination( const cms::Destination* dest ) :
+                StompDestinationTest< cms::Topic >( dest ) {}
+
+            MyDestination( const std::string& name )
+                : StompDestinationTest< cms::Topic >( name, cms::Destination::TOPIC )
+            {}
+
+            virtual ~MyDestination() {}
+
+            /**
+             * Converts the Destination Name into a String
+             * @return string name
+             */
+            virtual std::string toString(void) const {
+                return getName();
+            }
+
+            /**
+             * Converts the Destination to a String value representing the
+             * Provider specific name fot this destination, which is not
+             * necessarily equal to the User Supplied name of the Destination
+             * @return Provider specific Name
+             */
+            virtual std::string toProviderString(void) const {
+                return getName();
+            }
+
+            /**
+             * Creates a new instance of this destination type that is a
+             * copy of this one, and returns it.
+             * @returns cloned copy of this object
+             */
+            virtual cms::Destination* clone(void) const {
+                return new MyDestination( this );
+            }
+
+              /**
+             * Gets the name of this topic.
+             * @return The topic name.
+             */
+            virtual std::string getTopicName(void)
+                const throw( cms::CMSException ) { return getName(); }
+
+        };
+
+        StompDestinationTest() {}
+        virtual ~StompDestinationTest() {}
+
+        virtual void test();
+
+    };
+
+}}
+
+#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPDESTINATIONTEST_H_*/

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompDestinationTest.h
------------------------------------------------------------------------------
    svn:eol-style = native