activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r908852 [3/3] - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/ handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/ handcoded/o...
Date Thu, 11 Feb 2010 06:46:24 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=908852&r1=908851&r2=908852&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 Feb 11 06:46:23 2010
@@ -236,7 +236,10 @@
         writer.newLine();
         writer.newLine();
 
-        writeMarshallerImports(writer, false, outputPackage);
+        TreeSet<String> imports = new TreeSet<String>();
+        imports.add(getPackagePrefix() + ".marshaller.AmqpVersion");
+        imports.add(getPackagePrefix() + ".marshaller.Encoded");
+        writeMarshallerImports(writer, false, imports, outputPackage);
 
         writer.newLine();
         writer.write("public interface AmqpMarshaller {");
@@ -248,15 +251,11 @@
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(1) + "public <T> Encoded<T> encode(AmqpType<T>
data) throws AmqpEncodingError;");
-        writer.newLine();
-        
-        writer.newLine();
-        writer.write(tab(1) + "public AmqpType<?> decodeType(Buffer source) throws
AmqpEncodingError;");
+        writer.write(tab(1) + "public " + TypeRegistry.any().typeMapping + " decodeType(Buffer
source) throws AmqpEncodingError;");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(1) + "public AmqpType<?> unmarshalType(DataInput in) throws
IOException, AmqpEncodingError;");
+        writer.write(tab(1) + "public " + TypeRegistry.any().typeMapping + " unmarshalType(DataInput
in) throws IOException, AmqpEncodingError;");
         writer.newLine();
 
         // Generate Handler methods:
@@ -272,7 +271,11 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public " + amqpClass.getJavaType() + " unmarshal"
+ capFirst(amqpClass.getJavaType()) + "(DataInput in) throws IOException, AmqpEncodingError;");
+                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> 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.newLine();
             }
         }
@@ -293,7 +296,11 @@
         writer.newLine();
         writer.newLine();
 
