activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r747816 [1/5] - in /activemq/activemq-cpp/trunk: activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/ activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/ activemq-cpp-openwir...
Date Wed, 25 Feb 2009 15:23:51 GMT
Author: tabish
Date: Wed Feb 25 15:23:48 2009
New Revision: 747816

URL: http://svn.apache.org/viewvc?rev=747816&view=rev
Log:
Refactored OpenWire Command generator code that allows for overrides of code generation for specific commands that need changes or additional methods that aren't part of the Transmitted command but are need for internal use by the CPP client.  

Added:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java
      - copied, changed from r747057, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandHeaderGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandSourceGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageHeaderGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/MessageSourceGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/makefiles/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/makefiles/AmqCppMakefileGenerator.java
      - copied, changed from r746846, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java
      - copied, changed from r746846, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingHeadersGenerator.java
      - copied, changed from r746846, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/tests/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/tests/AmqCppTestMarshallingClassesGenerator.java
      - copied, changed from r746846, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/tests/AmqCppTestMarshallingHeadersGenerator.java
      - copied, changed from r746846, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java
Removed:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java
    activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/BrokerInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionControl.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionControl.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionError.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionError.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConnectionInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConsumerControl.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConsumerControl.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConsumerId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConsumerId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConsumerInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ConsumerInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ControlCommand.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ControlCommand.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DataArrayResponse.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DataArrayResponse.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DataResponse.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DataResponse.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DestinationInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DestinationInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DiscoveryEvent.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/DiscoveryEvent.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ExceptionResponse.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ExceptionResponse.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/FlushCommand.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/FlushCommand.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/IntegerResponse.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/IntegerResponse.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalQueueAck.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalQueueAck.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalTopicAck.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalTopicAck.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalTrace.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalTrace.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalTransaction.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/JournalTransaction.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/KeepAliveInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/KeepAliveInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/LastPartialCommand.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/LastPartialCommand.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/LocalTransactionId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/LocalTransactionId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Message.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageAck.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatch.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageDispatchNotification.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessageId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessagePull.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/MessagePull.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/NetworkBridgeFilter.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/NetworkBridgeFilter.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/PartialCommand.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/PartialCommand.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerAck.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ProducerInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/RemoveInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/RemoveInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/RemoveSubscriptionInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/RemoveSubscriptionInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ReplayCommand.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ReplayCommand.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/Response.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/SessionId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/SessionId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/SessionInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/SessionInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/ShutdownInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/SubscriptionInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/SubscriptionInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/TransactionId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/TransactionId.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/TransactionInfo.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/TransactionInfo.h
    activemq/activemq-cpp/trunk/src/main/activemq/commands/XATransactionId.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/commands/XATransactionId.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java?rev=747816&r1=747815&r2=747816&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java Wed Feb 25 15:23:48 2009
@@ -19,6 +19,12 @@
 
 import java.io.File;
 
