activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r746025 [1/2] - in /activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache: ./ activemq/ activemq/openwire/ activemq/openwire/tool/
Date Thu, 19 Feb 2009 22:13:31 GMT
Author: tabish
Date: Thu Feb 19 22:13:30 2009
New Revision: 746025

URL: http://svn.apache.org/viewvc?rev=746025&view=rev
Log:
Moved the OpenWire Generator code into its own project to make it easier to maintain and add other projects as needed to the activemq-cpp domain.

Added:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingClassesGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMarshallingHeadersGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java   (with props)

Added: 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/AmqCppClassesGenerator.java?rev=746025&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java Thu Feb 19 22:13:30 2009
@@ -0,0 +1,660 @@
+/*
+ *
+ * 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;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+/**
+ *
+ * @version $Revision: 409828 $
+ */
+public class AmqCppClassesGenerator 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();
+
+        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;
+        }
+    }
+
+    /**
+     * 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";
+        }
+    }
+
+    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(" */");
+    }
+
+    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;");
+        }
+
+        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("");
+            }
+
+        if( className.equals( "Message" ) ) {
+out.println("    this->properties.copy( srcPtr->properties );");
+out.println("    this->setAckHandler( srcPtr->getAckHandler() );");
+        }
+
+        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("    this->"+setter+"( Pointer<MessageId>( new MessageId( *( srcPtr->"+getter+"() ) ) ) );" );
+
+             } 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;");
+        }
+
+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();");
+    }
+
+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("    }");
+    }
+}
+
+    if( baseClass != null ) {
+out.println("    if( !"+ baseClass +"::equals( value ) ) {");
+out.println("        return false;");
+out.println("    }");
+    }
+
+out.println("    return true;" );
+out.println("}");
+
+   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 ";
+            }
+
+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("");
+
+            }
+        }
+
+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;
+    }
+
+    public void setTargetDir(String targetDir) {
+        this.targetDir = targetDir;
+    }
+
+}

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

