activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r907314 [4/4] - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/org/apache/activemq/amqp/generator/handcoded/ handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/ handcoded/org/apache/activemq...
Date Sat, 06 Feb 2010 21:46:42 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=907314&r1=907313&r2=907314&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
Sat Feb  6 21:46:41 2010
@@ -1,6 +1,12 @@
 package org.apache.activemq.amqp.generator;
 
-import static org.apache.activemq.amqp.generator.Utils.*;
+import static org.apache.activemq.amqp.generator.Utils.capFirst;
+import static org.apache.activemq.amqp.generator.Utils.javaPackageOf;
+import static org.apache.activemq.amqp.generator.Utils.tab;
+import static org.apache.activemq.amqp.generator.Utils.toJavaConstant;
+import static org.apache.activemq.amqp.generator.Utils.toJavaName;
+import static org.apache.activemq.amqp.generator.Utils.writeJavaComment;
+import static org.apache.activemq.amqp.generator.Utils.writeJavaCopyWrite;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -9,8 +15,9 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
 import java.util.StringTokenizer;
+import java.util.TreeSet;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
@@ -18,6 +25,7 @@
 import javax.xml.transform.Source;
 import javax.xml.transform.sax.SAXSource;
 
+import org.apache.activemq.amqp.generator.TypeRegistry.JavaTypeMapping;
 import org.apache.activemq.amqp.generator.jaxb.schema.Amqp;
 import org.apache.activemq.amqp.generator.jaxb.schema.Definition;
 import org.apache.activemq.amqp.generator.jaxb.schema.Section;
@@ -30,11 +38,11 @@
     private String[] inputFiles;
     private String outputDirectory;
     private String sourceDirectory;
-    private String packagePrefix;
+    private String packagePrefix = "org.apache.activemq.amqp.protocol";
 
     public static final HashSet<String> CONTROLS = new HashSet<String>();
     public static final HashSet<String> COMMANDS = new HashSet<String>();
-    public static final LinkedList<AmqpDefinition> DEFINITIONS = new LinkedList<AmqpDefinition>();
+    public static final LinkedHashMap<String, AmqpDefinition> DEFINITIONS = new LinkedHashMap<String,
AmqpDefinition>();
 
     public String[] getInputFile() {
         return inputFiles;
@@ -113,7 +121,8 @@
                         if (docOrDefinitionOrType instanceof Type) {
                             generateClassFromType(amqp, section, (Type) docOrDefinitionOrType);
                         } else if (docOrDefinitionOrType instanceof Definition) {
-                            DEFINITIONS.add(new AmqpDefinition((Definition) docOrDefinitionOrType));
+                            Definition def = (Definition) docOrDefinitionOrType;
+                            DEFINITIONS.put(def.getName(), new AmqpDefinition(def));
                         }
                     }
                 }
@@ -150,7 +159,10 @@
             amqpClass.generate(this);
         }
 
+        generatePrimitiveEncoderInterface();
         generateCommandHandler();
+        generateMarshallerInterface();
+        generateMarshaller();
         writeDefinitions();
     }
 
@@ -201,7 +213,7 @@
         writer.write("public interface Definitions {");
         writer.newLine();
         // Generate Handler methods:
