activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r515395 - in /activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts: AmqCppGeneratorTask.java AmqCppTestMarshallingHeadersGenerator.java
Date Wed, 07 Mar 2007 00:37:18 GMT
Author: tabish
Date: Tue Mar  6 16:37:18 2007
New Revision: 515395

URL: http://svn.apache.org/viewvc?view=rev&rev=515395
Log:
http://issues.apache.org/activemq/browse/AMQCPP-30

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppTestMarshallingHeadersGenerator.java
  (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppGeneratorTask.java

Modified: activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppGeneratorTask.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppGeneratorTask.java?view=diff&rev=515395&r1=515394&r2=515395
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppGeneratorTask.java (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppGeneratorTask.java Tue
Mar  6 16:37:18 2007
@@ -27,110 +27,117 @@
 import org.codehaus.jam.JamServiceParams;
 
 /**
- * 
+ *
  * @version $Revision: 384826 $
  */
 public class AmqCppGeneratorTask extends Task {
-	
-	int version = 2;
-	File source = new File(".");
-	File target = new File(".");
-	
+
+    int version = 2;
+    File source = new File(".");
+    File target = new File(".");
+
     public static void main(String[] args) {
-    	
+
         Project project = new Project();
         project.init();
-    	AmqCppGeneratorTask generator = new AmqCppGeneratorTask();
-    	generator.setProject(project);
-    	
-    	if( args.length > 0 ) {
-    		generator.version = Integer.parseInt(args[0]);
+        AmqCppGeneratorTask generator = new AmqCppGeneratorTask();
+        generator.setProject(project);
+
+        if( args.length > 0 ) {
+            generator.version = Integer.parseInt(args[0]);
             System.out.println( "Generator Version: " + Integer.parseInt(args[0]) );
         }
 
-    	if( args.length > 1 ) {
-    		generator.source = new File(args[1]);
+        if( args.length > 1 ) {
+            generator.source = new File(args[1]);
             System.out.println( "Generator Source: " + generator.source );
-        }  
-    	
-    	if( args.length > 2 ) {
-    		generator.target = new File(args[2]);
+        }
+
+        if( args.length > 2 ) {
+            generator.target = new File(args[2]);
             System.out.println( "Generator Source: " + generator.target );
-        }    	
-    	
-    	generator.execute();
-	}
-    
+        }
+
+        generator.execute();
+    }
+
     public void execute() throws BuildException {
         try {
-        	
-        	String sourceDir = source+"/src/main/java";
-        	
+
+            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)};            
+            JamServiceParams params = jamServiceFactory.createServiceParams();
+            File[] dirs = new File[]{new File(sourceDir)};
             params.includeSourcePattern(dirs, "**/*.java");
             JamService jam = jamServiceFactory.createService(params);
 
             {
-            	AmqCppClassesGenerator script = new AmqCppClassesGenerator();
-	        	script.setJam(jam);
-	        	script.setTargetDir(target+"/src/main");
-	        	script.setOpenwireVersion(version);
-	        	script.run();
+                AmqCppClassesGenerator script = new AmqCppClassesGenerator();
+                script.setJam(jam);
+                script.setTargetDir(target+"/src/main");
+                script.setOpenwireVersion(version);
+                script.run();
             }
             {
                 AmqCppHeadersGenerator script = new AmqCppHeadersGenerator();
-	        	script.setJam(jam);
-	        	script.setTargetDir(target+"/src/main");
-	        	script.setOpenwireVersion(version);
-	        	script.run();
+                script.setJam(jam);
+                script.setTargetDir(target+"/src/main");
+                script.setOpenwireVersion(version);
+                script.run();
             }
             {
                 AmqCppMarshallingHeadersGenerator script = new AmqCppMarshallingHeadersGenerator();
-	        	script.setJam(jam);
-	        	script.setTargetDir(target+"/src/main");
-	        	script.setOpenwireVersion(version);
-	        	script.run();
+                script.setJam(jam);
+                script.setTargetDir(target+"/src/main");
+                script.setOpenwireVersion(version);
+                script.run();
+            }
+            {
+                AmqCppTestMarshallingHeadersGenerator script = new AmqCppTestMarshallingHeadersGenerator();
+                script.setJam(jam);
+                script.setTargetDir(target+"/src/test");
+                script.setOpenwireVersion(version);
+                script.run();
             }
             {
                 AmqCppMarshallingClassesGenerator script = new AmqCppMarshallingClassesGenerator();
-	        	script.setJam(jam);
-	        	script.setTargetDir(target+"/src/main");
-	        	script.setOpenwireVersion(version);
-	        	script.run();
+                script.setJam(jam);
+                script.setTargetDir(target+"/src/main");
+                script.setOpenwireVersion(version);
+                script.run();
             }
-            
-            
+
+
         } catch (Exception e) {
-        	throw new BuildException(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;
-	}
+    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: activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppTestMarshallingHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppTestMarshallingHeadersGenerator.java?view=auto&rev=515395
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppTestMarshallingHeadersGenerator.java
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppTestMarshallingHeadersGenerator.java
Tue Mar  6 16:37:18 2007
@@ -0,0 +1,224 @@
+/**
+ *
+ * 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 org.codehaus.jam.JClass;
+
+/**
+ *
+ * @version $Revision: 381410 $
+ */
+public class AmqCppTestMarshallingHeadersGenerator extends JavaMarshallingGenerator {
+
+    protected String targetDir="./src/main";
+
+    public Object run() {
+        filePostFix = getFilePostFix();
+        if (destDir == null) {
+            destDir = new File(targetDir+"/activemq/connector/openwire/marshal/v"+getOpenwireVersion());
+        }
+        return super.run();
+    }
+
+    protected String getClassName(JClass jclass) {
+        return super.getClassName(jclass) + "Test";
+    }
+
+    protected String getBaseClassName(JClass jclass) {
+        String answer = jclass.getSimpleName();
+
+        if( answer.equals("ActiveMQTextMessage") ) {
+            answer = "MessageMarshaller";
+        } else if( answer.equals("ActiveMQBytesMessage") ) {
+            answer = "MessageMarshaller";
+        } else if( answer.equals("ActiveMQMapMessage") ) {
+            answer = "MessageMarshaller";
+        } else if( answer.equals("ActiveMQObjectMessage") ) {
+            answer = "MessageMarshaller";
+        } else if( answer.equals("ActiveMQStreamMessage") ) {
+            answer = "MessageMarshaller";
+        }
+
+        // We didn't map it, so let the base class handle it.
+        if( answer.equals( jclass.getSimpleName() ) ) {
+            answer = super.getBaseClassName(jclass);
+        }
+
+        return answer;
+    }
+
+    public boolean isMarshallAware(JClass j) {
+
+        String answer = jclass.getSimpleName();
+
+        if( answer.equals("ActiveMQTextMessage") ) {
+            return true;
+        } else if( answer.equals("ActiveMQBytesMessage") ) {
+            return true;
+        } else if( answer.equals("ActiveMQMapMessage") ) {
+            return true;
+        } else if( answer.equals("ActiveMQObjectMessage") ) {
+            return true;
+        } else if( answer.equals("ActiveMQStreamMessage") ) {
+            return true;
+        } else {
+            return super.isMarshallAware(jclass);
+        }
+    }
+
+    protected String getFilePostFix() {
+        return ".h";
+    }
+
+    public String toCppType(JClass type) {
+        String name = type.getSimpleName();
+        if (name.equals("String")) {
+            return "std::string";
+        }
+        else if( type.isArrayType() ) {
+            if( name.equals( "byte[]" ) )
+                name = "unsigned char[]";
+
+            JClass arrayClass = type.getArrayComponentType();
+
+            if( arrayClass.isPrimitiveType() ) {
+                return "std::vector<" + name.substring(0, name.length()-2) + ">";
+            } else {
+                return "std::vector<" + name.substring(0, name.length()-2) + "*>";
+            }
+        }
+        else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) {
+            return "BrokerError";
+        }
+        else if( name.equals("BaseDataStructure" ) ){
+            return "DataStructure";
+        }
+        else if( name.equals("ByteSequence") ) {
+            return "std::vector<char>";
+        }
+        else if( name.equals("boolean") ) {
+            return "bool";
+        }
+        else if( name.equals("long") ) {
+            return "long long";
+        }
+        else if( name.equals("byte") ) {
+            return "unsigned char";
+        }
+        else if( !type.isPrimitiveType() ) {
+            return name;
+        }
+        else {
+            return name;
+        }
+    }
+
+    protected 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);
+
+        if( isAbstractClass() ) {
+            return;
+        }
+
+out.println("");
+out.println("#ifndef _ACTIVEMQ_CONNECTOR_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_");
+out.println("#define _ACTIVEMQ_CONNECTOR_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_");
+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 <activemq/io/DataInputStream.h>");
+out.println("#include <activemq/io/DataOutputStream.h>");
+out.println("#include <activemq/io/IOException.h>");
+out.println("#include <activemq/connector/openwire/OpenWireFormat.h>");
+out.println("#include <activemq/connector/openwire/commands/DataStructure.h>");
+out.println("#include <activemq/connector/openwire/utils/BooleanStream.h>");
+out.println("");
+out.println("#include <cppunit/TestFixture.h>");
+out.println("#include <cppunit/extensions/HelperMacros.h>");
+out.println("");
+out.println("namespace activemq{");
+out.println("namespace connector{");
+out.println("namespace openwire{");
+out.println("namespace marshal{");
+out.println("namespace v"+getOpenwireVersion()+"{");
+out.println("");
+out.println("    /**");
+out.println("     * Marshalling Test code for Open Wire Format for "+className);
+out.println("     *");
+out.println("     *  NOTE!: This file is autogenerated - do not modify!");
+out.println("     *         if you need to make a change, please see the Java Classes");
+out.println("     *         in the activemq-openwire-generator module");
+out.println("     */");
+out.println("    class "+className+" : public CppUnit::TestFixture" );
+out.println("    {");
+out.println("");
+out.println("        CPPUNIT_TEST_SUITE( "+className+" );");
+out.println("        CPPUNIT_TEST( test );");
+out.println("        CPPUNIT_TEST_SUITE_END();");
+out.println("");
+out.println("    public:");
+out.println("");
+out.println("        "+className+"() {}");
+out.println("        virtual ~"+className+"() {}");
+out.println("");
+out.println("        /**");
+out.println("         * Test the marshaller and its marshalled type.");
+out.println("         */");
+out.println("        virtual void test();");
+out.println("");
+out.println("    };");
+out.println("");
+out.println("}}}}}");
+out.println("");
+out.println("#endif /*_ACTIVEMQ_CONNECTOR_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_"+className.toUpperCase()+"_H_*/");
+out.println("");
+        }
+
+    public String getTargetDir() {
+        return targetDir;
+    }
+
+    public void setTargetDir(String targetDir) {
+        this.targetDir = targetDir;
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/openwire-scripts/AmqCppTestMarshallingHeadersGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message