activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r946684 [2/2] - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/ main/java/org/apache/activemq/amqp/generator/
Date Thu, 20 May 2010 16:13:58 GMT
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java?rev=946684&r1=946683&r2=946684&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
(original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
Thu May 20 16:13:58 2010
@@ -269,15 +269,15 @@ public class Generator {
                 }
 
                 writer.newLine();
-                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> encode(" + amqpClass.getJavaType() + " data) throws AmqpEncodingError;");
+                writer.write(tab(1) + "public " + amqpClass.getTypeMapping().getGeneric("
") + "Encoded<" + amqpClass.getValueMapping().parameterized() + "> encode(" + amqpClass.typeMapping.parameterized()
+ " data) throws AmqpEncodingError;");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> decode" + amqpClass.getJavaType() + "(Buffer source, int offset) throws AmqpEncodingError;");
+                writer.write(tab(1) + "public " + amqpClass.getTypeMapping().getGeneric("
") + "Encoded<" + amqpClass.getValueMapping().parameterized() + "> decode" + amqpClass.getJavaType()
+ "(Buffer source, int offset) throws AmqpEncodingError;");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> unmarshal" + amqpClass.getJavaType() + "(DataInput in) throws IOException, AmqpEncodingError;");
+                writer.write(tab(1) + "public " + amqpClass.getTypeMapping().getGeneric("
") + "Encoded<" + amqpClass.getValueMapping().parameterized() + "> unmarshal" + amqpClass.getJavaType()
+ "(DataInput in) throws IOException, AmqpEncodingError;");
                 writer.newLine();
             }
         }
@@ -401,7 +401,7 @@ public class Generator {
                 }
                 writer.write(tab(2) + "{");
                 writer.newLine();
-                writer.write(tab(3) + "return " + amqpClass.bufferMapping + ".create(" +
amqpClass.getMarshaller() + ".createEncoded(encoded));");
+                writer.write(tab(3) + "return " + amqpClass.bufferMapping.getClassName()
+ ".create(" + amqpClass.getMarshaller() + ".createEncoded(encoded));");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
@@ -464,7 +464,7 @@ public class Generator {
                     continue;
                 }
                 writer.newLine();
-                writer.write(tab(1) + "public final Encoded<" + amqpClass.getValueMapping()
+ "> encode(" + amqpClass.getJavaType() + " data) throws AmqpEncodingError {");
+                writer.write(tab(1) + "public final " + amqpClass.getTypeMapping().getGeneric("
") + "Encoded<" + amqpClass.getValueMapping().parameterized() + "> encode(" + amqpClass.getTypeMapping().parameterized()+
" data) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return " + amqpClass.getJavaType() + "Marshaller.encode(data);");
                 writer.newLine();
@@ -472,7 +472,7 @@ public class Generator {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> decode" + amqpClass.getJavaType() + "(Buffer source, int offset) throws AmqpEncodingError
{");
+                writer.write(tab(1) + "public final " + amqpClass.getTypeMapping().getGeneric("
") + "Encoded<" + amqpClass.getValueMapping().parameterized() + "> decode" + amqpClass.getTypeMapping().shortName().nonGeneric()
+ "(Buffer source, int offset) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return " + amqpClass.getMarshaller() + ".createEncoded(source,
offset);");
                 writer.newLine();
@@ -480,7 +480,7 @@ public class Generator {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> unmarshal" + amqpClass.getJavaType() + "(DataInput in) throws IOException, AmqpEncodingError
{");
+                writer.write(tab(1) + "public final " + amqpClass.getTypeMapping().getGeneric("
") + "Encoded<" + amqpClass.getValueMapping().parameterized() + "> unmarshal" + amqpClass.getTypeMapping().shortName().nonGeneric()
+ "(DataInput in) throws IOException, AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return " + amqpClass.getMarshaller() + ".createEncoded(in);");
                 writer.newLine();
@@ -604,19 +604,19 @@ public class Generator {
             if (ac.isDescribed()) {
                 writer.newLine();
                 writeJavaComment(writer, 1, "Creates a " + ac.getTypeMapping());
-                writer.write(tab(1) + "public static final " + ac.getTypeMapping() + " create"
+ ac.getTypeMapping() + "() {");
+                writer.write(tab(1) + "public static final " + ac.getTypeMapping().getGeneric("
") + ac.getTypeMapping().parameterized() + " create" + ac.getTypeMapping().getClassName()
+ "() {");
                 writer.newLine();
-                writer.write(tab(2) + "return new " + ac.getBeanMapping() + "();");
+                writer.write(tab(2) + "return new " + ac.getBeanMapping().parameterized()
+ "();");
                 writer.newLine();
                 writer.write(tab(1) + "};");
                 writer.newLine();
             } else {
-                AmqpClass bt = ac.resolveBaseType();
+                AmqpClass bt = ac.getBaseType();
                 writer.newLine();
                 writeJavaComment(writer, 1, "Creates a " + ac.getTypeMapping());
-                writer.write(tab(1) + "public static final " + ac.getTypeMapping() + " create"
+ ac.getTypeMapping() + "(" + bt.getValueMapping() + " val) {");
+                writer.write(tab(1) + "public static final " + ac.getTypeMapping().getGeneric("
") + ac.getTypeMapping().parameterized() + " create" + ac.getTypeMapping().getClassName()
+ "(" + ac.getValueMapping().parameterized() + " val) {");
                 writer.newLine();
-                writer.write(tab(2) + "return new " + ac.getBeanMapping() + "(val);");
+                writer.write(tab(2) + "return new " + ac.getBeanMapping().parameterized()
+ "(val);");
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
@@ -624,9 +624,9 @@ public class Generator {
                 if(bt.getValueMapping().hasPrimitiveType())
                 {
                     writeJavaComment(writer, 1, "Creates a " + ac.getTypeMapping());
-                    writer.write(tab(1) + "public static final " + ac.getTypeMapping() +
" create" + ac.getTypeMapping() + "(" + bt.getValueMapping().getPrimitiveType() + " val) {");
+                    writer.write(tab(1) + "public static final " + ac.getTypeMapping().getGeneric("
") + ac.getTypeMapping().parameterized() + " create" + ac.getTypeMapping().getClassName()
+ "(" + bt.getValueMapping().getPrimitiveType() + " val) {");
                     writer.newLine();
-                    writer.write(tab(2) + "return new " + ac.getBeanMapping() + "(val);");
+                    writer.write(tab(2) + "return new " + ac.getBeanMapping().parameterized()
+ "(val);");
                     writer.newLine();
                     writer.write(tab(1) + "}");
                     writer.newLine();
@@ -635,9 +635,9 @@ public class Generator {
                 if(bt.isMutable())
                 {
                     writeJavaComment(writer, 1, "Creates an empty " + ac.getTypeMapping());
-                    writer.write(tab(1) + "public static final " + ac.getTypeMapping() +
" create" + ac.getTypeMapping() + "() {");
+                    writer.write(tab(1) + "public static final " + ac.getTypeMapping().getGeneric("
") + ac.getTypeMapping().parameterized() + " create" + ac.getTypeMapping().getClassName()
+ "() {");
                     writer.newLine();
-                    writer.write(tab(2) + "return new " + ac.getBeanMapping() + "();");
+                    writer.write(tab(2) + "return new " + ac.getBeanMapping().parameterized()
+ "();");
                     writer.newLine();
                     writer.write(tab(1) + "}");
                     writer.newLine();

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java?rev=946684&r1=946683&r2=946684&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java
(original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java
Thu May 20 16:13:58 2010
@@ -2,6 +2,7 @@ package org.apache.activemq.amqp.generat
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.StringTokenizer;
 
 public class TypeRegistry {
 
@@ -16,26 +17,30 @@ public class TypeRegistry {
         JAVA_TYPE_MAP.put("*", any.typeMapping);
 
         //
-        JAVA_TYPE_MAP.put("boolean", new JavaTypeMapping("boolean", "java.lang.Boolean",
"boolean"));
-        JAVA_TYPE_MAP.put("ubyte", new JavaTypeMapping("ubyte", "java.lang.Short", "short"));
-        JAVA_TYPE_MAP.put("ushort", new JavaTypeMapping("ushort", "java.lang.Integer", "int"));
-        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "java.lang.Long", "long"));
-        JAVA_TYPE_MAP.put("ulong", new JavaTypeMapping("ulong", "java.math.BigInteger"));
-        JAVA_TYPE_MAP.put("byte", new JavaTypeMapping("byte", "java.lang.Byte", "byte"));
-        JAVA_TYPE_MAP.put("short", new JavaTypeMapping("short", "java.lang.Short", "short"));
-        JAVA_TYPE_MAP.put("int", new JavaTypeMapping("int", "java.lang.Integer", "int"));
-        JAVA_TYPE_MAP.put("long", new JavaTypeMapping("long", "java.lang.Long", "long"));
-        JAVA_TYPE_MAP.put("float", new JavaTypeMapping("float", "java.lang.Float", "float"));
-        JAVA_TYPE_MAP.put("double", new JavaTypeMapping("double", "java.lang.Double", "double"));
-        JAVA_TYPE_MAP.put("char", new JavaTypeMapping("char", "java.lang.Integer", "int"));
-        JAVA_TYPE_MAP.put("timestamp", new JavaTypeMapping("timestamp", "java.util.Date"));
-        JAVA_TYPE_MAP.put("uuid", new JavaTypeMapping("uuid", "java.util.UUID"));
-        JAVA_TYPE_MAP.put("binary", new JavaTypeMapping("binary", "org.apache.activemq.util.buffer.Buffer"));
-        JAVA_TYPE_MAP.put("string", new JavaTypeMapping("string", "java.lang.String"));
-        JAVA_TYPE_MAP.put("symbol", new JavaTypeMapping("symbol", "java.lang.String"));
-        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", generator.getPackagePrefix()
+ ".types.IAmqpList", false, "<" + any.getJavaType() + ">"));
-        JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", generator.getPackagePrefix()
+ ".types.IAmqpMap", false, "<" + any.getJavaType() + ", " + any.getJavaType() + ">"));
-        JAVA_TYPE_MAP.put("null", new JavaTypeMapping("null", "java.lang.Object"));
+        JAVA_TYPE_MAP.put("boolean", new JavaTypeMapping("boolean", "java.lang", "Boolean",
"boolean"));
+        JAVA_TYPE_MAP.put("ubyte", new JavaTypeMapping("ubyte", "java.lang", "Short", "short"));
+        JAVA_TYPE_MAP.put("ushort", new JavaTypeMapping("ushort", "java.lang", "Integer",
"int"));
+        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "java.lang", "Long", "long"));
+        JAVA_TYPE_MAP.put("ulong", new JavaTypeMapping("ulong", "java.math", "BigInteger"));
+        JAVA_TYPE_MAP.put("byte", new JavaTypeMapping("byte", "java.lang", "Byte", "byte"));
+        JAVA_TYPE_MAP.put("short", new JavaTypeMapping("short", "java.lang", "Short", "short"));
+        JAVA_TYPE_MAP.put("int", new JavaTypeMapping("int", "java.lang", "Integer", "int"));
+        JAVA_TYPE_MAP.put("long", new JavaTypeMapping("long", "java.lang", "Long", "long"));
+        JAVA_TYPE_MAP.put("float", new JavaTypeMapping("float", "java.lang", "Float", "float"));
+        JAVA_TYPE_MAP.put("double", new JavaTypeMapping("double", "java.lang", "Double",
"double"));
+        JAVA_TYPE_MAP.put("char", new JavaTypeMapping("char", "java.lang", "Integer", "int"));
+        JAVA_TYPE_MAP.put("timestamp", new JavaTypeMapping("timestamp", "java.util", "Date"));
+        JAVA_TYPE_MAP.put("uuid", new JavaTypeMapping("uuid", "java.util", "UUID"));
+        JAVA_TYPE_MAP.put("binary", new JavaTypeMapping("binary", "org.apache.activemq.util.buffer",
"Buffer"));
+        JAVA_TYPE_MAP.put("string", new JavaTypeMapping("string", "java.lang", "String"));
+        JAVA_TYPE_MAP.put("symbol", new JavaTypeMapping("symbol", "java.lang", "String"));
+        JavaTypeMapping list = new JavaTypeMapping("list", generator.getPackagePrefix() +
".types", "IAmqpList");
+        list.setGenerics("E extends " + any.getJavaType());
+        JAVA_TYPE_MAP.put("list", list);
+        JavaTypeMapping map = new JavaTypeMapping("map", generator.getPackagePrefix() + ".types",
"IAmqpMap");
+        map.setGenerics("K extends " + any.getJavaType(), "V extends " + any.getJavaType());
+        JAVA_TYPE_MAP.put("map", map);
+        JAVA_TYPE_MAP.put("null", new JavaTypeMapping("null", "java.lang", "Object"));
 
     }
 
@@ -90,7 +95,7 @@ public class TypeRegistry {
             if (mapping == null) {
                 throw new UnknownTypeException("Primitive Type " + type + " not found");
             }
-            return mapping.javaType;
+            return mapping.className;
         }
 
         return amqpClass.getJavaType();
@@ -107,50 +112,43 @@ public class TypeRegistry {
     public static class JavaTypeMapping {
 
         private String amqpType;
-        private String shortName;
         private String packageName;
         private String fullName;
-        private String javaType;
+        private String className;
         private String primitiveType;
+        private String javaType;
+        private boolean array;
+        private String[] generics;
 
-        boolean array;
-        String generic;
-
-        JavaTypeMapping(String amqpType, String fullName, boolean array, String generic)
{
-            this(amqpType, fullName);
-            this.array = array;
-            setGeneric(generic);
-            if (array) {
-                javaType = javaType + " []";
+        JavaTypeMapping(JavaTypeMapping other) {
+            this.amqpType = other.amqpType;
+            this.packageName = other.packageName;
+            this.fullName = other.fullName;
+            this.className = other.className;
+            this.primitiveType = other.primitiveType;
+            this.array = other.array;
+            this.javaType = other.javaType;
+            if (other.generics != null) {
+                this.generics = new String[other.generics.length];
+                System.arraycopy(other.generics, 0, generics, 0, generics.length);
             }
         }
 
-        JavaTypeMapping(String amqpType, String fullName, String primitiveType) {
-            this.amqpType = amqpType;
-            this.fullName = fullName;
-            this.primitiveType = primitiveType;
-            this.packageName = fullName.substring(0, fullName.lastIndexOf("."));
-            this.shortName = fullName.substring(fullName.lastIndexOf(".") + 1);
-            this.javaType = shortName;
+        public JavaTypeMapping(String amqpType, String fullName) {
+            this(amqpType, fullName.substring(0, fullName.lastIndexOf(".")), fullName.substring(fullName.lastIndexOf(".")
+ 1), null);
         }
 
-        JavaTypeMapping(String amqpType, String fullName) {
-            this.amqpType = amqpType;
-            this.fullName = fullName;
-            this.packageName = fullName.substring(0, fullName.lastIndexOf("."));
-            this.shortName = fullName.substring(fullName.lastIndexOf(".") + 1);
-            this.javaType = shortName;
+        public JavaTypeMapping(String amqpType, String packageName, String className) {
+            this(amqpType, packageName, className, null);
         }
 
-        JavaTypeMapping(String amqpType, String packageName, String className, boolean inner)
{
+        JavaTypeMapping(String amqpType, String packageName, String className, String primitiveType)
{
             this.amqpType = amqpType;
             this.fullName = packageName + "." + className;
             this.packageName = packageName;
+            this.className = className;
             this.javaType = className;
-            if (inner) {
-                this.javaType = className;
-                this.shortName = className.substring(className.lastIndexOf(".") + 1);
-            }
+            this.primitiveType = primitiveType;
         }
 
         public boolean hasPrimitiveType() {
@@ -159,7 +157,7 @@ public class TypeRegistry {
 
         public String getPrimitiveType() {
             if (primitiveType == null) {
-                return javaType;
+                return className;
             }
             return primitiveType;
         }
@@ -173,15 +171,7 @@ public class TypeRegistry {
         }
 
         public String getClassName() {
-            return shortName;
-        }
-
-        public String getShortName() {
-            return shortName;
-        }
-
-        public void setShortName(String shortName) {
-            this.shortName = shortName;
+            return className;
         }
 
         public String getPackageName() {
@@ -201,33 +191,60 @@ public class TypeRegistry {
         }
 
         public String getJavaType() {
-            return javaType;
+            return className;
         }
 
-        private String parameratize(String str, String... generics) {
-            if (generic != null) {
-                if (generics != null && generics.length > 0) {
-                    boolean first = true;
-                    for (String g : generics) {
-                        if (!first) {
-                            str += ", " + g;
-                        } else {
-                            first = false;
-                            str += "<" + g;
-                        }
-                    }
-                    return str + ">";
+        public JavaTypeMapping shortName() {
+            if (javaType.indexOf(".") > 0) {
+                JavaTypeMapping rc = new JavaTypeMapping(this);
+                rc.javaType = javaType.substring(javaType.indexOf(".") + 1);
+                return rc;
+            } else {
+                return this;
+            }
+        }
 
-                } else {
-                    return javaType + generic;
-                }
+        public JavaTypeMapping nonGeneric() {
+            if (generics != null) {
+                JavaTypeMapping rc = new JavaTypeMapping(this);
+                rc.javaType = javaType.substring(javaType.indexOf(".") + 1);
+                rc.generics = null;
+                return rc;
+            } else {
+                return this;
+            }
+        }
 
+        public JavaTypeMapping parameterized() {
+            if (generics != null) {
+                JavaTypeMapping rc = new JavaTypeMapping(this);
+                for (int i = 0; i < generics.length; i++) {
+                    if (rc.generics[i].indexOf("extends") > 0) {
+                        rc.generics[i] = rc.generics[i].substring(0, rc.generics[i].indexOf("extends")).trim();
+                    }
+                }
+                return rc;
+            } else {
+                return this;
+            }
+        }
+        
+        public JavaTypeMapping wildcard() {
+            if (generics != null) {
+                JavaTypeMapping rc = new JavaTypeMapping(this);
+                for (int i = 0; i < generics.length; i++) {
+                    rc.generics[i] = "?";
+                }
+                return rc;
+            } else {
+                return this;
             }
-            return str;
         }
 
-        public void setJavaType(String javaType) {
-            this.javaType = javaType;
+        public JavaTypeMapping parameterized(String... generics) {
+            JavaTypeMapping rc = new JavaTypeMapping(this);
+            rc.generics = generics;
+            return rc;
         }
 
         public boolean isArray() {
@@ -238,17 +255,20 @@ public class TypeRegistry {
             this.array = array;
         }
 
-        public String getGeneric() {
-            return generic;
+        public boolean isGeneric() {
+            return generics != null;
         }
 
-        public void setGeneric(String generic) {
-            this.generic = generic;
-            javaType = shortName + generic;
+        public String[] getGenerics() {
+            return generics;
+        }
+        
+        public void setGenerics(String... generics) {
+            this.generics = generics;
         }
 
         public String getFullVersionMarshallerName(Generator generator) {
-            return generator.getMarshallerPackage() + "." + shortName + "Marshaller";
+            return generator.getMarshallerPackage() + "." + className + "Marshaller";
         }
 
         public String getImport() {
@@ -256,14 +276,32 @@ public class TypeRegistry {
         }
 
         public String toString() {
-            return getJavaType();
+            return javaType + getGeneric("");
+        }
+
+        public String getGeneric(String suffix) {
+            if (generics != null && generics.length > 0) {
+                String rc = "<";
+                boolean first = true;
+                for (String g : generics) {
+                    if (!first) {
+                        rc += ", ";
+                    } else {
+                        first = false;
+                    }
+                    rc += g;
+                }
+                return rc + ">" + (suffix != null ? suffix : "");
+            }
+            return "";
         }
     }
 
     public static class AmqpType extends AmqpClass {
 
         AmqpType(String amqpName, String fullName) {
-            super.typeMapping = new JavaTypeMapping(amqpName, fullName, false, "<?, ?>");
+            super.typeMapping = new JavaTypeMapping(amqpName, fullName);
+            typeMapping.setGenerics("?", "?");
             super.name = amqpName;
             super.setPrimitive(true);
             super.handcoded = true;



Mime
View raw message