Added: 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=746025&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java Thu Feb 19 22:13:30 2009
@@ -0,0 +1,172 @@
+/**
+ *
+ * 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;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.codehaus.jam.JamService;
+import org.codehaus.jam.JamServiceFactory;
+import org.codehaus.jam.JamServiceParams;
+
+/**
+ *
+ * @version $Revision: 384826 $
+ */
+public class AmqCppGeneratorTask extends Task {
+
+    int maxVersion = 3;
+    File source = new File(".");
+    File target = new File(".");
+
+    public static void main(String[] args) {
+
+        Project project = new Project();
+        project.init();
+        AmqCppGeneratorTask generator = new AmqCppGeneratorTask();
+        generator.setProject(project);
+
+        if( args.length > 0 ) {
+            generator.maxVersion = Integer.parseInt(args[0]);
+            System.out.println( "Generator Max Version: " + Integer.parseInt(args[0]) );
+        }
+
+        if( args.length > 1 ) {
+            generator.source = new File(args[1]);
+            System.out.println( "Generator Source: " + generator.source );
+        }
+
+        if( args.length > 2 ) {
+            generator.target = new File(args[2]);
+            System.out.println( "Generator Source: " + generator.target );
+        }
+
+        generator.execute();
+    }
+
+    public void execute() throws BuildException {
+        try {
+
+            String sourceDir = source+"/src/main/java";
+
+            System.out.println("Parsing source files in: " + sourceDir);
+
+            JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
+            JamServiceParams params = jamServiceFactory.createServiceParams();
+            File[] dirs = new File[]{new File(sourceDir)};
+            params.includeSourcePattern(dirs, "**/*.java");
+            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();
+                script.setJam(jam);
+                script.setTargetDir(target+"/src/main");
+                script.setOpenwireVersion(maxVersion);
+                script.run();
+            }
+            {
+                AmqCppMakefileGenerator script = new AmqCppMakefileGenerator(
+                    "activemq/commands" );
+                script.setTargetDir(target+"/src/main");
+                script.run();
+            }
+
+            for( int i = 1; i <= maxVersion; ++i ) {
+
+                {
+                    AmqCppMarshallingHeadersGenerator script = new AmqCppMarshallingHeadersGenerator();
+                    script.setJam(jam);
+                    script.setTargetDir(target+"/src/main");
+                    script.setOpenwireVersion(i);
+                    script.run();
+                }
+                {
+                    AmqCppMarshallingClassesGenerator script = new AmqCppMarshallingClassesGenerator();
+                    script.setJam(jam);
+                    script.setTargetDir(target+"/src/main");
+                    script.setOpenwireVersion(i);
+                    script.run();
+                }
+                {
+                   AmqCppTestMarshallingHeadersGenerator script = new AmqCppTestMarshallingHeadersGenerator();
+                    script.setJam(jam);
+                    script.setTargetDir(target+"/src/test");
+                    script.setOpenwireVersion(i);
+                    script.run();
+                }
+                {
+                    AmqCppTestMarshallingClassesGenerator script = new AmqCppTestMarshallingClassesGenerator();
+                    script.setJam(jam);
+                    script.setTargetDir(target+"/src/test");
+                    script.setOpenwireVersion(i);
+                    script.run();
+                }
+                {
+                    AmqCppMakefileGenerator script = new AmqCppMakefileGenerator(
+                        "activemq/wireformat/openwire/marshal/v" + i );
+                    script.setTargetDir(target+"/src/main");
+                    script.run();
+                }
+                {
+                    AmqCppMakefileGenerator script = new AmqCppMakefileGenerator(
+                        "activemq/wireformat/openwire/marshal/v" + i );
+                    script.setTargetDir(target+"/src/test");
+                    script.run();
+                }
+            }
+
+        } catch (Exception e) {
+            throw new BuildException(e);
+        }
+    }
+
+    public int getMaxVersion() {
+        return maxVersion;
+    }
+
+    public void setMaxVersion(int version) {
+        this.maxVersion = version;
+    }
+
+    public File getSource() {
+        return source;
+    }
+
+    public void setSource(File basedir) {
+        this.source = basedir;
+    }
+
+    public File getTarget() {
+        return target;
+    }
+
+    public void setTarget(File target) {
+        this.target = target;
+    }
+
+}

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

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java?rev=746025&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java Thu Feb 19 22:13:30 2009
@@ -0,0 +1,408 @@
+/**
+ *
+ * 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;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+
+/**
+ *
+ * @version $Revision: 379734 $
+ */
+public class AmqCppHeadersGenerator extends AmqCppClassesGenerator {
+
+    private Set<String> commandsWithShortcuts;
+
+    /*
+     * Here we store all Commands that need to have a isXXX method generated
+     * such as isMessage.  We then check in the <code>checkNeedsShortcut</code>
+     * method and if the Command being generated is in this list we create a
+     * method call to override the virtual method in the base Command interface.
+     */
+    {
+        commandsWithShortcuts = new HashSet<String>();
+        commandsWithShortcuts.add( "Response" );
+        commandsWithShortcuts.add( "MessageDispatch" );
+        commandsWithShortcuts.add( "BrokerInfo" );
+        commandsWithShortcuts.add( "KeepAliveInfo" );
+        commandsWithShortcuts.add( "WireFormatInfo" );
+        commandsWithShortcuts.add( "Message" );
+        commandsWithShortcuts.add( "MessageAck" );
+        commandsWithShortcuts.add( "ProducerAck" );
+        commandsWithShortcuts.add( "MessageDispatchNotification" );
+        commandsWithShortcuts.add( "ShutdownInfo" );
+    }
+
+    protected void checkNeedsShortcut( String className, PrintWriter out ) {
+
+        if( this.commandsWithShortcuts.contains( className ) ) {
+            out.println("        /**");
+            out.println("         * @return an answer of true to the is"+className+"() query.");
+            out.println("         */");
+            out.println("        virtual bool is"+className+"() const {");
+            out.println("            return true;");
+            out.println("        }");
+            out.println("");
+        }
+    }
+
+    protected String getFilePostFix() {
+        return ".h";
+    }
+
+    protected void generateFile(PrintWriter out) {
+        generateLicence(out);
+
+        boolean comparable = className.endsWith( "Id" );
+        boolean assignable = className.endsWith( "Id" );
+
+out.println("");
+out.println("#ifndef _ACTIVEMQ_COMMANDS_"+className.toUpperCase()+"_H_");
+out.println("#define _ACTIVEMQ_COMMANDS_"+className.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("");
+out.println("#include <activemq/util/Config.h>");
+out.println("#include <activemq/commands/"+baseClass+".h>");
+        if( className.equals( "Message" ) ) {
+out.println("#include <activemq/util/PrimitiveMap.h>");
+out.println("#include <decaf/util/Date.h>");
+        }
+out.println("#include <decaf/lang/Pointer.h>");
+
+        if( comparable ) {
+out.println("#include <decaf/lang/Comparable.h>");
+        }
+
+        List properties = getProperties();
+        Set<String> includeNames = new HashSet<String>();
+        for (Iterator iter = properties.iterator(); iter.hasNext();) {
+            JProperty property = (JProperty) iter.next();
+            if( !property.getType().isPrimitiveType() &&
+                !property.getType().getSimpleName().equals("String") &&
+                !property.getType().getSimpleName().equals("ByteSequence") )
+            {
+                includeNames.add( toHeaderFileName( property.getType() ) );
+            }
+        }
+
+        for( String includeName : includeNames ) {
+            if( includeName != null ) {
+                out.println("#include <activemq/commands/"+includeName+".h>");
+            }
+        }
+
+out.println("#include <vector>");
+out.println("#include <string>");
+out.println("");
+out.println("namespace activemq{");
+        if( className.equals( "Message" ) ) {
+out.println("namespace core{");
+out.println("    class ActiveMQAckHandler;");
+out.println("}");
+        }
+out.println("namespace commands{");
+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");
+out.println("     *         in the activemq-openwire-generator module");
+out.println("     *");
+out.println("     */");
+out.print("    class AMQCPP_API "+className+" : " );
+
+        if( comparable ) {
+out.println("public "+ baseClass +", public decaf::lang::Comparable<"+className+"> {" );
+        } else {
+out.print("public "+ baseClass +" {" );
+out.println("");
+        }
+
+        if( className.equals( "Message" ) ) {
+out.println("    private:");
+out.println("");
+out.println("        // Used to allow a client to call Message::acknowledge when in the Client");
+out.println("        // Ack mode.");
+out.println("        core::ActiveMQAckHandler* ackHandler;");
+out.println("");
+out.println("        // Message properties, these are Marshaled and Unmarshaled from the Message");
+out.println("        // Command's marshaledProperties vector.");
+out.println("        activemq::util::PrimitiveMap properties;");
+out.println("");
+        }
+
+out.println("    protected:");
+out.println("");
+
+            if( className.equals( "Message" ) ) {
+
+out.println("        static const unsigned int DEFAULT_MESSAGE_SIZE = 1024;");
+out.println("");
+
+            }
+
+       for (Iterator iter = properties.iterator(); iter.hasNext();) {
+            JProperty property = (JProperty) iter.next();
+            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+";");
+
+       }
+
+       String typeName = className.toUpperCase();
+
+       if( !assignable ) {
+out.println("");
+out.println("    protected:");
+out.println("");
+out.println("        "+className+"( const "+className+"& other );");
+out.println("        "+className+"& operator= ( const "+className+"& other );");
+       }
+out.println("");
+out.println("    public:");
+out.println("");
+out.println("        const static unsigned char ID_"+typeName+" = "+getOpenWireOpCode(jclass)+";");
+out.println("");
+        if( comparable ) {
+out.println("        typedef decaf::lang::PointerComparator<"+className+"> COMPARATOR;");
+out.println("");
+        }
+out.println("    public:");
+out.println("");
+out.println("        "+className+"();");
+            if( assignable ) {
+out.println("        "+className+"( const "+className+"& other );");
+            }
+out.println("        virtual ~"+className+"();");
+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 "+className+"* 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("");
+
+        // Check if a isXXX object shorcut should be generated and add it if so.
+        checkNeedsShortcut( className, out );
+
+        if( className.equals( "Message" ) ) {
+
+out.println("        /**");
+out.println("         * Handles the marshaling of the objects properties into the");
+out.println("         * internal byte array before the object is marshaled to the");
+out.println("         * wire");
+out.println("         * @param wireFormat - the wireformat controller");
+out.println("         */");
+out.println("        virtual void beforeMarshal( wireformat::WireFormat* wireFormat AMQCPP_UNUSED )");
+out.println("            throw ( decaf::io::IOException );");
+out.println("");
+out.println("        /**");
+out.println("         * Called after unmarshaling is started to cleanup the object being");
+out.println("         * unmarshaled.");
+out.println("         * @param wireFormat - the wireformat object to control unmarshaling");
+out.println("         */");
+out.println("        virtual void afterUnmarshal( wireformat::WireFormat* wireFormat AMQCPP_UNUSED )");
+out.println("            throw ( decaf::io::IOException );");
+out.println("");
+out.println("        /**");
+out.println("         * Indicates that this command is aware of Marshaling, and needs");
+out.println("         * to have its Marshaling methods invoked.");
+out.println("         * @returns boolean indicating desire to be in marshaling stages");
+out.println("         */");
+out.println("        virtual bool isMarshalAware() const {");
+out.println("            return true;");
+out.println("        }");
+out.println("");
+out.println("        /**");
+out.println("         * Sets the Acknowledgment Handler that this Message will use");
+out.println("         * when the Acknowledge method is called.");
+out.println("         * @param handler ActiveMQAckHandler to call");
+out.println("         */");
+out.println("        virtual void setAckHandler( core::ActiveMQAckHandler* handler ) {");
+out.println("            this->ackHandler = handler;");
+out.println("        }");
+out.println("");
+out.println("        /**");
+out.println("         * Gets the Acknowledgment Handler that this Message will use");
+out.println("         * when the Acknowledge method is called.");
+out.println("         * @returns handler ActiveMQAckHandler to call or NULL if not set");
+out.println("         */");
+out.println("        virtual core::ActiveMQAckHandler* getAckHandler() const {");
+out.println("            return this->ackHandler;");
+out.println("        }");
+out.println("");
+out.println("        /**");
+out.println("         * Returns the Size of this message in Bytes.");
+out.println("         * @returns number of bytes this message equates to.");
+out.println("         */");
+out.println("        virtual unsigned int getSize() const;");
+out.println("");
+out.println("        /**");
+out.println("         * Returns if this message has expired, meaning that its");
+out.println("         * Expiration time has elapsed.");
+out.println("         * @returns true if message is expired.");
+out.println("         */");
+out.println("        virtual bool isExpired() const {");
+out.println("            long long expireTime = this->getExpiration();");
+out.println("            long long currentTime = decaf::util::Date::getCurrentTimeMilliseconds();");
+out.println("            if( expireTime > 0 && currentTime > expireTime ) {");
+out.println("                return true;");
+out.println("            }");
+out.println("            return false;");
+out.println("        }");
+out.println("");
+out.println("        /**");
+out.println("         * Gets a reference to the Message's Properties object, allows the derived");
+out.println("         * classes to get and set their own specific properties.");
+out.println("         *");
+out.println("         * @return a reference to the Primitive Map that holds message properties.");
+out.println("         */");
+out.println("        util::PrimitiveMap& getMessageProperties() {");
+out.println("            return this->properties;");
+out.println("        }");
+out.println("        const util::PrimitiveMap& getMessageProperties() const {");
+out.println("            return this->properties;");
+out.println("        }");
+out.println("");
+
+        }
+
+        if( baseClass.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("");
+
+        }
+
+        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 = "";
+
+            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("");
+        }
+
+        if( comparable ) {
+out.println("        virtual int compareTo( const "+className+"& value ) const;");
+out.println("");
+out.println("        virtual bool equals( const "+className+"& value ) const;");
+out.println("");
+out.println("        virtual bool operator==( const "+className+"& value ) const;");
+out.println("");
+out.println("        virtual bool operator<( const "+className+"& value ) const;");
+out.println("");
+        }
+
+        if( assignable ) {
+out.println("        "+className+"& operator= ( const "+className+"& other );");
+        }
+
+out.println("    };");
+out.println("");
+out.println("}}");
+out.println("");
+out.println("#endif /*_ACTIVEMQ_COMMANDS_"+className.toUpperCase()+"_H_*/");
+
+    }
+
+}

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

