activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r450289 [3/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
Copied: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java (from r450087, incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java?view=diff&rev=450289&p1=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java&r1=450087&p2=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java&r2=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java (original)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppHeadersGenerator.java Tue Sep 26 19:42:47 2006
@@ -17,15 +17,134 @@
  */
 package org.apache.activemq.openwire.tool;
 
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
 
 /**
  *
  * @version $Revision: 379734 $
  */
-public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript {
+public class CppHeadersGenerator extends CppClassesGenerator {
 
     protected String getFilePostFix() {
         return ".hpp";
     }
+    
+	protected void generateFile(PrintWriter out) {
+		generateLicence(out);		
+		
+out.println("#ifndef ActiveMQ_"+className+"_hpp_");
+out.println("#define ActiveMQ_"+className+"_hpp_");
+out.println("");
+out.println("// Turn off warning message for ignored exception specification");
+out.println("#ifdef _MSC_VER");
+out.println("#pragma warning( disable : 4290 )");
+out.println("#endif");
+out.println("");
+out.println("#include <string>");
+out.println("#include \"activemq/command/"+baseClass+".hpp\"");
+
+		List properties = getProperties();
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+		    if( !property.getType().isPrimitiveType() &&
+		        !property.getType().getSimpleName().equals("String") &&
+		        !property.getType().getSimpleName().equals("ByteSequence") )
+		    {
+		        String includeName = toCppType(property.getType());
+		        if( property.getType().isArrayType() )
+		        {
+		            JClass arrayType = property.getType().getArrayComponentType();
+		            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.println("#include \"activemq/"+includeName+".hpp\"");
+				}  else {
+out.println("#include \"activemq/command/"+includeName+".hpp\"");
+				}
+		    }
+		}
+out.println("");
+out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
+out.println("#include \"ppr/io/IOutputStream.hpp\"");
+out.println("#include \"ppr/io/IInputStream.hpp\"");
+out.println("#include \"ppr/io/IOException.hpp\"");
+out.println("#include \"ppr/util/ifr/array\"");
+out.println("#include \"ppr/util/ifr/p\"");
+out.println("");
+out.println("namespace apache");
+out.println("{");
+out.println("  namespace activemq");
+out.println("  {");
+out.println("    namespace command");
+out.println("    {");
+out.println("      using namespace ifr;");
+out.println("      using namespace std;");
+out.println("      using namespace apache::activemq;");
+out.println("      using namespace apache::activemq::protocol;");
+out.println("      using namespace apache::ppr::io;");
+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("class "+className+" : public "+baseClass+"");
+out.println("{");
+out.println("protected:");
+
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+	        String type = toCppType(property.getType());
+	        String name = decapitalize(property.getSimpleName());
+out.println("    "+type+" "+name+" ;");
+	    }
+out.println("");
+out.println("public:");
+out.println("    const static unsigned char TYPE = "+getOpenWireOpCode(jclass)+";");
+out.println("");
+out.println("public:");
+out.println("    "+className+"() ;");
+out.println("    virtual ~"+className+"() ;");
+out.println("");
+out.println("    virtual unsigned char getDataStructureType() ;");
+
+		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("    virtual "+type+" get"+propertyName+"() ;");
+out.println("    virtual void set"+propertyName+"("+type+" "+parameterName+") ;");
+	    }
+out.println("");
+out.println("    virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;");
+out.println("    virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;");
+out.println("} ;");
+out.println("");
+out.println("/* namespace */");
+out.println("    }");
+out.println("  }");
+out.println("}");
+out.println("");
+out.println("#endif /*ActiveMQ_"+className+"_hpp_*/");
+}    
 
 }

