activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r379734 - in /incubator/activemq/trunk/activemq-core/src/gram: java/org/apache/activemq/openwire/tool/ script/
Date Wed, 22 Feb 2006 09:35:07 GMT
Author: jstrachan
Date: Wed Feb 22 01:35:03 2006
New Revision: 379734

URL: http://svn.apache.org/viewcvs?rev=379734&view=rev
Log:
added the autogeneration of the C++ headers and cpp files and refactored the class generation
scripts so that they are easier to work with

Added:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
  (with props)
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
  (with props)
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppClasses.groovy   (with
props)
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppHeaders.groovy   (with
props)
Modified:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy

Modified: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java?rev=379734&r1=379733&r2=379734&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
Wed Feb 22 01:35:03 2006
@@ -16,13 +16,13 @@
  */
 package org.apache.activemq.openwire.tool;
 
-import mx4j.tools.adaptor.http.GetAttributeCommandProcessor;
-
 import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
 import org.codehaus.jam.JamClassIterator;
 
 import java.io.File;
-import java.io.*;
+import java.io.FileWriter;
+import java.io.PrintWriter;
 import java.util.*;
 
 /**
@@ -66,18 +66,33 @@
         return null;
     }
 
+    /**
+     * Returns all the valid properties available on the current class
+     */
+    public List getProperties() {
+        List answer = new ArrayList();
+        JProperty[] properties = jclass.getDeclaredProperties();
+        for (int i = 0; i < properties.length; i++) {
+            JProperty property = properties[i];
+            if (isValidProperty(property)) {
+                answer.add(property);
+            }
+        }
+        return answer;
+    }
+    
     protected boolean isValidClass(JClass jclass) {
         if (jclass.getAnnotation("openwire:marshaller") == null) {
             return false;
         }
-        return manuallyMaintainedClasses.contains(jclass.getSimpleName());
+        return !manuallyMaintainedClasses.contains(jclass.getSimpleName());
     }
 
     protected void processClass(JClass jclass) {
         simpleName = jclass.getSimpleName();
         superclass = jclass.getSuperclass();
 
-        System.out.println("Processing class: " + simpleName);
+        System.out.println(getClass().getName() + " processing class: " + simpleName);
 
         className = getClassName(jclass);
 
@@ -88,6 +103,7 @@
         PrintWriter out = null;
         try {
             out = new PrintWriter(new FileWriter(destFile));
+            generateFile(out);
         }
         catch (Exception e) {
             throw new RuntimeException(e);
@@ -113,7 +129,7 @@
     }
 
     protected String getClassName(JClass jclass) {
-        return "AbstractCommand";
+        return jclass.getSimpleName();
     }
 
 }

Added: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java?rev=379734&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
Wed Feb 22 01:35:03 2006
@@ -0,0 +1,70 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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 org.codehaus.jam.JClass;
+
+import java.io.File;
+
+/**
+ * 
+ * @version $Revision$
+ */
+public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
+
+    public Object run() {
+        filePostFix = getFilePostFix();
+        destDir = new File("../openwire-cpp/src/command");
+        return super.run();
+    }
+
+    protected String getFilePostFix() {
+        return ".cpp";
+    }
+
+    /**
+     * Converts the Java type to a C++ type name
+     */
+    public String toCppType(JClass type) {
+        String name = type.getSimpleName();
+        if (name.equals("String")) {
+            return "p<string>";
+        }
+        else if (name.equals("Throwable") || name.equals("Exception")) {
+            return "BrokerError";
+        }
+        else if (name.equals("ByteSequence")) {
+            return "void*";
+        }
+        else if (name.equals("boolean")) {
+            return "bool";
+        }
+        else if (name.endsWith("Id")) {
+            return "p<" + name + ">";
+        }
+        else {
+            return name;
+        }
+    }
+
+    /**
+     * Converts the Java type to a C++ default value
+     */
+    public String toCppDefaultValue(JClass type) {
+        return "NULL";
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java?rev=379734&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
Wed Feb 22 01:35:03 2006
@@ -0,0 +1,30 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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;
+
+
+/**
+ *
+ * @version $Revision$
+ */
+public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript {
+
+    protected String getFilePostFix() {
+        return ".hpp";
+    }
+
+}

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java?rev=379734&r1=379733&r2=379734&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
Wed Feb 22 01:35:03 2006
@@ -17,7 +17,6 @@
 package org.apache.activemq.openwire.tool;
 
 import org.codehaus.gram.GramSupport;
-import org.codehaus.jam.JAnnotation;
 import org.codehaus.jam.JAnnotationValue;
 import org.codehaus.jam.JClass;
 import org.codehaus.jam.JField;
@@ -103,6 +102,8 @@
             return name;
         }
     }
+
+    
     public String getOpenWireOpCode(JClass aClass) {
         return annotationValue(aClass, "openwire:marshaller", "code", "0");
     }

