activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r894733 - /activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/
Date Wed, 30 Dec 2009 23:13:20 GMT
Author: tabish
Date: Wed Dec 30 23:13:19 2009
New Revision: 894733

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

Added:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/BrokerIdSourceGenerator.java
  (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdHeaderGenerator.java
  (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdSourceGenerator.java
  (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandSourceGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConnectionIdSourceGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConsumerIdSourceGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdHeaderGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdSourceGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/SessionIdSourceGenerator.java

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/BrokerIdSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/BrokerIdSourceGenerator.java?rev=894733&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/BrokerIdSourceGenerator.java
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/BrokerIdSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.openwire.tool.commands;
+
+import java.io.PrintWriter;
+
+public class BrokerIdSourceGenerator extends CommandSourceGenerator {
+
+    protected void generateToStringBody( PrintWriter out ) {
+        out.println("    return this->value;");
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/BrokerIdSourceGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java
Wed Dec 30 23:13:19 2009
@@ -78,7 +78,7 @@
 
         File headerFile = new File(destDir, className + ".h");
 
-        CommandHeaderGenerator hdrGenerator = generatorsFactory.getHeaderGenerator( className
);
+        CommandCodeGenerator hdrGenerator = generatorsFactory.getHeaderGenerator( className
);
 
         hdrGenerator.setJClass( getJclass() );
         hdrGenerator.setProperties( getProperties() );
@@ -115,7 +115,7 @@
 
         File sourceFile = new File(destDir, className + ".cpp");
 
-        CommandSourceGenerator srcGenerator = generatorsFactory.getSourceGenerator( className
);
+        CommandCodeGenerator srcGenerator = generatorsFactory.getSourceGenerator( className
);
 
         srcGenerator.setJClass( getJclass() );
         srcGenerator.setProperties( getProperties() );

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java
Wed Dec 30 23:13:19 2009
@@ -64,25 +64,11 @@
      *
      * @return a new Header File code generator.
      */
-    public CommandHeaderGenerator getHeaderGenerator( String className ) {
+    public CommandCodeGenerator getHeaderGenerator( String className ) {
 
-        CommandHeaderGenerator generator = null;
-        if( className.equals("Message") ) {
-            generator = new MessageHeaderGenerator();
-        } else if( className.equals("ConnectionId") ) {
-            generator = new ConnectionIdHeaderGenerator();
-        } else if( className.equals("ConsumerId") ) {
-            generator = new ConsumerIdHeaderGenerator();
-        } else if( className.equals("ProducerId") ) {
-            generator = new ProducerIdHeaderGenerator();
-        } else if( className.equals("SessionId") ) {
-            generator = new SessionIdHeaderGenerator();
-        } else if( className.equals("SessionInfo") ) {
-            generator = new SessionInfoHeaderGenerator();
-        } else {
-            generator = new CommandHeaderGenerator();
-        }
+        CommandCodeGenerator generator = null;
 
+        generator = this.getCodeGenerator( className, "Header" );
         if( className.endsWith("Id") ) {
             generator.setComparable( true );
             generator.setAssignable( true );
@@ -103,25 +89,11 @@
      *
      * @return a new Source File code generator.
      */
-    public CommandSourceGenerator getSourceGenerator( String className ) {
+    public CommandCodeGenerator getSourceGenerator( String className ) {
 
-        CommandSourceGenerator generator = null;
-        if( className.equals("Message") ) {
-            generator = new MessageSourceGenerator();
-        } else if( className.equals("ConnectionId") ) {
-            generator = new ConnectionIdSourceGenerator();
-        } else if( className.equals("ConsumerId") ) {
-            generator = new ConsumerIdSourceGenerator();
-        } else if( className.equals("ProducerId") ) {
-            generator = new ProducerIdSourceGenerator();
-        } else if( className.equals("SessionId") ) {
-            generator = new SessionIdSourceGenerator();
-        } else if( className.equals("SessionInfo") ) {
-            generator = new SessionInfoSourceGenerator();
-        } else {
-            generator = new CommandSourceGenerator();
-        }
+        CommandCodeGenerator generator = null;
 
+        generator = this.getCodeGenerator( className, "Source" );
         if( className.endsWith("Id") ) {
             generator.setComparable( true );
             generator.setAssignable( true );
@@ -130,4 +102,41 @@
         return generator;
     }
 
+    /**
+     * Given a class name return an instance of a CSharp Class File Generator
+     * that can generate the file for the Class.
+     *
+     * @param className - name of the class to find the generator for
+     * @param fileType - type identifier for the generator, either "Source" or "Header"
+     *
+     * @return a new Header File code generator.
+     */
+    public CommandCodeGenerator getCodeGenerator( String className, String fileType ) {
+
+        Class<?> generatorClass = null;
+
+        try {
+            generatorClass = Class.forName( "org.apache.activemq.openwire.tool.commands."
+ className + fileType + "Generator" );
+        } catch( ClassNotFoundException e ) {
+            try {
+                generatorClass = Class.forName( "org.apache.activemq.openwire.tool.commands.Command"
+ fileType + "Generator" );
+            } catch(ClassNotFoundException e1) {
+                e1.printStackTrace();
+                return null;
+            }
+        }
+
+        CommandCodeGenerator generator;
+        try {
+            generator = (CommandCodeGenerator) generatorClass.newInstance();
+        } catch (InstantiationException e) {
+            e.printStackTrace();
+            return null;
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+            return null;
+        }
+
+        return generator;
+    }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandSourceGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandSourceGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -108,17 +108,7 @@
         out.println("////////////////////////////////////////////////////////////////////////////////");
         out.println("std::string "+getClassName()+"::toString() const {");
         out.println("");
-        out.println("    ostringstream stream;" );
-        out.println("");
-        out.println("    stream << \"Begin Class = "+getClassName()+"\" << std::endl;"
);
-        out.println("    stream << \" Value of "+getClassName()+"::ID_" + getClassName().toUpperCase()
+ " = "+getOpenWireOpCode()+"\" << std::endl;");
         generateToStringBody(out);
-        if( getBaseClassName() != null ) {
-            out.println("    stream << "+ getBaseClassName() +"::toString();");
-        }
-        out.println("    stream << \"End Class = "+getClassName()+"\" << std::endl;"
);
-        out.println("");
-        out.println("    return stream.str();");
         out.println("}");
         out.println("");
         out.println("////////////////////////////////////////////////////////////////////////////////");
@@ -246,48 +236,98 @@
     }
 
     protected void generateToStringBody( PrintWriter out ) {
+
+        out.println("    ostringstream stream;" );
+        out.println("");
+
+        if( getBaseClassName().equals( "BaseCommand" ) ) {
+            out.println("    stream << \""+getClassName()+" { \"" );
+            out.println("           << \"commandId = \" << this->getCommandId()
<< \", \"");
+            out.println("           << \"responseRequired = \" << boolalpha <<
this->isResponseRequired();");
+
+            if( getProperties().size() > 0 ) {
+                out.println("    stream << \", \";");
+            }
+        } else {
+            out.println("    stream << \""+getClassName()+" { \";" );
+        }
+
+        int length = getProperties().size();
+        int count = 0;
+
         for( JProperty property : getProperties() ) {
+
             String type = toCppType(property.getType());
             String propertyName = property.getSimpleName();
             String parameterName = decapitalize(propertyName);
             String getter = property.getGetter().getSimpleName();
 
             if( property.getType().getSimpleName().equals("ByteSequence") ) {
-                out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName
+ " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
-                out.println("        stream << \" Value of "+propertyName+"[\" <<
i" + parameterName+" << \"] = \" << this->"+getter+"()[i"+parameterName+"]
<< std::endl;" );
-                out.println("    }" );
+
+                out.println("    stream << \""+propertyName+" = \";");
+                out.println("    if( this->"+getter+"().size() > 0 ) {");
+                out.println("        stream << \"[size=\" << this->" + getter
+ "().size() << \"]\";");
+                out.println("    } else {");
+                out.println("        stream << \"NULL\";");
+                out.println("    }");
+
             } else if( type.equals("unsigned char") ){
-                out.println("    stream << \" Value of "+propertyName+" = \" <<
(int)this->"+getter+"() << std::endl;");
-            } else if( property.getType().isPrimitiveType() ||
-                       type.equals("std::string") ){
+                out.println("    stream << \""+propertyName+" = \" << (int)this->"+getter+"();");
+
+            } else if( property.getType().isPrimitiveType() || type.equals("std::string")
){
+
+                out.println("    stream << \""+propertyName+" = \" << this->"+getter+"();");
 
-                out.println("    stream << \" Value of "+propertyName+" = \" <<
this->"+getter+"() << std::endl;");
             } else if( property.getType().isArrayType() &&
                        !property.getType().getArrayComponentType().isPrimitiveType() ) {
 
-                out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName
+ " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
-                out.println("        stream << \" Value of "+propertyName+"[\" <<
i" + parameterName+" << \"] is Below:\" << std::endl;" );
-                out.println("        if( this->"+getter+"()[i"+parameterName+"] != NULL
) {");
-                out.println("            stream << this->"+getter+"()[i"+parameterName+"]->toString()
<< std::endl;");
-                out.println("        } else {");
-                out.println("            stream << \"   Object is NULL\" << std::endl;");
+                out.println("    stream << \""+propertyName+" = \";");
+                out.println("    if( this->"+getter+"().size() > 0 ) {");
+                out.println("        stream << \"[\";");
+                out.println("        for( size_t i" + parameterName + " = 0; i" + parameterName
+ " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
+                out.println("            if( this->"+getter+"()[i"+parameterName+"] !=
NULL ) {");
+                out.println("                stream << this->"+getter+"()[i"+parameterName+"]->toString()
<< \", \";");
+                out.println("            } else {");
+                out.println("                stream << \"NULL\" << \", \";");
+                out.println("            }");
                 out.println("        }");
+                out.println("        stream << \"]\";");
+                out.println("    } else {");
+                out.println("        stream << \"NULL\";");
                 out.println("    }");
+
             } else if( property.getType().isArrayType() &&
                        property.getType().getArrayComponentType().isPrimitiveType() ) {
 
-                out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName
+ " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
-                out.println("        stream << \" Value of "+propertyName+"[\" <<
i"+parameterName+" << \"] = \" << this->"+getter+"()[i"+parameterName+"] <<
std::endl;");
+                out.println("    stream << \""+propertyName+" = \";");
+                out.println("    if( this->"+getter+"().size() > 0 ) {");
+                out.println("        stream << \"[\";");
+                out.println("        for( size_t i" + parameterName + " = 0; i" + parameterName
+ " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
+                out.println("            stream << this->"+getter+"()[i"+parameterName+"]
<< \",\";");
+                out.println("        }");
+                out.println("        stream << \"]\";");
+                out.println("    } else {");
+                out.println("        stream << \"NULL\";");
                 out.println("    }");
+
             } else {
-                out.println("    stream << \" Value of "+propertyName+" is Below:\"
<< std::endl;" );
+
+                out.println("    stream << \""+propertyName+" = \";" );
                 out.println("    if( this->"+getter+"() != NULL ) {");
-                out.println("        stream << this->"+getter+"()->toString()
<< std::endl;");
+                out.println("        stream << this->"+getter+"()->toString();");
                 out.println("    } else {");
-                out.println("        stream << \"   Object is NULL\" << std::endl;");
+                out.println("        stream << \"NULL\";");
                 out.println("    }");
             }
+
+            if( ++count < length ) {
+                out.println("    stream << \", \";");
+            }
         }
+
+        out.println("    stream << \" }\";" );
+        out.println("");
+        out.println("    return stream.str();");
     }
 
     protected void generateEqualsBody( PrintWriter out ) {

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConnectionIdSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConnectionIdSourceGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConnectionIdSourceGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConnectionIdSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -49,4 +49,8 @@
 
         super.generateAdditionalConstructors(out);
     }
+
+    protected void generateToStringBody( PrintWriter out ) {
+        out.println("    return this->value;");
+    }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConsumerIdSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConsumerIdSourceGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConsumerIdSourceGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ConsumerIdSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -17,6 +17,7 @@
 package org.apache.activemq.openwire.tool.commands;
 
 import java.io.PrintWriter;
+import java.util.Set;
 
 public class ConsumerIdSourceGenerator extends CommandSourceGenerator {
 
@@ -33,4 +34,22 @@
         super.generateAdditionalMethods(out);
     }
 
+    protected void populateIncludeFilesSet() {
+
+        super.populateIncludeFilesSet();
+
+        Set<String> includes = getIncludeFiles();
+        includes.add("<sstream>");
+    }
+
+    protected void generateToStringBody( PrintWriter out ) {
+        out.println("    ostringstream stream;" );
+        out.println("");
+        out.println("    stream << this->connectionId << \":\"");
+        out.println("           << this->sessionId << \":\"");
+        out.println("           << this->value;");
+        out.println("");
+        out.println("    return stream.str();");
+    }
+
 }

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdHeaderGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdHeaderGenerator.java?rev=894733&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdHeaderGenerator.java
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdHeaderGenerator.java
Wed Dec 30 23:13:19 2009
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.openwire.tool.commands;
+
+import java.io.PrintWriter;
+import java.util.Set;
+
+public class MessageIdHeaderGenerator extends CommandHeaderGenerator {
+
+    protected void populateIncludeFilesSet() {
+        Set<String> includes = getIncludeFiles();
+        includes.add("<activemq/commands/ProducerInfo.h>");
+        includes.add("<activemq/commands/ProducerId.h>");
+
+        super.populateIncludeFilesSet();
+    }
+
+    protected void generateAdditionalConstructors( PrintWriter out ) {
+
+        out.println("        "+getClassName()+"( const std::string& messageKey );");
+        out.println("");
+        out.println("        "+getClassName()+"( const Pointer<ProducerInfo>& producerInfo,
long long producerSequenceId );");
+        out.println("");
+        out.println("        "+getClassName()+"( const Pointer<ProducerId>& producerId,
long long producerSequenceId );");
+        out.println("");
+        out.println("        "+getClassName()+"( const std::string& producerId, long
long producerSequenceId );");
+        out.println("");
+
+        super.generateAdditionalConstructors(out);
+    }
+
+    protected void generateProperties( PrintWriter out ) {
+
+        out.println("    private:");
+        out.println("");
+        out.println("        mutable std::string key;");
+        out.println("");
+
+        super.generateProperties(out);
+    }
+
+    protected void generateAdditonalMembers( PrintWriter out ) {
+        out.println("        void setValue( const std::string& key );");
+        out.println("");
+        out.println("        void setTextView( const std::string& key );");
+        out.println("");
+
+        super.generateAdditonalMembers( out );
+    }
+
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdHeaderGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdSourceGenerator.java?rev=894733&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdSourceGenerator.java
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -0,0 +1,100 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.openwire.tool.commands;
+
+import java.io.PrintWriter;
+import java.util.Set;
+
+public class MessageIdSourceGenerator extends CommandSourceGenerator {
+
+    protected void generateAdditionalConstructors( PrintWriter out ) {
+
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("MessageId::MessageId( const std::string& messageKey ) {");
+        out.println("    this->setValue( messageKey );");
+        out.println("}");
+        out.println("");
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("MessageId::MessageId( const Pointer<ProducerInfo>& producerInfo,
long long producerSequenceId ) {");
+        out.println("    this->producerId = producerInfo->getProducerId();");
+        out.println("    this->producerSequenceId = producerSequenceId;");
+        out.println("}");
+        out.println("");
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("MessageId::MessageId( const Pointer<ProducerId>& producerId,
long long producerSequenceId ) {");
+        out.println("    this->producerId = producerId;");
+        out.println("    this->producerSequenceId = producerSequenceId;");
+        out.println("}");
+        out.println("");
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("MessageId::MessageId( const std::string& producerId, long long producerSequenceId
) {");
+        out.println("    this->producerId.reset( new ProducerId( producerId ) );");
+        out.println("    this->producerSequenceId = producerSequenceId;");
+        out.println("}");
+        out.println("");
+
+        super.generateAdditionalConstructors(out);
+    }
+
+    protected void generateAdditionalMethods( PrintWriter out ) {
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("void MessageId::setValue( const std::string& key ) {");
+        out.println("");
+        out.println("    std::string messageKey = key;");
+        out.println("");
+        out.println("    // Parse off the sequenceId");
+        out.println("    std::size_t p = messageKey.rfind( ':' );");
+        out.println("");
+        out.println("    if( p != std::string::npos ) {");
+        out.println("        producerSequenceId = Long::parseLong( messageKey.substr( p +
1, std::string::npos ) );");
+        out.println("        messageKey = messageKey.substr( 0, p );");
+        out.println("    }");
+        out.println("");
+        out.println("    this->producerId.reset( new ProducerId( messageKey ) );");
+        out.println("    this->key = messageKey;");
+        out.println("}");
+        out.println("");
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("void MessageId::setTextView( const std::string& key ) {");
+        out.println("    this->key = key;");
+        out.println("}");
+        out.println("");
+
+        super.generateAdditionalMethods(out);
+    }
+
+    protected void populateIncludeFilesSet() {
+
+        super.populateIncludeFilesSet();
+
+        Set<String> includes = getIncludeFiles();
+        includes.add("<decaf/lang/Long.h>");
+        includes.add("<sstream>");
+    }
+
+    protected void generateToStringBody( PrintWriter out ) {
+        out.println("");
+        out.println("    if( key == \"\" ) {");
+        out.println("        this->key = this->producerId->toString() + \":\" +
");
+        out.println("                    Long::toString( this->producerSequenceId ) +
\":\" + ");
+        out.println("                    Long::toString( this->brokerSequenceId );");
+        out.println("    }");
+        out.println("");
+        out.println("    return this->key;");
+    }
+
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageIdSourceGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdHeaderGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdHeaderGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdHeaderGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdHeaderGenerator.java
Wed Dec 30 23:13:19 2009
@@ -29,11 +29,9 @@
     }
 
     protected void generateAdditionalConstructors( PrintWriter out ) {
-        out.println("        "+getClassName()+"( const SessionId& sessionId, long long
consumerId ) {");
-        out.println("            this->connectionId = sessionId.getConnectionId();");
-        out.println("            this->sessionId = sessionId.getValue();");
-        out.println("            this->value = consumerId;");
-        out.println("        }");
+        out.println("        "+getClassName()+"( const SessionId& sessionId, long long
consumerId );");
+        out.println("");
+        out.println("        "+getClassName()+"( std::string producerId );");
         out.println("");
 
         super.generateAdditionalConstructors(out);
@@ -52,6 +50,8 @@
     protected void generateAdditonalMembers( PrintWriter out ) {
         out.println("        const Pointer<SessionId>& getParentId() const;");
         out.println("");
+        out.println("        void setProducerSessionKey( std::string sessionKey );");
+        out.println("");
 
         super.generateAdditonalMembers( out );
     }

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdSourceGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdSourceGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ProducerIdSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -17,9 +17,37 @@
 package org.apache.activemq.openwire.tool.commands;
 
 import java.io.PrintWriter;
+import java.util.Set;
 
 public class ProducerIdSourceGenerator extends CommandSourceGenerator {
 
+    protected void generateAdditionalConstructors( PrintWriter out ) {
+
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("ProducerId::ProducerId( const SessionId& sessionId, long long consumerId
) {");
+        out.println("    this->connectionId = sessionId.getConnectionId();");
+        out.println("    this->sessionId = sessionId.getValue();");
+        out.println("    this->value = consumerId;");
+        out.println("}");
+        out.println("");
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("ProducerId::ProducerId( std::string producerKey ) {");
+        out.println("");
+        out.println("    // Parse off the producerId");
+        out.println("    std::size_t p = producerKey.rfind( ':' );");
+        out.println("");
+        out.println("    if( p != std::string::npos ) {");
+        out.println("        value = Long::parseLong( producerKey.substr( p + 1, std::string::npos
) );");
+        out.println("        producerKey = producerKey.substr( 0, p );");
+        out.println("    }");
+        out.println("");
+        out.println("    setProducerSessionKey( producerKey );");
+        out.println("}");
+        out.println("");
+
+        super.generateAdditionalConstructors(out);
+    }
+
     protected void generateAdditionalMethods( PrintWriter out ) {
         out.println("////////////////////////////////////////////////////////////////////////////////");
         out.println("const Pointer<SessionId>& ProducerId::getParentId() const
{");
@@ -29,8 +57,40 @@
         out.println("    return this->parentId;");
         out.println("}");
         out.println("");
+        out.println("////////////////////////////////////////////////////////////////////////////////");
+        out.println("void ProducerId::setProducerSessionKey( std::string sessionKey ) {");
+        out.println("");
+        out.println("    // Parse off the value");
+        out.println("    std::size_t p = sessionKey.rfind( ':' );");
+        out.println("");
+        out.println("    if( p != std::string::npos ) {");
+        out.println("        this->sessionId = Long::parseLong( sessionKey.substr( p +
1, std::string::npos ) );");
+        out.println("        sessionKey = sessionKey.substr( 0, p );");
+        out.println("    }");
+        out.println("");
+        out.println("    // The rest is the value");
+        out.println("    this->connectionId = sessionKey;");
+        out.println("}");
 
         super.generateAdditionalMethods(out);
     }
 
+    protected void populateIncludeFilesSet() {
+
+        super.populateIncludeFilesSet();
+
+        Set<String> includes = getIncludeFiles();
+        includes.add("<decaf/lang/Long.h>");
+        includes.add("<sstream>");
+    }
+
+    protected void generateToStringBody( PrintWriter out ) {
+        out.println("    ostringstream stream;" );
+        out.println("");
+        out.println("    stream << this->connectionId << \":\"");
+        out.println("           << this->sessionId << \":\"");
+        out.println("           << this->value;");
+        out.println("");
+        out.println("    return stream.str();");
+    }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/SessionIdSourceGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/SessionIdSourceGenerator.java?rev=894733&r1=894732&r2=894733&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/SessionIdSourceGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/SessionIdSourceGenerator.java
Wed Dec 30 23:13:19 2009
@@ -26,10 +26,19 @@
         includes.add("<activemq/commands/ProducerId.h>");
         includes.add("<activemq/commands/ConsumerId.h>");
         includes.add("<activemq/commands/ConnectionId.h>");
+        includes.add("<sstream>");
 
         super.populateIncludeFilesSet();
     }
 
+    protected void generateToStringBody( PrintWriter out ) {
+        out.println("    ostringstream stream;" );
+        out.println("");
+        out.println("    stream << this->connectionId << \":\" << this->value;");
+        out.println("");
+        out.println("    return stream.str();");
+    }
+
     protected void generateAdditionalConstructors( PrintWriter out ) {
 
         out.println("////////////////////////////////////////////////////////////////////////////////");



Mime
View raw message