+import org.apache.activemq.openwire.tool.commands.CommandClassGenerator;
+import org.apache.activemq.openwire.tool.makefiles.AmqCppMakefileGenerator;
+import org.apache.activemq.openwire.tool.marshallers.AmqCppMarshallingClassesGenerator;
+import org.apache.activemq.openwire.tool.marshallers.AmqCppMarshallingHeadersGenerator;
+import org.apache.activemq.openwire.tool.tests.AmqCppTestMarshallingClassesGenerator;
+import org.apache.activemq.openwire.tool.tests.AmqCppTestMarshallingHeadersGenerator;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
@@ -75,14 +81,7 @@
             JamService jam = jamServiceFactory.createService(params);
 
             {
-                AmqCppClassesGenerator script = new AmqCppClassesGenerator();
-                script.setJam(jam);
-                script.setTargetDir(target+"/src/main");
-                script.setOpenwireVersion(maxVersion);
-                script.run();
-            }
-            {
-                AmqCppHeadersGenerator script = new AmqCppHeadersGenerator();
+                CommandClassGenerator script = new CommandClassGenerator();
                 script.setJam(jam);
                 script.setTargetDir(target+"/src/main");
                 script.setOpenwireVersion(maxVersion);

Copied: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java (from r747057, activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.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?p2=activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java&p1=activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java&r1=747057&r2=747816&rev=747816&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandClassGenerator.java Wed Feb 25 15:23:48 2009
@@ -14,649 +14,143 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.openwire.tool;
+package org.apache.activemq.openwire.tool.commands;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.List;
 
+import org.apache.activemq.openwire.tool.MultiSourceGenerator;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.FixCRLF;
 import org.codehaus.jam.JClass;
-import org.codehaus.jam.JProperty;
 
 /**
  *
  * @version $Revision: 409828 $
  */
-public class AmqCppClassesGenerator extends MultiSourceGenerator {
+public class CommandClassGenerator extends MultiSourceGenerator {
 
-    protected String targetDir="./src/main";
-
-    protected void processClass(JClass jclass) {
-        super.processClass( jclass );
-    }
-
-    public Object run() {
-        filePostFix = getFilePostFix();
-        if (destDir == null) {
-            destDir = new File(
-                targetDir+"/activemq/commands");
-        }
-
-        return super.run();
-    }
-
-    protected String getFilePostFix() {
-        return ".cpp";
-    }
-
-    public String toHeaderFileName( JClass type ) {
-        String name = type.getSimpleName();
+    private CommandCodeGeneratorsFactory generatorsFactory =
+        new CommandCodeGeneratorsFactory();
 
-        if( name.equals( "String" ) ) {
-            return null;
-        } else if( type.isArrayType() ) {
-            JClass arrayClass = type.getArrayComponentType();
-            return toHeaderFileName( arrayClass );
-        } else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) {
-            return "BrokerError";
-        } else if( name.equals("BaseDataStructure" ) ){
-            return "DataStructure";
-        } else if( name.equals("ByteSequence") ) {
-            return "std::vector<unsigned char>";
-        } else if( !type.isPrimitiveType() ) {
-            return name;
-        } else {
-            return null;
-        }
-    }
-
-    public String toCppType(JClass type) {
-        String name = type.getSimpleName();
-        if (name.equals("String")) {
-            return "std::string";
-        }
-        else if( type.isArrayType() ) {
-            if( name.equals( "byte[]" ) )
-                name = "unsigned char[]";
-
-            JClass arrayClass = type.getArrayComponentType();
-
-            if( arrayClass.isPrimitiveType() ) {
-                return "std::vector<" + name.substring( 0, name.length()-2 ) + ">";
-            } else {
-                return "std::vector< decaf::lang::Pointer<" +
-                       name.substring( 0, name.length()-2 ) + "> >";
-            }
-        }
-        else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) {
-            return "BrokerError";
-        }
-        else if( name.equals("BaseDataStructure" ) ){
-            return "DataStructure";
-        }
-        else if( name.equals("ByteSequence") ) {
-            return "std::vector<unsigned char>";
-        }
-        else if( name.equals("boolean") ) {
-            return "bool";
-        }
-        else if( name.equals("long") ) {
-            return "long long";
-        }
-        else if( name.equals("byte") ) {
-            return "unsigned char";
-        }
-        else if( !type.isPrimitiveType() ) {
-            return name;
-        }
-        else {
-            return name;
-        }
-    }
+    protected String targetDir="./src/main";
 
-    /**
-     * Converts the Java type to a C++ default value
-     */
-    public String toCppDefaultValue(JClass type) {
-        String name = type.getSimpleName();
-
-        if (name.equals("boolean")) {
-            return "false";
-        } else if( name.equals("String") ) {
-            return "\"\"";
-        } else if( !type.isPrimitiveType() ) {
-            return "NULL";
-        } else {
-            return "0";
-        }
+    public String getTargetDir() {
+        return targetDir;
     }
 
-    protected void generateLicence(PrintWriter out) {
-out.println("/*");
-out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
-out.println(" * contributor license agreements.  See the NOTICE file distributed with");
-out.println(" * this work for additional information regarding copyright ownership.");
-out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
-out.println(" * (the \"License\"); you may not use this file except in compliance with");
-out.println(" * the License.  You may obtain a copy of the License at");
-out.println(" *");
-out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
-out.println(" *");
-out.println(" * Unless required by applicable law or agreed to in writing, software");
-out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
-out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
-out.println(" * See the License for the specific language governing permissions and");
-out.println(" * limitations under the License.");
-out.println(" */");
+    public void setTargetDir(String targetDir) {
+        this.targetDir = targetDir;
     }
 
-    protected void generateFile(PrintWriter out) throws Exception {
-        generateLicence(out);
-
-        boolean comparable = className.endsWith("Id");
-        boolean assignable = className.endsWith("Id");
-
-out.println("#include <activemq/commands/"+className+".h>");
-out.println("#include <activemq/state/CommandVisitor.h>");
-out.println("#include <activemq/exceptions/ActiveMQException.h>");
-out.println("#include <decaf/lang/exceptions/NullPointerException.h>");
-
-        if( className.equals( "Message" ) ) {
-out.println("#include <activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.h>");
-out.println("#include <activemq/wireformat/openwire/marshal/PrimitiveMapMarshaller.h>");
-        }
-
-        if( comparable ) {
-out.println("#include <apr_strings.h>");
-        }
-
-out.println("");
-out.println("using namespace std;");
-out.println("using namespace activemq;");
-out.println("using namespace activemq::exceptions;");
-out.println("using namespace activemq::commands;");
-out.println("using namespace decaf::lang;");
-out.println("using namespace decaf::lang::exceptions;");
-out.println("");
-out.println("/*");
-out.println(" *");
-out.println(" *  Command and marshaling code for OpenWire format for "+className );
-out.println(" *");
-out.println(" *");
-out.println(" *  NOTE!: This file is auto generated - do not modify!");
-out.println(" *         if you need to make a change, please see the Java Classes in the");
-out.println(" *         activemq-core module");
-out.println(" *");
-out.println(" */");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(""+className+"::"+className+"() {");
-out.println("");
-
-        if( className.equals( "Message" ) ) {
-            out.println("    this->ackHandler = NULL;");
-            out.println("    this->readOnlyBody = false;");
-            out.println("    this->readOnlyProperties = false;");
-        }
-
-        List properties = getProperties();
-        for (Iterator iter = properties.iterator(); iter.hasNext();) {
-            JProperty property = (JProperty) iter.next();
-            String type = toCppType(property.getType());
-            String value = toCppDefaultValue(property.getType());
-            String propertyName = property.getSimpleName();
-            String parameterName = decapitalize(propertyName);
-
-            if( property.getType().isPrimitiveType() ||
-                type.startsWith("std::string") ) {
-
-out.println("    this->"+parameterName+" = "+value+";");
-            }
-        }
-out.println("}");
-out.println("");
-    if( assignable ) {
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(""+className+"::"+className+"( const "+className+"& other ) {");
-out.println("    this->copyDataStructure( &other );");
-out.println("}");
-out.println("");
-    }
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(""+className+"::~"+className+"() {");
-out.println("");
-out.println("}");
-
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(className+"* "+className+"::cloneDataStructure() const {");
-
-    String newInstance = decapitalize( className );
-
-out.println("    std::auto_ptr<"+className+"> "+newInstance+"( new "+className+"() );");
-out.println("");
-out.println("    // Copy the data from the base class or classes");
-out.println("    "+newInstance+"->copyDataStructure( this );");
-out.println("");
-out.println("    return "+newInstance+".release();");
-out.println("}");
-
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("void "+className+"::copyDataStructure( const DataStructure* src ) {");
-out.println("");
-out.println("    // Protect against invalid self assignment.");
-out.println("    if( this == src ) {");
-out.println("        return;");
-out.println("    }");
-out.println("");
-out.println("    const "+className+"* srcPtr = dynamic_cast<const "+className+"*>( src );");
-out.println("");
-out.println("    if( srcPtr == NULL || src == NULL ) {");
-out.println("        throw decaf::lang::exceptions::NullPointerException(");
-out.println("            __FILE__, __LINE__,");
-out.println("            \""+className+"::copyDataStructure - src is NULL or invalid\" );");
-out.println("    }");
-out.println("");
-
-            if( baseClass != null ) {
-    out.println("    // Copy the data of the base class or classes");
-    out.println("    "+ baseClass +"::copyDataStructure( src );");
-    out.println("");
-            }
+    protected void processClass(JClass jclass) {
 
-        if( className.equals( "Message" ) ) {
-out.println("    this->properties.copy( srcPtr->properties );");
-out.println("    this->setAckHandler( srcPtr->getAckHandler() );");
+        // Prepare the State variables for the current class
+        simpleName = jclass.getSimpleName();
+        superclass = jclass.getSuperclass();
+        className = getClassName(jclass);
+        baseClass = getBaseClassName(jclass);
+
+        System.out.println(getClass().getName() + " processing class: " + simpleName);
+
+        try {
+            // Using the current JClass state in the MultiSourceGenerator we can
+            // now generate the Header and Source for the CPP commands.
+            generateHeaderFile();
+            generateSourceFile();
+        } catch (Exception e) {
+            e.printStackTrace();
         }
-
-        for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
-             JProperty property = (JProperty) iter.next();
-             String getter = property.getGetter().getSimpleName();
-             String setter = property.getSetter().getSimpleName();
-
-             if( className.equals( "Message" ) &&
-                 property.getType().getSimpleName().equals( "MessageId" ) ) {
-out.println("    if( this->getMessageId() != NULL ) {");
-out.println("        this->"+setter+"( Pointer<MessageId>( new MessageId( *( srcPtr->"+getter+"() ) ) ) );" );
-out.println("    }");
-             } else {
-out.println("    this->"+setter+"( srcPtr->"+getter+"() );");
-             }
     }
 
-out.println("}");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("unsigned char "+className+"::getDataStructureType() const {");
-out.println("    return "+className+"::ID_" + className.toUpperCase() + ";");
-out.println("}");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("std::string "+className+"::toString() const {");
-out.println("");
-
-out.println("    ostringstream stream;" );
-out.println("");
-out.println("    stream << \"Begin Class = "+className+"\" << std::endl;" );
-out.println("    stream << \" Value of "+className+"::ID_" + className.toUpperCase() + " = "+getOpenWireOpCode(jclass)+"\" << std::endl;");
-
-        if( className.equals( "Message" ) ) {
-out.println("    stream << \" Value of ackHandler = \" << ackHandler << std::endl;");
-out.println("    stream << \" Value of properties = \" << this->properties.toString() << std::endl;");
-out.println("    stream << \" Value of readOnlyBody = \" << this->readOnlyBody << std::endl;");
-out.println("    stream << \" Value of readOnlyProperties = \" << this->readOnlyBody << std::endl;");
+    public Object run() {
+        filePostFix = ".cpp";
+        if (destDir == null) {
+            destDir = new File(
+                targetDir+"/activemq/commands");
         }
 
-for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
-    JProperty property = (JProperty) iter.next();
-    String type = toCppType(property.getType());
-    String propertyName = property.getSimpleName();
-    String parameterName = decapitalize(propertyName);
-    String constNess = "";
-    String getter = property.getGetter().getSimpleName();
-    String setter = property.getSetter().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("    }" );
-
-    } 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 << \" Value of "+propertyName+" = \" << this->"+getter+"() << std::endl;");
-
-    } else if( property.getType().isArrayType() &&
-               !property.getType().getArrayComponentType().isPrimitiveType() ) {
-
-        String arrayType = property.getType().getArrayComponentType().getSimpleName();
-
-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("        }");
-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("    }");
-    } else {
-out.println("    stream << \" Value of "+propertyName+" is Below:\" << std::endl;" );
-out.println("    if( this->"+getter+"() != NULL ) {");
-out.println("        stream << this->"+getter+"()->toString() << std::endl;");
-out.println("    } else {");
-out.println("        stream << \"   Object is NULL\" << std::endl;");
-out.println("    }");
-    }
-}
-
-    if( baseClass != null ) {
-out.println("    stream << "+ baseClass +"::toString();");
+        return super.run();
     }
 
-out.println("    stream << \"End Class = "+className+"\" << std::endl;" );
-out.println("");
-out.println("    return stream.str();");
-out.println("}");
-
-// equals
-
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("bool "+className+"::equals( const DataStructure* value ) const {");
-
-out.println("");
-out.println("    if( this == value ) {");
-out.println("        return true;");
-out.println("    }");
-out.println("");
-out.println("    const "+className+"* valuePtr = dynamic_cast<const "+className+"*>( value );");
-out.println("");
-out.println("    if( valuePtr == NULL || value == NULL ) {");
-out.println("        return false;");
-out.println("    }");
-out.println("");
-
-        if( className.equals( "Message" ) ) {
-out.println("    if( ackHandler != valuePtr->getAckHandler() ){");
-out.println("        return false;");
-out.println("    }");
-out.println("");
-out.println("    if( !properties.equals( valuePtr->properties ) ) {");
-out.println("        return false;");
-out.println("    }");
-out.println("");
-        }
-
-for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
-    JProperty property = (JProperty) iter.next();
-    String type = toCppType(property.getType());
-    String propertyName = property.getSimpleName();
-    String parameterName = decapitalize(propertyName);
-    String constNess = "";
-    String getter = property.getGetter().getSimpleName();
-    String setter = property.getSetter().getSimpleName();
-
-    if( property.getType().getSimpleName().equals("ByteSequence") ) {
-
-out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
-out.println("        if( this->"+getter+"()[i" + parameterName+"] != valuePtr->"+getter+"()[i"+parameterName+"] ) {" );
-out.println("            return false;" );
-out.println("        }" );
-out.println("    }" );
-
-    } else if( property.getType().isPrimitiveType() || type.equals("std::string") ){
-
-out.println("    if( this->"+getter+"() != valuePtr->"+getter+"() ) {");
-out.println("        return false;" );
-out.println("    }" );
-
-    } else if( property.getType().isArrayType() &&
-               !property.getType().getArrayComponentType().isPrimitiveType() ) {
-
-        String arrayType = property.getType().getArrayComponentType().getSimpleName();
-
-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("            if( !this->"+getter+"()[i"+parameterName+"]->equals( valuePtr->"+getter+"()[i"+parameterName+"].get() ) ) {" );
-out.println("                return false;");
-out.println("            }");
-out.println("        } else if( valuePtr->"+getter+"()[i"+parameterName+"] != NULL ) {");
-out.println("            return false;");
-out.println("        }");
-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("        if( this->"+getter+"()[i"+parameterName+"] != valuePtr->"+getter+"()[i"+parameterName+"] ) {");
-out.println("            return false;");
-out.println("        }");
-out.println("    }");
-    } else {
-out.println("    if( this->"+getter+"() != NULL ) {");
-out.println("        if( !this->"+getter+"()->equals( valuePtr->"+getter+"().get() ) ) {" );
-out.println("            return false;");
-out.println("        }");
-out.println("    } else if( valuePtr->"+getter+"() != NULL ) {");
-out.println("        return false;");
-out.println("    }");
-    }
-}
+    protected void generateHeaderFile() throws Exception {
 
-    if( baseClass != null ) {
-out.println("    if( !"+ baseClass +"::equals( value ) ) {");
-out.println("        return false;");
-out.println("    }");
-    }
+        File headerFile = new File(destDir, className + ".h");
 
-out.println("    return true;" );
-out.println("}");
+        CommandHeaderGenerator hdrGenerator = generatorsFactory.getHeaderGenerator( className );
 
-   if( className.equals( "Message" ) ) {
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("unsigned int "+className+"::getSize() const {");
-out.println("");
-out.println("    unsigned int size = DEFAULT_MESSAGE_SIZE;");
-out.println("");
-out.println("    size += (unsigned int)this->getContent().size();");
-out.println("    size += (unsigned int)this->getMarshalledProperties().size();");
-out.println("");
-out.println("    return size;");
-out.println("}");
-   }
-
-   if( baseClass.equals( "BaseCommand" ) ) {
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("decaf::lang::Pointer<commands::Command> "+className+"::visit( activemq::state::CommandVisitor* visitor ) ");
-out.println("    throw( exceptions::ActiveMQException ) {");
-out.println("");
-out.println("    return visitor->process"+className+"( this );");
-out.println("}");
-   }
-
-       for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
-            JProperty property = (JProperty) iter.next();
-            String type = toCppType(property.getType());
-            String propertyName = property.getSimpleName();
-            String parameterName = decapitalize(propertyName);
-            String getter = property.getGetter().getSimpleName();
-            String setter = property.getSetter().getSimpleName();
-            String constNess = "";
-
-            if( !property.getType().isPrimitiveType() &&
-                !property.getType().getSimpleName().equals("ByteSequence") &&
-                !property.getType().getSimpleName().equals("String") &&
-                !type.startsWith("std::vector") ) {
-
-                type = "decaf::lang::Pointer<" + type + ">&";
-                constNess = "const ";
-            } else if( property.getType().getSimpleName().equals("String") ||
-                       type.startsWith( "std::vector") ) {
-                type = type + "&";
-                constNess = "const ";
+        hdrGenerator.setJClass( getJclass() );
+        hdrGenerator.setProperties( getProperties() );
+        hdrGenerator.setMarshalAware( isMarshallerAware() );
+        hdrGenerator.setClassName( getClassName() );
+        hdrGenerator.setBaseClassName( getBaseClass() );
+        hdrGenerator.setOpenWireOpCode( getOpenWireOpCode(getJclass()) );
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(headerFile));
+            hdrGenerator.generate(out);
+        } catch( Exception e ) {
+            throw new RuntimeException(e);
+        } finally {
+            if( out != null ) {
+                out.close();
             }
-
-out.println("");
-
-    if( property.getType().isPrimitiveType() ) {
-
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(type+" "+className+"::"+getter+"() const {");
-out.println("    return "+parameterName+";");
-out.println("}");
-out.println("");
-
-    } else {
-
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("const "+type+" "+className+"::"+getter+"() const {");
-out.println("    return "+parameterName+";");
-out.println("}");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(""+type+" "+className+"::"+getter+"() {");
-out.println("    return "+parameterName+";");
-out.println("}");
-out.println("");
-
-    }
-
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("void " + className + "::" + setter+"( " + constNess + type+ " " + parameterName +" ) {");
-out.println("    this->"+parameterName+" = "+parameterName+";");
-out.println("}");
         }
-out.println("");
-
-        if( comparable ) {
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("int " + className + "::compareTo( const "+className+"& value ) const {");
-out.println("");
-out.println("    if( this == &value ) {");
-out.println("        return 0;");
-out.println("    }");
-out.println("");
-
-        for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
-            JProperty property = (JProperty) iter.next();
-            String type = toCppType(property.getType());
-            String propertyName = property.getSimpleName();
-            String parameterName = decapitalize(propertyName);
-            String getter = property.getGetter().getSimpleName();
-            String setter = property.getSetter().getSimpleName();
-
-            if( !property.getType().isPrimitiveType() &&
-                !property.getType().getSimpleName().equals("ByteSequence") &&
-                !property.getType().getSimpleName().equals("String") &&
-                !type.startsWith("std::vector") ) {
-
-out.println("    int "+parameterName+"Comp = this->"+parameterName+"->compareTo( *( value."+parameterName+" ) );");
-out.println("    if( "+parameterName+"Comp != 0 ) {");
-out.println("        return "+parameterName+"Comp;");
-out.println("    }");
-out.println("");
-
-            } else if( property.getType().getSimpleName().equals("String") ) {
-
-out.println("    int "+parameterName+"Comp = apr_strnatcasecmp( this->"+parameterName+".c_str(), value."+parameterName+".c_str() );");
-out.println("    if( "+parameterName+"Comp != 0 ) {");
-out.println("        return "+parameterName+"Comp;");
-out.println("    }");
-out.println("");
-            } else {
-
-out.println("    if( this->"+parameterName+" > value."+parameterName+" ) {");
-out.println("        return 1;");
-out.println("    } else if( this->"+parameterName+" < value."+parameterName+" ) {");
-out.println("        return -1;");
-out.println("    }");
-out.println("");
 
+        // Use the FixCRLF Ant Task to make sure the file has consistent
+        // newlines
+        // so that SVN does not complain on checkin.
+        Project project = new Project();
+        project.init();
+        FixCRLF fixCRLF = new FixCRLF();
+        fixCRLF.setProject(project);
+        fixCRLF.setSrcdir(headerFile.getParentFile());
+        fixCRLF.setIncludes(headerFile.getName());
+        fixCRLF.execute();
+    }
+
+    protected void generateSourceFile() throws Exception {
+
+        File sourceFile = new File(destDir, className + ".cpp");
+
+        CommandSourceGenerator srcGenerator = generatorsFactory.getSourceGenerator( className );
+
+        srcGenerator.setJClass( getJclass() );
+        srcGenerator.setProperties( getProperties() );
+        srcGenerator.setMarshalAware( isMarshallerAware() );
+        srcGenerator.setClassName( getClassName() );
+        srcGenerator.setBaseClassName( getBaseClass() );
+        srcGenerator.setOpenWireOpCode( getOpenWireOpCode(getJclass()) );
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(sourceFile));
+            srcGenerator.generate(out);
+        } catch( Exception e ) {
+            throw new RuntimeException( e );
+        } finally {
+            if( out != null ) {
+                out.close();
             }
         }
 
-out.println("    return 0;");
-out.println("}");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("bool " + className + "::equals( const "+className+"& value ) const {");
-out.println("    return this->equals( &value );");
-out.println("}");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("bool " + className + "::operator==( const "+className+"& value ) const {");
-out.println("    return this->compareTo( value ) == 0;");
-out.println("}");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("bool " + className + "::operator<( const "+className+"& value ) const {");
-out.println("    return this->compareTo( value ) < 0;");
-out.println("}");
-        }
-
-        if( assignable ) {
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println(""+className+"& "+className+"::operator= ( const "+className+"& other ) {");
-out.println("    this->copyDataStructure( &other );");
-out.println("}");
-out.println("");
-        }
-
-        if( className.equals( "Message" ) ) {
-
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("    void Message::beforeMarshal( wireformat::WireFormat* wireFormat AMQCPP_UNUSED )");
-out.println("        throw ( decaf::io::IOException ) {");
-out.println("");
-out.println("        try{");
-out.println("");
-out.println("            marshalledProperties.clear();");
-out.println("            if( !properties.isEmpty() )");
-out.println("            {");
-out.println("                wireformat::openwire::marshal::PrimitiveMapMarshaller::marshal(");
-out.println("                    &properties, marshalledProperties );");
-out.println("            }");
-out.println("        }");
-out.println("        AMQ_CATCH_RETHROW( decaf::io::IOException )");
-out.println("        AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException )");
-out.println("        AMQ_CATCHALL_THROW( decaf::io::IOException )");
-out.println("    }");
-out.println("");
-out.println("////////////////////////////////////////////////////////////////////////////////");
-out.println("    void Message::afterUnmarshal( wireformat::WireFormat* wireFormat AMQCPP_UNUSED )");
-out.println("        throw ( decaf::io::IOException ) {");
-out.println("");
-out.println("        try{");
-out.println("");
-out.println("            wireformat::openwire::marshal::PrimitiveMapMarshaller::unmarshal(");
-out.println("                &properties, marshalledProperties );");
-out.println("        }");
-out.println("        AMQ_CATCH_RETHROW( decaf::io::IOException )");
-out.println("        AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException )");
-out.println("        AMQ_CATCHALL_THROW( decaf::io::IOException )");
-out.println("    }");
-out.println("");
-        }
-    }
-
-    public String getTargetDir() {
-        return targetDir;
+        // Use the FixCRLF Ant Task to make sure the file has consistent
+        // newlines
+        // so that SVN does not complain on checkin.
+        Project project = new Project();
+        project.init();
+        FixCRLF fixCRLF = new FixCRLF();
+        fixCRLF.setProject(project);
+        fixCRLF.setSrcdir(sourceFile.getParentFile());
+        fixCRLF.setIncludes(sourceFile.getName());
+        fixCRLF.execute();
     }
 
-    public void setTargetDir(String targetDir) {
-        this.targetDir = targetDir;
+    @Override
+    protected void generateFile(PrintWriter arg0) throws Exception {
+        // Not used here since we override the process method.
     }
 
 }

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGenerator.java?rev=747816&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGenerator.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGenerator.java Wed Feb 25 15:23:48 2009
@@ -0,0 +1,238 @@
+/**
+ * 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.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+public abstract class CommandCodeGenerator {
+
+    private JClass jClass;
+    private List<JProperty> properties;
+    private boolean marshalAware = false;
+    private String className;
+    private String baseClassName;
+    private Set<String> includeFiles = new HashSet<String>();
+    private String openWireOpCode;
+    private boolean comparable = false;
+    private boolean assignable = false;
+    private boolean genIsClass = false;
+
+    public abstract void generate( PrintWriter out );
+
+    protected void generateLicence(PrintWriter out) {
+        out.println("/*");
+        out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+        out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+        out.println(" * this work for additional information regarding copyright ownership.");
+        out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+        out.println(" * (the \"License\"); you may not use this file except in compliance with");
+        out.println(" * the License.  You may obtain a copy of the License at");
+        out.println(" *");
+        out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+        out.println(" *");
+        out.println(" * Unless required by applicable law or agreed to in writing, software");
+        out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+        out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+        out.println(" * See the License for the specific language governing permissions and");
+        out.println(" * limitations under the License.");
+        out.println(" */");
+        out.println("");
+    }
+
+    public boolean isGenIsClass() {
+        return genIsClass;
+    }
+
+    public void setGenIsClass(boolean genIsClass) {
+        this.genIsClass = genIsClass;
+    }
+
+    public boolean isComparable() {
+        return comparable;
+    }
+
+    public void setComparable(boolean comparable) {
+        this.comparable = comparable;
+    }
+
+    public boolean isAssignable() {
+        return assignable;
+    }
+
+    public void setAssignable(boolean assignable) {
+        this.assignable = assignable;
+    }
+
+    public JClass getJClass() {
+        return jClass;
+    }
+
+    public void setJClass(JClass jClass) {
+        this.jClass = jClass;
+    }
+
+    public List<JProperty> getProperties() {
+        return properties;
+    }
+
+    public void setProperties(List<JProperty> properties) {
+        this.properties = properties;
+    }
+
+    public boolean isMarshalAware() {
+        return marshalAware;
+    }
+
+    public void setMarshalAware(boolean marshalAware) {
+        this.marshalAware = marshalAware;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+
+    public void setClassName(String className) {
+        this.className = className;
+    }
+
+    public String getBaseClassName() {
+        return baseClassName;
+    }
+
+    public void setBaseClassName(String baseClassName) {
+        this.baseClassName = baseClassName;
+    }
+
+    public Set<String> getIncludeFiles() {
+        return includeFiles;
+    }
+
+    public void setIncludeFiles(Set<String> includeFiles) {
+        this.includeFiles = includeFiles;
+    }
+
+    public String getOpenWireOpCode() {
+        return openWireOpCode;
+    }
+
+    public void setOpenWireOpCode(String openWireOpCode) {
+        this.openWireOpCode = openWireOpCode;
+    }
+
+    protected String toHeaderFileName( JClass type ) {
+        String name = type.getSimpleName();
+
+        if( name.equals( "String" ) ) {
+            return null;
+        } else if( type.isArrayType() ) {
+            JClass arrayClass = type.getArrayComponentType();
+            return toHeaderFileName( arrayClass );
+        } else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) {
+            return "BrokerError";
+        } else if( name.equals("BaseDataStructure" ) ){
+            return "DataStructure";
+        } else if( name.equals("ByteSequence") ) {
+            return "std::vector<unsigned char>";
+        } else if( !type.isPrimitiveType() ) {
+            return name;
+        } else {
+            return null;
+        }
+    }
+
+    protected String toCppType(JClass type) {
+        String name = type.getSimpleName();
+        if (name.equals("String")) {
+            return "std::string";
+        }
+        else if( type.isArrayType() ) {
+            if( name.equals( "byte[]" ) )
+                name = "unsigned char[]";
+
+            JClass arrayClass = type.getArrayComponentType();
+
+            if( arrayClass.isPrimitiveType() ) {
+                return "std::vector<" + name.substring( 0, name.length()-2 ) + ">";
+            } else {
+                return "std::vector< decaf::lang::Pointer<" +
+                       name.substring( 0, name.length()-2 ) + "> >";
+            }
+        }
+        else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) {
+            return "BrokerError";
+        }
+        else if( name.equals("BaseDataStructure" ) ){
+            return "DataStructure";
+        }
+        else if( name.equals("ByteSequence") ) {
+            return "std::vector<unsigned char>";
+        }
+        else if( name.equals("boolean") ) {
+            return "bool";
+        }
+        else if( name.equals("long") ) {
+            return "long long";
+        }
+        else if( name.equals("byte") ) {
+            return "unsigned char";
+        }
+        else if( !type.isPrimitiveType() ) {
+            return name;
+        }
+        else {
+            return name;
+        }
+    }
+
+    /**
+     * Converts the Java type to a C++ default value
+     */
+    protected String toCppDefaultValue(JClass type) {
+        String name = type.getSimpleName();
+
+        if (name.equals("boolean")) {
+            return "false";
+        } else if( name.equals("String") ) {
+            return "\"\"";
+        } else if( !type.isPrimitiveType() ) {
+            return "NULL";
+        } else {
+            return "0";
+        }
+    }
+
+    protected String decapitalize(String text) {
+        if (text == null) {
+            return null;
+        }
+        return text.substring(0, 1).toLowerCase() + text.substring(1);
+    }
+
+    protected String capitalize(String text) {
+        if (text == null) {
+            return null;
+        }
+        return text.substring(0, 1).toUpperCase() + text.substring(1);
+    }
+
+}

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