Copied: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingClassesGenerator.java (from r450087, incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingClassesGenerator.java?view=diff&rev=450289&p1=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java&r1=450087&p2=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingClassesGenerator.java&r2=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java (original)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingClassesGenerator.java Tue Sep 26 19:42:47 2006
@@ -23,6 +23,9 @@
 import org.codehaus.jam.JProperty;
 
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 
@@ -30,7 +33,7 @@
  *
  * @version $Revision: 381410 $
  */
-public abstract class OpenWireCppMarshallingClassesScript extends OpenWireCppMarshallingHeadersScript {
+public class CppMarshallingClassesGenerator extends CppMarshallingHeadersGenerator {
 
     protected String getFilePostFix() {
         return ".cpp";
@@ -238,5 +241,166 @@
                 }
             }
         }
+    }
+    
+    
+	protected void generateFile(PrintWriter out) throws Exception {
+		generateLicence(out);
+		
+out.println("#include \"marshal/"+className+".hpp\"");
+out.println("");
+out.println("using namespace apache::activemq::client::marshal;");
+out.println("");
+out.println("/*");
+out.println(" *  Marshalling code for Open Wire Format for "+jclass.getSimpleName()+"");
+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("{");
+out.println("    // no-op");
+out.println("}");
+out.println("");
+out.println(""+className+"::~"+className+"()");
+out.println("{");
+out.println("    // no-op");
+out.println("}");
+out.println("");
+
+		if( !isAbstractClass() ) {
+out.println("");
+out.println("");
+out.println("IDataStructure* "+className+"::createObject() ");
+out.println("{");
+out.println("    return new "+jclass.getSimpleName()+"();");
+out.println("}");
+out.println("");
+out.println("char "+className+"::getDataStructureType() ");
+out.println("{");
+out.println("    return "+jclass.getSimpleName()+".ID_"+jclass.getSimpleName()+";");
+out.println("}");
+		}
+
+out.println("");
+out.println("    /* ");
+out.println("     * Un-marshal an object instance from the data input stream");
+out.println("     */ ");
+out.println("void "+className+"::unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ");
+out.println("{");
+out.println("    base.unmarshal(wireFormat, o, dataIn, bs);");
+ 
+		List properties = getProperties();
+		boolean marshallerAware = isMarshallerAware();
+		if( !properties.isEmpty() || marshallerAware )  {
+out.println("");
+out.println("    "+jclass.getSimpleName()+"& info = ("+jclass.getSimpleName()+"&) o;");
+		}
+
+		if( marshallerAware ) {
+out.println("");
+out.println("    info.beforeUnmarshall(wireFormat);");
+out.println("        ");
+		}
+
+		generateTightUnmarshalBody(out);
+
+		if( marshallerAware ) {
+out.println("");
+out.println("    info.afterUnmarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("}");
+out.println("");
+out.println("");
+out.println("/*");
+out.println(" * Write the booleans that this object uses to a BooleanStream");
+out.println(" */");
+out.println("int "+className+"::marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) {");
+out.println("    "+jclass.getSimpleName()+"& info = ("+jclass.getSimpleName()+"&) o;");
+
+
+		if( marshallerAware ) {
+out.println("");
+out.println("    info.beforeMarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("    int rc = base.marshal1(wireFormat, info, bs);");
+
+		int baseSize = generateMarshal1Body(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("void "+className+"::marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) {");
+out.println("    base.marshal2(wireFormat, o, dataOut, bs);");
+
+		if( !properties.isEmpty() || marshallerAware ) {
+out.println("");
+out.println("    "+jclass.getSimpleName()+"& info = ("+jclass.getSimpleName()+"&) o;");
+		}
+
+		generateMarshal2Body(out);
+
+		if( marshallerAware ) {
+out.println("");
+out.println("    info.afterMarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("}");
+    }
+ 	
+    public void generateFactory(PrintWriter out) {
+		generateLicence(out);
+out.println("");
+out.println("// Marshalling code for Open Wire Format");
+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-openwire module");
+out.println("//");
+out.println("");
+out.println("#include \"marshal/"+className+".hpp\"");
+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("#include \"marshal/"+jclass.getSimpleName()+"Marshaller.hpp\"");
+	    }        
+
+out.println("");
+out.println("");
+out.println("using namespace apache::activemq::client::marshal;");
+out.println("");
+out.println("");
+out.println("void MarshallerFactory::configure(ProtocolFormat& format) ");
+out.println("{");
+
+		for (Iterator iter = list.iterator(); iter.hasNext();) {
+			JClass jclass = (JClass) iter.next();
+out.println("    format.addMarshaller(new "+jclass.getSimpleName()+"Marshaller());");
+	    }        
+
+out.println("");
+out.println("}");
+
     }
 }

Copied: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingHeadersGenerator.java (from r450087, incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingHeadersGenerator.java?view=diff&rev=450289&p1=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java&r1=450087&p2=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingHeadersGenerator.java&r2=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java (original)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/CppMarshallingHeadersGenerator.java Tue Sep 26 19:42:47 2006
@@ -18,22 +18,168 @@
 package org.apache.activemq.openwire.tool;
 
 import java.io.File;
+import java.io.PrintWriter;
 
 /**
  *
  * @version $Revision: 381410 $
  */
-public abstract class OpenWireCppMarshallingHeadersScript extends OpenWireJavaMarshallingScript {
+public class CppMarshallingHeadersGenerator extends JavaMarshallingGenerator {
+
+	protected String targetDir="./src";
 
     public Object run() {
         filePostFix = getFilePostFix();
         if (destDir == null) {
-            destDir = new File("../openwire-cpp/src/marshal");
+            destDir = new File(targetDir+"/marshal");
         }
         return super.run();
-    }
+    }	   
     
     protected String getFilePostFix() {
         return ".hpp";
     }
+    
+    
+	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("#ifndef "+className+"_hpp_");
+out.println("#define "+className+"_hpp_");
+out.println("");
+out.println("#include <string>");
+out.println("");
+out.println("#include \"command/IDataStructure.hpp\"");
+out.println("");
+out.println("/* we could cut this down  - for now include all possible headers */");
+out.println("#include \"command/BrokerId.hpp\"");
+out.println("#include \"command/ConnectionId.hpp\"");
+out.println("#include \"command/ConsumerId.hpp\"");
+out.println("#include \"command/ProducerId.hpp\"");
+out.println("#include \"command/SessionId.hpp\"");
+out.println("");
+out.println("#include \"io/BinaryReader.hpp\"");
+out.println("#include \"io/BinaryWriter.hpp\"");
+out.println("");
+out.println("#include \"command/"+baseClass+".hpp\"");
+out.println("#include \"util/ifr/p.hpp\"");
+out.println("");
+out.println("#include \"protocol/ProtocolFormat.hpp\"");
+out.println("");
+out.println("namespace apache");
+out.println("{");
+out.println("  namespace activemq");
+out.println("  {");
+out.println("    namespace client");
+out.println("    {");
+out.println("      namespace marshal");
+out.println("      {");
+out.println("        using namespace ifr ;");
+out.println("        using namespace apache::activemq::client::command;");
+out.println("        using namespace apache::activemq::client::io;");
+out.println("        using namespace apache::activemq::client::protocol;");
+out.println("");
+out.println("/*");
+out.println(" *");
+out.println(" */");
+out.println("class "+className+" : public "+baseClass+"");
+out.println("{");
+out.println("public:");
+out.println("    "+className+"() ;");
+out.println("    virtual ~"+className+"() ;");
+out.println("");
+out.println("    virtual IDataStructure* createCommand() ;");
+out.println("    virtual char getDataStructureType() ;");
+out.println("    ");
+out.println("    virtual void unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ;");
+out.println("    virtual int marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) ;");
+out.println("    virtual void marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) ;");
+out.println("} ;");
+out.println("");
+out.println("/* namespace */");
+out.println("     }");
+out.println("    }");
+out.println("  }");
+out.println("}");
+out.println("#endif /*"+className+"_hpp_*/");
+        }
+ 	
+    public void generateFactory(PrintWriter out) {
+		generateLicence(out);
+out.println("");
+out.println("// Marshalling code for Open Wire Format ");
+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-openwire module");
+out.println("//");
+out.println("");
+out.println("#ifndef MarshallerFactory_hpp_");
+out.println("#define MarshallerFactory_hpp_");
+out.println("");
+out.println("");
+out.println("namespace apache");
+out.println("{");
+out.println("  namespace activemq");
+out.println("  {");
+out.println("    namespace client");
+out.println("    {");
+out.println("      namespace marshal");
+out.println("      {");
+out.println("        using namespace ifr ;");
+out.println("        using namespace std ;");
+out.println("        using namespace apache::activemq::client;");
+out.println("        using namespace apache::activemq::client::command;");
+out.println("        using namespace apache::activemq::client::io;");
+out.println("");
+out.println("/*");
+out.println(" * ");
+out.println(" */");
+out.println("class MarshallerFactory");
+out.println("{");
+out.println("public:");
+out.println("    MarshallerFactory() ;");
+out.println("    virtual ~MarshallerFactory() ;");
+out.println("");
+out.println("	  virtual void configure(ProtocolFormat& format) ;");
+out.println("} ;");
+out.println("");
+out.println("/* namespace */");
+out.println("      }");
+out.println("    }");
+out.println("  }");
+out.println("}");
+out.println("");
+out.println("#endif /*MarshallerFactory_hpp_*/");
+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/JavaGeneratorTask.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaGeneratorTask.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaGeneratorTask.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaGeneratorTask.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,105 @@
+/**
+ *
+ * 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 JavaGeneratorTask extends Task {
+	
+	int version = 2;
+	File basedir = new File(".");
+	
+    public static void main(String[] args) {
+    	
+        Project project = new Project();
+        project.init();
+    	JavaGeneratorTask generator = new JavaGeneratorTask();
+    	generator.setProject(project);
+    	
+    	if( args.length > 0 ) {
+    		generator.version = Integer.parseInt(args[0]);
+    	}
+
+    	if( args.length > 1 ) {
+    		generator.basedir = new File(args[1]);
+    	}    	
+    	
+    	generator.execute();
+	}
+    
+    public void execute() throws BuildException {
+        try {
+        	
+        	String sourceDir = basedir+"/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);
+
+            {
+	            JavaMarshallingGenerator script = new JavaMarshallingGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(basedir+"/src/main/java");
+	        	script.setOpenwireVersion(version);
+	        	script.run();
+            }
+            {
+	            JavaTestsGenerator script = new JavaTestsGenerator();
+	        	script.setJam(jam);
+	        	script.setTargetDir(basedir+"/src/test/java");
+	        	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 getBasedir() {
+		return basedir;
+	}
+
+	public void setBasedir(File basedir) {
+		this.basedir = basedir;
+	}
+
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaMarshallingGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaMarshallingGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaMarshallingGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaMarshallingGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,733 @@
+/**
+ *
+ * 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.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+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.JPackage;
+import org.codehaus.jam.JProperty;
+
+/**
+ * 
+ * @version $Revision: 384826 $
+ */
+public class JavaMarshallingGenerator extends MultiSourceGenerator {
+
+	protected List concreteClasses = new ArrayList();
+	protected File factoryFile;
+	protected String factoryFileName = "MarshallerFactory";
+	protected String indent = "    ";
+	protected String targetDir="src/main/java";
+	
+	public Object run() {
+		if (destDir == null) {
+			destDir = new File(targetDir+"/org/apache/activemq/openwire/v" + getOpenwireVersion());
+		}
+		Object answer = super.run();
+		processFactory();
+		return answer;
+	}
+
+	protected void generateFile(PrintWriter out) throws Exception {
+
+		generateLicence(out);
+out.println("");
+out.println("package org.apache.activemq.openwire.v" + getOpenwireVersion() + ";");
+out.println("");
+out.println("import java.io.DataInputStream;");
+out.println("import java.io.DataOutputStream;");
+out.println("import java.io.IOException;");
+out.println("");
+out.println("import org.apache.activemq.openwire.*;");
+out.println("import org.apache.activemq.command.*;");
+out.println("");
+out.println("");
+		for (int i = 0; i < getJclass().getImportedPackages().length; i++) {
+			JPackage pkg = getJclass().getImportedPackages()[i];
+			for (int j = 0; j < pkg.getClasses().length; j++) {
+				JClass clazz = pkg.getClasses()[j];
+out.println("import " + clazz.getQualifiedName() + ";");
+			}
+		}
+
+out.println("");
+out.println("/**");
+out.println(" * Marshalling code for Open Wire Format for "+getClassName()+"");
+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(" * @version $Revision$");
+out.println(" */");
+out.println("public " + getAbstractClassText() + "class " + getClassName() + " extends " + getBaseClass() + " {");
+out.println("");
+
+		if (!isAbstractClass()) {
+
+out.println("    /**");
+out.println("     * Return the type of Data Structure we marshal");
+out.println("     * @return short representation of the type data structure");
+out.println("     */");
+out.println("    public byte getDataStructureType() {");
+out.println("        return "+getJclass().getSimpleName()+".DATA_STRUCTURE_TYPE;");
+out.println("    }");
+out.println("    ");
+out.println("    /**");
+out.println("     * @return a new object instance");
+out.println("     */");
+out.println("    public DataStructure createObject() {");
+out.println("        return new "+getJclass().getSimpleName()+"();");
+out.println("    }");
+out.println("");
+		}
+
+out.println("    /**");
+out.println("     * Un-marshal an object instance from the data input stream");
+out.println("     *");
+out.println("     * @param o the object to un-marshal");
+out.println("     * @param dataIn the data input stream to build the object from");
+out.println("     * @throws IOException");
+out.println("     */");
+out.println("    public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn, BooleanStream bs) throws IOException {");
+out.println("        super.tightUnmarshal(wireFormat, o, dataIn, bs);");
+
+		if (!getProperties().isEmpty()) {
+out.println("");
+out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().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("    /**");
+out.println("     * Write the booleans that this object uses to a BooleanStream");
+out.println("     */");
+out.println("    public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {");
+
+		if (!getProperties().isEmpty()) {
+out.println("");
+out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+		}
+
+		if (isMarshallerAware()) {
+out.println("");
+out.println("        info.beforeMarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("        int rc = super.tightMarshal1(wireFormat, o, 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("     * @param o the instance to be marshaled");
+out.println("     * @param dataOut the output stream");
+out.println("     * @throws IOException thrown if an error occurs");
+out.println("     */");
+out.println("    public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut, BooleanStream bs) throws IOException {");
+out.println("        super.tightMarshal2(wireFormat, o, dataOut, bs);");
+		if (!getProperties().isEmpty()) {
+out.println("");
+out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().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("     * @param o the object to un-marshal");
+out.println("     * @param dataIn the data input stream to build the object from");
+out.println("     * @throws IOException");
+out.println("     */");
+out.println("    public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn) throws IOException {");
+out.println("        super.looseUnmarshal(wireFormat, o, dataIn);");
+
+		if (!getProperties().isEmpty()) {
+out.println("");
+out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().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("    /**");
+out.println("     * Write the booleans that this object uses to a BooleanStream");
+out.println("     */");
+out.println("    public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut) throws IOException {");
+
+		if (!getProperties().isEmpty()) {
+out.println("");
+out.println("        " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
+		}
+
+		if (isMarshallerAware()) {
+out.println("");
+out.println("        info.beforeMarshall(wireFormat);");
+		}
+
+out.println("");
+out.println("        super.looseMarshal(wireFormat, o, dataOut);");
+
+		generateLooseMarshalBody(out);
+
+out.println("");
+out.println("    }");
+out.println("}");
+	}
+
+	private 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 processFactory() {
+		if (factoryFile == null) {
+			factoryFile = new File(destDir, factoryFileName + filePostFix);
+		}
+		PrintWriter out = null;
+		try {
+			out = new PrintWriter(new FileWriter(factoryFile));
+			generateFactory(out);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (out != null) {
+				out.close();
+			}
+		}
+	}
+
+	protected void generateFactory(PrintWriter out) {
+		generateLicence(out);
+out.println("");
+out.println("package org.apache.activemq.openwire.v"+getOpenwireVersion()+";");
+out.println("");
+out.println("import org.apache.activemq.openwire.DataStreamMarshaller;");
+out.println("import org.apache.activemq.openwire.OpenWireFormat;");
+out.println("");
+out.println("/**");
+out.println(" * MarshallerFactory for Open Wire Format.");
+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(" * @version $Revision$");
+out.println(" */");
+out.println("public class MarshallerFactory {");
+out.println("");
+out.println("    /**");
+out.println("     * Creates a Map of command type -> Marshallers");
+out.println("     */");
+out.println("    static final private DataStreamMarshaller marshaller[] = new DataStreamMarshaller[256];");
+out.println("    static {");
+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("        add(new " + jclass.getSimpleName() + "Marshaller());");
+		}
+
+out.println("");
+out.println("    }");
+out.println("");
+out.println("    static private void add(DataStreamMarshaller dsm) {");
+out.println("        marshaller[dsm.getDataStructureType()] = dsm;");
+out.println("    }");
+out.println("    ");
+out.println("    static public DataStreamMarshaller[] createMarshallerMap(OpenWireFormat wireFormat) {");
+out.println("        return marshaller;");
+out.println("    }");
+out.println("}");
+	}
+
+	protected void processClass(JClass jclass) {
+		super.processClass(jclass);
+
+		if (!jclass.isAbstract()) {
+			concreteClasses.add(jclass);
+		}
+	}
+
+	protected String getClassName(JClass jclass) {
+		return super.getClassName(jclass) + "Marshaller";
+	}
+
+	protected String getBaseClassName(JClass jclass) {
+		String answer = "BaseDataStreamMarshaller";
+		JClass superclass = jclass.getSuperclass();
+		if (superclass != null) {
+			String superName = superclass.getSimpleName();
+			if (!superName.equals("Object") && !superName.equals("JNDIBaseStorable") && !superName.equals("DataStructureSupport")) {
+				answer = superName + "Marshaller";
+			}
+		}
+		return answer;
+	}
+
+	protected void initialiseManuallyMaintainedClasses() {
+	}
+
+	protected void generateTightUnmarshalBody(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 propertyTypeName = propertyType.getSimpleName();
+
+			if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
+				generateTightUnmarshalBodyForArrayProperty(out, property, size);
+			} else {
+				generateTightUnmarshalBodyForProperty(out, property, size);
+			}
+		}
+	}
+
+	protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+		String setter = property.getSetter().getSimpleName();
+		String type = property.getType().getSimpleName();
+
+		if (type.equals("boolean")) {
+			out.println("        info." + setter + "(bs.readBoolean());");
+		} else if (type.equals("byte")) {
+			out.println("        info." + setter + "(dataIn.readByte());");
+		} else if (type.equals("char")) {
+			out.println("        info." + setter + "(dataIn.readChar());");
+		} else if (type.equals("short")) {
+			out.println("        info." + setter + "(dataIn.readShort());");
+		} else if (type.equals("int")) {
+			out.println("        info." + setter + "(dataIn.readInt());");
+		} else if (type.equals("long")) {
+			out.println("        info." + setter + "(tightUnmarshalLong(wireFormat, dataIn, bs));");
+		} else if (type.equals("String")) {
+			out.println("        info." + setter + "(tightUnmarshalString(dataIn, bs));");
+		} else if (type.equals("byte[]")) {
+			if (size != null) {
+				out.println("        info." + setter + "(tightUnmarshalConstByteArray(dataIn, bs, " + size.asInt() + "));");
+			} else {
+				out.println("        info." + setter + "(tightUnmarshalByteArray(dataIn, bs));");
+			}
+		} else if (type.equals("ByteSequence")) {
+			out.println("        info." + setter + "(tightUnmarshalByteSequence(dataIn, bs));");
+		} else if (isThrowable(property.getType())) {
+			out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalThrowable(wireFormat, dataIn, bs));");
+		} else if (isCachedProperty(property)) {
+			out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalCachedObject(wireFormat, dataIn, bs));");
+		} else {
+			out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalNestedObject(wireFormat, dataIn, bs));");
+		}
+	}
+
+	protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+		JClass propertyType = property.getType();
+		String arrayType = propertyType.getArrayComponentType().getQualifiedName();
+		String setter = property.getSetter().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 + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
+			out.println("            }");
+			out.println("            info." + setter + "(value);");
+			out.println("        }");
+		} else {
+			out.println("        if (bs.readBoolean()) {");
+			out.println("            short size = dataIn.readShort();");
+			out.println("            " + arrayType + " value[] = new " + arrayType + "[size];");
+			out.println("            for( int i=0; i < size; i++ ) {");
+			out.println("                value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
+			out.println("            }");
+			out.println("            info." + setter + "(value);");
+			out.println("        }");
+			out.println("        else {");
+			out.println("            info." + setter + "(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.getGetter().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.println("        rc += tightMarshalString1(" + getter + ", bs);");
+			} else if (type.equals("byte[]")) {
+				if (size == null) {
+					out.println("        rc += tightMarshalByteArray1(" + getter + ", bs);");
+				} else {
+					out.println("        rc += tightMarshalConstByteArray1(" + getter + ", bs, " + size.asInt() + ");");
+				}
+			} else if (type.equals("ByteSequence")) {
+				out.println("        rc += tightMarshalByteSequence1(" + getter + ", bs);");
+			} 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 += tightMarshalThrowable1(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.getGetter().getSimpleName() + "()";
+
+			if (type.equals("boolean")) {
+				out.println("        bs.readBoolean();");
+			} else if (type.equals("byte")) {
+				out.println("        dataOut.writeByte(" + getter + ");");
+			} else if (type.equals("char")) {
+				out.println("        dataOut.writeChar(" + getter + ");");
+			} else if (type.equals("short")) {
+				out.println("        dataOut.writeShort(" + getter + ");");
+			} else if (type.equals("int")) {
+				out.println("        dataOut.writeInt(" + 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[]")) {
+				String mandatory = getMandatoryFlag(annotation);
+				if (size != null) {
+					out.println("        tightMarshalConstByteArray2(" + getter + ", dataOut, bs, " + size.asInt() + ");");
+				} else {
+					out.println("        tightMarshalByteArray2(" + getter + ", dataOut, bs);");
+				}
+			} else if (type.equals("ByteSequence")) {
+				out.println("        tightMarshalByteSequence2(" + getter + ", dataOut, bs);");
+			} 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("        tightMarshalThrowable2(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);");
+				}
+			}
+		}
+	}
+
+	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.getGetter().getSimpleName() + "()";
+
+			if (type.equals("boolean")) {
+				out.println("        dataOut.writeBoolean(" + getter + ");");
+			} else if (type.equals("byte")) {
+				out.println("        dataOut.writeByte(" + getter + ");");
+			} else if (type.equals("char")) {
+				out.println("        dataOut.writeChar(" + getter + ");");
+			} else if (type.equals("short")) {
+				out.println("        dataOut.writeShort(" + getter + ");");
+			} else if (type.equals("int")) {
+				out.println("        dataOut.writeInt(" + 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[]")) {
+				if (size != null) {
+					out.println("        looseMarshalConstByteArray(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
+				} else {
+					out.println("        looseMarshalByteArray(wireFormat, " + getter + ", dataOut);");
+				}
+			} else if (type.equals("ByteSequence")) {
+				out.println("        looseMarshalByteSequence(wireFormat, " + getter + ", dataOut);");
+			} 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("        looseMarshalThrowable(wireFormat, " + getter + ", dataOut);");
+			} else {
+				if (isCachedProperty(property)) {
+					out.println("        looseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+				} else {
+					out.println("        looseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+				}
+			}
+		}
+	}
+
+	protected void generateLooseUnmarshalBody(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 propertyTypeName = propertyType.getSimpleName();
+
+			if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
+				generateLooseUnmarshalBodyForArrayProperty(out, property, size);
+			} else {
+				generateLooseUnmarshalBodyForProperty(out, property, size);
+			}
+		}
+	}
+
+	protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+		String setter = property.getSetter().getSimpleName();
+		String type = property.getType().getSimpleName();
+
+		if (type.equals("boolean")) {
+			out.println("        info." + setter + "(dataIn.readBoolean());");
+		} else if (type.equals("byte")) {
+			out.println("        info." + setter + "(dataIn.readByte());");
+		} else if (type.equals("char")) {
+			out.println("        info." + setter + "(dataIn.readChar());");
+		} else if (type.equals("short")) {
+			out.println("        info." + setter + "(dataIn.readShort());");
+		} else if (type.equals("int")) {
+			out.println("        info." + setter + "(dataIn.readInt());");
+		} else if (type.equals("long")) {
+			out.println("        info." + setter + "(looseUnmarshalLong(wireFormat, dataIn));");
+		} else if (type.equals("String")) {
+			out.println("        info." + setter + "(looseUnmarshalString(dataIn));");
+		} else if (type.equals("byte[]")) {
+			if (size != null) {
+				out.println("        info." + setter + "(looseUnmarshalConstByteArray(dataIn, " + size.asInt() + "));");
+			} else {
+				out.println("        info." + setter + "(looseUnmarshalByteArray(dataIn));");
+			}
+		} else if (type.equals("ByteSequence")) {
+			out.println("        info." + setter + "(looseUnmarshalByteSequence(dataIn));");
+		} else if (isThrowable(property.getType())) {
+			out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalThrowable(wireFormat, dataIn));");
+		} else if (isCachedProperty(property)) {
+			out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalCachedObject(wireFormat, dataIn));");
+		} else {
+			out.println("        info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalNestedObject(wireFormat, dataIn));");
+		}
+	}
+
+	protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+		JClass propertyType = property.getType();
+		String arrayType = propertyType.getArrayComponentType().getQualifiedName();
+		String setter = property.getSetter().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 + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
+			out.println("            }");
+			out.println("            info." + setter + "(value);");
+			out.println("        }");
+		} else {
+			out.println("        if (dataIn.readBoolean()) {");
+			out.println("            short size = dataIn.readShort();");
+			out.println("            " + arrayType + " value[] = new " + arrayType + "[size];");
+			out.println("            for( int i=0; i < size; i++ ) {");
+			out.println("                value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
+			out.println("            }");
+			out.println("            info." + setter + "(value);");
+			out.println("        }");
+			out.println("        else {");
+			out.println("            info." + setter + "(null);");
+			out.println("        }");
+		}
+	}
+
+	/**
+	 * Returns whether or not the given annotation has a mandatory flag on it or
+	 * not
+	 */
+	protected String getMandatoryFlag(JAnnotation annotation) {
+		JAnnotationValue value = annotation.getValue("mandatory");
+		if (value != null) {
+			String text = value.asString();
+			if (text != null && text.equalsIgnoreCase("true")) {
+				return "true";
+			}
+		}
+		return "false";
+	}
+
+	public List getConcreteClasses() {
+		return concreteClasses;
+	}
+
+	public void setConcreteClasses(List concreteClasses) {
+		this.concreteClasses = concreteClasses;
+	}
+
+	public File getFactoryFile() {
+		return factoryFile;
+	}
+
+	public void setFactoryFile(File factoryFile) {
+		this.factoryFile = factoryFile;
+	}
+
+	public String getFactoryFileName() {
+		return factoryFileName;
+	}
+
+	public void setFactoryFileName(String factoryFileName) {
+		this.factoryFileName = factoryFileName;
+	}
+
+	public String getIndent() {
+		return indent;
+	}
+
+	public void setIndent(String indent) {
+		this.indent = indent;
+	}
+
+	public String getTargetDir() {
+		return targetDir;
+	}
+
+	public void setTargetDir(String sourceDir) {
+		this.targetDir = sourceDir;
+	}
+}

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaTestsGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaTestsGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaTestsGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/JavaTestsGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,216 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JPackage;
+import org.codehaus.jam.JProperty;
+
+
+/**
+ * 
+ * @version $Revision: 384826 $
+ */
+public class JavaTestsGenerator extends MultiSourceGenerator {
+
+	protected String targetDir="src/test/java";
+
+	public Object run() {
+		if (destDir == null) {
+			destDir = new File(targetDir+"/org/apache/activemq/openwire/v" + getOpenwireVersion());
+		}
+		return super.run();
+	}
+	
+	protected String getClassName(JClass jclass) {
+    	if( isAbstract(jclass) ) {
+        	return super.getClassName(jclass) + "TestSupport";
+    	} else {
+        	return super.getClassName(jclass) + "Test";
+    	}
+	}
+
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "DataFileGeneratorTestSupport";
+        if (superclass != null) {
+            String name = superclass.getSimpleName();
+            if (name!=null 
+            		&& !name.equals("JNDIBaseStorable") 
+    				&& !name.equals("DataStructureSupport") 
+    				&& !name.equals("Object")) {
+        	   answer = name + "Test";
+    		   if (isAbstract(getJclass().getSuperclass())) 
+    			   answer += "Support";
+            }
+        }
+        return answer;
+    }
+
+	private 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) {
+
+		generateLicence(out);
+
+out.println("package org.apache.activemq.openwire.v"+openwireVersion+";");
+out.println("");
+out.println("import java.io.DataInputStream;");
+out.println("import java.io.DataOutputStream;");
+out.println("import java.io.IOException;");
+out.println("");
+out.println("import org.apache.activemq.openwire.*;");
+out.println("import org.apache.activemq.command.*;");
+out.println("");
+		for (int i = 0; i < getJclass().getImportedPackages().length; i++) {
+			JPackage pkg = getJclass().getImportedPackages()[i];
+			for (int j = 0; j < pkg.getClasses().length; j++) {
+				JClass clazz = pkg.getClasses()[j];
+out.println("import " + clazz.getQualifiedName() + ";");
+			}
+		}
+
+		boolean marshallerAware = isMarshallAware(jclass);
+
+out.println("");
+out.println("/**");
+out.println(" * Test case for the OpenWire marshalling for "+jclass.getSimpleName()+"");
+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(" * @version $Revision: $");
+out.println(" */");
+out.println("public "+getAbstractClassText()+"class "+className+" extends "+baseClass+" {");
+out.println("");
+		if (!isAbstractClass()) {
+out.println("");
+out.println("    public static "+jclass.getSimpleName()+"Test SINGLETON = new "+jclass.getSimpleName()+"Test();");
+out.println("");
+out.println("    public Object createObject() throws Exception {");
+out.println("        "+jclass.getSimpleName()+" info = new "+jclass.getSimpleName()+"();");
+out.println("        populateObject(info);");
+out.println("        return info;");
+out.println("    }");
+		}
+out.println("");
+out.println("    protected void populateObject(Object object) throws Exception {");
+out.println("        super.populateObject(object);");
+out.println("        "+getJclass().getSimpleName()+" info = ("+getJclass().getSimpleName()+") object;");
+out.println("");
+
+		TestDataGenerator generator = new TestDataGenerator();
+
+		List properties = getProperties();
+		for (Iterator iter = properties.iterator(); iter.hasNext();) {
+			JProperty property = (JProperty) iter.next();
+
+			JAnnotation annotation = property.getAnnotation("openwire:property");		   
+			String size = stringValue(annotation, "size");
+			String testSize = stringValue(annotation, "testSize");
+		    String type = property.getType().getSimpleName();
+		    boolean cached = isCachedProperty(property);
+		    String propertyName = property.getSimpleName();
+		    if ("-1".equals(testSize)) 
+		    	continue;
+		   		    
+		    
+		    String setterName = property.getSetter().getSimpleName();
+		    
+		    if( type.equals("boolean")) {
+out.println("        info."+setterName+"("+generator.createBool()+");");
+		    } else if( type.equals("byte")) {
+out.println("        info."+setterName+"("+generator.createByte()+");");
+		    } else if( type.equals("char")) {
+out.println("        info."+setterName+"("+generator.createChar()+");");
+		    } else if( type.equals("short")) {
+out.println("        info."+setterName+"("+generator.createShort()+");");
+		    } else if( type.equals("int")) {
+out.println("        info."+setterName+"("+generator.createInt()+");");
+		    } else if( type.equals("long")) {
+out.println("        info."+setterName+"("+generator.createLong()+");");
+		    } else if( type.equals("byte[]")) {
+out.println("        info."+setterName+"("+generator.createByteArray(propertyName)+");");
+		    } else if( type.equals("String")) {
+out.println("        info."+setterName+"(\""+generator.createString(propertyName)+"\");");
+		    } else if( type.equals("ByteSequence")) {
+out.println("        {");
+out.println("            byte data[] = "+generator.createByteArray(propertyName)+";");
+out.println("            info."+setterName+"(new org.apache.activemq.util.ByteSequence(data,0,data.length));");
+out.println(        "}");       
+		    } else if( type.equals("Throwable")) {
+out.println("        info."+setterName+"(createThrowable(\""+generator.createString(propertyName)+"\"));");
+		    } else {
+			    if( property.getType().isArrayType() ) {
+			    	String arrayType = property.getType().getArrayComponentType().getSimpleName();
+		      	    if (size == null) 
+		      	      size = "2";
+			  	    if (arrayType == jclass.getSimpleName())
+			  	      size = "0";
+out.println("        {");
+out.println("            "+arrayType+" value[] = new "+arrayType+"["+size+"];");
+out.println("            for( int i=0; i < "+size+"; i++ ) {");
+out.println("                value[i] = create"+arrayType+"(\""+generator.createString(propertyName)+"\");");
+out.println("            }");
+out.println("            info."+setterName+"(value);");
+out.println("        }");
+	    		} else {
+out.println("        info."+setterName+"(create"+type+"(\""+generator.createString(propertyName)+"\"));");
+	            }
+	        }
+	    }
+            
+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/MultiSourceGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/MultiSourceGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/MultiSourceGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/MultiSourceGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,234 @@
+/**
+ *
+ * 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.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.FixCRLF;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+import org.codehaus.jam.JamClassIterator;
+
+/**
+ * 
+ * @version $Revision: 386442 $
+ */
+public abstract class MultiSourceGenerator extends OpenWireGenerator {
+    protected Set manuallyMaintainedClasses = new HashSet();
+    protected File destDir;
+    protected File destFile;
+
+    protected JClass jclass;
+    protected JClass superclass;
+    protected String simpleName;
+    protected String className;
+    protected String baseClass;
+    protected StringBuffer buffer;
+
+    public MultiSourceGenerator() {
+        initialiseManuallyMaintainedClasses();
+    }
+
+    public Object run() {
+        if (destDir == null) {
+            throw new IllegalArgumentException("No destDir defined!");
+        }
+        System.out.println(getClass().getName() + " generating files in: " + destDir);
+        destDir.mkdirs();
+        buffer = new StringBuffer();
+
+        JamClassIterator iter = getClasses();
+        while (iter.hasNext()) {
+            jclass = iter.nextClass();
+            if (isValidClass(jclass)) {
+                processClass(jclass);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns all the valid properties available on the current class
+     */
+    public List getProperties() {
+        List answer = new ArrayList();
+        JProperty[] properties = jclass.getDeclaredProperties();
+        for (int i = 0; i < properties.length; i++) {
+            JProperty property = properties[i];
+            if (isValidProperty(property)) {
+                answer.add(property);
+            }
+        }
+        return answer;
+    }
+
+    protected boolean isValidClass(JClass jclass) {
+        if (jclass.getAnnotation("openwire:marshaller") == null) {
+            return false;
+        }
+        return !manuallyMaintainedClasses.contains(jclass.getSimpleName());
+    }
+
+    protected void processClass(JClass jclass) {
+        simpleName = jclass.getSimpleName();
+        superclass = jclass.getSuperclass();
+
+        System.out.println(getClass().getName() + " processing class: " + simpleName);
+
+        className = getClassName(jclass);
+
+        destFile = new File(destDir, className + filePostFix);
+
+        baseClass = getBaseClassName(jclass);
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(destFile));
+            generateFile(out);
+        }
+        catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+        
+        // Use the FixCRLF Ant Task to make sure the file has consistent newlines
+        // so that SVN does not complain on checkin.
+        Project project = new Project();
+        project.init();
+        FixCRLF fixCRLF = new FixCRLF();
+        fixCRLF.setProject(project);
+        fixCRLF.setSrcdir(destFile.getParentFile());
+        fixCRLF.setIncludes(destFile.getName());
+        fixCRLF.execute();
+    }
+
+    protected abstract void generateFile(PrintWriter out) throws Exception;
+
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "BaseDataStructure";
+        if (superclass != null) {
+            String name = superclass.getSimpleName();
+            if (name != null && !name.equals("Object")) {
+                answer = name;
+            }
+        }
+        return answer;
+    }
+
+    protected String getClassName(JClass jclass) {
+        return jclass.getSimpleName();
+    }
+    
+    public boolean isAbstractClass() {
+        return jclass != null & jclass.isAbstract();
+    }
+
+    public String getAbstractClassText() {
+        return isAbstractClass() ? "abstract " : "";
+    }
+    
+    public boolean isMarshallerAware() {
+        return isMarshallAware(jclass);
+    }
+
+    protected void initialiseManuallyMaintainedClasses() {
+        String[] names = { "ActiveMQDestination", "ActiveMQTempDestination", "ActiveMQQueue", "ActiveMQTopic", "ActiveMQTempQueue", "ActiveMQTempTopic",
+                "BaseCommand", "ActiveMQMessage", "ActiveMQTextMessage", "ActiveMQMapMessage", "ActiveMQBytesMessage", "ActiveMQStreamMessage",
+                "ActiveMQStreamMessage", "DataStructureSupport", "WireFormatInfo", "ActiveMQObjectMessage" };
+
+        for (int i = 0; i < names.length; i++) {
+            manuallyMaintainedClasses.add(names[i]);
+        }
+    }
+
+	public String getBaseClass() {
+		return baseClass;
+	}
+
+	public void setBaseClass(String baseClass) {
+		this.baseClass = baseClass;
+	}
+
+	public String getClassName() {
+		return className;
+	}
+
+	public void setClassName(String className) {
+		this.className = className;
+	}
+
+	public File getDestDir() {
+		return destDir;
+	}
+
+	public void setDestDir(File destDir) {
+		this.destDir = destDir;
+	}
+
+	public File getDestFile() {
+		return destFile;
+	}
+
+	public void setDestFile(File destFile) {
+		this.destFile = destFile;
+	}
+
+	public JClass getJclass() {
+		return jclass;
+	}
+
+	public void setJclass(JClass jclass) {
+		this.jclass = jclass;
+	}
+
+	public Set getManuallyMaintainedClasses() {
+		return manuallyMaintainedClasses;
+	}
+
+	public void setManuallyMaintainedClasses(Set manuallyMaintainedClasses) {
+		this.manuallyMaintainedClasses = manuallyMaintainedClasses;
+	}
+
+	public String getSimpleName() {
+		return simpleName;
+	}
+
+	public void setSimpleName(String simpleName) {
+		this.simpleName = simpleName;
+	}
+
+	public JClass getSuperclass() {
+		return superclass;
+	}
+
+	public void setSuperclass(JClass superclass) {
+		this.superclass = superclass;
+	}
+
+}

Copied: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireGenerator.java (from r450087, incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java)
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireGenerator.java?view=diff&rev=450289&p1=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java&r1=450087&p2=incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireGenerator.java&r2=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java (original)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireGenerator.java Tue Sep 26 19:42:47 2006
@@ -17,7 +17,7 @@
  */
 package org.apache.activemq.openwire.tool;
 
-import org.codehaus.gram.GramSupport;
+import org.codehaus.jam.JAnnotation;
 import org.codehaus.jam.JAnnotationValue;
 import org.codehaus.jam.JClass;
 import org.codehaus.jam.JField;
@@ -29,12 +29,14 @@
 /**
  * @version $Revision$
  */
-public abstract class OpenWireScript extends GramSupport {
+public abstract class OpenWireGenerator {
 
-    private String openwireVersion;
+    protected int openwireVersion;
     protected String filePostFix = ".java";
+    protected JamService jam;
+    
 
-    public boolean isValidProperty(JProperty it) {
+	public boolean isValidProperty(JProperty it) {
         JMethod getter = it.getGetter();
         return getter != null && it.getSetter() != null && getter.isStatic() == false && getter.getAnnotation("openwire:property") != null;
     }
@@ -74,8 +76,7 @@
                 }
             }
             return false;
-        }
-        else {
+        } else {
             String simpleName = j.getSimpleName();
             return simpleName.equals("ActiveMQMessage") || simpleName.equals("WireFormatInfo");
         }
@@ -88,21 +89,18 @@
     }
 
     public JamService getJam() {
-        return (JamService) getBinding().getVariable("jam");
+        return jam;
     }
 
     public JamClassIterator getClasses() {
         return getJam().getClasses();
     }
 