-        for (AmqpDefinition def : DEFINITIONS) {
+        for (AmqpDefinition def : DEFINITIONS.values()) {
             writer.newLine();
             def.writeJavaDoc(writer, 1);
             writer.write(tab(1) + "public static final String " + capFirst(toJavaConstant(def.getName()))
+ " = \"" + def.getValue() + "\";");
@@ -213,6 +225,382 @@
         writer.close();
     }
 
+    private void generateMarshallerInterface() throws IOException, UnknownTypeException {
+        String outputPackage = new String(packagePrefix + ".marshaller");
+        File out = new File(outputDirectory + File.separator + outputPackage.replace(".",
File.separator) + File.separator + "AmqpMarshaller.java");
+
+        BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+        writeJavaCopyWrite(writer);
+        writer.write("package " + outputPackage + ";");
+        writer.newLine();
+        writer.newLine();
+
+        writeMarshallerImports(writer, false, outputPackage);
+
+        writer.newLine();
+        writer.write("public interface AmqpMarshaller {");
+        writer.newLine();
+
+        writer.newLine();
+        writeJavaComment(writer, 1, "@return the protocol version of the marshaller");
+        writer.write(tab(1) + "public AmqpVersion getVersion();");
+        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.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "public AmqpType<?> unmarshalType(DataInput in) throws
IOException, AmqpEncodingError;");
+        writer.newLine();
+
+        // Generate Handler methods:
+        for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+            if (amqpClass.needsMarshaller()) {
+
+                if (amqpClass.name.equals("*")) {
+                    continue;
+                }
+
+                writer.newLine();
+                writer.write(tab(1) + "public Encoded<" + amqpClass.getValueMapping()
+ "> encode(" + amqpClass.getJavaType() + " data) throws AmqpEncodingError;");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public " + amqpClass.getJavaType() + " unmarshal"
+ capFirst(amqpClass.getJavaType()) + "(DataInput in) throws IOException, AmqpEncodingError;");
+                writer.newLine();
+            }
+        }
+
+        writer.write("}");
+        writer.flush();
+        writer.close();
+
+    }
+
+    private void generateMarshaller() throws IOException, UnknownTypeException {
+        File out = new File(outputDirectory + File.separator + getMarshallerPackage().replace(".",
File.separator) + File.separator + "AmqpMarshaller.java");
+
+        BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+        writeJavaCopyWrite(writer);
+        writer.write("package " + getMarshallerPackage() + ";");
+        writer.newLine();
+        writer.newLine();
+
+        writeMarshallerImports(writer, false, getMarshallerPackage());
+
+        writer.newLine();
+        writer.write("public class AmqpMarshaller implements " + getPackagePrefix() + ".marshaller.AmqpMarshaller
{");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "static final AmqpMarshaller SINGLETON = new AmqpMarshaller();");
+        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();
+
+        writer.newLine();
+        writer.write(tab(1) + "public static final AmqpMarshaller getMarshaller() {");
+        writer.newLine();
+        writer.write(tab(2) + "return SINGLETON;");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "private static final HashMap<Long, DescribedTypeMarshaller<?>>
DESCRIBED_NUMERIC_TYPES = new HashMap<Long, DescribedTypeMarshaller<?>>();");
+        writer.newLine();
+        writer.write(tab(1) + "private static final HashMap<String, DescribedTypeMarshaller<?>>
DESCRIBED_SYMBOLIC_TYPES = new HashMap<String, DescribedTypeMarshaller<?>>();");
+        writer.newLine();
+        writer.write(tab(1) + "static {");
+        writer.newLine();
+
+        for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+            if (amqpClass.isDescribed()) {
+                writer.write(tab(2) + "DESCRIBED_NUMERIC_TYPES.put(" + amqpClass.getTypeMapping()
+ "Marshaller.NUMERIC_ID, " + amqpClass.getTypeMapping() + "Marshaller.SINGLETON);");
+                writer.newLine();
+                writer.write(tab(2) + "DESCRIBED_SYMBOLIC_TYPES.put(" + amqpClass.getTypeMapping()
+ "Marshaller.SYMBOLIC_ID, " + amqpClass.getTypeMapping() + "Marshaller.SINGLETON);");
+                writer.newLine();
+            }
+        }
+        writer.write(tab(1) + "}");
+        writer.newLine();
+        writer.newLine();
+        writeJavaComment(writer, 1, "@return the protocol version of the marshaller");
+        writer.write(tab(1) + "public final AmqpVersion getVersion() {");
+        writer.newLine();
+        writer.write(tab(2) + "return VERSION;");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
+        // Generate Handler methods:
+
+        writer.newLine();
+        writer.write(tab(1) + "public final <T> Encoded<T> encode(AmqpType<T>
data) throws AmqpEncodingError {");
+        writer.newLine();
+        writer.write(tab(2) + "throw new UnsupportedOperationException();");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "public final AmqpType<?> unmarshalType(DataInput in)
throws IOException, AmqpEncodingError {");
+        writer.newLine();
+        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<?> decodeType(Buffer source) throws
AmqpEncodingError {");
+        writer.newLine();
+        writer.write(tab(2) + "return ENCODER.decode(source);");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "final AmqpType<?> decodeType(EncodedBuffer encoded)
throws AmqpEncodingError {");
+        writer.newLine();
+        writer.write(tab(2) + "switch(encoded.getEncodingFormatCode()) {");
+        writer.newLine();
+        for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+            if (amqpClass.isPrimitive() && !amqpClass.getName().equals("*")) {
+
+                writer.write(tab(2) + "//" + amqpClass.getTypeMapping() + " Encoded: ");
+                writer.newLine();
+                if (!amqpClass.hasMultipleEncodings() && !amqpClass.hasNonFixedEncoding())
{
+                    writer.write(tab(2) + "case " + amqpClass.getTypeMapping() + "Marshaller.FORMAT_CODE:
");
+                    writer.newLine();
+                } else {
+                    for (AmqpEncoding encoding : amqpClass.encodings) {
+
+                        writer.write(tab(2) + "case (byte) " + encoding.getCode() + ":");
+                        writer.newLine();
+                    }
+                }
+                writer.write(tab(2) + "{");
+                writer.newLine();
+                writer.write(tab(3) + "return " + amqpClass.getMarshaller() + ".decodeType(encoded);");
+                writer.newLine();
+                writer.write(tab(2) + "}");
+                writer.newLine();
+            }
+        }
+        writer.write(tab(2) + "default: {");
+        writer.newLine();
+        writer.write(tab(3) + "//TODO: Create an unknown or any type");
+        writer.newLine();
+        writer.write(tab(3) + "throw new AmqpEncodingError(\"Unrecognized format code:\"
+ encoded.getEncodingFormatCode());");
+        writer.newLine();
+        writer.write(tab(2) + "}");
+        writer.newLine();
+        writer.write(tab(2) + "}");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "final AmqpType<?> decodeType(DescribedBuffer buffer)
throws AmqpEncodingError {");
+        writer.newLine();
+        writer.write(tab(2) + "AmqpType<?> descriptor = decodeType(buffer.getDescriptor());");
+        writer.newLine();
+        writer.write(tab(2) + "//TODO might want to revisit whether or not the cast is needed
here:");
+        writer.newLine();
+        writer.write(tab(2) + "DescribedTypeMarshaller<?> dtm = null;");
+        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.newLine();
+        writer.write(tab(2) + "}");
+        writer.newLine();
+        writer.write(tab(2) + "else if(descriptor instanceof AmqpSymbol) {");
+        writer.newLine();
+        writer.write(tab(3) + "dtm = DESCRIBED_SYMBOLIC_TYPES.get(((AmqpSymbol)descriptor).getValue());");
+        writer.newLine();
+        writer.write(tab(2) + "}");
+        writer.newLine();
+        writer.newLine();
+        writer.write(tab(2) + "if(dtm != null) {");
+        writer.newLine();
+        writer.write(tab(3) + "return dtm.decodeDescribedType(descriptor, buffer);");
+        writer.newLine();
+        writer.write(tab(2) + "}");
+        writer.newLine();
+        writer.newLine();
+        writer.write(tab(2) + "//TODO spec actuall indicates that we should be able to pass
along unknown types. so we should just create");
+        writer.newLine();
+        writer.write(tab(2) + "//an placeholder type");
+        writer.newLine();
+        writer.write(tab(2) + "throw new AmqpEncodingError(\"Unrecognized described type:\"
+ descriptor);");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+
+        for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+            if (amqpClass.needsMarshaller()) {
+
+                if (amqpClass.name.equals("*")) {
+                    continue;
+                }
+                writer.newLine();
+                writer.write(tab(1) + "public final Encoded<" + amqpClass.getValueMapping()
+ "> encode(" + amqpClass.getJavaType() + " data) throws AmqpEncodingError {");
+                writer.newLine();
+                writer.write(tab(2) + "return " + amqpClass.getJavaType() + "Marshaller.encode(data);");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final " + amqpClass.getJavaType() + " unmarshal"
+ capFirst(amqpClass.getJavaType()) + "(DataInput in) throws IOException, AmqpEncodingError
{");
+                writer.newLine();
+                writer.write(tab(2) + "return " + amqpClass.getJavaType() + "Marshaller.unmarshalType(new
" + amqpClass.getJavaType() + "(), in);");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+            }
+        }
+
+        writer.write("}");
+        writer.flush();
+        writer.close();
+
+    }
+
+    private void generatePrimitiveEncoderInterface() throws IOException, UnknownTypeException
{
+
+        String outputPackage = getMarshallerPackage();
+        File out = new File(outputDirectory + File.separator + outputPackage.replace(".",
File.separator) + File.separator + "PrimitiveEncoder.java");
+
+        BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+        writeJavaCopyWrite(writer);
+        writer.write("package " + outputPackage + ";");
+        writer.newLine();
+        writer.newLine();
+
+        writeMarshallerImports(writer, true, getMarshallerPackage(), getPackagePrefix() +
".types");
+
+        writer.write("import org.apache.activemq.util.buffer.Buffer;");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write("public interface PrimitiveEncoder {");
+        writer.newLine();
+
+        HashSet<String> filters = new HashSet<String>();
+        filters.add("*");
+        filters.add("list");
+        filters.add("map");
+
+        // Write out encoding serializers:
+        classLoop: for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+            if (!amqpClass.isPrimitive() || filters.contains(amqpClass.getName())) {
+                continue;
+            }
+
+            String javaType = amqpClass.getValueMapping().getJavaType();
+
+            if (amqpClass.encodings != null) {
+
+                if (amqpClass.hasNonZeroEncoding()) {
+                    for (AmqpEncoding encoding : amqpClass.encodings) {
+                        String encName = capFirst(toJavaName(amqpClass.name));
+                        if (amqpClass.hasMultipleEncodings()) {
+                            encName += capFirst(toJavaName(encoding.getName()));
+                        }
+
+                        writer.newLine();
+                        writeJavaComment(writer, 1, "Writes a " + javaType + " encoded as
" + encoding.getLabel());
+                        writer.write(tab(1) + "public void write" + encName + "(" + javaType
+ " val, DataOutput buf) throws IOException, AmqpEncodingError;");
+                        writer.newLine();
+
+                        writeJavaComment(writer, 1, "Encodes a " + javaType + " as " + encoding.getLabel(),
"", "The encoded data should be written into the supplied buffer at the given offset.");
+                        writer.write(tab(1) + "public void encode" + encName + "(" + javaType
+ " val, Buffer buf, int offset) throws AmqpEncodingError;");
+                        writer.newLine();
+
+                        writer.newLine();
+                        writeJavaComment(writer, 1, "Reads a " + javaType + " encoded as
" + encoding.getLabel());
+                        if (amqpClass.hasNonFixedEncoding()) {
+                            writer.write(tab(1) + "public " + javaType + " read" + encName
+ "(int size, DataInput dis) throws IOException, AmqpEncodingError;");
+                        } else {
+                            writer.write(tab(1) + "public " + javaType + " read" + encName
+ "(DataInput dis) throws IOException, AmqpEncodingError;");
+                        }
+                        writer.newLine();
+
+                        writer.newLine();
+                        writeJavaComment(writer, 1, "Decodes a " + javaType + " encoded as
" + encoding.getLabel());
+                        if (amqpClass.hasNonFixedEncoding()) {
+                            writer.write(tab(1) + "public " + javaType + " decode" + encName
+ "(Buffer encoded, int offset, int length) throws AmqpEncodingError;");
+                        } else {
+                            writer.write(tab(1) + "public " + javaType + " decode" + encName
+ "(Buffer encoded, int offset) throws AmqpEncodingError;");
+                        }
+                        writer.newLine();
+                    }
+                }
+            }
+        }
+
+        writer.write("}");
+        writer.newLine();
+        writer.flush();
+        writer.close();
+    }
+
+    private void writeMarshallerImports(BufferedWriter writer, boolean primitiveOnly, String...
packageFilters) throws IOException, UnknownTypeException {
+        TreeSet<String> imports = new TreeSet<String>();
+        HashSet<String> filters = new HashSet<String>();
+        filters.add("java.lang");
+        for (String filter : packageFilters) {
+            filters.add(filter);
+        }
+
+        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()) {
+                continue;
+            }
+            if (amqpClass.needsMarshaller()) {
+                imports.add(amqpClass.getTypeMapping().getImport());
+                JavaTypeMapping vMap = amqpClass.getValueMapping();
+                if (vMap != null && vMap.getImport() != null) {
+                    imports.add(vMap.getImport());
+                }
+            }
+        }
+
+        for (String i : imports) {
+            if (!filters.contains(javaPackageOf(i))) {
+                writer.write("import " + i + ";");
+                writer.newLine();
+            }
+
+        }
+
+    }
+
     private void generateClassFromType(Amqp source, Section section, Type type) throws Exception
{
         AmqpClass amqpClass = new AmqpClass();
         amqpClass.parseFromType(this, source, section, type);
@@ -220,4 +608,12 @@
         System.out.println("Found: " + amqpClass);
     }
 
+    public String getVersionPackageName() {
+        return "v" + DEFINITIONS.get("MAJOR").getValue() + "_" + DEFINITIONS.get("MINOR").getValue()
+ "_" + DEFINITIONS.get("REVISION").getValue();
+    }
+
+    public String getMarshallerPackage() {
+        return packagePrefix + ".marshaller." + getVersionPackageName();
+    }
+
 }

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java?rev=907314&r1=907313&r2=907314&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java
(original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java
Sat Feb  6 21:46:41 2010
@@ -7,7 +7,7 @@
         Generator gen = new Generator();
         gen.setInputFiles("C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/transport.xml",
"C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/messaging.xml",
                 "C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/types.xml",
"C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/security.xml");
-        gen.setPackagePrefix("org.apache.activemq.amqp.protocol.v1pr2");
+        
         gen.setOutputDirectory("C:/dev/fuse/amq6.0/activemq-amqp/src/main/java");
         gen.setSourceDirectory("C:/dev/fuse/amq6.0/activemq-amqp-generator/src/handcoded");
         try {

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=907314&r1=907313&r2=907314&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
Sat Feb  6 21:46:41 2010
@@ -9,25 +9,25 @@
     private static final HashMap<String, AmqpClass> GENERATED_TYPE_MAP = new HashMap<String,
AmqpClass>();
 
     static {
-        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.int"));
-        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "java.lang.long"));
+        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.int"));
-        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.int"));
+        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", "java.lang.byte", true,
null));
+        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"));
 
     }
@@ -102,13 +102,14 @@
 
     public static class JavaTypeMapping {
 
-        String amqpType;
-        String shortName;
-        String packageName;
-        String fullName;
-        String javaType;
+        private String amqpType;
+        private String shortName;
+        private String packageName;
+        private String fullName;
+        private String javaType;
 
         boolean array;
+        private boolean inner;
         String generic;
 
         JavaTypeMapping(String amqpType, String fullName, boolean array, String generic)
{
@@ -131,6 +132,18 @@
             this.javaType = shortName;
         }
 
+        JavaTypeMapping(String amqpType, String packageName, String className, boolean inner)
{
+            this.amqpType = amqpType;
+            this.fullName = packageName + "." + className;
+            this.packageName = packageName;
+            this.inner = inner;
+            this.javaType = className;
+            if (inner) {
+                this.javaType = className;
+                this.shortName = className.substring(className.lastIndexOf(".") + 1);
+            }
+        }
+
         public String getAmqpType() {
             return amqpType;
         }
@@ -187,22 +200,31 @@
             this.generic = generic;
         }
 
+        public String getFullVersionMarshallerName(Generator generator) {
+            return generator.getMarshallerPackage() + "." + shortName + "Marshaller";
+        }
+
         public String getImport() {
-            if (packageName.startsWith("java.lang")) {
-                return null;
+            if  (inner) {
+                return fullName.substring(0, fullName.lastIndexOf("."));
             } else {
                 return fullName;
             }
         }
+
+        public String toString() {
+            return javaType;
+        }
     }
 
     public static class AmqpType extends AmqpClass {
 
         AmqpType(String amqpName, String fullName) {
-            super.typeMapping = new JavaTypeMapping(amqpName, fullName);
+            super.typeMapping = new JavaTypeMapping(amqpName, fullName, false, "<?>");
             super.name = amqpName;
             super.setPrimitive(true);
             super.handcoded = true;
+            super.valueMapping = typeMapping;
         }
     }
 

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Utils.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Utils.java?rev=907314&r1=907313&r2=907314&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Utils.java
(original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Utils.java
Sat Feb  6 21:46:41 2010
@@ -129,6 +129,11 @@
         return rc.toArray(new String[] {});
     }
 
+    public static final String javaPackageOf(String fullName)
+    {
+        return fullName.substring(0, fullName.lastIndexOf("."));
+    }
+    
     public static final List<File> findFiles(File dir) {
         LinkedList<File> rc = new LinkedList<File>();
         for (File file : dir.listFiles()) {



Mime
View raw message