Added: 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=747816&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandCodeGeneratorsFactory.java Wed Feb 25 15:23:48 2009
@@ -0,0 +1,105 @@
+/**
+ * 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.util.HashSet;
+import java.util.Set;
+
+/**
+ * Provides methods to get a Source file and Header file Code generator given a Class
+ * name.
+ *
+ * @since 2.0
+ */
+public class CommandCodeGeneratorsFactory {
+
+    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( "KeepAliveInfo" );
+        commandsWithShortcuts.add( "WireFormatInfo" );
+        commandsWithShortcuts.add( "MessageAck" );
+        commandsWithShortcuts.add( "ProducerAck" );
+        commandsWithShortcuts.add( "MessageDispatchNotification" );
+        commandsWithShortcuts.add( "ShutdownInfo" );
+    }
+
+    /**
+     * Given a class name return an instance of a Header File Generator
+     * that can generate the header file for the Class.
+     *
+     * @param className - name of the class to find the generator for
+     *
+     * @return a new Header File code generator.
+     */
+    public CommandHeaderGenerator getHeaderGenerator( String className ) {
+
+        CommandHeaderGenerator generator = null;
+        if( className.equals("Message") ) {
+            generator = new MessageHeaderGenerator();
+        } else {
+            generator = new CommandHeaderGenerator();
+        }
+
+        if( className.endsWith("Id") ) {
+            generator.setComparable( true );
+            generator.setAssignable( true );
+        }
+
+        if( this.commandsWithShortcuts.contains( className ) ) {
+            generator.setGenIsClass( true );
+        }
+
+        return generator;
+    }
+
+    /**
+     * Given a class name return an instance of a Source File Generator
+     * that can generate the source file for the Class.
+     *
+     * @param className - name of the class to find the generator for
+     *
+     * @return a new Source File code generator.
+     */
+    public CommandSourceGenerator getSourceGenerator( String className ) {
+
+        CommandSourceGenerator generator = null;
+        if( className.equals("Message") ) {
+            generator = new MessageSourceGenerator();
+        } else {
+            generator = new CommandSourceGenerator();
+        }
+
+        if( className.endsWith("Id") ) {
+            generator.setComparable( true );
+            generator.setAssignable( true );
+        }
+
+        return generator;
+    }
+
+}

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

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandHeaderGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandHeaderGenerator.java?rev=747816&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandHeaderGenerator.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/commands/CommandHeaderGenerator.java Wed Feb 25 15:23:48 2009
@@ -0,0 +1,291 @@
+/**
+ * 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.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.codehaus.jam.JProperty;
+
+public class CommandHeaderGenerator extends CommandCodeGenerator {
+
+    public void generate( PrintWriter out ) {
+
+        // Start with the license.
+        generateLicence(out);
+
+        out.println("");
+        out.println("#ifndef _ACTIVEMQ_COMMANDS_"+getClassName().toUpperCase()+"_H_");
+        out.println("#define _ACTIVEMQ_COMMANDS_"+getClassName().toUpperCase()+"_H_");
+        out.println("");
+        out.println("// Turn off warning message for ignored exception specification");
+        out.println("#ifdef _MSC_VER");
+        out.println("#pragma warning( disable : 4290 )");
+        out.println("#endif");
+        out.println("");
+
+        populateIncludeFilesSet();
+        for( String include : getIncludeFiles() ) {
+            if( include != null ) {
+                out.println("#include "+include);
+            }
+        }
+
+        out.println("");
+        generateNamespaceWrapper( out );
+
+        out.println("    /*");
+        out.println("     *");
+        out.println("     *  Command code for OpenWire format for "+getClassName() );
+        out.println("     *");
+        out.println("     *  NOTE!: This file is auto generated - do not modify!");
+        out.println("     *         if you need to make a change, please see the Java Classes");
+        out.println("     *         in the activemq-cpp-openwire-generator module");
+        out.println("     *");
+        out.println("     */");
+
+        generateClassDefinition( out );
+        generateProperties( out );
+
+        if( !isAssignable() ) {
+            out.println("    protected:");
+            out.println("");
+            out.println("        "+getClassName()+"( const "+getClassName()+"& other );");
+            out.println("        "+getClassName()+"& operator= ( const "+getClassName()+"& other );");
+            out.println("");
+        }
+
+        out.println("    public:");
+        out.println("");
+        out.println("        "+getClassName()+"();");
+        out.println("");
+
+        if( isAssignable() ) {
+            out.println("        "+getClassName()+"( const "+getClassName()+"& other );");
+            out.println("");
+        }
+
+        generateAdditionalConstructors( out );
+
+        out.println("        virtual ~"+getClassName()+"();");
+        out.println("");
+        out.println("        /**");
+        out.println("         * Get the unique identifier that this object and its own");
+        out.println("         * Marshaler share.");
+        out.println("         * @returns new DataStructure type copy.");
+        out.println("         */");
+        out.println("        virtual unsigned char getDataStructureType() const;");
+        out.println("");
+        out.println("        /**");
+        out.println("         * Clone this object and return a new instance that the");
+        out.println("         * caller now owns, this will be an exact copy of this one");
+        out.println("         * @returns new copy of this object.");
+        out.println("         */");
+        out.println("        virtual "+getClassName()+"* cloneDataStructure() const;");
+        out.println("");
+        out.println("        /**");
+        out.println("         * Copy the contents of the passed object into this object's");
+        out.println("         * members, overwriting any existing data.");
+        out.println("         * @param src - Source Object");
+        out.println("         */");
+        out.println("        virtual void copyDataStructure( const DataStructure* src );");
+        out.println("");
+        out.println("        /**");
+        out.println("         * Returns a string containing the information for this DataStructure");
+        out.println("         * such as its type and value of its elements.");
+        out.println("         * @return formatted string useful for debugging.");
+        out.println("         */");
+        out.println("        virtual std::string toString() const;");
+        out.println("");
+        out.println("        /**" );
+        out.println("         * Compares the DataStructure passed in to this one, and returns if" );
+        out.println("         * they are equivalent.  Equivalent here means that they are of the" );
+        out.println("         * same type, and that each element of the objects are the same." );
+        out.println("         * @returns true if DataStructure's are Equal." );
+        out.println("         */" );
+        out.println("        virtual bool equals( const DataStructure* value ) const;" );
+        out.println("");
+
+        generateAdditonalMembers( out );
+        generatePropertyAccessors( out );
+
+        if( isComparable() ) {
+            out.println("        virtual int compareTo( const "+getClassName()+"& value ) const;");
+            out.println("");
+            out.println("        virtual bool equals( const "+getClassName()+"& value ) const;");
+            out.println("");
+            out.println("        virtual bool operator==( const "+getClassName()+"& value ) const;");
+            out.println("");
+            out.println("        virtual bool operator<( const "+getClassName()+"& value ) const;");
+            out.println("");
+        }
+
+        if( isAssignable() ) {
+            out.println("        "+getClassName()+"& operator= ( const "+getClassName()+"& other );");
+            out.println("");
+        }
+
+        if( isGenIsClass() ) {
+            out.println("        /**");
+            out.println("         * @return an answer of true to the is"+getClassName()+"() query.");
+            out.println("         */");
+            out.println("        virtual bool is"+getClassName()+"() const {");
+            out.println("            return true;");
+            out.println("        }");
+            out.println("");
+        }
+
+        if( getBaseClassName().equals( "BaseCommand" ) ) {
+            out.println("        /**" );
+            out.println("         * Allows a Visitor to visit this command and return a response to the" );
+            out.println("         * command based on the command type being visited.  The command will call" );
+            out.println("         * the proper processXXX method in the visitor." );
+            out.println("         * " );
+            out.println("         * @return a Response to the visitor being called or NULL if no response." );
+            out.println("         */" );
+            out.println("        virtual decaf::lang::Pointer<commands::Command> visit( activemq::state::CommandVisitor* visitor )" );
+            out.println("            throw( exceptions::ActiveMQException );" );
+            out.println("");
+        }
+
+        out.println("    };");
+        out.println("");
+        out.println("}}");
+        out.println("");
+        out.println("#endif /*_ACTIVEMQ_COMMANDS_"+getClassName().toUpperCase()+"_H_*/");
+    }
+
+    protected void populateIncludeFilesSet() {
+
+        Set<String> includes = getIncludeFiles();
+
+        includes.add("<vector>");
+        includes.add("<string>");
+        includes.add("<activemq/util/Config.h>");
+        includes.add("<activemq/commands/"+getBaseClassName()+".h>");
+        includes.add("<decaf/lang/Pointer.h>");
+
+        if( isComparable() ) {
+            includes.add("<decaf/lang/Comparable.h>");
+        }
+
+        for( JProperty property : getProperties() ) {
+            if( !property.getType().isPrimitiveType() &&
+                !property.getType().getSimpleName().equals("String") &&
+                !property.getType().getSimpleName().equals("ByteSequence") )
+            {
+
+                if( toHeaderFileName( property.getType() ) != null ) {
+                    includes.add(
+                        "<activemq/commands/"+toHeaderFileName( property.getType() )+".h>");
+                }
+            }
+        }
+    }
+
+    protected void generateNamespaceWrapper( PrintWriter out ) {
+        out.println("namespace activemq{");
+        out.println("namespace commands{");
+        out.println("");
+    }
+
+    protected void generateClassDefinition( PrintWriter out ) {
+        out.print("    class AMQCPP_API "+getClassName()+" : " );
+
+        if( isComparable() ) {
+            out.println("public "+ getBaseClassName() +", public decaf::lang::Comparable<"+getClassName()+"> {" );
+        } else {
+            out.print("public "+ getBaseClassName() +" {" );
+            out.println("");
+        }
+    }
+
+    protected void generateProperties( PrintWriter out ) {
+        out.println("    protected:");
+        out.println("");
+
+        for( JProperty property : getProperties() ) {
+            String type = toCppType(property.getType());
+            String name = decapitalize(property.getSimpleName());
+
+            if( !property.getType().isPrimitiveType() &&
+                !property.getType().getSimpleName().equals("ByteSequence") &&
+                !property.getType().getSimpleName().equals("String") &&
+                !type.startsWith("std::vector") ) {
+
+                type = "decaf::lang::Pointer<" + type + ">";
+            }
+
+            out.println("        "+type+" "+name+";");
+        }
+
+        out.println("");
+        out.println("    public:");
+        out.println("");
+        out.println("        const static unsigned char ID_"+
+                    getClassName().toUpperCase()+" = "+getOpenWireOpCode()+";");
+        out.println("");
+        if( isComparable() ) {
+            out.println("        typedef decaf::lang::PointerComparator<"+getClassName()+"> COMPARATOR;");
+            out.println("");
+        }
+    }
+
+    protected void generateAdditionalConstructors( PrintWriter out ) {
+    }
+
+    protected void generateAdditonalMembers( PrintWriter out ) {
+    }
+
+    protected void generatePropertyAccessors( PrintWriter out ) {
+
+        for( JProperty property : getProperties() ) {
+            String type = toCppType(property.getType());
+            String propertyName = property.getSimpleName();
+            String parameterName = decapitalize(propertyName);
+            String constness = "";
+
+            if( !property.getType().isPrimitiveType() &&
+                !property.getType().getSimpleName().equals("ByteSequence") &&
+                !property.getType().getSimpleName().equals("String") &&
+                !type.startsWith("std::vector") ) {
+
+                    type = "decaf::lang::Pointer<" + type + ">&";
+                    constness = "const ";
+            } else if( property.getType().getSimpleName().equals("String") ||
+                       type.startsWith("std::vector") ) {
+
+                type = type + "&";
+                constness = "const ";
+            }
+
+            if( property.getType().isPrimitiveType() ) {
+                out.println("        virtual "+type+" "+property.getGetter().getSimpleName()+"() const;");
+            } else {
+                out.println("        virtual const "+type+" "+property.getGetter().getSimpleName()+"() const;");
+                out.println("        virtual "+type+" "+property.getGetter().getSimpleName()+"();");
+            }
+
+            out.println("        virtual void "+property.getSetter().getSimpleName()+"( "+constness+type+" "+parameterName+" );");
+            out.println("");
+        }
+    }
+
+}

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



Mime
View raw message