activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r450289 [2/3] - in /incubator/activemq/trunk: activemq-core/ activemq-core/src/main/java/org/apache/activemq/openwire/v2/ activemq-core/src/test/java/org/apache/activemq/openwire/v2/ activemq-openwire-generator/src/main/java/org/apache/acti...
Date Wed, 27 Sep 2006 02:42:51 GMT
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CGeneratorTask.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CGeneratorTask.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CGeneratorTask.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CGeneratorTask.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,120 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.codehaus.jam.JamService;
+import org.codehaus.jam.JamServiceFactory;
+import org.codehaus.jam.JamServiceParams;
+
+/**
+ * 
+ * @version $Revision: 384826 $
+ */
+public class CGeneratorTask extends Task {
+	
+	int version = 2;
+	File source = new File(".");
+	File target = new File(".");
+	
+    public static void main(String[] args) {
+    	
+        Project project = new Project();
+        project.init();
+    	CGeneratorTask generator = new CGeneratorTask();
+    	generator.setProject(project);
+    	
+    	if( args.length > 0 ) {
+    		generator.version = Integer.parseInt(args[0]);
+    	}
+
+    	if( args.length > 1 ) {
+    		generator.source = new File(args[1]);
+    	}  
+    	
+    	if( args.length > 2 ) {
+    		generator.target = new File(args[2]);
+    	}    	
+    	
+    	generator.execute();
+	}
+    
+    public void execute() throws BuildException {
+        try {
+        	
+        	String sourceDir = source+"/src/main/java";
+        	
+            System.out.println("Parsing source files in: " + sourceDir);
+
+            JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
+            JamServiceParams params = jamServiceFactory.createServiceParams();            
+            File[] dirs = new File[]{new File(sourceDir)};            
+            params.includeSourcePattern(dirs, "**/*.java");
+            JamService jam = jamServiceFactory.createService(params);
+
+            {
+            	CHeadersGenerator script = new CHeadersGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src/libopenwire");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            {
+            	CSourcesGenerator script = new CSourcesGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src/libopenwire");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            
+            
+            
+        } catch (Exception e) {
+        	throw new BuildException(e);
+        }
+    }
+
+	public int getVersion() {
+		return version;
+	}
+
+	public void setVersion(int version) {
+		this.version = version;
+	}
+
+	public File getSource() {
+		return source;
+	}
+
+	public void setSource(File basedir) {
+		this.source = basedir;
+	}
+
+	public File getTarget() {
+		return target;
+	}
+
+	public void setTarget(File target) {
+		this.target = target;
+	}
+
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CHeadersGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,261 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+/**
+ * 
+ * @version $Revision: 383749 $
+ */
+public class CHeadersGenerator extends SingleSourceGenerator {
+
+    protected String targetDir = "./src/lib/openwire";
+
+    public Object run() {
+        filePostFix = ".h";
+        if (destFile == null) {
+            destFile = new File(targetDir + "/ow_commands_v" + getOpenwireVersion() + ".h");
+        }
+        return super.run();
+    }
+
+    public String getTargetDir() {
+        return targetDir;
+    }
+
+    public void setTargetDir(String targetDir) {
+        this.targetDir = targetDir;
+    }
+
+    protected void generateLicence(PrintWriter out) {
+out.println("/**");
+out.println(" *");
+out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+out.println(" * this work for additional information regarding copyright ownership.");
+out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+out.println(" * (the \"License\"); you may not use this file except in compliance with");
+out.println(" * the License.  You may obtain a copy of the License at");
+out.println(" *");
+out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+out.println(" *");
+out.println(" * Unless required by applicable law or agreed to in writing, software");
+out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+out.println(" * See the License for the specific language governing permissions and");
+out.println(" * limitations under the License.");
+out.println(" */");
+    }
+
+    String changeCase(String value) {
+        StringBuffer b = new StringBuffer();
+        char[] cs = value.toCharArray();
+        for (int i = 0; i < cs.length; i++) {
+            char c = cs[i];
+            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.
+     */
+    protected List sort(List source) {
+        LinkedHashMap rc = new LinkedHashMap();
+    	ArrayList classes = new ArrayList(source);
+        Collections.sort(classes, new Comparator(){
+			public int compare(Object o1, Object o2) {
+				JClass c1 = (JClass) o1;
+				JClass c2 = (JClass) o2;
+				return c1.getSimpleName().compareTo(c2.getSimpleName());
+			}});
+    	
+        // lets make a map of all the class names
+        HashMap classNames = new HashMap();
+        for (Iterator iter = classes.iterator(); iter.hasNext();) {
+            JClass c = (JClass) iter.next();
+            classNames.put(c, c);
+        }
+
+        // Add all classes that have no parent first
+        for (Iterator iter = classes.iterator(); iter.hasNext();) {
+            JClass c = (JClass) iter.next();
+            if (!classNames.containsKey(c.getSuperclass()))
+                rc.put(c, c);
+        }
+
+        // now lets add the rest
+        for (Iterator iter = classes.iterator(); iter.hasNext();) {
+            JClass c = (JClass) iter.next();
+            if (!rc.containsKey(c))
+                rc.put(c,c);
+        }
+
+        return new ArrayList(rc.keySet());
+    }
+
+    void generateFields(PrintWriter out, JClass jclass) {
+
+        if (jclass.getSuperclass() == null || jclass.getSuperclass().getSimpleName().equals("Object")) {
+            out.println("");
+            out.println("   ow_byte structType;");
+        } else {
+            generateFields(out, jclass.getSuperclass());
+        }
+
+        ArrayList properties = new ArrayList();
+        jclass.getDeclaredProperties();
+        for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
+            JProperty p = jclass.getDeclaredProperties()[i];
+            if (isValidProperty(p)) {
+                properties.add(p);
+            }
+        }
+        for (Iterator iter = properties.iterator(); iter.hasNext();) {
+            JProperty property = (JProperty) iter.next();
+            JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            String name = toPropertyCase(property.getSimpleName());
+            boolean cached = isCachedProperty(property);
+
+            String type = property.getType().getQualifiedName();
+            if (type.equals("boolean")) {
+                out.println("   ow_"+type+" "+name+";");
+            } else if (type.equals("byte")) {
+                out.println("   ow_"+type+" "+name+";");
+            } else if (type.equals("char")) {
+                out.println("   ow_"+type+" "+name+";");
+            } else if (type.equals("short")) {
+                out.println("   ow_"+type+" "+name+";");
+            } else if (type.equals("int")) {
+                out.println("   ow_"+type+" "+name+";");
+            } else if (type.equals("long")) {
+                out.println("   ow_"+type+" "+name+";");
+            } else if (type.equals("byte[]")) {
+                out.println("   ow_byte_array *"+name+";");
+            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
+                out.println("   ow_byte_array *"+name+";");
+            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
+                out.println("   ow_byte_array *"+name+";");
+            } else if (type.equals("java.lang.String")) {
+                out.println("   ow_string *"+name+";");
+            } else {
+                if (property.getType().isArrayType()) {
+                    out.println("   ow_DataStructure_array *"+name+";");
+                } else if (isThrowable(property.getType())) {
+                    out.println("   ow_throwable *"+name+";");
+                } else {
+                    out.println("   struct ow_" + property.getType().getSimpleName() + " *"+name+";");
+                }
+            }
+        }
+    }
+    
+    
+    protected void generateSetup(PrintWriter out) {
+        generateLicence(out);
+out.println("");
+out.println("/*****************************************************************************************");
+out.println(" *  ");
+out.println(" * NOTE!: This file is auto generated - do not modify!");
+out.println(" *        if you need to make a change, please see the modify the groovy scripts in the");
+out.println(" *        under src/gram/script and then use maven openwire:generate to regenerate ");
+out.println(" *        this file.");
+out.println(" *  ");
+out.println(" *****************************************************************************************/");
+out.println(" ");
+out.println("#ifndef OW_COMMANDS_V"+openwireVersion+"_H");
+out.println("#define OW_COMMANDS_V"+openwireVersion+"_H");
+out.println("");
+out.println("#include \"ow.h\"");
+out.println("");
+out.println("#ifdef __cplusplus");
+out.println("extern \"C\" {");
+out.println("#endif /* __cplusplus */");
+out.println("      ");
+out.println("#define OW_WIREFORMAT_VERSION "+openwireVersion+"");
+
+out.println("#define OW_WIREFORMAT_STACK_TRACE_MASK     0x00000001;");
+out.println("#define OW_WIREFORMAT_TCP_NO_DELAY_MASK    0x00000002;");
+out.println("#define OW_WIREFORMAT_CACHE_MASK           0x00000004;");
+out.println("#define OW_WIREFORMAT_COMPRESSION_MASK     0x00000008;");
+
+		for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+			JClass jclass = (JClass) iterator.next();
+		    String name = jclass.getSimpleName();
+		    String type = ("ow_"+name).toUpperCase()+"_TYPE";
+		    if( !isAbstract(jclass) ) {
+		    	out.println("#define "+type+" "+getOpenWireOpCode(jclass));
+		    }
+		 }
+
+out.println("      ");
+out.println("apr_status_t ow_bitmarshall(ow_bit_buffer *buffer, ow_DataStructure *object);");
+out.println("apr_status_t ow_marshall(ow_byte_buffer *buffer, ow_DataStructure *object);");
+    }
+    
+    protected void generateFile(PrintWriter out) throws Exception {
+
+        String structName = jclass.getSimpleName();
+        String type = "OW_" + structName.toUpperCase() + "_TYPE";
+
+out.println("");
+out.println("typedef struct ow_"+structName+" {");
+
+        // This recusivly generates the field definitions of the class and it's supper classes.
+        generateFields(out, jclass);
+
+out.println("");
+out.println("} ow_"+structName+";");
+out.println("ow_"+structName+" *ow_"+structName+"_create(apr_pool_t *pool);");
+out.println("ow_boolean ow_is_a_"+structName+"(ow_DataStructure *object);");
+
+    }
+    
+    protected void generateTearDown(PrintWriter out) {
+out.println("");
+out.println("#ifdef __cplusplus");
+out.println("}");
+out.println("#endif");
+out.println("");
+out.println("#endif  /* ! OW_COMMANDS_V"+openwireVersion+"_H */");
+    }
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpClassesGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpClassesGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpClassesGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpClassesGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,222 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+/**
+ *
+ * @version $Revision: 383749 $
+ */
+public class CSharpClassesGenerator extends MultiSourceGenerator {
+	
+	protected String targetDir="./src/main/csharp";
+
+    public Object run() {
+        filePostFix = ".cs";
+        if (destDir == null) {
+            destDir = new File(targetDir+"/ActiveMQ/Commands");
+        }        
+        return super.run();
+    }
+    
+    public String makeHashCodeBody() throws Exception {
+        if (simpleName.endsWith("Id")) {
+            StringWriter buffer = new StringWriter();
+            PrintWriter out = new PrintWriter(buffer);
+            out.println("            int answer = 0;");
+            Iterator iter = getProperties().iterator();
+            while (iter.hasNext()) {
+                JProperty property = (JProperty) iter.next();
+                out.println("            answer = (answer * 37) + HashCode(" + property.getSimpleName() + ");");
+            }
+            out.println("            return answer;");
+            return buffer.toString();
+        }
+        return null;
+    }
+
+    public String makeEqualsBody() throws Exception {
+        if (simpleName.endsWith("Id")) {
+            StringWriter buffer = new StringWriter();
+            PrintWriter out = new PrintWriter(buffer);
+            
+            Iterator iter = getProperties().iterator();
+            while (iter.hasNext()) {
+                JProperty property = (JProperty) iter.next();
+                String name = property.getSimpleName();
+                out.println("            if (! Equals(this." + name + ", that." + name + ")) return false;");
+            }
+            out.println("            return true;");
+            return buffer.toString();
+        }
+        return null;
+    }
+    
+    public String makeToStringBody() throws Exception {
+            StringWriter buffer = new StringWriter();
+            PrintWriter out = new PrintWriter(buffer);
+            out.println("            return GetType().Name + \"[\"");
+            Iterator iter = getProperties().iterator();
+            while (iter.hasNext()) {
+                JProperty property = (JProperty) iter.next();
+                String name = property.getSimpleName();
+                out.println("                + \" " + name + "=\" + " + name);
+            }
+            out.println("                + \" ]\";");
+            return buffer.toString();
+    }
+
+	private void generateLicence(PrintWriter out) {
+out.println("/*");
+out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+out.println(" * this work for additional information regarding copyright ownership.");
+out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+out.println(" * (the \"License\"); you may not use this file except in compliance with");
+out.println(" * the License.  You may obtain a copy of the License at");
+out.println(" *");
+out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+out.println(" *");
+out.println(" * Unless required by applicable law or agreed to in writing, software");
+out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+out.println(" * See the License for the specific language governing permissions and");
+out.println(" * limitations under the License.");
+out.println(" */");
+	}
+
+
+	protected void generateFile(PrintWriter out) throws Exception {
+		generateLicence(out);
+
+out.println("//");
+out.println("//  NOTE!: This file is autogenerated - do not modify!");
+out.println("//         if you need to make a change, please see the Groovy scripts in the");
+out.println("//         activemq-core module");
+out.println("//");
+out.println("");
+out.println("using System;");
+out.println("using System.Collections;");
+out.println("");
+out.println("using ActiveMQ.OpenWire;");
+out.println("using ActiveMQ.Commands;");
+out.println("");
+out.println("namespace ActiveMQ.Commands");
+out.println("{");
+out.println("    /// <summary>");
+out.println("    ///  The ActiveMQ "+jclass.getSimpleName()+" Command");
+out.println("    /// </summary>");
+  out.print("    public class "+jclass.getSimpleName()+" : "+baseClass);
+
+
+  	for (int i = 0; i < jclass.getInterfaces().length; i++) {
+		JClass intf = jclass.getInterfaces()[i];
+		out.print(", "+intf.getSimpleName());
+	}
+    
+out.println("");
+out.println("    {");
+out.println("        public const byte ID_"+jclass.getSimpleName()+" = "+getOpenWireOpCode(jclass)+";");
+out.println("    			");
+
+		List properties = getProperties();
+		String type;
+		Object name;
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+	        type = toCSharpType(property.getType());
+	        name = decapitalize(property.getSimpleName());
+out.println("        "+type+" "+name+";");
+    }
+
+	String text = makeHashCodeBody();
+	if (text != null) {
+out.println("");
+out.println("		public override int GetHashCode() {");
+out.println(""+text+"");
+out.println("		}");
+	}
+
+	text = makeEqualsBody();
+	if (text != null) {
+out.println("");
+out.println("		public override bool Equals(object that) {");
+out.println("	    	if (that is "+className+") {");
+out.println("	    	    return Equals(("+className+") that);");
+out.println("			}");
+out.println("			return false;");
+out.println("    	}");
+out.println("");    
+out.println("		public virtual bool Equals("+className+" that) {");
+out.println(""+text+"");
+out.println("		}");
+	}
+	    
+	text = makeToStringBody();
+	if (text != null) {
+out.println("");	
+out.println("		public override string ToString() {");
+out.println(""+text+"");
+out.println("		}");
+	}
+	    
+out.println("");
+out.println("        public override byte GetDataStructureType() {");
+out.println("            return ID_"+jclass.getSimpleName()+";");
+out.println("        }");
+out.println("");
+out.println("");
+out.println("        // Properties");
+
+				for (Iterator iter = properties.iterator(); iter.hasNext();) {
+					JProperty property = (JProperty) iter.next();
+                    type = toCSharpType(property.getType());
+                    name = decapitalize(property.getSimpleName());
+                    String propertyName = property.getSimpleName();
+                    String getter = capitalize(property.getGetter().getSimpleName());
+                    String setter = capitalize(property.getSetter().getSimpleName());
+
+out.println("");
+out.println("        public "+type+" "+propertyName+"");
+out.println("        {");
+out.println("            get { return "+name+"; }");
+out.println("            set { this."+name+" = value; }            ");
+out.println("        }");
+                }
+
+out.println("");
+out.println("    }");
+out.println("}");
+	}
+
+	public String getTargetDir() {
+		return targetDir;
+	}
+
+	public void setTargetDir(String targetDir) {
+		this.targetDir = targetDir;
+	}
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpGeneratorTask.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpGeneratorTask.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpGeneratorTask.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpGeneratorTask.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,118 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.codehaus.jam.JamService;
+import org.codehaus.jam.JamServiceFactory;
+import org.codehaus.jam.JamServiceParams;
+
+/**
+ * 
+ * @version $Revision: 384826 $
+ */
+public class CSharpGeneratorTask extends Task {
+	
+	int version = 2;
+	File source = new File(".");
+	File target = new File(".");
+	
+    public static void main(String[] args) {
+    	
+        Project project = new Project();
+        project.init();
+    	CSharpGeneratorTask generator = new CSharpGeneratorTask();
+    	generator.setProject(project);
+    	
+    	if( args.length > 0 ) {
+    		generator.version = Integer.parseInt(args[0]);
+    	}
+
+    	if( args.length > 1 ) {
+    		generator.source = new File(args[1]);
+    	}  
+    	
+    	if( args.length > 2 ) {
+    		generator.target = new File(args[2]);
+    	}    	
+    	
+    	generator.execute();
+	}
+    
+    public void execute() throws BuildException {
+        try {
+        	
+        	String sourceDir = source+"/src/main/java";
+        	
+            System.out.println("Parsing source files in: " + sourceDir);
+
+            JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
+            JamServiceParams params = jamServiceFactory.createServiceParams();            
+            File[] dirs = new File[]{new File(sourceDir)};            
+            params.includeSourcePattern(dirs, "**/*.java");
+            JamService jam = jamServiceFactory.createService(params);
+
+            {
+            	CSharpClassesGenerator script = new CSharpClassesGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src/main/csharp");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            {
+            	CSharpMarshallingGenerator script = new CSharpMarshallingGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src/main/csharp");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            
+        } catch (Exception e) {
+        	throw new BuildException(e);
+        }
+    }
+
+	public int getVersion() {
+		return version;
+	}
+
+	public void setVersion(int version) {
+		this.version = version;
+	}
+
+	public File getSource() {
+		return source;
+	}
+
+	public void setSource(File basedir) {
+		this.source = basedir;
+	}
+
+	public File getTarget() {
+		return target;
+	}
+
+	public void setTarget(File target) {
+		this.target = target;
+	}
+
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpMarshallingGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpMarshallingGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpMarshallingGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSharpMarshallingGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,641 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ *
+ * @version $Revision: 384390 $
+ */
+public class CSharpMarshallingGenerator extends JavaMarshallingGenerator {
+
+	protected String targetDir="./src/main/csharp";
+
+    public Object run() {
+        filePostFix = ".cs";
+        if (destDir == null) {
+            destDir = new File(targetDir+"/ActiveMQ/OpenWire/V"+getOpenwireVersion());
+        }        
+        return super.run();
+    }
+    
+    //////////////////////////////////////////////////////////////////////////////////////
+    // This section is for the tight wire format encoding generator
+    //////////////////////////////////////////////////////////////////////////////////////
+
+    protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+
+        String propertyName = property.getSimpleName();
+        String type = property.getType().getSimpleName();
+
+        if (type.equals("boolean")) {
+            out.println("        info." + propertyName + " = bs.ReadBoolean();");
+        }
+        else if (type.equals("byte")) {
+            out.println("        info." + propertyName + " = dataIn.ReadByte();");
+        }
+        else if (type.equals("char")) {
+            out.println("        info." + propertyName + " = dataIn.ReadChar();");
+        }
+        else if (type.equals("short")) {
+            out.println("        info." + propertyName + " = dataIn.ReadInt16();");
+        }
+        else if (type.equals("int")) {
+            out.println("        info." + propertyName + " = dataIn.ReadInt32();");
+        }
+        else if (type.equals("long")) {
+            out.println("        info." + propertyName + " = TightUnmarshalLong(wireFormat, dataIn, bs);");
+        }
+        else if (type.equals("String")) {
+            out.println("        info." + propertyName + " = TightUnmarshalString(dataIn, bs);");
+        }
+        else if (type.equals("byte[]") || type.equals("ByteSequence")) {
+            if (size != null) {
+                out.println("        info." + propertyName + " = ReadBytes(dataIn, " + size.asInt() + ");");
+            }
+            else {
+                out.println("        info." + propertyName + " = ReadBytes(dataIn, bs.ReadBoolean());");
+            }
+        }
+        else if (isThrowable(property.getType())) {
+            out.println("        info." + propertyName + " = TightUnmarshalBrokerError(wireFormat, dataIn, bs);");
+        }
+        else if (isCachedProperty(property)) {
+            out.println("        info." + propertyName + " = (" + type + ") TightUnmarshalCachedObject(wireFormat, dataIn, bs);");
+        }
+        else {
+            out.println("        info." + propertyName + " = (" + type + ") TightUnmarshalNestedObject(wireFormat, dataIn, bs);");
+        }
+    }
+
+    protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+        JClass propertyType = property.getType();
+        String arrayType = propertyType.getArrayComponentType().getSimpleName();
+        String propertyName = property.getSimpleName();
+        out.println();
+        if (size != null) {
+            out.println("        {");
+            out.println("            " + arrayType + "[] value = new " + arrayType + "[" + size.asInt() + "];");
+            out.println("            " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") TightUnmarshalNestedObject(wireFormat,dataIn, bs);");
+            out.println("            }");
+            out.println("            info." + propertyName + " = value;");
+            out.println("        }");
+        }
+        else {
+            out.println("        if (bs.ReadBoolean()) {");
+            out.println("            short size = dataIn.ReadInt16();");
+            out.println("            " + arrayType + "[] value = new " + arrayType + "[size];");
+            out.println("            for( int i=0; i < size; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") TightUnmarshalNestedObject(wireFormat,dataIn, bs);");
+            out.println("            }");
+            out.println("            info." + propertyName + " = value;");
+            out.println("        }");
+            out.println("        else {");
+            out.println("            info." + propertyName + " = null;");
+            out.println("        }");
+        }
+    }
+
+    protected int generateTightMarshal1Body(PrintWriter out) {
+        List properties = getProperties();
+        int baseSize = 0;
+        for (Iterator iter = properties.iterator(); iter.hasNext();) {
+            JProperty property = (JProperty) iter.next();
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String type = propertyType.getSimpleName();
+            String getter = "info." + property.getSimpleName();
+
+            if (type.equals("boolean")) {
+                out.println("        bs.WriteBoolean(" + getter + ");");
+            }
+            else if (type.equals("byte")) {
+                baseSize += 1;
+            }
+            else if (type.equals("char")) {
+                baseSize += 2;
+            }
+            else if (type.equals("short")) {
+                baseSize += 2;
+            }
+            else if (type.equals("int")) {
+                baseSize += 4;
+            }
+            else if (type.equals("long")) {
+                out.println("        rc += TightMarshalLong1(wireFormat, " + getter + ", bs);");
+            }
+            else if (type.equals("String")) {
+                out.print("");
+                out.println("        rc += TightMarshalString1(" + getter + ", bs);");
+            }
+            else if (type.equals("byte[]") || type.equals("ByteSequence")) {
+                if (size == null) {
+                    out.println("        bs.WriteBoolean(" + getter + "!=null);");
+                    out.println("        rc += " + getter + "==null ? 0 : " + getter + ".Length+4;");
+                }
+                else {
+                    baseSize += size.asInt();
+                }
+            }
+            else if (propertyType.isArrayType()) {
+                if (size != null) {
+                    out.println("        rc += TightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
+                }
+                else {
+                    out.println("        rc += TightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
+                }
+            }
+            else if (isThrowable(propertyType)) {
+                out.println("        rc += TightMarshalBrokerError1(wireFormat, " + getter + ", bs);");
+            }
+            else {
+                if (isCachedProperty(property)) {
+                    out.println("        rc += TightMarshalCachedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
+                }
+                else {
+                    out.println("        rc += TightMarshalNestedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
+                }
+            }
+        }
+        return baseSize;
+    }
+
+    protected void generateTightMarshal2Body(PrintWriter out) {
+        List properties = getProperties();
+        for (Iterator iter = properties.iterator(); iter.hasNext();) {
+            JProperty property = (JProperty) iter.next();
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String type = propertyType.getSimpleName();
+            String getter = "info." + property.getSimpleName();
+
+            if (type.equals("boolean")) {
+                out.println("        bs.ReadBoolean();");
+            }
+            else if (type.equals("byte")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("char")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("short")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("int")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("long")) {
+                out.println("        TightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
+            }
+            else if (type.equals("String")) {
+                out.println("        TightMarshalString2(" + getter + ", dataOut, bs);");
+            }
+            else if (type.equals("byte[]") || type.equals("ByteSequence")) {
+                if (size != null) {
+                    out.println("        dataOut.Write(" + getter + ", 0, " + size.asInt() + ");");
+                }
+                else {
+                    out.println("        if(bs.ReadBoolean()) {");
+                    out.println("           dataOut.Write(" + getter + ".Length);");
+                    out.println("           dataOut.Write(" + getter + ");");
+                    out.println("        }");
+                }
+            }
+            else if (propertyType.isArrayType()) {
+                if (size != null) {
+                    out.println("        TightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
+                }
+                else {
+                    out.println("        TightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
+                }
+            }
+            else if (isThrowable(propertyType)) {
+                out.println("        TightMarshalBrokerError2(wireFormat, " + getter + ", dataOut, bs);");
+            }
+            else {
+                if (isCachedProperty(property)) {
+                    out.println("        TightMarshalCachedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
+                }
+                else {
+                    out.println("        TightMarshalNestedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
+                }
+            }
+        }
+    }
+    
+    //////////////////////////////////////////////////////////////////////////////////////
+    // This section is for the loose wire format encoding generator
+    //////////////////////////////////////////////////////////////////////////////////////
+    
+    protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+
+        String propertyName = property.getSimpleName();
+        String type = property.getType().getSimpleName();
+
+        if (type.equals("boolean")) {
+            out.println("        info." + propertyName + " = dataIn.ReadBoolean();");
+        }
+        else if (type.equals("byte")) {
+            out.println("        info." + propertyName + " = dataIn.ReadByte();");
+        }
+        else if (type.equals("char")) {
+            out.println("        info." + propertyName + " = dataIn.ReadChar();");
+        }
+        else if (type.equals("short")) {
+            out.println("        info." + propertyName + " = dataIn.ReadInt16();");
+        }
+        else if (type.equals("int")) {
+            out.println("        info." + propertyName + " = dataIn.ReadInt32();");
+        }
+        else if (type.equals("long")) {
+            out.println("        info." + propertyName + " = LooseUnmarshalLong(wireFormat, dataIn);");
+        }
+        else if (type.equals("String")) {
+            out.println("        info." + propertyName + " = LooseUnmarshalString(dataIn);");
+        }
+        else if (type.equals("byte[]") || type.equals("ByteSequence")) {
+            if (size != null) {
+                out.println("        info." + propertyName + " = ReadBytes(dataIn, " + size.asInt() + ");");
+            }
+            else {
+                out.println("        info." + propertyName + " = ReadBytes(dataIn, dataIn.ReadBoolean());");
+            }
+        }
+        else if (isThrowable(property.getType())) {
+            out.println("        info." + propertyName + " = LooseUnmarshalBrokerError(wireFormat, dataIn);");
+        }
+        else if (isCachedProperty(property)) {
+            out.println("        info." + propertyName + " = (" + type + ") LooseUnmarshalCachedObject(wireFormat, dataIn);");
+        }
+        else {
+            out.println("        info." + propertyName + " = (" + type + ") LooseUnmarshalNestedObject(wireFormat, dataIn);");
+        }
+    }
+
+    protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+        JClass propertyType = property.getType();
+        String arrayType = propertyType.getArrayComponentType().getSimpleName();
+        String propertyName = property.getSimpleName();
+        out.println();
+        if (size != null) {
+            out.println("        {");
+            out.println("            " + arrayType + "[] value = new " + arrayType + "[" + size.asInt() + "];");
+            out.println("            " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") LooseUnmarshalNestedObject(wireFormat,dataIn);");
+            out.println("            }");
+            out.println("            info." + propertyName + " = value;");
+            out.println("        }");
+        }
+        else {
+            out.println("        if (dataIn.ReadBoolean()) {");
+            out.println("            short size = dataIn.ReadInt16();");
+            out.println("            " + arrayType + "[] value = new " + arrayType + "[size];");
+            out.println("            for( int i=0; i < size; i++ ) {");
+            out.println("                value[i] = (" + arrayType + ") LooseUnmarshalNestedObject(wireFormat,dataIn);");
+            out.println("            }");
+            out.println("            info." + propertyName + " = value;");
+            out.println("        }");
+            out.println("        else {");
+            out.println("            info." + propertyName + " = null;");
+            out.println("        }");
+        }
+    }
+
+
+    protected void generateLooseMarshalBody(PrintWriter out) {
+        List properties = getProperties();
+        for (Iterator iter = properties.iterator(); iter.hasNext();) {
+            JProperty property = (JProperty) iter.next();
+            JAnnotation annotation = property.getAnnotation("openwire:property");
+            JAnnotationValue size = annotation.getValue("size");
+            JClass propertyType = property.getType();
+            String type = propertyType.getSimpleName();
+            String getter = "info." + property.getSimpleName();
+
+            if (type.equals("boolean")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("byte")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("char")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("short")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("int")) {
+                out.println("        dataOut.Write(" + getter + ");");
+            }
+            else if (type.equals("long")) {
+                out.println("        LooseMarshalLong(wireFormat, " + getter + ", dataOut);");
+            }
+            else if (type.equals("String")) {
+                out.println("        LooseMarshalString(" + getter + ", dataOut);");
+            }
+            else if (type.equals("byte[]") || type.equals("ByteSequence")) {
+                if (size != null) {
+                    out.println("        dataOut.Write(" + getter + ", 0, " + size.asInt() + ");");
+                }
+                else {
+                    out.println("        dataOut.Write(" + getter + "!=null);");
+                    out.println("        if(" + getter + "!=null) {");
+                    out.println("           dataOut.Write(" + getter + ".Length);");
+                    out.println("           dataOut.Write(" + getter + ");");
+                    out.println("        }");
+                }
+            }
+            else if (propertyType.isArrayType()) {
+                if (size != null) {
+                    out.println("        LooseMarshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
+                }
+                else {
+                    out.println("        LooseMarshalObjectArray(wireFormat, " + getter + ", dataOut);");
+                }
+            }
+            else if (isThrowable(propertyType)) {
+                out.println("        LooseMarshalBrokerError(wireFormat, " + getter + ", dataOut);");
+            }
+            else {
+                if (isCachedProperty(property)) {
+                    out.println("        LooseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+                }
+                else {
+                    out.println("        LooseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+                }
+            }
+        }
+    }
+
+	public String getTargetDir() {
+		return targetDir;
+	}
+
+	public void setTargetDir(String targetDir) {
+		this.targetDir = targetDir;
+	}
+
+	private void generateLicence(PrintWriter out) {
+out.println("/*");
+out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+out.println(" * this work for additional information regarding copyright ownership.");
+out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+out.println(" * (the \"License\"); you may not use this file except in compliance with");
+out.println(" * the License.  You may obtain a copy of the License at");
+out.println(" *");
+out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+out.println(" *");
+out.println(" * Unless required by applicable law or agreed to in writing, software");
+out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+out.println(" * See the License for the specific language governing permissions and");
+out.println(" * limitations under the License.");
+out.println(" */");
+	}
+
+	protected void generateFile(PrintWriter out) throws Exception {
+		generateLicence(out);
+out.println("");
+out.println("//");
+out.println("// NOTE!: This file is autogenerated - do not modify!");
+out.println("//        if you need to make a change, please see the Groovy scripts in the");
+out.println("//        activemq-core module");
+out.println("//");
+out.println("");
+out.println("using System;");
+out.println("using System.Collections;");
+out.println("using System.IO;");
+out.println("");
+out.println("using ActiveMQ.Commands;");
+out.println("using ActiveMQ.OpenWire;");
+out.println("using ActiveMQ.OpenWire.V"+getOpenwireVersion()+";");
+out.println("");
+out.println("namespace ActiveMQ.OpenWire.V"+getOpenwireVersion()+"");
+out.println("{");
+out.println("  /// <summary>");
+out.println("  ///  Marshalling code for Open Wire Format for "+jclass.getSimpleName()+"");
+out.println("  /// </summary>");
+out.println("  "+getAbstractClassText()+"class "+getClassName()+" : "+getBaseClass()+"");
+out.println("  {");
+
+		if( !isAbstractClass() ) {
+out.println("");
+out.println("");
+out.println("    public override DataStructure CreateObject() ");
+out.println("    {");
+out.println("        return new "+jclass.getSimpleName()+"();");
+out.println("    }");
+out.println("");
+out.println("    public override byte GetDataStructureType() ");
+out.println("    {");
+out.println("        return "+jclass.getSimpleName()+".ID_"+jclass.getSimpleName()+";");
+out.println("    }");
+		}
+
+/*
+ * Generate the tight encoding marshallers
+ */ 
+out.println("");
+out.println("    // ");
+out.println("    // Un-marshal an object instance from the data input stream");
+out.println("    // ");
+out.println("    public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs) ");
+out.println("    {");
+out.println("        base.TightUnmarshal(wireFormat, o, dataIn, bs);");
+ 
+		if( !getProperties().isEmpty() || isMarshallerAware() ) {
+out.println("");
+out.println("        "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
+		}
+
+		if( isMarshallerAware() ){
+out.println("");
+out.println("        info.BeforeUnmarshall(wireFormat);");
+out.println("");
+        }
+
+generateTightUnmarshalBody(out);
+
+		if( isMarshallerAware() ){
+out.println("");
+out.println("        info.AfterUnmarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("    }");
+out.println("");
+out.println("    //");
+out.println("    // Write the booleans that this object uses to a BooleanStream");
+out.println("    //");
+out.println("    public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) {");
+out.println("        "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
+
+		if( isMarshallerAware() ) {
+out.println("");
+out.println("        info.BeforeMarshall(wireFormat);");
+		}
+		
+out.println("");
+out.println("        int rc = base.TightMarshal1(wireFormat, info, bs);");
+
+int baseSize = generateTightMarshal1Body(out);
+    
+out.println("");
+out.println("        return rc + "+baseSize+";");
+out.println("    }");
+out.println("");
+out.println("    // ");
+out.println("    // Write a object instance to data output stream");
+out.println("    //");
+out.println("    public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs) {");
+out.println("        base.TightMarshal2(wireFormat, o, dataOut, bs);");
+
+		if( !getProperties().isEmpty() || isMarshallerAware() ) {
+out.println("");
+out.println("        "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
+		}
+
+		generateTightMarshal2Body(out);
+
+		if( isMarshallerAware() ) {
+out.println("");
+out.println("        info.AfterMarshall(wireFormat);");
+		}
+		
+out.println("");
+out.println("    }");
+
+out.println("");
+out.println("    // ");
+out.println("    // Un-marshal an object instance from the data input stream");
+out.println("    // ");
+out.println("    public override void LooseUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn) ");
+out.println("    {");
+out.println("        base.LooseUnmarshal(wireFormat, o, dataIn);");
+ 
+		if( !getProperties().isEmpty() || isMarshallerAware() )  {
+out.println("");
+out.println("        "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");		
+		}
+
+		if( isMarshallerAware() ) {
+out.println("");
+out.println("        info.BeforeUnmarshall(wireFormat);");
+out.println("");
+		}
+
+		generateLooseUnmarshalBody(out);
+
+		if( isMarshallerAware() ) {
+out.println("");
+out.println("        info.AfterUnmarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("    }");
+out.println("");
+out.println("    // ");
+out.println("    // Write a object instance to data output stream");
+out.println("    //");
+out.println("    public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut) {");
+
+		if( !getProperties().isEmpty() || isMarshallerAware() ) {
+out.println("");
+out.println("        "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
+		}
+
+		if( isMarshallerAware() ) {
+out.println("");
+out.println("        info.BeforeMarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("        base.LooseMarshal(wireFormat, o, dataOut);");
+
+		generateLooseMarshalBody(out);
+
+		if( isMarshallerAware() ) {
+out.println("");
+out.println("        info.AfterMarshall(wireFormat);");
+		}
+out.println("");
+out.println("    }");
+out.println("  }");
+out.println("}");
+		
+	}
+	
+	
+    public void generateFactory(PrintWriter out) {
+		generateLicence(out);
+out.println("");
+out.println("//");
+out.println("// NOTE!: This file is autogenerated - do not modify!");
+out.println("//        if you need to make a change, please see the Groovy scripts in the");
+out.println("//        activemq-core module");
+out.println("//");
+out.println("");
+out.println("using System;");
+out.println("using System.Collections;");
+out.println("using System.IO;");
+out.println("");
+out.println("using ActiveMQ.Commands;");
+out.println("using ActiveMQ.OpenWire;");
+out.println("using ActiveMQ.OpenWire.V"+getOpenwireVersion()+";");
+out.println("");
+out.println("namespace ActiveMQ.OpenWire.V"+getOpenwireVersion()+"");
+out.println("{");
+out.println("	/// <summary>");
+out.println("	/// Used to create marshallers for a specific version of the wire protocol");
+out.println("	/// </summary>");
+out.println("    public class MarshallerFactory");
+out.println("    {");
+out.println("        public void configure(OpenWireFormat format) ");
+out.println("        {");
+
+		List list = new ArrayList(getConcreteClasses());
+		Collections.sort(list, new Comparator(){
+			public int compare(Object o1, Object o2) {
+				JClass c1 = (JClass) o1;
+				JClass c2 = (JClass) o2;
+				return c1.getSimpleName().compareTo(c2.getSimpleName());
+			}});
+		
+		for (Iterator iter = list.iterator(); iter.hasNext();) {
+			JClass jclass = (JClass) iter.next();
+out.println("            format.addMarshaller(new "+jclass.getSimpleName()+"Marshaller());");
+	    }        
+
+out.println("");
+out.println("    	}");
+out.println("    }");
+out.println("}");
+
+	}	
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CSourcesGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,381 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+/**
+ * 
+ * @version $Revision: 383749 $
+ */
+public class CSourcesGenerator extends CHeadersGenerator {
+
+	public Object run() {
+		filePostFix = ".c";
+		if (destFile == null) {
+			destFile = new File(targetDir + "/ow_commands_v" + getOpenwireVersion() + ".c");
+		}
+		return super.run();
+	}
+
+	protected List sort(List source) {
+		return source;
+	}
+
+	protected void generateSetup(PrintWriter out) {
+		generateLicence(out);
+		out.println("");
+		out.println("/*****************************************************************************************");
+		out.println(" *  ");
+		out.println(" * NOTE!: This file is auto generated - do not modify!");
+		out.println(" *        if you need to make a change, please see the modify the groovy scripts in the");
+		out.println(" *        under src/gram/script and then use maven openwire:generate to regenerate ");
+		out.println(" *        this file.");
+		out.println(" *  ");
+		out.println(" *****************************************************************************************/");
+		out.println("");
+		out.println("");
+		out.println("#include \"ow_commands_v"+openwireVersion+".h\"");
+		out.println("");
+		out.println("#define SUCCESS_CHECK( f ) { apr_status_t rc=f; if(rc!=APR_SUCCESS) return rc; }");
+		out.println("");
+	}
+
+	protected void generateFile(PrintWriter out) throws Exception {
+    
+        ArrayList properties = new ArrayList();
+        jclass.getDeclaredProperties();
+        for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
+            JProperty p = jclass.getDeclaredProperties()[i];
+            if (isValidProperty(p)) {
+                properties.add(p);
+            }
+        }
+        
+		String name = jclass.getSimpleName();
+		String type = ("ow_"+name).toUpperCase()+"_TYPE";
+		String baseName = "DataStructure";
+		JClass superclass = jclass.getSuperclass();	            
+		while( superclass.getSuperclass() != null ) {
+		   if( sortedClasses.contains(superclass) ) {
+		      baseName = superclass.getSimpleName();
+		      break;
+		   } else {
+		      superclass = superclass.getSuperclass();
+		   }
+		}
+               
+out.println("ow_boolean ow_is_a_"+name+"(ow_DataStructure *object) {");
+out.println("   if( object == 0 )");
+out.println("      return 0;");
+out.println("      ");
+out.println("   switch(object->structType) {");
+
+		for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+			JClass sub = (JClass) iterator.next();
+			String subtype = "OW_"+sub.getSimpleName().toUpperCase()+"_TYPE";
+			if( jclass.isAssignableFrom(sub) && !isAbstract(sub) ) {
+out.println("");
+out.println("   case "+subtype+":");
+			}            
+		}
+out.println("");
+out.println("      return 1;");
+out.println("   }");
+out.println("   return 0;");
+out.println("}");
+               
+		if( !isAbstract(jclass) ) {
+out.println("");
+out.println("");
+out.println("ow_"+name+" *ow_"+name+"_create(apr_pool_t *pool) ");
+out.println("{");
+out.println("   ow_"+name+" *value = apr_pcalloc(pool,sizeof(ow_"+name+"));");
+out.println("   if( value!=0 ) {");
+out.println("      ((ow_DataStructure*)value)->structType = "+type+";");
+out.println("   }");
+out.println("   return value;");
+out.println("}");
+        }
+               
+out.println("");
+out.println("");
+out.println("apr_status_t ow_marshal1_"+name+"(ow_bit_buffer *buffer, ow_"+name+" *object)");
+out.println("{");
+out.println("   ow_marshal1_"+baseName+"(buffer, (ow_"+baseName+"*)object);");
+
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+			String propname = toPropertyCase(property.getSimpleName());
+			boolean cached = isCachedProperty(property);
+			JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+			JAnnotationValue size = annotation.getValue("size");
+
+           type = property.getType().getQualifiedName();
+           if( type.equals("boolean")) {
+out.println("   ow_bit_buffer_append(buffer, object->"+propname+");");
+                   } else if( type.equals("byte")) {
+                   } else if( type.equals("char")) {
+                   } else if( type.equals("short")) {
+                   } else if( type.equals("int")) {
+                   } else if( type.equals("long")) {
+out.println("   ow_marshal1_long(buffer, object->"+propname+");");
+                   } else if( type.equals("byte[]")) {
+                     if( size ==null ) {
+out.println("   ow_bit_buffer_append(buffer,  object->"+propname+"!=0 );");
+                     }
+                   } else if( type.equals("org.apache.activeio.packet.ByteSequence")) {
+                     if( size ==null ) {
+out.println("   ow_bit_buffer_append(buffer,  object->"+propname+"!=0 );");
+                     }
+                   } else if( type.equals("java.lang.String")) {
+out.println("   ow_marshal1_string(buffer, object->"+propname+");");
+                   } else {
+                         if( property.getType().isArrayType() ) {
+                           if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
+                           } else {
+out.println("   SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->"+propname+"));");
+                           }
+                         } else if( isThrowable(property.getType()) ) {    	    
+out.println("   SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->"+propname+"));");
+                         } else {
+                           if( cached ) {
+out.println("   SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->"+propname+"));");
+                           } else {
+out.println("   SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->"+propname+"));");
+                           }
+                       }
+                   }
+out.println("");
+               }
+
+
+out.println("   ");
+out.println("	return APR_SUCCESS;");
+out.println("}");
+out.println("apr_status_t ow_marshal2_"+name+"(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_"+name+" *object)");
+out.println("{");
+out.println("   ow_marshal2_"+baseName+"(buffer, bitbuffer, (ow_"+baseName+"*)object);   ");
+
+			for (Iterator iter = properties.iterator(); iter.hasNext();) {
+				JProperty property = (JProperty) iter.next();
+                   JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+                   JAnnotationValue size = annotation.getValue("size");
+                   Object propname = toPropertyCase(property.getSimpleName());
+                   boolean cached = isCachedProperty(property);
+                   
+                   type = property.getType().getQualifiedName();
+                   if( type.equals("boolean") ) {
+out.println("   ow_bit_buffer_read(bitbuffer);");
+                   } else if( type.equals("byte") ) {
+out.println("   SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
+                   } else if( type.equals("char") ) {
+out.println("   SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
+                   } else if( type.equals("short") ) {
+out.println("   SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
+                   } else if( type.equals("int") ) {
+out.println("   SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
+                   } else if( type.equals("long") ) {
+out.println("   SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->"+propname+"));");
+                   } else if( type.equals("byte[]") ) {
+                       if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
+                       } else {
+out.println("   SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->"+propname+"));");
+                       }
+                   } else if( type.equals("org.apache.activeio.packet.ByteSequence") ) {
+                       if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
+                       } else {
+out.println("   SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->"+propname+"));");
+                       }
+                   } else if( type.equals("java.lang.String") ) {
+out.println("   SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->"+propname+"));");
+                   } else {
+                      if( property.getType().isArrayType() ) {
+                         if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->"+propname+", "+size.asInt()+"));");
+                         } else {
+out.println("   SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->"+propname+"));");
+                         }
+                      } else if( isThrowable(property.getType()) ) {    	    
+out.println("   SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->"+propname+"));");
+                      } else {
+                           if( cached ) {
+out.println("   SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->"+propname+"));");
+                           } else {
+out.println("   SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->"+propname+"));");
+                           }                      
+                      }
+                   }
+out.println("");
+               }
+
+out.println("   ");
+out.println("	return APR_SUCCESS;");
+out.println("}");
+out.println("");
+out.println("apr_status_t ow_unmarshal_"+name+"(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_"+name+" *object, apr_pool_t *pool)");
+out.println("{");
+out.println("   ow_unmarshal_"+baseName+"(buffer, bitbuffer, (ow_"+baseName+"*)object, pool);   ");
+
+	for (Iterator iter = properties.iterator(); iter.hasNext();) {
+		JProperty property = (JProperty) iter.next();
+                   JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
+                   JAnnotationValue size = annotation.getValue("size");
+                   String propname = toPropertyCase(property.getSimpleName());
+                   boolean cached = isCachedProperty(property);
+                   
+                   type = property.getType().getQualifiedName();
+
+                   if( type.equals("boolean") ) {
+out.println("   object->"+propname+" = ow_bit_buffer_read(bitbuffer);");
+                   } else if( type.equals("byte") ) {
+out.println("   SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
+                   } else if( type.equals("char") ) {
+out.println("   SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
+                   } else if( type.equals("short") ) {
+out.println("   SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
+                   } else if( type.equals("int") ) {
+out.println("   SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
+                   } else if( type.equals("long") ) {
+out.println("   SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->"+propname+", pool));");
+                   } else if( type.equals("byte[]") ) {
+                       if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->"+propname+", "+size.asInt()+", pool));");
+                       } else {
+out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->"+propname+", pool));");
+                       }
+                   } else if( type.equals("org.apache.activeio.packet.ByteSequence") ) {
+                       if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->"+propname+", "+size.asInt()+", pool));");
+                       } else {
+out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->"+propname+", pool));");
+                       }
+                   } else if( type.equals("java.lang.String") ) {
+out.println("   SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->"+propname+", pool));");
+                   } else {
+                      if( property.getType().isArrayType() ) {
+                        if( size!=null ) {
+out.println("   SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->"+propname+", "+size.asInt()+", pool));");
+                        } else {
+out.println("   SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->"+propname+", pool));");
+                        }
+                      } else if( isThrowable(property.getType()) ) {    	    
+out.println("   SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->"+propname+", pool));");
+                      } else {
+                           if( cached ) {
+out.println("   SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->"+propname+", pool));");
+                           } else {
+out.println("   SUCCESS_CHECK(ow_unmarshal_nested_object(buffer, bitbuffer, (ow_DataStructure**)&object->"+propname+", pool));");
+                           }                      
+                      }
+                   }
+out.println("");
+               }
+
+out.println("   ");
+out.println("	return APR_SUCCESS;");
+out.println("}");
+         }  
+         
+	protected void generateTearDown(PrintWriter out) {
+out.println("");
+out.println("ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)");
+out.println("{");
+out.println("   switch( type ) {");
+		for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+			JClass jclass = (JClass) iterator.next();
+            String name = jclass.getSimpleName();
+            String type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out.println("      case "+type+": return (ow_DataStructure *)ow_"+name+"_create(pool);");
+            }
+         }
+         
+out.println("");
+out.println("   }");
+out.println("   return 0;");
+out.println("}");
+out.println("");
+out.println("apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)");
+out.println("{");
+out.println("   switch( object->structType ) {");
+
+		for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+			JClass jclass = (JClass) iterator.next();
+            String name = jclass.getSimpleName();
+            String type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out.println("      case "+type+": return ow_marshal1_"+name+"(buffer, (ow_"+name+"*)object);");
+            }
+         }
+         
+out.println("");
+out.println("   }");
+out.println("   return APR_EGENERAL;");
+out.println("}");
+out.println("");
+out.println("apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)");
+out.println("{");
+out.println("   switch( object->structType ) {");
+
+		for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+			JClass jclass = (JClass) iterator.next();
+            String name = jclass.getSimpleName();
+            String type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out.println("      case "+type+": return ow_marshal2_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object);");
+            }
+         }
+
+out.println("");
+out.println("   }");
+out.println("   return APR_EGENERAL;");
+out.println("}");
+out.println("");
+out.println("apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)");
+out.println("{");
+out.println("   switch( object->structType ) {");
+
+		for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+			JClass jclass = (JClass) iterator.next();
+            String name = jclass.getSimpleName();
+            String type = ("ow_"+name).toUpperCase()+"_TYPE";
+            if( !isAbstract(jclass) ) {
+out.println("      case "+type+": return ow_unmarshal_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object, pool);");
+            }
+         }
+
+out.println("");
+out.println("   }");
+out.println("   return APR_EGENERAL;");
+out.println("}");
+ 
+	}
+}

Copied: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java (from r450087, incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java?view=diff&rev=450289&p1=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java&r1=450087&p2=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java&r2=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java (original)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppClassesGenerator.java Tue Sep 26 19:42:47 2006
@@ -17,20 +17,26 @@
  */
 package org.apache.activemq.openwire.tool;
 
-import org.codehaus.jam.JClass;
-
 import java.io.File;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
 
 /**
  * 
  * @version $Revision: 409828 $
  */
-public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
+public class CppClassesGenerator extends MultiSourceGenerator {
+
+	protected String targetDir="./src/main/cpp";
 
     public Object run() {
         filePostFix = getFilePostFix();
         if (destDir == null) {
-            destDir = new File("../openwire-cpp/src/main/cpp/activemq/command");
+            destDir = new File(targetDir+"/activemq/command");
         }
         return super.run();
     }
@@ -207,4 +213,117 @@
         else
             return "" ;
     }
+    
+    
+	protected void generateLicence(PrintWriter out) {
+out.println("/*");
+out.println(" *");
+out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
+out.println(" * contributor license agreements.  See the NOTICE file distributed with");
+out.println(" * this work for additional information regarding copyright ownership.");
+out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
+out.println(" * (the \"License\"); you may not use this file except in compliance with");
+out.println(" * the License.  You may obtain a copy of the License at");
+out.println(" *");
+out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
+out.println(" *");
+out.println(" * Unless required by applicable law or agreed to in writing, software");
+out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
+out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
+out.println(" * See the License for the specific language governing permissions and");
+out.println(" * limitations under the License.");
+out.println(" */");
+	}
+
+	protected void generateFile(PrintWriter out) throws Exception {
+		generateLicence(out);		
+out.println("#include \"activemq/command/"+className+".hpp\"");
+out.println("");
+out.println("using namespace apache::activemq::command;");
+out.println("");
+out.println("/*");
+out.println(" *");
+out.println(" *  Command and marshalling code for OpenWire format for "+className+"");
+out.println(" *");
+out.println(" *");
+out.println(" *  NOTE!: This file is autogenerated - do not modify!");
+out.println(" *         if you need to make a change, please see the Groovy scripts in the");
+out.println(" *         activemq-core module");
+out.println(" *");
+out.println(" */");
+out.println(""+className+"::"+className+"()");
+out.println("{");
+
+		List properties = getProperties();
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+	        String value = toCppDefaultValue(property.getType());
+	        String propertyName = property.getSimpleName();
+	        String parameterName = decapitalize(propertyName);
+out.println("    this->"+parameterName+" = "+value+" ;");
+		}
+out.println("}");
+out.println("");
+out.println(""+className+"::~"+className+"()");
+out.println("{");
+out.println("}");
+out.println("");
+out.println("unsigned char "+className+"::getDataStructureType()");
+out.println("{");
+out.println("    return "+className+"::TYPE ; ");
+out.println("}");
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+	        String type = toCppType(property.getType());
+	        String propertyName = property.getSimpleName();
+	        String parameterName = decapitalize(propertyName);
+out.println("");
+out.println("        ");
+out.println(""+type+" "+className+"::get"+propertyName+"()");
+out.println("{");
+out.println("    return "+parameterName+" ;");
+out.println("}");
+out.println("");
+out.println("void "+className+"::set"+propertyName+"("+type+" "+parameterName+")");
+out.println("{");
+out.println("    this->"+parameterName+" = "+parameterName+" ;");
+out.println("}");
+	    }
+out.println("");
+out.println("int "+className+"::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)");
+out.println("{");
+out.println("    int size = 0 ;");
+out.println("");
+out.println("    size += "+baseClass+"::marshal(marshaller, mode, ostream) ; ");
+
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+	        String marshalMethod = toMarshalMethodName(property.getType());
+	        String propertyName = decapitalize(property.getSimpleName());
+out.println("    size += marshaller->"+marshalMethod+"("+propertyName+", mode, ostream) ; ");
+	    }
+out.println("    return size ;");
+out.println("}");
+out.println("");
+out.println("void "+className+"::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)");
+out.println("{");
+out.println("    "+baseClass+"::unmarshal(marshaller, mode, istream) ; ");
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+	        String cast = toUnmarshalCast(property.getType());
+	        String unmarshalMethod = toUnmarshalMethodName(property.getType());
+	        String propertyName = decapitalize(property.getSimpleName());
+out.println("    "+propertyName+" = "+cast+"(marshaller->"+unmarshalMethod+"(mode, istream)) ; ");
+	    }
+out.println("}");
+	}
+
+	public String getTargetDir() {
+		return targetDir;
+	}
+
+	public void setTargetDir(String targetDir) {
+		this.targetDir = targetDir;
+	}
+	
 }

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppGeneratorTask.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,133 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.codehaus.jam.JamService;
+import org.codehaus.jam.JamServiceFactory;
+import org.codehaus.jam.JamServiceParams;
+
+/**
+ * 
+ * @version $Revision: 384826 $
+ */
+public class CppGeneratorTask extends Task {
+	
+	int version = 2;
+	File source = new File(".");
+	File target = new File(".");
+	
+    public static void main(String[] args) {
+    	
+        Project project = new Project();
+        project.init();
+    	CppGeneratorTask generator = new CppGeneratorTask();
+    	generator.setProject(project);
+    	
+    	if( args.length > 0 ) {
+    		generator.version = Integer.parseInt(args[0]);
+    	}
+
+    	if( args.length > 1 ) {
+    		generator.source = new File(args[1]);
+    	}  
+    	
+    	if( args.length > 2 ) {
+    		generator.target = new File(args[2]);
+    	}    	
+    	
+    	generator.execute();
+	}
+    
+    public void execute() throws BuildException {
+        try {
+        	
+        	String sourceDir = source+"/src/main/java";
+        	
+            System.out.println("Parsing source files in: " + sourceDir);
+
+            JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
+            JamServiceParams params = jamServiceFactory.createServiceParams();            
+            File[] dirs = new File[]{new File(sourceDir)};            
+            params.includeSourcePattern(dirs, "**/*.java");
+            JamService jam = jamServiceFactory.createService(params);
+
+            {
+            	CppClassesGenerator script = new CppClassesGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src/main/cpp");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            {
+            	CppHeadersGenerator script = new CppHeadersGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src/main/cpp");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            {
+            	CppMarshallingHeadersGenerator script = new CppMarshallingHeadersGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            {
+            	CppMarshallingClassesGenerator script = new CppMarshallingClassesGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(target+"/src");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            
+            
+        } catch (Exception e) {
+        	throw new BuildException(e);
+        }
+    }
+
+	public int getVersion() {
+		return version;
+	}
+
+	public void setVersion(int version) {
+		this.version = version;
+	}
+
+	public File getSource() {
+		return source;
+	}
+
+	public void setSource(File basedir) {
+		this.source = basedir;
+	}
+
+	public File getTarget() {
+		return target;
+	}
+
+	public void setTarget(File target) {
+		this.target = target;
+	}
+
+}



Mime
View raw message