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 2009/02/12 21:08:19 UTC

svn commit: r743861 - in /activemq/activemq-cpp/trunk/src/main: activemq/commands/ java/org/apache/activemq/openwire/tool/

Author: tabish
Date: Thu Feb 12 20:08:18 2009
New Revision: 743861

URL: http://svn.apache.org/viewvc?rev=743861&view=rev
Log:
Adds generated isXXX methods to highly used commands to reduce the number of casts needed thought the CPP code.

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/commands/BaseCommand.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Command.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/WireFormatInfo.h
    activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/BaseCommand.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/BaseCommand.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/BaseCommand.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/BaseCommand.h Thu Feb 12 20:08:18 2009
@@ -112,6 +112,34 @@
             return BaseDataStructure::equals( value );
         }
 
+        virtual bool isResponse() const {
+            return false;
+        }
+        virtual bool isMessageDispatch() const  {
+            return false;
+        }
+        virtual bool isBrokerInfo() const  {
+            return false;
+        }
+        virtual bool isWireFormatInfo() const  {
+            return false;
+        }
+        virtual bool isMessage() const  {
+            return false;
+        }
+        virtual bool isMessageAck() const  {
+            return false;
+        }
+        virtual bool isProducerAck() const  {
+            return false;
+        }
+        virtual bool isMessageDispatchNotification() const  {
+            return false;
+        }
+        virtual bool isShutdownInfo() const  {
+            return false;
+        }
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.h Thu Feb 12 20:08:18 2009
@@ -111,6 +111,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isBrokerInfo() query.
+         */
+        virtual bool isBrokerInfo() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/Command.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/Command.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/Command.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/Command.h Thu Feb 12 20:08:18 2009
@@ -75,6 +75,21 @@
         virtual decaf::lang::Pointer<commands::Command> visit(
             activemq::state::CommandVisitor* visitor ) throw( exceptions::ActiveMQException ) = 0;
 
+        /*
+         * This section contains a set of short-cut methods for determining if a
+         * Command is of a certain type.  These are the most commonly used Commands
+         * and we save several casts and some ugly code by just adding these here.
+         */
+        virtual bool isResponse() const = 0;
+        virtual bool isMessageDispatch() const = 0;
+        virtual bool isBrokerInfo() const = 0;
+        virtual bool isWireFormatInfo() const = 0;
+        virtual bool isMessage() const = 0;
+        virtual bool isMessageAck() const = 0;
+        virtual bool isProducerAck() const = 0;
+        virtual bool isMessageDispatchNotification() const = 0;
+        virtual bool isShutdownInfo() const = 0;
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h Thu Feb 12 20:08:18 2009
@@ -150,6 +150,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isMessage() query.
+         */
+        virtual bool isMessage() const {
+            return true;
+        }
+
+        /**
          * Handles the marshaling of the objects properties into the
          * internal byte array before the object is marshaled to the
          * wire

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.h Thu Feb 12 20:08:18 2009
@@ -108,6 +108,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isMessageAck() query.
+         */
+        virtual bool isMessageAck() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.h Thu Feb 12 20:08:18 2009
@@ -104,6 +104,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isMessageDispatch() query.
+         */
+        virtual bool isMessageDispatch() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.h Thu Feb 12 20:08:18 2009
@@ -104,6 +104,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isMessageDispatchNotification() query.
+         */
+        virtual bool isMessageDispatchNotification() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.h Thu Feb 12 20:08:18 2009
@@ -100,6 +100,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isProducerAck() query.
+         */
+        virtual bool isProducerAck() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.h Thu Feb 12 20:08:18 2009
@@ -98,6 +98,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isResponse() query.
+         */
+        virtual bool isResponse() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.h Thu Feb 12 20:08:18 2009
@@ -97,6 +97,13 @@
         virtual bool equals( const DataStructure* value ) const;
 
         /**
+         * @return an answer of true to the isShutdownInfo() query.
+         */
+        virtual bool isShutdownInfo() const {
+            return true;
+        }
+
+        /**
          * Allows a Visitor to visit this command and return a response to the
          * command based on the command type being visited.  The command will call
          * the proper processXXX method in the visitor.

Modified: activemq/activemq-cpp/trunk/src/main/activemq/commands/WireFormatInfo.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/commands/WireFormatInfo.h?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/commands/WireFormatInfo.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/commands/WireFormatInfo.h Thu Feb 12 20:08:18 2009
@@ -243,6 +243,13 @@
          */
         bool isValid() const;
 
+        /**
+         * @returns answers true to the isWireFormatInfo query
+         */
+        virtual bool isWireFormatInfo() const {
+            return true;
+        }
+
     public:
 
         /**

Modified: activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java?rev=743861&r1=743860&r2=743861&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java (original)
+++ activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java Thu Feb 12 20:08:18 2009
@@ -33,6 +33,40 @@
  */
 public class AmqCppHeadersGenerator extends AmqCppClassesGenerator {
 
+    private Set<String> commandsWithShortcuts;
+
+    /*
+     * Here we store all Commands that need to have a isXXX method generated
+     * such as isMessage.  We then check in the <code>checkNeedsShortcut</code>
+     * method and if the Command being generated is in this list we create a
+     * method call to override the virtual method in the base Command interface.
+     */
+    {
+        commandsWithShortcuts = new HashSet<String>();
+        commandsWithShortcuts.add( "Response" );
+        commandsWithShortcuts.add( "MessageDispatch" );
+        commandsWithShortcuts.add( "BrokerInfo" );
+        commandsWithShortcuts.add( "WireFormatInfo" );
+        commandsWithShortcuts.add( "Message" );
+        commandsWithShortcuts.add( "MessageAck" );
+        commandsWithShortcuts.add( "ProducerAck" );
+        commandsWithShortcuts.add( "MessageDispatchNotification" );
+        commandsWithShortcuts.add( "ShutdownInfo" );
+    }
+
+    protected void checkNeedsShortcut( String className, PrintWriter out ) {
+
+        if( this.commandsWithShortcuts.contains( className ) ) {
+            out.println("        /**");
+            out.println("         * @return an answer of true to the is"+className+"() query.");
+            out.println("         */");
+            out.println("        virtual bool is"+className+"() const {");
+            out.println("            return true;");
+            out.println("        }");
+            out.println("");
+        }
+    }
+
     protected String getFilePostFix() {
         return ".h";
     }
@@ -215,6 +249,9 @@
 out.println("        virtual bool equals( const DataStructure* value ) const;" );
 out.println("");
 
+        // Check if a isXXX object shorcut should be generated and add it if so.
+        checkNeedsShortcut( className, out );
+
         if( className.equals( "Message" ) ) {
 
 out.println("        /**");