activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r419354 [2/2] - in /incubator/activemq/trunk/activemq-openwire-generator: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/activemq/ src/main/java/org/apache/activemq/openwire/ src/main/...
Date Wed, 05 Jul 2006 21:59:39 GMT
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/TestDataGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/TestDataGenerator.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/TestDataGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/TestDataGenerator.java Wed Jul  5 14:59:37 2006
@@ -0,0 +1,67 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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;
+
+/**
+ * A simple helper class to help auto-generate test data when code generating test cases
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class TestDataGenerator {
+    private int stringCounter;
+
+    private boolean boolCounter;
+    private byte byteCounter;
+    private char charCounter = 'a';
+    private short shortCounter;
+    private int intCounter;
+    private long longCounter;
+    
+    public String createByte() {
+        return "(byte) " + (++byteCounter);
+    }
+    
+    public String createChar() {
+        return "'" + (charCounter++) + "'";
+    }
+    
+    public String createShort() {
+        return "(short) " + (++shortCounter);
+    }
+
+    public int createInt() {
+        return ++intCounter;
+    }
+
+    public long createLong() {
+        return ++longCounter;
+    }
+
+    public String createString(String property) {
+        return property + ":" + (++stringCounter);
+    }
+
+    public boolean createBool() {
+        boolCounter = !boolCounter;
+        return boolCounter;
+    }
+    
+    public String createByteArray(String property) {
+        return "\"" + createString(property) + "\".getBytes()";
+    }
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCMarshalling.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCMarshalling.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCMarshalling.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCMarshalling.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,633 @@
+/**
+ *
+ * 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.OpenWireScript
+
+/**
+ * Generates the Java marshalling code for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCMarshalling extends OpenWireScript {
+
+	String changeCase(String value) {
+		StringBuffer b = new StringBuffer();
+		value.each { c |
+			if( Character.isUpperCase((char)c) ) {
+				b.append('_');
+				b.append(Character.toLowerCase((char)c));
+			} else {
+				b.append(c);
+			}
+		}
+		return b.toString();
+	}
+   
+	String toPropertyCase(String value) {
+      return value.substring(0,1).toLowerCase()+value.substring(1);
+	}
+	
+	/**
+	 * Sort the class list so that base classes come up first.
+	 */
+	def sort(classes) {
+   
+      classes = (java.util.List)classes;      
+	  def rc = [];
+      def objectClass;
+     
+      // lets make a map of all the class names
+      def classNames = [:]
+	 for (c in classes) {
+	     def name = c.simpleName
+	     classNames[name] = name
+	 }
+      
+      // Add all classes that have no parent first
+     for (c in classes) {
+       if( !classNames.containsKey(c.superclass))
+          rc.add(c)
+      }
+      
+      // now lets add the rest
+     for (c in classes) {
+         if (!rc.contains(c))
+             rc.add(c)
+      }
+      
+	return rc;
+	}
+   
+   
+   def generateFields(out, jclass) {
+   
+//      println("getting fields for: ${jclass.simpleName}");
+      if( jclass.superclass == null || jclass.superclass.simpleName.equals("Object") ) {
+out << """
+   ow_byte structType;
+""";
+      } else {
+         generateFields(out, jclass.superclass);
+      }
+
+      def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+      for (property in properties) {
+          def annotation = property.getter.getAnnotation("openwire:property");
+          def size = annotation.getValue("size");
+          def name = toPropertyCase(property.simpleName);
+          def cached = isCachedProperty(property);
+          
+          out << "   "
+          def type = property.type.qualifiedName
+          switch (type) {
+          case "boolean":
+              out << "ow_$type $name;"; break;
+              break;
+          case "byte":
+              out << "ow_$type $name;"; break;
+              break;
+          case "char":
+              out << "ow_$type $name;"; break;
+              break;
+          case "short":
+              out << "ow_$type $name;"; break;
+              break;
+          case "int":
+              out << "ow_$type $name;"; break;
+              break;
+          case "long":
+              out << "ow_$type $name;"; break;
+              break;
+          case "byte[]":
+              out << "ow_byte_array *$name;"; break;
+              break;
+          case "org.apache.activeio.packet.ByteSequence":
+              out << "ow_byte_array *$name;"; break;
+              break;
+	      case "org.apache.activeio.packet.ByteSequence":
+              out << "ow_byte_array *$name;"; break;
+              break;
+          case "java.lang.String":
+              out << "ow_string *$name;"; break;
+              break;
+          default:
+                if( property.type.arrayType ) {
+                  out << "ow_DataStructure_array *$name;"; break;
+                } else if( isThrowable(property.type) ) {    	    
+                  out << "ow_throwable *$name;"; break;
+                } else {
+                  out << "struct ow_"+property.type.simpleName+" *$name;"; break;
+              }
+          }
+out << """
+"""
+      }
+   
+   }
+
+    Object run() {
+    
+        def openwireVersion = getProperty("version");
+        
+        def destDir = new File("../openwire-c/src/libopenwire")
+        println "Generating C marshalling code to directory ${destDir}"
+        
+        def openwireClasses = classes.findAll {
+        		it.getAnnotation("openwire:marshaller")!=null
+        }
+        
+        println "Sorting classes..."
+	     openwireClasses = sort(openwireClasses);
+	
+        def concreteClasses = new ArrayList()
+        int counter = 0
+        Map map = [:]
+
+        destDir.mkdirs()
+        
+      //////////////////////////////////////////////////////////////////////
+      //
+      // Start generateing the ow_commands_v1.h File
+      //
+      //////////////////////////////////////////////////////////////////////
+        def file = new File(destDir, "ow_commands_v${openwireVersion}.h")
+        file.withWriter { out |
+        
+out << """/**
+ *
+ * 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.
+ */
+
+/*****************************************************************************************
+ *  
+ * NOTE!: This file is auto generated - do not modify!
+ *        if you need to make a change, please see the modify the groovy scripts in the
+ *        under src/gram/script and then use maven openwire:generate to regenerate 
+ *        this file.
+ *  
+ *****************************************************************************************/
+ 
+#ifndef OW_COMMANDS_V${openwireVersion}_H
+#define OW_COMMANDS_V${openwireVersion}_H
+
+#include "ow.h"
+#include "ow_command_types_v${openwireVersion}.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+      
+#define OW_WIREFORMAT_VERSION ${openwireVersion}
+      
+apr_status_t ow_bitmarshall(ow_bit_buffer *buffer, ow_DataStructure *object);
+apr_status_t ow_marshall(ow_byte_buffer *buffer, ow_DataStructure *object);
+"""        
+           
+	        for (jclass in openwireClasses) {
+	               
+	            println "Processing ${jclass.simpleName}"
+	            
+	            def structName = jclass.simpleName;
+	            def type = "OW_"+structName.toUpperCase()+"_TYPE"
+	            
+               counter++;
+out << """
+typedef struct ow_${structName} {
+"""
+   // This recusivly generates the field definitions of the class and it's supper classes.
+   generateFields(out, jclass);
+   
+out << """
+} ow_${structName};
+ow_${structName} *ow_${structName}_create(apr_pool_t *pool);
+ow_boolean ow_is_a_${structName}(ow_DataStructure *object);
+"""
+	        }
+           
+out << """
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* ! OW_COMMANDS_V${openwireVersion}_H */
+"""
+           
+		}
+		
+      //////////////////////////////////////////////////////////////////////
+      //
+      // Start generateing the ow_commands_v1.c File
+      //
+      //////////////////////////////////////////////////////////////////////
+      
+      file = new File(destDir, "ow_commands_v${openwireVersion}.c")
+      file.withWriter { out |
+      
+out << """/**
+ *
+ * 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.
+ */
+
+/*****************************************************************************************
+ *  
+ * NOTE!: This file is auto generated - do not modify!
+ *        if you need to make a change, please see the modify the groovy scripts in the
+ *        under src/gram/script and then use maven openwire:generate to regenerate 
+ *        this file.
+ *  
+ *****************************************************************************************/
+
+
+#include "ow_commands_v${openwireVersion}.h"
+
+#define SUCCESS_CHECK( f ) { apr_status_t rc=f; if(rc!=APR_SUCCESS) return rc; }
+
+"""
+         for (jclass in openwireClasses) {
+	
+	            properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+	            def name = jclass.simpleName;
+	            def type = ("ow_"+name).toUpperCase()+"_TYPE"
+	            
+	            def baseName="DataStructure";
+	            
+	            def superclass = jclass.superclass;	            
+	            while( superclass.superclass != null ) {
+  	              if( openwireClasses.contains(superclass) ) {
+                      baseName = superclass.simpleName;
+                      break;
+                   } else {
+                      superclass = superclass.superclass;
+                   }
+	            }
+               
+out << """
+ow_boolean ow_is_a_${name}(ow_DataStructure *object) {
+   if( object == 0 )
+      return 0;
+      
+   switch(object->structType) {"""
+            for (sub in openwireClasses) {
+	            def subtype = "OW_"+sub.simpleName.toUpperCase()+"_TYPE"
+               if( jclass.isAssignableFrom(sub) && !isAbstract(sub) ) {
+out << """
+   case $subtype:"""
+               
+               }            
+            }
+out << """
+      return 1;
+   }
+   return 0;
+}
+"""
+               
+
+               if( !isAbstract(jclass) ) {
+out << """
+
+ow_${name} *ow_${name}_create(apr_pool_t *pool) 
+{
+   ow_${name} *value = apr_pcalloc(pool,sizeof(ow_${name}));
+   if( value!=0 ) {
+      ((ow_DataStructure*)value)->structType = ${type};
+   }
+   return value;
+}
+"""
+               }
+               
+out << """
+
+apr_status_t ow_marshal1_${name}(ow_bit_buffer *buffer, ow_${name} *object)
+{
+   ow_marshal1_${baseName}(buffer, (ow_${baseName}*)object);
+"""
+
+	             properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+               for (property in properties) {
+                   def propname = toPropertyCase(property.simpleName);
+                   def cached = isCachedProperty(property);
+                   def annotation = property.getter.getAnnotation("openwire:property");
+                   def size = annotation.getValue("size");
+
+                   out << "   ";
+                   type = property.type.qualifiedName
+                   switch (type) {
+                   
+                   case "boolean":
+                       out << "ow_bit_buffer_append(buffer, object->$propname);"; break;
+                       break;
+                   case "byte":break;
+                   case "char":break;
+                   case "short":break;
+                   case "int":break;
+                   case "long":
+                       out << "ow_marshal1_long(buffer, object->$propname);"; break;
+                       break;
+                   case "byte[]":
+                     if( size ==null ) {
+                        out << """
+                        ow_bit_buffer_append(buffer,  object->$propname!=0 );
+                        """;
+                     }
+                     break;
+                   case "org.apache.activeio.packet.ByteSequence":
+                     if( size ==null ) {
+                        out << """
+                        ow_bit_buffer_append(buffer,  object->$propname!=0 );
+                        """;
+                     }
+                     break;
+                   case "java.lang.String":
+                       out << "ow_marshal1_string(buffer, object->$propname);"; break;
+                   default:
+                         if( property.type.arrayType ) {
+                           if( size!=null ) {
+                              out << "SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->$propname, ${size.asInt()}));"; break;
+                           } else {
+                              out << "SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->$propname));"; break;
+                           }
+                         } else if( isThrowable(property.type) ) {    	    
+                           out << "SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->$propname));"; break;
+                         } else {
+                           if( cached ) {
+                              out << "SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->$propname));"; break;
+                           } else {
+                              out << "SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->$propname));"; break;
+                           }
+                       }
+                   }
+out << """
+"""
+               }
+
+
+out << """   
+	return APR_SUCCESS;
+}
+apr_status_t ow_marshal2_${name}(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_${name} *object)
+{
+   ow_marshal2_${baseName}(buffer, bitbuffer, (ow_${baseName}*)object);   
+"""
+
+	             properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+               for (property in properties) {
+                   def annotation = property.getter.getAnnotation("openwire:property");
+                   def size = annotation.getValue("size");
+                   def propname = toPropertyCase(property.simpleName);
+                   def cached = isCachedProperty(property);
+                   
+                   out << "   "
+                   type = property.type.qualifiedName
+                   switch (type) {                   
+                   case "boolean": 
+                       out << "ow_bit_buffer_read(bitbuffer);"; break;
+                   case "byte":
+                       out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
+                       break;
+                   case "char":
+                       out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
+                       break;
+                   case "short":
+                       out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
+                       break;
+                   case "int":
+                       out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
+                       break;
+                   case "long":
+                       out << "SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->$propname));"; break;
+                       break;
+                   case "byte[]":
+                       if( size!=null ) {
+                          out << "SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->$propname, ${size.asInt()}));"; break;
+                       } else {
+                          out << "SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->$propname));"; break;
+                       }
+                       break;
+                   case "org.apache.activeio.packet.ByteSequence":
+                       if( size!=null ) {
+                          out << "SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->$propname, ${size.asInt()}));"; break;
+                       } else {
+                          out << "SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->$propname));"; break;
+                       }
+                       break;
+                   case "java.lang.String":
+                       out << "SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->$propname));"; break;
+                       break;
+                   default:
+                      if( property.type.arrayType ) {
+                         if( size!=null ) {
+                            out << "SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->$propname, ${size.asInt()}));"; break;
+                         } else {
+                            out << "SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->$propname));"; break;
+                         }
+                      } else if( isThrowable(property.type) ) {    	    
+                        out << "SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->$propname));"; break;
+                      } else {
+                           if( cached ) {
+                              out << "SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->$propname));"; break;
+                           } else {
+                              out << "SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->$propname));"; break;
+                           }                      
+                      }
+                   }
+out << """
+"""
+               }
+
+out << """   
+	return APR_SUCCESS;
+}
+
+apr_status_t ow_unmarshal_${name}(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_${name} *object, apr_pool_t *pool)
+{
+   ow_unmarshal_${baseName}(buffer, bitbuffer, (ow_${baseName}*)object, pool);   
+"""
+
+	             properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+               for (property in properties) {
+                   def annotation = property.getter.getAnnotation("openwire:property");
+                   def size = annotation.getValue("size");
+                   def propname = toPropertyCase(property.simpleName);
+                   def cached = isCachedProperty(property);
+                   
+                   out << "   "
+                   type = property.type.qualifiedName
+                   switch (type) {                   
+                   case "boolean":
+                       out << "object->$propname = ow_bit_buffer_read(bitbuffer);"; break;
+                       break;
+                   case "byte":
+                       out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
+                       break;
+                   case "char":
+                       out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
+                       break;
+                   case "short":
+                       out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
+                       break;
+                   case "int":
+                       out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
+                       break;
+                   case "long":
+                       out << "SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->$propname, pool));"; break;
+                       break;
+                   case "byte[]":
+                       if( size!=null ) {
+                           out << "SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->$propname, ${size.asInt()}, pool));"; break;
+                       } else {
+                           out << "SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->$propname, pool));"; break;
+                       }
+                       break;
+                   case "org.apache.activeio.packet.ByteSequence":
+                       if( size!=null ) {
+                           out << "SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->$propname, ${size.asInt()}, pool));"; break;
+                       } else {
+                           out << "SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->$propname, pool));"; break;
+                       }
+                       break;
+                   case "java.lang.String":
+                       out << "SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->$propname, pool));"; break;
+                       break;
+                   default:
+                      if( property.type.arrayType ) {
+                        if( size!=null ) {
+                           out << "SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->$propname, ${size.asInt()}, pool));"; break;
+                        } else {
+                           out << "SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->$propname, pool));"; break;
+                        }
+                      } else if( isThrowable(property.type) ) {    	    
+                         out << "SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->$propname, pool));"; break;
+                      } else {
+                           if( cached ) {
+                              out << "SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->$propname, pool));"; break;
+                           } else {
+                              out << "SUCCESS_CHECK(ow_unmarshal_nested_object(buffer, bitbuffer, (ow_DataStructure**)&object->$propname, pool));"; break;
+                           }                      
+                      }
+                   }
+out << """
+"""
+               }
+
+out << """   
+	return APR_SUCCESS;
+}
+"""
+         }  
+         
+         
+out << """
+ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)
+{
+   switch( type ) {
+"""
+         for (jclass in openwireClasses) {
+            def name = jclass.simpleName;
+            def type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out << """
+      case ${type}: return (ow_DataStructure *)ow_${name}_create(pool);"""
+            }
+         }
+         
+out << """
+   }
+   return 0;
+}
+
+apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)
+{
+   switch( object->structType ) {
+"""
+         for (jclass in openwireClasses) {
+            def name = jclass.simpleName;
+            def type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out << """
+      case ${type}: return ow_marshal1_${name}(buffer, (ow_${name}*)object);"""
+            }
+         }
+         
+out << """
+   }
+   return APR_EGENERAL;
+}
+
+apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)
+{
+   switch( object->structType ) {
+"""
+         for (jclass in openwireClasses) {
+            def name = jclass.simpleName;
+            def type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out << """
+      case ${type}: return ow_marshal2_${name}(buffer, bitbuffer, (ow_${name}*)object);"""
+            }
+         }
+
+out << """
+   }
+   return APR_EGENERAL;
+}
+
+apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)
+{
+   switch( object->structType ) {
+"""
+         for (jclass in openwireClasses) {
+            def name = jclass.simpleName;
+            def type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out << """
+      case ${type}: return ow_unmarshal_${name}(buffer, bitbuffer, (ow_${name}*)object, pool);"""
+            }
+         }
+
+out << """
+   }
+   return APR_EGENERAL;
+}
+"""
+      }
+   }
+}

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCMarshalling.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpClasses.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpClasses.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpClasses.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpClasses.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,143 @@
+/**
+ *
+ * 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.OpenWireCSharpClassesScript
+
+/**
+ * Generates the C# commands for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCSharpClasses extends OpenWireCSharpClassesScript {
+
+	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.
+*/
+
+//
+//  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
+//
+
+using System;
+using System.Collections;
+
+using ActiveMQ.OpenWire;
+using ActiveMQ.Commands;
+
+namespace ActiveMQ.Commands
+{
+	/// <summary>
+    ///  The ActiveMQ ${jclass.simpleName} Command
+	/// </summary>
+    public class ${jclass.simpleName} : $baseClass"""
+        
+    for( i in jclass.interfaces ) {
+    	out << ", ${i.simpleName}";
+    }
+    
+out << """
+    {
+        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;
+"""
+    }
+
+	def text = makeHashCodeBody()
+	if (text != null) out << 
+"""
+		public override int GetHashCode() {
+$text
+		}
+	
+"""	
+	   
+	text = makeEqualsBody()
+	if (text != null) out << 
+"""
+		public override bool Equals(object that) {
+	    	if (that is ${className}) {
+	    	    return Equals((${className}) that);
+			}
+			return false;
+    	}
+    
+		public virtual bool Equals(${className} that) {
+$text
+		}
+	
+"""	
+	    
+	text = makeToStringBody()
+	if (text != null) out << """
+		public override string ToString() {
+$text
+		}
+	
+"""	
+	    
+    out << """
+
+        public override byte GetDataStructureType() {
+            return ID_${jclass.simpleName};
+        }
+
+
+        // Properties
+"""
+                for (property in properties) {
+                    def type = toCSharpType(property.type)
+                    def name = decapitalize(property.simpleName)
+                    def propertyName = property.simpleName
+                    def getter = capitalize(property.getter.simpleName)
+                    def setter = capitalize(property.setter.simpleName)
+
+
+                    out << """
+        public $type $propertyName
+        {
+            get { return $name; }
+            set { this.$name = value; }            
+        }
+"""
+                }
+
+                out << """
+    }
+}
+"""
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpClasses.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpMarshalling.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpMarshalling.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpMarshalling.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpMarshalling.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,276 @@
+/**
+ *
+ * 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.OpenWireCSharpMarshallingScript
+
+/**
+ * Generates the C# marshalling code for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCSharpMarshalling extends OpenWireCSharpMarshallingScript {
+
+ 	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.
+*/
+
+//
+// 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
+//
+
+using System;
+using System.Collections;
+using System.IO;
+
+using ActiveMQ.Commands;
+using ActiveMQ.OpenWire;
+using ActiveMQ.OpenWire.V${openwireVersion};
+
+namespace ActiveMQ.OpenWire.V${openwireVersion}
+{
+  /// <summary>
+  ///  Marshalling code for Open Wire Format for ${jclass.simpleName}
+  /// </summary>
+  ${abstractClassText}class $className : $baseClass
+  {
+"""
+
+if( !abstractClass ) out << """
+
+    public override DataStructure CreateObject() 
+    {
+        return new ${jclass.simpleName}();
+    }
+
+    public override byte GetDataStructureType() 
+    {
+        return ${jclass.simpleName}.ID_${jclass.simpleName};
+    }
+"""
+
+/*
+ * Generate the tight encoding marshallers
+ */ 
+out << """
+    // 
+    // Un-marshal an object instance from the data input stream
+    // 
+    public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs) 
+    {
+        base.TightUnmarshal(wireFormat, o, dataIn, bs);
+"""
+ 
+if( !properties.isEmpty() || marshallerAware )  out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+if( marshallerAware ) out << """
+        info.BeforeUnmarshall(wireFormat);
+        
+"""
+
+generateTightUnmarshalBody(out)
+
+if( marshallerAware ) out << """
+        info.AfterUnmarshall(wireFormat);
+"""
+
+out << """
+    }
+"""
+
+out << """
+    //
+    // Write the booleans that this object uses to a BooleanStream
+    //
+    public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) {
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+if( marshallerAware ) out << """
+        info.BeforeMarshall(wireFormat);
+"""
+
+out << """
+        int rc = base.TightMarshal1(wireFormat, info, bs);
+"""
+
+def baseSize = generateTightMarshal1Body(out)
+    
+out << """
+        return rc + ${baseSize};
+    }
+
+    // 
+    // Write a object instance to data output stream
+    //
+    public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs) {
+        base.TightMarshal2(wireFormat, o, dataOut, bs);
+"""
+
+if( !properties.isEmpty() || marshallerAware ) out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+generateTightMarshal2Body(out)
+
+if( marshallerAware ) out << """
+        info.AfterMarshall(wireFormat);
+"""
+
+out << """
+    }
+"""
+
+/*
+ * Generate the loose encoding marshallers
+ */ 
+out << """
+    // 
+    // Un-marshal an object instance from the data input stream
+    // 
+    public override void LooseUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn) 
+    {
+        base.LooseUnmarshal(wireFormat, o, dataIn);
+"""
+ 
+if( !properties.isEmpty() || marshallerAware )  out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+if( marshallerAware ) out << """
+        info.BeforeUnmarshall(wireFormat);
+        
+"""
+
+generateLooseUnmarshalBody(out)
+
+if( marshallerAware ) out << """
+        info.AfterUnmarshall(wireFormat);
+"""
+
+out << """
+    }
+"""
+
+out << """
+    // 
+    // Write a object instance to data output stream
+    //
+    public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut) {
+"""
+
+if( !properties.isEmpty() || marshallerAware ) out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+if( marshallerAware ) out << """
+        info.BeforeMarshall(wireFormat);
+"""
+
+out << """
+        base.LooseMarshal(wireFormat, o, dataOut);
+"""
+
+generateLooseMarshalBody(out)
+
+if( marshallerAware ) out << """
+        info.AfterMarshall(wireFormat);
+"""
+out << """
+    }
+"""
+
+
+out << """    
+  }
+}
+"""
+        }
+ 	
+ 
+    void generateFactory(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.
+*/
+
+//
+// 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
+//
+
+using System;
+using System.Collections;
+using System.IO;
+
+using ActiveMQ.Commands;
+using ActiveMQ.OpenWire;
+using ActiveMQ.OpenWire.V${openwireVersion};
+
+namespace ActiveMQ.OpenWire.V${openwireVersion}
+{
+	/// <summary>
+	/// Used to create marshallers for a specific version of the wire protocol
+	/// </summary>
+    public class MarshallerFactory
+    {
+        public void configure(OpenWireFormat format) 
+        {
+"""
+
+    for (jclass in concreteClasses) {
+	    out << """
+            format.addMarshaller(new ${jclass.simpleName}Marshaller());"""
+    }        
+
+    out << """
+    	}
+    }
+}
+"""
+    }
+}
+ 	
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpMarshalling.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppClasses.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppClasses.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppClasses.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppClasses.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,125 @@
+/**
+ *
+ * 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 "activemq/command/${className}.hpp"
+
+using namespace apache::activemq::command;
+
+/*
+ *
+ *  Command and marshalling code for OpenWire 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}()
+{
+}
+
+unsigned char ${className}::getDataStructureType()
+{
+    return ${className}::TYPE ; 
+}
+"""
+    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} ;
+}
+"""
+    }
+out << """
+int ${className}::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)
+{
+    int size = 0 ;
+
+    size += ${baseClass}::marshal(marshaller, mode, ostream) ; """
+    for (property in properties) {
+        def marshalMethod = toMarshalMethodName(property.type)
+        def propertyName = decapitalize(property.simpleName)
+        out << """
+    size += marshaller->${marshalMethod}(${propertyName}, mode, ostream) ; """
+    }
+out << """
+    return size ;
+}
+
+void ${className}::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)
+{
+    ${baseClass}::unmarshal(marshaller, mode, istream) ; """
+    for (property in properties) {
+        def cast = toUnmarshalCast(property.type)
+        def unmarshalMethod = toUnmarshalMethodName(property.type)
+        def propertyName = decapitalize(property.simpleName)
+        out << """
+    ${propertyName} = ${cast}(marshaller->${unmarshalMethod}(mode, istream)) ; """
+    }
+out << """
+}
+"""
+    }
+}

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppClasses.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppHeaders.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppHeaders.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppHeaders.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppHeaders.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,153 @@
+/**
+ *
+ * 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 ActiveMQ_${className}_hpp_
+#define ActiveMQ_${className}_hpp_
+
+// Turn off warning message for ignored exception specification
+#ifdef _MSC_VER
+#pragma warning( disable : 4290 )
+#endif
+
+#include <string>
+"""
+    out << """#include "activemq/command/${baseClass}.hpp"
+"""
+for (property in properties)
+{
+    if( !property.type.isPrimitiveType() &&
+         property.type.simpleName != "String" &&
+         property.type.simpleName != "ByteSequence" )
+    {
+        def includeName = toCppType(property.type)
+        if( property.type.isArrayType() )
+        {
+            def arrayType = property.type.arrayComponentType ;
+            if( arrayType.isPrimitiveType() )
+                continue ;
+        }
+        if( includeName.startsWith("array<") )
+            includeName = includeName.substring(6, includeName.length()-1) ;
+        else if( includeName.startsWith("p<") )
+            includeName = includeName.substring(2, includeName.length()-1)
+
+        if( includeName.equals("IDataStructure") )
+            out << """#include "activemq/${includeName}.hpp"
+"""
+        else
+            out << """#include "activemq/command/${includeName}.hpp"
+"""
+    }
+}
+out << """
+#include "activemq/protocol/IMarshaller.hpp"
+#include "ppr/io/IOutputStream.hpp"
+#include "ppr/io/IInputStream.hpp"
+#include "ppr/io/IOException.hpp"
+#include "ppr/util/ifr/array"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace activemq
+  {
+    namespace command
+    {
+      using namespace ifr;
+      using namespace std;
+      using namespace apache::activemq;
+      using namespace apache::activemq::protocol;
+      using namespace apache::ppr::io;
+
+/*
+ *
+ *  Command and marshalling code for OpenWire 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}
+{
+protected:
+"""
+    for (property in properties) {
+        def type = toCppType(property.type)
+        def name = decapitalize(property.simpleName)
+        out << """    $type $name ;
+"""
+    }
+    out << """
+public:
+    const static unsigned char TYPE = ${getOpenWireOpCode(jclass)};
+
+public:
+    ${className}() ;
+    virtual ~${className}() ;
+
+    virtual unsigned char getDataStructureType() ;
+"""
+    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 << """
+    virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;
+    virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*ActiveMQ_${className}_hpp_*/
+"""
+    }
+}

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppHeaders.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingClasses.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingClasses.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingClasses.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingClasses.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,207 @@
+/**
+ *
+ * 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.OpenWireCppMarshallingClassesScript
+
+/**
+ * Generates the C++ marshalling classes for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCppMarshallingClasses extends OpenWireCppMarshallingClassesScript {
+
+ 	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 "marshal/${className}.hpp"
+
+using namespace apache::activemq::client::marshal;
+
+/*
+ *  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
+ */
+
+${className}::${className}()
+{
+    // no-op
+}
+
+${className}::~${className}()
+{
+    // no-op
+}
+
+"""
+
+if( !abstractClass ) out << """
+
+IDataStructure* ${className}::createObject() 
+{
+    return new ${jclass.simpleName}();
+}
+
+char ${className}::getDataStructureType() 
+{
+    return ${jclass.simpleName}.ID_${jclass.simpleName};
+}
+"""
+
+out << """
+    /* 
+     * Un-marshal an object instance from the data input stream
+     */ 
+void ${className}::unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) 
+{
+    base.unmarshal(wireFormat, o, dataIn, bs);
+"""
+ 
+if( !properties.isEmpty() || marshallerAware )  out << """
+    ${jclass.simpleName}& info = (${jclass.simpleName}&) o;
+"""
+
+if( marshallerAware ) out << """
+    info.beforeUnmarshall(wireFormat);
+        
+"""
+
+generateTightUnmarshalBody(out)
+
+if( marshallerAware ) out << """
+    info.afterUnmarshall(wireFormat);
+"""
+
+out << """
+}
+
+
+/*
+ * Write the booleans that this object uses to a BooleanStream
+ */
+int ${className}::marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) {
+    ${jclass.simpleName}& info = (${jclass.simpleName}&) o;
+"""
+
+
+if( marshallerAware ) out << """
+    info.beforeMarshall(wireFormat);
+"""
+
+out << """
+    int rc = base.marshal1(wireFormat, info, bs);
+"""
+
+def baseSize = generateMarshal1Body(out)
+    
+out << """
+    return rc + ${baseSize};
+}
+
+/* 
+ * Write a object instance to data output stream
+ */
+void ${className}::marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) {
+    base.marshal2(wireFormat, o, dataOut, bs);
+"""
+
+if( !properties.isEmpty() || marshallerAware ) out << """
+    ${jclass.simpleName}& info = (${jclass.simpleName}&) o;
+"""
+
+generateMarshal2Body(out)
+
+if( marshallerAware ) out << """
+    info.afterMarshall(wireFormat);
+"""
+
+out << """
+}
+"""
+    }
+ 	
+ 	
+    void generateFactory(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.
+*/
+
+// Marshalling code for Open Wire Format
+//
+//
+// 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
+//
+
+#include "marshal/${className}.hpp"
+
+"""
+
+		    for (jclass in concreteClasses) {
+		        out << """#include "marshal/${jclass.simpleName}Marshaller.hpp"
+"""
+		    }        
+
+		    out << """
+
+using namespace apache::activemq::client::marshal;
+
+
+void MarshallerFactory::configure(ProtocolFormat& format) 
+{
+"""
+
+    for (jclass in concreteClasses) {
+	    out << """
+    format.addMarshaller(new ${jclass.simpleName}Marshaller());"""
+    }        
+
+    out << """
+}
+"""
+    }
+}
+ 	
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingClasses.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingHeaders.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingHeaders.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingHeaders.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingHeaders.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,171 @@
+/**
+ *
+ * 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.OpenWireCppMarshallingHeadersScript
+
+/**
+ * Generates the C++ marshalling headers for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateCppMarshallingHeaders extends OpenWireCppMarshallingHeadersScript {
+
+ 	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>
+
+#include "command/IDataStructure.hpp"
+
+/* we could cut this down  - for now include all possible headers */
+#include "command/BrokerId.hpp"
+#include "command/ConnectionId.hpp"
+#include "command/ConsumerId.hpp"
+#include "command/ProducerId.hpp"
+#include "command/SessionId.hpp"
+
+#include "io/BinaryReader.hpp"
+#include "io/BinaryWriter.hpp"
+
+#include "command/${baseClass}.hpp"
+#include "util/ifr/p.hpp"
+
+#include "protocol/ProtocolFormat.hpp"
+
+namespace apache
+{
+  namespace activemq
+  {
+    namespace client
+    {
+      namespace marshal
+      {
+        using namespace ifr ;
+        using namespace apache::activemq::client::command;
+        using namespace apache::activemq::client::io;
+        using namespace apache::activemq::client::protocol;
+
+/*
+ *
+ */
+class ${className} : public ${baseClass}
+{
+public:
+    ${className}() ;
+    virtual ~${className}() ;
+
+    virtual IDataStructure* createCommand() ;
+    virtual char getDataStructureType() ;
+    
+    virtual void unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ;
+    virtual int marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) ;
+    virtual void marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) ;
+} ;
+
+/* namespace */
+     }
+    }
+  }
+}
+#endif /*${className}_hpp_*/
+"""
+        }
+ 	
+ 
+    void generateFactory(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.
+*/
+
+// Marshalling code for Open Wire Format 
+//
+//
+// 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
+//
+
+#ifndef MarshallerFactory_hpp_
+#define MarshallerFactory_hpp_
+
+
+namespace apache
+{
+  namespace activemq
+  {
+    namespace client
+    {
+      namespace marshal
+      {
+        using namespace ifr ;
+        using namespace std ;
+        using namespace apache::activemq::client;
+        using namespace apache::activemq::client::command;
+        using namespace apache::activemq::client::io;
+
+/*
+ * 
+ */
+class MarshallerFactory
+{
+public:
+    MarshallerFactory() ;
+    virtual ~MarshallerFactory() ;
+
+	  virtual void configure(ProtocolFormat& format) ;
+} ;
+
+/* namespace */
+      }
+    }
+  }
+}
+
+#endif /*MarshallerFactory_hpp_*/
+"""
+    }
+}
+ 	
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingHeaders.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaMarshalling.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaMarshalling.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaMarshalling.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaMarshalling.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,295 @@
+/**
+ *
+ * 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.OpenWireJavaMarshallingScript
+
+/**
+ * Generates the Java marshalling code for the Open Wire Format
+ *
+ * @version $Revision$
+ */
+class GenerateJavaMarshalling extends OpenWireJavaMarshallingScript {
+
+ 	void generateFile(PrintWriter out) {
+        out << """/**
+ *
+ * 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.v${openwireVersion};
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.activemq.openwire.*;
+import org.apache.activemq.command.*;
+
+"""
+for (pkg in jclass.importedPackages) {
+    for (clazz in pkg.classes) {
+       out << "import "+clazz.qualifiedName+";"
+    }
+}
+out << """
+
+/**
+ * Marshalling code for Open Wire Format for ${className}
+ *
+ *
+ * NOTE!: This file is auto generated - do not modify!
+ *        if you need to make a change, please see the modify the groovy scripts in the
+ *        under src/gram/script and then use maven openwire:generate to regenerate 
+ *        this file.
+ *
+ * @version \$Revision\$
+ */
+public ${abstractClassText}class ${className} extends ${baseClass} {
+"""
+
+if( !abstractClass ) out << """
+    /**
+     * Return the type of Data Structure we marshal
+     * @return short representation of the type data structure
+     */
+    public byte getDataStructureType() {
+        return ${jclass.simpleName}.DATA_STRUCTURE_TYPE;
+    }
+    
+    /**
+     * @return a new object instance
+     */
+    public DataStructure createObject() {
+        return new ${jclass.simpleName}();
+    }
+"""
+
+out << """
+    /**
+     * Un-marshal an object instance from the data input stream
+     *
+     * @param o the object to un-marshal
+     * @param dataIn the data input stream to build the object from
+     * @throws IOException
+     */
+    public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn, BooleanStream bs) throws IOException {
+        super.tightUnmarshal(wireFormat, o, dataIn, bs);
+"""
+
+if( !properties.isEmpty() )  out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+if( marshallerAware ) out << """
+        info.beforeUnmarshall(wireFormat);
+        
+"""
+
+generateTightUnmarshalBody(out)
+
+if( marshallerAware ) out << """
+        info.afterUnmarshall(wireFormat);
+"""
+
+out << """
+    }
+
+
+    /**
+     * Write the booleans that this object uses to a BooleanStream
+     */
+    public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {
+"""
+
+
+if( !properties.isEmpty() ) out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+
+if( marshallerAware ) out << """
+        info.beforeMarshall(wireFormat);
+"""
+
+out << """
+        int rc = super.tightMarshal1(wireFormat, o, bs);
+"""
+
+def baseSize = generateTightMarshal1Body(out)
+    
+out << """
+        return rc + ${baseSize};
+    }
+
+    /**
+     * Write a object instance to data output stream
+     *
+     * @param o the instance to be marshaled
+     * @param dataOut the output stream
+     * @throws IOException thrown if an error occurs
+     */
+    public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut, BooleanStream bs) throws IOException {
+        super.tightMarshal2(wireFormat, o, dataOut, bs);
+"""
+
+if( !properties.isEmpty() ) out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+generateTightMarshal2Body(out)
+
+if( marshallerAware ) out << """
+        info.afterMarshall(wireFormat);
+"""
+
+out << """
+    }
+"""
+
+out << """
+    /**
+     * Un-marshal an object instance from the data input stream
+     *
+     * @param o the object to un-marshal
+     * @param dataIn the data input stream to build the object from
+     * @throws IOException
+     */
+    public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn) throws IOException {
+        super.looseUnmarshal(wireFormat, o, dataIn);
+"""
+
+if( !properties.isEmpty() )  out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+if( marshallerAware ) out << """
+        info.beforeUnmarshall(wireFormat);
+        
+"""
+
+generateLooseUnmarshalBody(out)
+
+if( marshallerAware ) out << """
+        info.afterUnmarshall(wireFormat);
+"""
+
+out << """
+    }
+
+
+    /**
+     * Write the booleans that this object uses to a BooleanStream
+     */
+    public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut) throws IOException {
+"""
+
+if( !properties.isEmpty() ) out << """
+        ${jclass.simpleName} info = (${jclass.simpleName})o;
+"""
+
+
+if( marshallerAware ) out << """
+        info.beforeMarshall(wireFormat);
+"""
+
+out << """
+        super.looseMarshal(wireFormat, o, dataOut);
+"""
+
+generateLooseMarshalBody(out)
+    
+out << """
+    }
+}
+"""
+        }
+ 	
+ 
+    	void generateFactory(PrintWriter out) {
+            out << """/**
+ *
+ * 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.v${openwireVersion};
+
+import org.apache.activemq.openwire.DataStreamMarshaller;
+import org.apache.activemq.openwire.OpenWireFormat;
+
+/**
+ * MarshallerFactory for Open Wire Format.
+ *
+ *
+ * NOTE!: This file is auto generated - do not modify!
+ *        if you need to make a change, please see the modify the groovy scripts in the
+ *        under src/gram/script and then use maven openwire:generate to regenerate 
+ *        this file.
+ *
+ * @version \$Revision\$
+ */
+public class MarshallerFactory {
+
+    /**
+     * Creates a Map of command type -> Marshallers
+     */
+    static final private DataStreamMarshaller marshaller[] = new DataStreamMarshaller[256];
+    static {
+"""
+
+for (jclass in concreteClasses) {
+out << """
+        add(new ${jclass.simpleName}Marshaller());"""
+}        
+
+out << """
+
+	}
+
+	static private void add(DataStreamMarshaller dsm) {
+        marshaller[dsm.getDataStructureType()] = dsm;
+    }
+	
+    static public DataStreamMarshaller[] createMarshallerMap(OpenWireFormat wireFormat) {
+        return marshaller;
+    }
+}
+"""
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaMarshalling.groovy
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaTests.groovy
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaTests.groovy?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaTests.groovy (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaTests.groovy Wed Jul  5 14:59:37 2006
@@ -0,0 +1,222 @@
+/**
+ *
+ * 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.OpenWireScript
+import org.apache.activemq.openwire.tool.TestDataGenerator
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.FixCRLF;
+
+/**
+ * Generates the Java test code for the Open Wire Format
+ *
+ * @version $Revision: $
+ */
+class GenerateJavaTests extends OpenWireScript {
+
+    Object run() {
+    
+        def openwireVersion = getProperty("version");
+        
+        def destDir = new File("src/test/java/org/apache/activemq/openwire/v${openwireVersion}")
+        println "Generating Java test code to directory ${destDir}"
+        
+        def openwireClasses = classes.findAll {
+        		it.getAnnotation("openwire:marshaller")!=null
+        }
+
+        def concreteClasses = new ArrayList()
+        def buffer = new StringBuffer()
+        int counter = 0
+        Map map = [:]
+
+        destDir.mkdirs()
+        for (jclass in openwireClasses) {
+
+            println "Processing ${jclass.simpleName}"
+            def abstractText = "abstract "
+            def classIsAbstract = isAbstract(jclass);
+            def isBaseAbstract = isAbstract(jclass.superclass);
+            if( !classIsAbstract ) {
+              concreteClasses.add(jclass)
+              abstractText = ""
+            }
+            
+            def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+            
+            def testClassName = jclass.simpleName + "Test"
+            if (classIsAbstract) 
+                testClassName += "Support"
+
+            def file = new File(destDir, testClassName + ".java")
+
+            buffer << """
+${jclass.simpleName}Test.class
+"""
+
+            file.withWriter { out |
+out << """/**
+ *
+ * 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.v${openwireVersion};
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.activemq.openwire.*;
+import org.apache.activemq.command.*;
+"""
+for (pkg in jclass.importedPackages) {
+    for (clazz in pkg.classes) {
+       out << "import "+clazz.qualifiedName+";"
+    }
+}
+
+def baseClass = "DataFileGeneratorTestSupport"
+if (!jclass.superclass.simpleName.equals("JNDIBaseStorable") && !jclass.superclass.simpleName.equals("DataStructureSupport") && !jclass.superclass.simpleName.equals("Object") ) {
+   baseClass = jclass.superclass.simpleName + "Test";
+   if (isBaseAbstract) 
+       baseClass += "Support"
+}
+
+def marshallerAware = isMarshallAware(jclass);
+    
+out << """
+
+/**
+ * Test case for the OpenWire marshalling for ${jclass.simpleName}
+ *
+ *
+ * NOTE!: This file is auto generated - do not modify!
+ *        if you need to make a change, please see the modify the groovy scripts in the
+ *        under src/gram/script and then use maven openwire:generate to regenerate 
+ *        this file.
+ *
+ * @version \$Revision: \$
+ */
+public ${abstractText}class $testClassName extends $baseClass {
+"""
+	if (!classIsAbstract) 
+		out << """
+
+    public static ${jclass.simpleName}Test SINGLETON = new ${jclass.simpleName}Test();
+
+    public Object createObject() throws Exception {
+    		${jclass.simpleName} info = new ${jclass.simpleName}();
+    		populateObject(info);
+    		return info;
+    }
+"""
+	out << """
+    
+    protected void populateObject(Object object) throws Exception {
+    		super.populateObject(object);
+    		${jclass.simpleName} info = (${jclass.simpleName}) object;
+"""
+
+def generator = new TestDataGenerator();
+
+for (property in properties) {
+    def annotation = property.getter.getAnnotation("openwire:property");
+    def size = annotation.getValue("size");
+    def testSize = stringValue(annotation, "testSize");
+    def type = property.type.simpleName
+    def cached = isCachedProperty(property);
+    def propertyName = property.simpleName;
+    if (testSize == "-1") continue
+    
+    out << "        "
+    switch (type) {
+    case "boolean":
+        out << "info.${property.setter.simpleName}(${generator.createBool()});"; break;
+    case "byte":
+        out << "info.${property.setter.simpleName}(${generator.createByte()});"; break;
+    case "char":
+        out << "info.${property.setter.simpleName}(${generator.createChar()});"; break;
+    case "short":
+        out << "info.${property.setter.simpleName}(${generator.createShort()});"; break;
+    case "int":
+        out << "info.${property.setter.simpleName}(${generator.createInt()});"; break;
+    case "long":
+	    out << "info.${property.setter.simpleName}(${generator.createLong()});"; break;
+    case "byte[]":
+	    out << """info.${property.setter.simpleName}(${generator.createByteArray(propertyName)});"""; break;
+    case "String":
+	    out << """info.${property.setter.simpleName}("${generator.createString(propertyName)}");"""; break;
+    case "ByteSequence":
+    		out << """
+    		{
+        		byte data[] = ${generator.createByteArray(propertyName)};
+        		info.${property.setter.simpleName}(new org.apache.activeio.packet.ByteSequence(data,0,data.length));
+    		}
+    		""";
+        break;
+    case "Throwable":
+	    out << """info.${property.setter.simpleName}(createThrowable("${generator.createString(propertyName)}"));"""; break;
+    default:
+    	    if( property.type.arrayType ) {
+      	    def arrayType = property.type.arrayComponentType.simpleName;
+      	    if (size == null) 
+      	      size = 2
+      	    if (arrayType == jclass.simpleName)
+      	      size = 0
+      	     	
+      	    out << """
+    		    {
+	            ${arrayType} value[] = new ${arrayType}[${size}];
+	            for( int i=0; i < ${size}; i++ ) {
+	                value[i] = create${arrayType}("${generator.createString(propertyName)}");
+	            }
+	            info.${property.setter.simpleName}(value);
+            }"""
+        		} 
+        		else {
+        			out << """info.${property.setter.simpleName}(create${type}("${generator.createString(propertyName)}"));"""
+            }
+        }
+        out.newLine() 
+    }
+        out << """
+            }
+        }
+"""
+}
+        // 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(file.getParentFile());
+        fixCRLF.setIncludes(file.getName());
+        fixCRLF.execute();
+
+		}
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaTests.groovy
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message