activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r797631 - in /activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator: ./ src/main/java/org/apache/activemq/openwire/tool/marshallers/
Date Fri, 24 Jul 2009 20:03:53 GMT
Author: tabish
Date: Fri Jul 24 20:03:53 2009
New Revision: 797631

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

Update the generator to produce better marshallers and handle the ActiveMQ 5.3 codebase.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/pom.xml
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java
    activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingHeadersGenerator.java

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/pom.xml?rev=797631&r1=797630&r2=797631&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/pom.xml (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/pom.xml Fri Jul 24 20:03:53
2009
@@ -53,16 +53,6 @@
           <value>Sun Microsystems Inc.</value>
         </property>
       </activation>
-      <dependencies>
-        <dependency>
-          <groupId>com.sun</groupId>
-          <artifactId>tools</artifactId>
-          <version>1.5</version>
-           <scope>system</scope>
-           <!-- Only a JDK of 1.5.0 B11 or greater seems to work. -->
-           <systemPath>/opt/local/jdk1.5/lib/tools.jar</systemPath>
-        </dependency>
-      </dependencies>
     </profile>
   </profiles>
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java?rev=797631&r1=797630&r2=797631&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingClassesGenerator.java
Fri Jul 24 20:03:53 2009
@@ -26,7 +26,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -56,9 +55,7 @@
             return true;
         }
 