Modified: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy?rev=379734&r1=379733&r2=379734&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy (original)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy Wed
Feb 22 01:35:03 2006
@@ -17,21 +17,29 @@
 import org.apache.activemq.openwire.tool.OpenWireCSharpClassesScript
 
 /**
- * Generates the C# marshalling code for the Open Wire Format
+ * Generates the C# commands for the Open Wire Format
  *
  * @version $Revision$
  */
 class GenerateCSharpClasses extends OpenWireCSharpClassesScript {
 
 	void generateFile(PrintWriter out) {
-                out << """//
-// Marshalling code for Open Wire Format for ${jclass.simpleName}
-//
-//
-// NOTE!: This file is autogenerated - do not modify!
-//        if you need to make a change, please see the Groovy scripts in the
-//        activemq-openwire module
-//
+                out << """/*
+* Copyright 2006 The Apache Software Foundation or its licensors, as
+* applicable.
+*
+* Licensed 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.
+*/
 
 using System;
 using System.Collections;
@@ -41,21 +49,27 @@
 
 namespace OpenWire.Client.Commands
 {
+    //
+    //  Marshalling code for Open Wire Format for ${jclass.simpleName}
+    //
+    //
+    //  NOTE!: This file is autogenerated - do not modify!
+    //         if you need to make a change, please see the Groovy scripts in the
+    //         activemq-core module
+    //
     public class ${jclass.simpleName} : $baseClass
     {
-    			public const byte ID_${jclass.simpleName} = ${getOpenWireOpCode(jclass)};
+		public const byte ID_${jclass.simpleName} = ${getOpenWireOpCode(jclass)};
     			
 """
-                for (property in properties) {
-
-                    def type = toCSharpType(property.type)
-                    def name = decapitalize(property.simpleName)
-                    out << """        $type $name;
+    for (property in properties) {
+        def type = toCSharpType(property.type)
+        def name = decapitalize(property.simpleName)
+        out << """        $type $name;
 """
-                }
-
-                out << """
+    }
 
+    out << """
 
         // TODO generate Equals method
         // TODO generate GetHashCode method

Added: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppClasses.groovy
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppClasses.groovy?rev=379734&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppClasses.groovy (added)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppClasses.groovy Wed Feb
22 01:35:03 2006
@@ -0,0 +1,92 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+import org.apache.activemq.openwire.tool.OpenWireCppClassesScript
+
+/**
+ * Generates the C++ commands for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCppClasses extends OpenWireCppClassesScript {
+
+	void generateFile(PrintWriter out) {
+                out << """/*
+* Copyright 2006 The Apache Software Foundation or its licensors, as
+* applicable.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#include "command/${className}.hpp"
+
+using namespace apache::activemq::client::command;
+
+/*
+ *
+ *  Marshalling code for Open Wire Format for ${className}
+ *
+ *
+ *  NOTE!: This file is autogenerated - do not modify!
+ *         if you need to make a change, please see the Groovy scripts in the
+ *         activemq-core module
+ *
+ */
+${className}::${className}()
+{"""
+    for (property in properties) {
+        def value = toCppDefaultValue(property.type)
+        def propertyName = property.simpleName
+        def parameterName = decapitalize(propertyName)
+        out << """
+    this->${parameterName} = ${value} ;"""
+    }
+    out << """
+}
+
+${className}::~${className}()
+{
+}
+"""
+    for (property in properties) {
+        def type = toCppType(property.type)
+        def propertyName = property.simpleName
+        def parameterName = decapitalize(propertyName)
+        out << """
+        
+${type} ${className}::get${propertyName}()
+{
+    return ${parameterName} ;
+}
+
+void ${className}::set${propertyName}(${type} ${parameterName})
+{
+    this->${parameterName} = ${parameterName} ;
+}
+"""
+
+    }
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppClasses.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppHeaders.groovy
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppHeaders.groovy?rev=379734&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppHeaders.groovy (added)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppHeaders.groovy Wed Feb
22 01:35:03 2006
@@ -0,0 +1,121 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+import org.apache.activemq.openwire.tool.OpenWireCppHeadersScript
+
+/**
+ * Generates the C++ commands for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCppHeaders extends OpenWireCppHeadersScript {
+
+	void generateFile(PrintWriter out) {
+                out << """/*
+* Copyright 2006 The Apache Software Foundation or its licensors, as
+* applicable.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#ifndef ${className}_hpp_
+#define ${className}_hpp_
+
+#include <string>
+
+/* we could cut this down  - for now include all possible headers */
+#include "command/BaseCommand.hpp"
+#include "command/BrokerId.hpp"
+#include "command/ConnectionId.hpp"
+#include "command/ConsumerId.hpp"
+#include "command/ProducerId.hpp"
+#include "command/SessionId.hpp"
+
+#include "command/${baseClass}.hpp"
+#include "util/ifr/p"
+
+namespace apache
+{
+  namespace activemq
+  {
+    namespace client
+    {
+      namespace command
+      {
+        using namespace ifr;
+        using namespace apache::activemq::client;
+
+/*
+ *
+ *  Marshalling code for Open Wire Format for ${className}
+ *
+ *
+ *  NOTE!: This file is autogenerated - do not modify!
+ *         if you need to make a change, please see the Groovy scripts in the
+ *         activemq-core module
+ *
+ */
+class ${className} : public ${baseClass}
+{
+private:
+"""
+    for (property in properties) {
+        def type = toCppType(property.type)
+        def name = decapitalize(property.simpleName)
+        out << """    $type $name ;
+"""
+    }
+    out << """
+public:
+    const static int TYPE = ${getOpenWireOpCode(jclass)};
+
+public:
+    ${className}() ;
+    virtual ~${className}() ;
+
+"""
+    for (property in properties) {
+        def type = toCppType(property.type)
+        def propertyName = property.simpleName
+        def parameterName = decapitalize(propertyName)
+        out << """
+    virtual ${type} get${propertyName}() ;
+    virtual void set${propertyName}(${type} ${parameterName}) ;
+"""
+    }
+    out << """
+
+} ;
+
+/* namespace */
+      }
+    }
+  }
+}
+
+#endif /*${className}_hpp_*/
+"""
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCppHeaders.groovy
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message