-        writeMarshallerImports(writer, false, getMarshallerPackage());
+        TreeSet<String> imports = new TreeSet<String>();
+        imports.add(getMarshallerPackage() + ".Encoder.*");
+        imports.add(getPackagePrefix() + ".marshaller.AmqpVersion");
+        imports.add(getPackagePrefix() + ".marshaller.Encoded");
+        writeMarshallerImports(writer, false, imports, getMarshallerPackage());
 
         writer.newLine();
         writer.write("public class AmqpMarshaller implements " + getPackagePrefix() + ".marshaller.AmqpMarshaller
{");
@@ -304,10 +311,6 @@
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(1) + "private static final Encoder ENCODER = Encoder.SINGLETON;");
-        writer.newLine();
-
-        writer.newLine();
         writer.write(tab(1) + "public static final AmqpVersion VERSION = new AmqpVersion((short)"
+ DEFINITIONS.get("MAJOR").getValue() + ", (short)" + DEFINITIONS.get("MINOR").getValue()
                 + ", (short)" + DEFINITIONS.get("REVISION").getValue() + ");");
         writer.newLine();
@@ -348,33 +351,32 @@
         writer.newLine();
 
         // Generate Handler methods:
-
         writer.newLine();
-        writer.write(tab(1) + "public final <T> Encoded<T> encode(AmqpType<T>
data) throws AmqpEncodingError {");
+        writer.write(tab(1) + "public final " + TypeRegistry.any().typeMapping + " unmarshalType(DataInput
in) throws IOException, AmqpEncodingError {");
         writer.newLine();
-        writer.write(tab(2) + "throw new UnsupportedOperationException();");
+        writer.write(tab(2) + "return Encoder.unmarshalType(in);");
         writer.newLine();
         writer.write(tab(1) + "}");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(1) + "public final AmqpType<?> unmarshalType(DataInput in)
throws IOException, AmqpEncodingError {");
+        writer.write(tab(1) + "public final " + TypeRegistry.any().typeMapping + " decodeType(Buffer
source) throws AmqpEncodingError {");
         writer.newLine();
-        writer.write(tab(2) + "return ENCODER.unmarshalType(in);");
+        writer.write(tab(2) + "return Encoder.decode(source);");
         writer.newLine();
         writer.write(tab(1) + "}");
         writer.newLine();
-        
+
         writer.newLine();
-        writer.write(tab(1) + "public final AmqpType<?> decodeType(Buffer source) throws
AmqpEncodingError {");
+        writer.write(tab(1) + "final " + TypeRegistry.any().typeMapping + " decodeType(EncodedBuffer
encoded) throws AmqpEncodingError {");
         writer.newLine();
-        writer.write(tab(2) + "return ENCODER.decode(source);");
+        writer.write(tab(2) + "if(encoded.isDescribed()) {");
         writer.newLine();
-        writer.write(tab(1) + "}");
+        writer.write(tab(2) + "return decodeType(encoded.asDescribed());");
         writer.newLine();
-
+        writer.write(tab(2) + "}");
         writer.newLine();
-        writer.write(tab(1) + "final AmqpType<?> decodeType(EncodedBuffer encoded)
throws AmqpEncodingError {");
+
         writer.newLine();
         writer.write(tab(2) + "switch(encoded.getEncodingFormatCode()) {");
         writer.newLine();
@@ -395,7 +397,7 @@
                 }
                 writer.write(tab(2) + "{");
                 writer.newLine();
-                writer.write(tab(3) + "return " + amqpClass.getMarshaller() + ".decodeType(encoded);");
+                writer.write(tab(3) + "return " + amqpClass.bufferMapping + ".create(" +
amqpClass.getMarshaller() + ".createEncoded(encoded));");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
@@ -415,9 +417,9 @@
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(1) + "final AmqpType<?> decodeType(DescribedBuffer buffer)
throws AmqpEncodingError {");
+        writer.write(tab(1) + "final " + TypeRegistry.any().typeMapping + " decodeType(DescribedBuffer
buffer) throws AmqpEncodingError {");
         writer.newLine();
-        writer.write(tab(2) + "AmqpType<?> descriptor = decodeType(buffer.getDescriptor());");
+        writer.write(tab(2) + TypeRegistry.any().typeMapping + " descriptor = decodeType(buffer.getDescriptorBuffer());");
         writer.newLine();
         writer.write(tab(2) + "//TODO might want to revisit whether or not the cast is needed
here:");
         writer.newLine();
@@ -425,7 +427,7 @@
         writer.newLine();
         writer.write(tab(2) + "if(descriptor instanceof AmqpUlong) {");
         writer.newLine();
-        writer.write(tab(3) + "dtm = DESCRIBED_NUMERIC_TYPES.get(((AmqpUlong)descriptor).getValue());");
+        writer.write(tab(3) + "dtm = DESCRIBED_NUMERIC_TYPES.get(((AmqpUlong)descriptor).getValue().longValue());");
         writer.newLine();
         writer.write(tab(2) + "}");
         writer.newLine();
@@ -466,9 +468,17 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public final " + amqpClass.getJavaType() + " unmarshal"
+ capFirst(amqpClass.getJavaType()) + "(DataInput in) throws IOException, AmqpEncodingError
{");
+                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> decode" + amqpClass.getJavaType() + "(Buffer source, int offset) throws AmqpEncodingError
{");
+                writer.newLine();
+                writer.write(tab(2) + "return " + amqpClass.getMarshaller() + ".createEncoded(source,
offset);");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> unmarshal" + amqpClass.getJavaType() + "(DataInput in) throws IOException, AmqpEncodingError
{");
                 writer.newLine();
-                writer.write(tab(2) + "return " + amqpClass.getJavaType() + "Marshaller.unmarshalType(new
" + amqpClass.getJavaType() + "(), in);");
+                writer.write(tab(2) + "return " + amqpClass.getMarshaller() + ".createEncoded(in);");
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
@@ -493,9 +503,9 @@
         writer.newLine();
         writer.newLine();
 
-        writeMarshallerImports(writer, true, getMarshallerPackage(), getPackagePrefix() +
".types");
-
-        writer.write("import org.apache.activemq.util.buffer.Buffer;");
+        TreeSet<String> imports = new TreeSet<String>();
+        imports.add("java.io.DataOutput");
+        writeMarshallerImports(writer, true, imports, getMarshallerPackage(), getPackagePrefix()
+ ".types");
         writer.newLine();
 
         writer.newLine();
@@ -561,8 +571,7 @@
         writer.close();
     }
 
-    private void writeMarshallerImports(BufferedWriter writer, boolean primitiveOnly, String...
packageFilters) throws IOException, UnknownTypeException {
-        TreeSet<String> imports = new TreeSet<String>();
+    private void writeMarshallerImports(BufferedWriter writer, boolean primitiveOnly, TreeSet<String>
imports, String... packageFilters) throws IOException, UnknownTypeException {
         HashSet<String> filters = new HashSet<String>();
         filters.add("java.lang");
         for (String filter : packageFilters) {
@@ -570,16 +579,11 @@
         }
 
         imports.add("java.io.DataInput");
-        imports.add("java.io.DataOutput");
         imports.add("java.io.IOException");
-        imports.add(getPackagePrefix() + ".marshaller.AmqpVersion");
-        imports.add(getPackagePrefix() + ".marshaller.Encoded");
-        imports.add(getPackagePrefix() + ".marshaller.Encoding");
         imports.add(getPackagePrefix() + ".marshaller.AmqpEncodingError");
-        imports.add(getMarshallerPackage() + ".Encoder.*");
 
         for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
-            if (primitiveOnly && !amqpClass.isPrimitive()) {
+            if (primitiveOnly && (!amqpClass.isPrimitive() || amqpClass.isList()
|| amqpClass.isMap())) {
                 continue;
             }
             if (amqpClass.needsMarshaller()) {

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=908852&r1=908851&r2=908852&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 Feb 11 06:46:23 2010
@@ -26,13 +26,35 @@
         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", "java.util.List", false, "<AmqpType<?>>"));
-        JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", "java.util.HashMap", false, "<AmqpType<?>,
AmqpType<?>>"));
+        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", "java.util.List", false, "<AmqpType<?,?>>"));
+        JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", "java.util.HashMap", false, "<AmqpType<?,?>,
AmqpType<?,?>>"));
         JAVA_TYPE_MAP.put("null", new JavaTypeMapping("null", "java.lang.Object"));
 
     }
 
     static final void init(Generator generator) {
+        
+        JAVA_TYPE_MAP.put("boolean", new JavaTypeMapping("boolean", "java.lang.Boolean"));
+        JAVA_TYPE_MAP.put("ubyte", new JavaTypeMapping("ubyte", "java.lang.Short"));
+        JAVA_TYPE_MAP.put("ushort", new JavaTypeMapping("ushort", "java.lang.Integer"));
+        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "java.lang.Long"));
+        JAVA_TYPE_MAP.put("ulong", new JavaTypeMapping("ulong", "java.math.BigInteger"));
+        JAVA_TYPE_MAP.put("byte", new JavaTypeMapping("byte", "java.lang.Byte"));
+        JAVA_TYPE_MAP.put("short", new JavaTypeMapping("short", "java.lang.Short"));
+        JAVA_TYPE_MAP.put("int", new JavaTypeMapping("int", "java.lang.Integer"));
+        JAVA_TYPE_MAP.put("long", new JavaTypeMapping("long", "java.lang.Long"));
+        JAVA_TYPE_MAP.put("float", new JavaTypeMapping("float", "java.lang.Float"));
+        JAVA_TYPE_MAP.put("double", new JavaTypeMapping("double", "java.lang.Double"));
+        JAVA_TYPE_MAP.put("char", new JavaTypeMapping("char", "java.lang.Integer"));
+        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"));
+        JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", "java.util.HashMap", false, "<AmqpType<?,?>,
AmqpType<?,?>>"));
+        JAVA_TYPE_MAP.put("null", new JavaTypeMapping("null", "java.lang.Object"));
+        
         // Add in the wildcard type:
         AmqpClass any = new AmqpType("*", generator.getPackagePrefix() + ".types.AmqpType");
         GENERATED_TYPE_MAP.put("*", any);
@@ -54,6 +76,11 @@
         return mapping;
     }
 
+    public static AmqpClass any()
+    {
+        return GENERATED_TYPE_MAP.get("*");
+    }
+    
     public static AmqpClass resolveAmqpClass(AmqpField amqpField) throws UnknownTypeException
{
         return resolveAmqpClass(amqpField.getType());
     }
@@ -205,11 +232,7 @@
         }
 
         public String getImport() {
-            if  (inner) {
-                return fullName.substring(0, fullName.lastIndexOf("."));
-            } else {
-                return fullName;
-            }
+            return fullName;
         }
 
         public String toString() {
@@ -220,7 +243,7 @@
     public static class AmqpType extends AmqpClass {
 
         AmqpType(String amqpName, String fullName) {
-            super.typeMapping = new JavaTypeMapping(amqpName, fullName, false, "<?>");
+            super.typeMapping = new JavaTypeMapping(amqpName, fullName, false, "<?, ?>");
             super.name = amqpName;
             super.setPrimitive(true);
             super.handcoded = true;



Mime
View raw message