-    public String getOpenwireVersion() {
-        if (openwireVersion == null) {
-            openwireVersion = (String) getProperty("version");
-        }
+    public int getOpenwireVersion() {
         return openwireVersion;
     }
 
-    public void setOpenwireVersion(String openwireVersion) {
+    public void setOpenwireVersion(int openwireVersion) {
         this.openwireVersion = openwireVersion;
     }
 
@@ -128,7 +126,43 @@
         }
     }
 
-    public String getOpenWireOpCode(JClass aClass) {
-        return annotationValue(aClass, "openwire:marshaller", "code", "0");
-    }
+    public String getOpenWireOpCode(JClass element) {
+    	if (element != null) {
+			JAnnotation annotation = element.getAnnotation("openwire:marshaller");
+			return stringValue(annotation, "code", "0");
+		}
+		return "0";
+    }
+    
+    protected String stringValue(JAnnotation annotation, String name) {
+		return stringValue(annotation, name, null);
+	}
+	
+	protected String stringValue(JAnnotation annotation, String name, String defaultValue) {
+        if (annotation != null) {
+            JAnnotationValue value = annotation.getValue(name);
+            if (value != null) {
+                return value.asString();
+            }
+        }
+        return defaultValue;
+	}
+
+	public void setJam(JamService jam) {
+		this.jam = jam;
+	}
+	
+	public String decapitalize(String text) {
+		if (text == null) {
+			return null;
+		}
+		return text.substring(0, 1).toLowerCase() + text.substring(1);
+	}
+
+	public String capitalize(String text) {
+		if (text == null) {
+			return null;
+		}
+		return text.substring(0, 1).toUpperCase() + text.substring(1);
+	}
 }

Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/SingleSourceGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/SingleSourceGenerator.java?view=auto&rev=450289
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/SingleSourceGenerator.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/SingleSourceGenerator.java Tue Sep 26 19:42:47 2006
@@ -0,0 +1,238 @@
+/**
+ *
+ * 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.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.FixCRLF;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+import org.codehaus.jam.JamClassIterator;
+
+/**
+ * 
+ * @version $Revision: 386442 $
+ */
+public abstract class SingleSourceGenerator extends OpenWireGenerator {
+	
+    protected Set manuallyMaintainedClasses = new HashSet();
+    protected File destFile;
+
+    protected JClass jclass;
+    protected JClass superclass;
+    protected String simpleName;
+    protected String className;
+    protected String baseClass;
+	protected List sortedClasses;
+
+    public SingleSourceGenerator() {
+        initialiseManuallyMaintainedClasses();
+    }
+
+    public Object run() {
+    	
+        if (destFile == null) {
+            throw new IllegalArgumentException("No destFile defined!");
+        }        
+        destFile.getParentFile().mkdirs();
+
+        PrintWriter out = null;
+        try {
+        	out =  new PrintWriter(new FileWriter(destFile));
+        	
+        	ArrayList classes = new ArrayList();        	
+   	     	JamClassIterator iter = getClasses();
+            while (iter.hasNext()) {
+				jclass = iter.nextClass();				
+                if (isValidClass(jclass)) {
+                	classes.add(jclass);
+                }
+            }
+   	        sortedClasses = sort(classes);
+   	        
+        	generateSetup(out);
+   	        for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
+				jclass = (JClass) iterator.next();				
+                simpleName = jclass.getSimpleName();
+                superclass = jclass.getSuperclass();
+                className = getClassName(jclass);
+                baseClass = getBaseClassName(jclass);
+
+                System.out.println(getClass().getName() + " processing class: " + simpleName);
+                generateFile(out);
+            }        
+            generateTearDown(out);
+        	
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+        
+        // Use the FixCRLF Ant Task to make sure the file has consistent newlines
+        // so that SVN does not complain on checkin.
+        Project project = new Project();
+        project.init();
+        FixCRLF fixCRLF = new FixCRLF();
+        fixCRLF.setProject(project);
+        fixCRLF.setSrcdir(destFile.getParentFile());
+        fixCRLF.setIncludes(destFile.getName());
+        fixCRLF.execute();
+        return null;
+    }
+    
+    protected List sort(List classes) {
+		return classes;
+	}
+
+	protected void generateTearDown(PrintWriter out) {
+	}
+
+    protected void generateSetup(PrintWriter out) {
+	}
+
+	/**
+     * Returns all the valid properties available on the current class
+     */
+    public List getProperties() {
+        List answer = new ArrayList();
+        JProperty[] properties = jclass.getDeclaredProperties();
+        for (int i = 0; i < properties.length; i++) {
+            JProperty property = properties[i];
+            if (isValidProperty(property)) {
+                answer.add(property);
+            }
+        }
+        return answer;
+    }
+
+    protected boolean isValidClass(JClass jclass) {
+        if (jclass==null || jclass.getAnnotation("openwire:marshaller") == null) {
+            return false;
+        }
+        return true;
+        //return !manuallyMaintainedClasses.contains(jclass.getSimpleName());
+    }
+
+
+    protected abstract void generateFile(PrintWriter out) throws Exception;
+
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "BaseDataStructure";
+        if (superclass != null) {
+            String name = superclass.getSimpleName();
+            if (name != null && !name.equals("Object")) {
+                answer = name;
+            }
+        }
+        return answer;
+    }
+
+    protected String getClassName(JClass jclass) {
+        return jclass.getSimpleName();
+    }
+    
+    public boolean isAbstractClass() {
+        return jclass != null & jclass.isAbstract();
+    }
+
+    public String getAbstractClassText() {
+        return isAbstractClass() ? "abstract " : "";
+    }
+    
+    public boolean isMarshallerAware() {
+        return isMarshallAware(jclass);
+    }
+
+    protected void initialiseManuallyMaintainedClasses() {
+        String[] names = { "ActiveMQDestination", "ActiveMQTempDestination", "ActiveMQQueue", "ActiveMQTopic", "ActiveMQTempQueue", "ActiveMQTempTopic",
+                "BaseCommand", "ActiveMQMessage", "ActiveMQTextMessage", "ActiveMQMapMessage", "ActiveMQBytesMessage", "ActiveMQStreamMessage",
+                "ActiveMQStreamMessage", "DataStructureSupport", "WireFormatInfo", "ActiveMQObjectMessage" };
+
+        for (int i = 0; i < names.length; i++) {
+            manuallyMaintainedClasses.add(names[i]);
+        }
+    }
+
+	public String getBaseClass() {
+		return baseClass;
+	}
+
+	public void setBaseClass(String baseClass) {
+		this.baseClass = baseClass;
+	}
+
+	public String getClassName() {
+		return className;
+	}
+
+	public void setClassName(String className) {
+		this.className = className;
+	}
+
+	public File getDestFile() {
+		return destFile;
+	}
+
+	public void setDestFile(File destFile) {
+		this.destFile = destFile;
+	}
+
+	public JClass getJclass() {
+		return jclass;
+	}
+
+	public void setJclass(JClass jclass) {
+		this.jclass = jclass;
+	}
+
+	public Set getManuallyMaintainedClasses() {
+		return manuallyMaintainedClasses;
+	}
+
+	public void setManuallyMaintainedClasses(Set manuallyMaintainedClasses) {
+		this.manuallyMaintainedClasses = manuallyMaintainedClasses;
+	}
+
+	public String getSimpleName() {
+		return simpleName;
+	}
+
+	public void setSimpleName(String simpleName) {
+		this.simpleName = simpleName;
+	}
+
+	public JClass getSuperclass() {
+		return superclass;
+	}
+
+	public void setSuperclass(JClass superclass) {
+		this.superclass = superclass;
+	}
+
+}



Mime
View raw message