You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/01/09 15:58:26 UTC

svn commit: r367310 - in /incubator/activemq/trunk/activemq-core/src: gram/java/org/activemq/openwire/tool/ gram/script/ main/java/org/apache/activemq/command/ main/java/org/apache/activemq/openwire/v1/

Author: jstrachan
Date: Mon Jan  9 06:58:16 2006
New Revision: 367310

URL: http://svn.apache.org/viewcvs?rev=367310&view=rev
Log:
updated the C# generation scripts to create valid C# code

Modified:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpMarshalling.groovy
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java

Modified: incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java?rev=367310&r1=367309&r2=367310&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java (original)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java Mon Jan  9 06:58:16 2006
@@ -17,6 +17,7 @@
 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;
@@ -69,5 +70,27 @@
             }
         }
         return false; //j.getSuperclass()!=null && isMarshallAware(j.getSuperclass());
+    }
+    
+    /**
+     * Converts the Java type to a C# type name
+     */
+    public String toCSharpType(JClass type) {
+        String name = type.getSimpleName();
+        if (name.equals("String")) {
+            return "string";
+        }
+        else if (name.equals("Throwable") || name.equals("Exception") || name.equals("ByteSequence")) {
+            return "byte[]";
+        }
+        else if (name.equals("boolean")) {
+            return "bool";
+        }
+        else {
+            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=367310&r1=367309&r2=367310&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy (original)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy Mon Jan  9 06:58:16 2006
@@ -31,6 +31,8 @@
         		it.getAnnotation("openwire:marshaller")!=null
         }
 
+			  def destinationNames = ['ActiveMQDestination', 'ActiveMQTempDestination', 'ActiveMQQueue', 'ActiveMQTopic', 'ActiveMQTempQueue', 'ActiveMQTempTopic']
+			  
         println "Generating Java marshalling code to directory ${destDir}"
 
         def buffer = new StringBuffer()
@@ -40,15 +42,24 @@
 
         for (jclass in messageClasses) {
 
+						if (destinationNames.contains(jclass.simpleName)) continue
+						
             println "Processing $jclass.simpleName"
 
             def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
             def file = new File(destDir, jclass.simpleName + ".cs")
 
+
+            String baseClass = jclass.superclass.simpleName
+            if (baseClass == "Object") {
+            		baseClass = "AbstractCommand"
+        		 }
+            /*
             String baseClass = "AbstractCommand"
             if (jclass.superclass?.simpleName == "ActiveMQMessage") {
                 baseClass = "ActiveMQMessage"
             }
+            */
 
             buffer << """
 ${jclass.simpleName}.class
@@ -73,7 +84,7 @@
 {
     public class ${jclass.simpleName} : $baseClass
     {
-    			public const int ID_${jclass.simpleName} = ${getEnum(jclass)};
+    			public const byte ID_${jclass.simpleName} = ${getOpenWireOpCode(jclass)};
     			
 """
                 for (property in properties) {
@@ -92,7 +103,7 @@
         // TODO generate ToString method
 
 
-        public override int GetCommandType() {
+        public override byte GetCommandType() {
             return ID_${jclass.simpleName};
         }
 
@@ -131,36 +142,6 @@
 }
 """
             }
-        }
-    }
-
-    def getEnum(type) {
-    			return 1
-		}
-		
-    def toCSharpType(type) {
-        def name = type.qualifiedName
-        switch (type) {
-            case "java.lang.String":
-                return "string"
-            case "java.lang.Throwable":
-                return "string"
-            case "java.lang.Throwable":
-                return "string"
-            case "boolean":
-                return "bool"
-            case "org.activeio.ByteSequence":
-                return "byte[]"
-            case "org.apache.activemq.command.DataStructure[]":
-                return "Command[]"
-            case "org.apache.activemq.command.DataStructure":
-                return "Command"
-            case "org.apache.activemq.message.ActiveMQDestination":
-                return "ActiveMQDestination"
-            case "org.apache.activemq.message.ActiveMQXid":
-                return "ActiveMQXid"
-            default:
-                return type.simpleName
         }
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpMarshalling.groovy
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpMarshalling.groovy?rev=367310&r1=367309&r2=367310&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpMarshalling.groovy (original)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpMarshalling.groovy Mon Jan  9 06:58:16 2006
@@ -54,7 +54,8 @@
                 baseClass = "ActiveMQMessageMarshaller"
             }
             
-            def notAbstract = jclass.simpleName != "ActiveMQDestination"
+            //def notAbstract = jclass.simpleName != "ActiveMQDestination"
+            def notAbstract = jclass.isAbstract() == false
             def abstractText = (notAbstract) ? "" : "abstract "
 					
 					 def marshallerType = jclass.simpleName + "Marshaller"
@@ -82,6 +83,7 @@
 						writeMethodBuffer << """
 				case ${jclass.simpleName}.ID_${jclass.simpleName}:
 						${marshallerField}.WriteCommand(command, dataOut);
+						break;
 						
 """						
 					 }
@@ -132,13 +134,13 @@
                     }
                     out << "            info.${propertyName} = "
 
-                    type = property.type.simpleName
+                    type = toCSharpType(property.type)
                     switch (type) {
-                        case "String":
+                        case "string":
                             out << "dataIn.ReadString()"
                             break;
 
-                        case "boolean":
+                        case "bool":
                             out << "dataIn.ReadBoolean()"
                             break;
 
@@ -190,8 +192,19 @@
                             out << "ReadDataStructures(dataIn)"
                             break;
 
+                        case "DataStructure":
+                            out << "CommandMarshallerRegistry.ReadCommand(dataIn)"
+                            break;
+
+                        case "Throwable":
+                            out << "ReadThrowable(dataIn)"
+                            break;
+
                         default:
-                            out << "(${type}) CommandMarshallerRegistry.${type}Marshaller.ReadCommand(dataIn)"
+                        		if (property.type.isAbstract()) 
+                            	out << "(${type}) CommandMarshallerRegistry.ReadCommand(dataIn)"
+                        		else
+                            	out << "(${type}) CommandMarshallerRegistry.${type}Marshaller.ReadCommand(dataIn)"
                     }
                     out << """;
 """
@@ -218,13 +231,13 @@
                     def getter = "info." + propertyName
                     out << "            "
 
-                    type = property.type.simpleName
+                    type = toCSharpType(property.type)
                     switch (type) {
-                        case "String":
+                        case "string":
                             out << "dataOut.Write($getter);"
                             break;
 
-                        case "boolean":
+                        case "bool":
                             out << "dataOut.Write($getter);"
                             break;
 
@@ -276,8 +289,19 @@
                             out << "WriteDataStructures($getter, dataOut);"
                             break;
 
+                        case "DataStructure":
+                            out << "CommandMarshallerRegistry.WriteCommand((Command) $getter, dataOut);"
+                            break;
+
+                        case "Throwable":
+                            out << "WriteThrowable($getter, dataOut);"
+                            break;
+
                         default:
-                            out << "CommandMarshallerRegistry.${type}Marshaller.WriteCommand($getter, dataOut);"
+                        		if (property.type.isAbstract()) 
+	                            out << "CommandMarshallerRegistry.WriteCommand($getter, dataOut);"
+  		   										else                         		
+	                            out << "CommandMarshallerRegistry.${type}Marshaller.WriteCommand($getter, dataOut);"
                     }
                     out << """
 """
@@ -328,11 +352,11 @@
 
 				public static void WriteCommand(Command command, BinaryWriter dataOut) 
 				{
-				    int commandID = command.CommandType;
+				    byte commandID = command.GetCommandType();
 						dataOut.Write(commandID);
 						switch (commandID) 
 						{
-$readMethodBuffer						
+$writeMethodBuffer						
 								default:
 										throw new Exception("Unknown command type: " + commandID);
 						}

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java?rev=367310&r1=367309&r2=367310&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/DiscoveryEvent.java Mon Jan  9 06:58:16 2006
@@ -20,7 +20,7 @@
 /**
  * Represents a discovery event containing the details of the service
  *
- * @openwire:marshaller code="55"
+ * @openwire:marshaller code="40"
  * @version $Revision:$
  */
 public class DiscoveryEvent implements DataStructure {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java?rev=367310&r1=367309&r2=367310&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/MarshallerFactory.java Mon Jan  9 06:58:16 2006
@@ -59,6 +59,7 @@
         add(new ConsumerInfoMarshaller());
         add(new ConnectionIdMarshaller());
         add(new ActiveMQTempTopicMarshaller());
+        add(new DiscoveryEventMarshaller());
         add(new ConnectionInfoMarshaller());
         add(new KeepAliveInfoMarshaller());
         add(new XATransactionIdMarshaller());