Added: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java?rev=746025&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/AmqCppMakefileGenerator.java Thu Feb 19 22:13:30 2009
@@ -0,0 +1,178 @@
+/**
+ *
+ * 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;
+
+import java.util.Iterator;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.FixCRLF;
+
+/**
+*
+* @version $Revision: 379734 $
+*/
+public class AmqCppMakefileGenerator {
+
+    protected String targetDir="./src/main";
+    protected String targetPath;
+
+    private ArrayList<String> sources = new ArrayList<String>();
+    private ArrayList<String> headers = new ArrayList<String>();
+
+    private File destDir;
+    private File destFile;
+    private StringBuffer buffer;
+
+    public AmqCppMakefileGenerator( String targetPath ) {
+        this.targetPath = targetPath;
+    }
+
+    protected String getFilePostFix() {
+        return ".mk";
+    }
+
+    protected String getFilePrefix() {
+        return "srcmakefile";
+    }
+
+    public String getTargetDir() {
+        return targetDir;
+    }
+
+    public void setTargetDir( String targetDir ) {
+        this.targetDir = targetDir;
+    }
+
+    /**
+     * Derived classes provide the location of the Makefile.
+     */
+    protected File getDestDir() {
+        return new File( targetDir + "/" + targetPath );
+    }
+
+
+    private void processDirectory( File destDir ) {
+        if( destDir == null ) {
+            throw new IllegalArgumentException("No destDir defined!");
+        }
+
+        File[] files = destDir.listFiles();
+
+        for( File file : files ) {
+
+            if( file.getName().endsWith("cpp") ) {
+                sources.add( file.getName() );
+            }
+
+            if( file.getName().endsWith("h") ) {
+                headers.add( file.getName() );
+            }
+        }
+    }
+
+    public void run() {
+
+        destDir = getDestDir();
+
+        if( destDir == null ) {
+            throw new IllegalArgumentException("No destDir defined!");
+        }
+
+        // Get all the sources from the dir.
+        processDirectory( destDir );
+
+        System.out.println(getClass().getName() + " generating files in: " + destDir);
+        destDir.mkdirs();
+        buffer = new StringBuffer();
+
+        destFile = new File( destDir, getFilePrefix() + getFilePostFix() );
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(destFile));
+            generateFile(out);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+
+        // 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(destFile.getParentFile());
+        fixCRLF.setIncludes(destFile.getName());
+        fixCRLF.execute();
+    }
+
+    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("# ---------------------------------------------------------------------------");
+    }
+
+    protected void generateFile(PrintWriter out) {
+        generateLicence(out);
+
+        // Put the file lists in alphabetical order.
+        Collections.sort( sources );
+        Collections.sort( headers );
+
+        out.println("");
+        out.print("cc_sources +=");
+
+        for( String source : sources ) {
+            out.println(" \\");
+            out.print("    " + targetPath + "/" + source);
+        }
+
+        out.println("");
+        out.println("");
+        out.print("h_sources +=");
+
+        for( String header : headers ) {
+            out.println(" \\");
+            out.print("    " + targetPath + "/" + header);
+        }
+
+        out.println("");
+    }
+}

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



Mime
View raw message