-        List properties = getProperties();
-        for (Iterator iter = properties.iterator(); iter.hasNext();) {
-            JProperty property = (JProperty) iter.next();
+        for ( JProperty property : getProperties() ) {
             JClass propertyType = property.getType();
             String type = propertyType.getSimpleName();
 
@@ -87,9 +84,7 @@
             return true;
         }
 
-        List properties = getProperties();
-        for (Iterator iter = properties.iterator(); iter.hasNext();) {
-            JProperty property = (JProperty) iter.next();
+        for ( JProperty property : getProperties() ) {
             JClass propertyType = property.getType();
             String type = propertyType.getSimpleName();
 
@@ -107,12 +102,26 @@
     // This section is for the tight wire format encoding generator
     //////////////////////////////////////////////////////////////////////////////////////
 
+    protected void generateTightUnmarshalBody(PrintWriter out) {
+        for ( JProperty property : getProperties() ) {
+            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();
         String nativeType = toCppType(property.getType());
-        String propertyName = property.getType().getSimpleName();
 
         if( type.equals("boolean") ) {
             out.println("        info->" + setter + "( bs->readBoolean() );");
@@ -188,10 +197,8 @@
     }
 
     protected int generateTightMarshal1Body(PrintWriter out) {
-        List properties = getProperties();
         int baseSize = 0;
-        for (Iterator iter = properties.iterator(); iter.hasNext();) {
-            JProperty property = (JProperty) iter.next();
+        for ( JProperty property : getProperties() ) {
             JAnnotation annotation = property.getAnnotation("openwire:property");
             JAnnotationValue size = annotation.getValue("size");
             JClass propertyType = property.getType();
@@ -253,10 +260,11 @@
     }
 
     protected void generateTightMarshal2Body(PrintWriter out) {
-        List properties = getProperties();
+
         int count = 0;
-        for (Iterator iter = properties.iterator(); iter.hasNext();) {
-            JProperty property = (JProperty) iter.next();
+
+        for ( JProperty property : getProperties() ) {
+
             JAnnotation annotation = property.getAnnotation("openwire:property");
             JAnnotationValue size = annotation.getValue("size");
             JClass propertyType = property.getType();
@@ -322,9 +330,25 @@
     // This section is for the loose wire format encoding generator
     //////////////////////////////////////////////////////////////////////////////////////
 
+    protected void generateLooseUnmarshalBody(PrintWriter out) {
+
+        for ( JProperty property : getProperties() ) {
+
+            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 propertyName = property.getSimpleName();
         String type = property.getType().getSimpleName();
         String nativeType = toCppType(property.getType());
         String setter = property.getSetter().getSimpleName();
@@ -375,7 +399,6 @@
     protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty
property, JAnnotationValue size) {
         JClass propertyType = property.getType();
         String arrayType = propertyType.getArrayComponentType().getSimpleName();
-        String propertyName = property.getSimpleName();
         String setter = property.getSetter().getSimpleName();
         String getter = property.getGetter().getSimpleName();
 
@@ -406,9 +429,9 @@
 
 
     protected void generateLooseMarshalBody(PrintWriter out) {
-        List properties = getProperties();
-        for (Iterator iter = properties.iterator(); iter.hasNext();) {
-            JProperty property = (JProperty) iter.next();
+
+        for ( JProperty property : getProperties() ) {
+
             JAnnotation annotation = property.getAnnotation("openwire:property");
             JAnnotationValue size = annotation.getValue("size");
             JClass propertyType = property.getType();
@@ -524,7 +547,7 @@
 out.println("        "+baseClass+"::tightUnmarshal( wireFormat, dataStructure, dataIn, bs
);");
 out.println("");
 
-    List properties = getProperties();
+    List<JProperty> properties = getProperties();
     boolean marshallerAware = isMarshallerAware();
     if( !properties.isEmpty() || marshallerAware ) {
 
@@ -673,18 +696,15 @@
 
 out.println("#include <activemq/wireformat/openwire/marshal/v"+getOpenwireVersion()+"/MarshallerFactory.h>");
 
-    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());
-    }});
+        List<JClass> list = new ArrayList<JClass>(getConcreteClasses());
+        Collections.sort(list, new Comparator<JClass>(){
+            public int compare(JClass c1, JClass c2) {
+                return c1.getSimpleName().compareTo(c2.getSimpleName());
+        }});
 
-    for (Iterator iter = list.iterator(); iter.hasNext();) {
-        JClass jclass = (JClass) iter.next();
+        for ( JClass jclass : list ) {
 out.println("#include <activemq/wireformat/openwire/marshal/v"+getOpenwireVersion()+"/"+jclass.getSimpleName()+"Marshaller.h>");
-    }
+        }
 
 out.println("");
 out.println("/*");
@@ -708,10 +728,9 @@
 out.println("void MarshallerFactory::configure( OpenWireFormat* format ) {");
 out.println("");
 
-    for (Iterator iter = list.iterator(); iter.hasNext();) {
-        JClass jclass = (JClass) iter.next();
+        for ( JClass jclass : list ) {
 out.println("    format->addMarshaller( new "+jclass.getSimpleName()+"Marshaller() );");
-}
+        }
 
 out.println("}");
 out.println("");

Modified: activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingHeadersGenerator.java?rev=797631&r1=797630&r2=797631&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingHeadersGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/marshallers/AmqCppMarshallingHeadersGenerator.java
Fri Jul 24 20:03:53 2009
@@ -18,29 +18,82 @@
 package org.apache.activemq.openwire.tool.marshallers;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
 
-import org.apache.activemq.openwire.tool.JavaMarshallingGenerator;
+import org.apache.activemq.openwire.tool.MultiSourceGenerator;
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
 import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
 
 /**
  *
  * @version $Revision: 381410 $
  */
-public class AmqCppMarshallingHeadersGenerator extends JavaMarshallingGenerator {
+public class AmqCppMarshallingHeadersGenerator extends MultiSourceGenerator {
 
     protected String targetDir="./src/main";
+    protected List<JClass> concreteClasses = new ArrayList<JClass>();
+    protected File factoryFile;
+    protected String factoryFileName = "MarshallerFactory";
+    protected String indent = "    ";
+
+    /**
+     * Overrides the base class init since we don't mark any marshaller classes as
+     * being manually maintained.
+     */
+    protected void initialiseManuallyMaintainedClasses() {
+    }
+
+    /**
+     * Returns all the valid properties available on the current class. Overrides the
+     * method in {@link MultiSourceGenerator} to add filtering on the Openwire Version
+     * number so that we can rerun this tool for older versions and produce an exact
+     * match to what was previously generated.
+     *
+     * @return List of Properties valid for the current {@link JClass} and Openwire version.
+     */
+    public List<JProperty> getProperties() {
+        List<JProperty> answer = new ArrayList<JProperty>();
+        JProperty[] properties = jclass.getDeclaredProperties();
+        for (int i = 0; i < properties.length; i++) {
+            JProperty property = properties[i];
+            if (isValidProperty(property)) {
+
+                JAnnotation annotation = property.getAnnotation("openwire:property");
+                JAnnotationValue version = annotation.getValue("version");
+
+                if( version.asInt() <= this.getOpenwireVersion() ) {
+                    answer.add(property);
+                }
+            }
+        }
+        return answer;
+    }
 
     public Object run() {
         filePostFix = getFilePostFix();
         if (destDir == null) {
             destDir = new File(targetDir+"/activemq/wireformat/openwire/marshal/v"+getOpenwireVersion());
         }
-        return super.run();
+        Object answer = super.run();
+        processFactory();
+        return answer;
     }
 
     protected void processClass(JClass jclass) {
-        super.processClass( 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) {
@@ -60,9 +113,17 @@
             answer = "MessageMarshaller";
         }
 
-        // We didn't map it, so let the base class handle it.
+        // We didn't map it directly so we turn it into something generic.
         if( answer.equals( jclass.getSimpleName() ) ) {
-            answer = super.getBaseClassName(jclass);
+            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;
         }
 
         return answer;
@@ -298,6 +359,23 @@
 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();
+            }
+        }
+    }
+
     public void generateFactory(PrintWriter out) {
         generateLicence(out);
 out.println("#ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSAHAL_V"+getOpenwireVersion()+"_MARSHALERFACTORY_H_");
@@ -338,6 +416,14 @@
 out.println("#endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_MARSHAL_V"+getOpenwireVersion()+"_MARSHALLERFACTORY_H_*/");
     }
 
+    public List<JClass> getConcreteClasses() {
+        return concreteClasses;
+    }
+
+    public void setConcreteClasses(List<JClass> concreteClasses) {
+        this.concreteClasses = concreteClasses;
+    }
+
     public String getTargetDir() {
         return targetDir;
     }



Mime
View raw message