activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r899082 - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: main/java/org/apache/activemq/amqp/generator/ main/resources/ main/resources/org/ main/resources/org/apache/ main/resources/org/apache/activemq/ main/resource...
Date Thu, 14 Jan 2010 06:59:34 GMT
Author: cmacnaug
Date: Thu Jan 14 06:59:34 2010
New Revision: 899082

URL: http://svn.apache.org/viewvc?rev=899082&view=rev
Log:
Updating generator with hardcoded encodings, and BIO serialization logic

Added:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.jtemp
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpType.jtemp
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/AmqpAny.jtemp
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/test/java/org/apache/activemq/amqp/generator/handcoded/
Removed:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Marshalable.java
Modified:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDescriptor.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpEncoding.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Utils.java

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java?rev=899082&r1=899081&r2=899082&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java Thu Jan 14 06:59:34 2010
@@ -1,20 +1,27 @@
 package org.apache.activemq.amqp.generator;
 
-import java.io.BufferedOutputStream;
+import static org.apache.activemq.amqp.generator.Utils.capFirst;
+import static org.apache.activemq.amqp.generator.Utils.padHex;
+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.writeJavaCopyWrite;
+
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.TreeMap;
-import static org.apache.activemq.amqp.generator.Utils.*;
-import org.apache.activemq.amqp.generator.jaxb.schema.*;
+
+import org.apache.activemq.amqp.generator.jaxb.schema.Choice;
+import org.apache.activemq.amqp.generator.jaxb.schema.Descriptor;
+import org.apache.activemq.amqp.generator.jaxb.schema.Doc;
+import org.apache.activemq.amqp.generator.jaxb.schema.Encoding;
+import org.apache.activemq.amqp.generator.jaxb.schema.Field;
+import org.apache.activemq.amqp.generator.jaxb.schema.Type;
 
 public class AmqpClass {
 
@@ -23,7 +30,7 @@
     protected AmqpChoice choice;
     protected AmqpException exception;
     protected AmqpDescriptor descriptor;
-    protected AmqpEncoding encoding;
+    protected LinkedList<AmqpEncoding> encodings;
     protected String restrictedType;
 
     protected boolean restricted;
@@ -32,6 +39,7 @@
     LinkedHashMap<String, AmqpField> fields = new LinkedHashMap<String, AmqpField>();
     protected String javaPackage = "";
     protected String javaType = "";
+    public boolean handcoded;
 
     public void parseFromType(Generator generator, String source, Type type) {
         this.name = type.getName();
@@ -60,8 +68,12 @@
                 doc = new AmqpDoc();
                 doc.parseFromDoc((Doc) typeAttribute);
             } else if (typeAttribute instanceof Encoding) {
-                encoding = new AmqpEncoding();
+                if (encodings == null) {
+                    encodings = new LinkedList<AmqpEncoding>();
+                }
+                AmqpEncoding encoding = new AmqpEncoding();
                 encoding.parseFromEncoding((Encoding) typeAttribute);
+                encodings.add(encoding);
             } else if (typeAttribute instanceof org.apache.activemq.amqp.generator.jaxb.schema.Exception) {
                 exception = new AmqpException();
                 exception.parseFromException((org.apache.activemq.amqp.generator.jaxb.schema.Exception) typeAttribute);
@@ -78,6 +90,9 @@
     }
 
     public void generate(Generator generator) throws IOException, UnknownTypeException {
+        if (handcoded) {
+            return;
+        }
         String className = getJavaType();
 
         File file = new File(generator.getOutputDirectory() + File.separator + new String(javaPackage + "." + className).replace(".", File.separator) + ".java");
@@ -87,72 +102,35 @@
         }
         BufferedWriter writer = new BufferedWriter(new FileWriter(file));
 
-        writeCopyWrite(writer);
+        writeJavaCopyWrite(writer);
         writer.write("package " + javaPackage + ";\n");
         writer.newLine();
-        if (writeImports(writer)) {
-            writer.newLine();
-        }
-
-        writer.write("public class " + className + " {");
-        writer.newLine();
-        writer.newLine();
-
-        if (writeConstants(writer)) {
-            writer.newLine();
+        if (writeImports(writer, generator)) {
             writer.newLine();
         }
 
-        if (writeFields(writer)) {
-            writer.newLine();
+        writer.write("public class " + className);
+        if (isPrimitive() || descriptor != null) {
+            writer.write(" implements AmqpType");
         }
+        writer.write(" {");
+        writer.newLine();
 
-        if (writeFieldAccesors(writer)) {
-            writer.newLine();
-        }
+        writeConstants(writer);
+        
+        writeFields(writer);
+        
+        writeFieldAccesors(writer);
+        
+        writeSerializers(writer); 
+        
         writer.write("}");
         writer.flush();
         writer.close();
 
     }
 
-    private static void writeCopyWrite(BufferedWriter writer) throws IOException {
-        writer.write("/**");
-        writer.newLine();
-        writer.write(" * Licensed to the Apache Software Foundation (ASF) under one or more");
-        writer.newLine();
-        writer.write(" * contributor license agreements.  See the NOTICE file distributed with");
-        writer.newLine();
-        writer.write(" * this work for additional information regarding copyright ownership.");
-        writer.newLine();
-        writer.write(" * The ASF licenses this file to You under the Apache License, Version 2.0");
-        writer.newLine();
-        writer.write(" * (the \"License\"); you may not use this file except in compliance with");
-        writer.newLine();
-        writer.write(" * the License.  You may obtain a copy of the License at");
-        writer.newLine();
-        writer.write(" *");
-        writer.newLine();
-        writer.write(" *      http://www.apache.org/licenses/LICENSE-2.0");
-        writer.newLine();
-        writer.write(" *");
-        writer.newLine();
-        writer.write(" * Unless required by applicable law or agreed to in writing, software");
-        writer.newLine();
-        writer.write(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
-        writer.newLine();
-        writer.write(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
-        writer.newLine();
-        writer.write(" * See the License for the specific language governing permissions and");
-        writer.newLine();
-        writer.write(" * limitations under the License.");
-        writer.newLine();
-        writer.write(" */");
-        writer.newLine();
-        writer.newLine();
-    }
-
-    private boolean writeImports(BufferedWriter writer) throws IOException, UnknownTypeException {
+    private boolean writeImports(BufferedWriter writer, Generator generator) throws IOException, UnknownTypeException {
 
         HashSet<String> imports = new HashSet<String>();
 
@@ -160,6 +138,18 @@
             imports.add(field.getJavaPackage());
         }
 
+        if (isPrimitive()) {
+            imports.add(TypeRegistry.getJavaPackage(name));
+            imports.add("java.io");
+            imports.add(generator.getPackagePrefix());
+        }
+
+        if (descriptor != null) {
+            imports.add(generator.getPackagePrefix());
+            imports.add(generator.getPackagePrefix() + ".types" );
+            imports.add("java.io");
+        }
+
         imports.remove(getJavaPackage());
         imports.remove("java.lang");
 
@@ -175,18 +165,172 @@
 
     private boolean writeConstants(BufferedWriter writer) throws IOException, UnknownTypeException {
         boolean ret = false;
+
+        // Write out the descriptor (for compound types):
+        if (descriptor != null) {
+            ret = true;
+            writer.newLine();
+            writer.write(tab(1) + "public static final String SYMBOLIC_NAME = \"" + descriptor.getSymbolicName() + "\";");
+            writer.newLine();
+            writer.write(tab(1) + "//Format code: " + descriptor.getFormatCode() + ":");
+            writer.newLine();
+            writer.write(tab(1) + "public static final long CATEGORY = " + descriptor.getCategory() + ";");
+            writer.newLine();
+            writer.write(tab(1) + "public static final long DESCRIPTOR_ID = " + descriptor.getDescriptorId() + ";");
+            writer.newLine();
+            writer.write(tab(1) + "public static final long FORMAT_CODE = CATEGORY << 32 | DESCRIPTOR_ID; //(" + (descriptor.getCategory() << 32 | descriptor.getDescriptorId()) + "L)");
+            writer.newLine();
+            writer.write(tab(1) + "//Hard coded constructor (minus the trailing primitive format code whose encoding may vary):");
+            writer.newLine();
+            writer.write(tab(1) + "public static final byte [] CONSTRUCTOR = new byte [] {");
+            writer.newLine();
+            writer.write(tab(2) + "(byte) 0x00,                                         // COMPOUND_TYPE);");
+            writer.newLine();
+            // TODO retrieve ulong encoding from the ulong itself:
+            writer.write(tab(2) + "(byte) 0x80,                                         // ulong descriptor encoding)");
+            writer.newLine();
+            // Add the category code:
+            writer.write(tab(2));
+            String categoryHex = padHex(descriptor.getFormatCode().substring(2, descriptor.getFormatCode().indexOf(":")), 8);
+            for (int i = 0; i < 8; i += 2) {
+                writer.write("(byte) 0x" + categoryHex.substring(i, i + 2) + ", ");
+            }
+            writer.write(" // CATEGORY CODE");
+            writer.newLine();
+            writer.write(tab(2));
+            // Add the descriptor id code:
+            String descriptorIdHex = padHex(descriptor.getFormatCode().substring(descriptor.getFormatCode().indexOf(":") + 3), 8);
+
+            for (int i = 0; i < 8; i += 2) {
+                writer.write("(byte) 0x" + descriptorIdHex.substring(i, i + 2));
+                if (i < 6) {
+                    writer.write(", ");
+                }
+            }
+            writer.write("   // DESCRIPTOR ID CODE");
+            writer.newLine();
+            writer.write(tab(1) + "};");
+            writer.newLine();
+        }
+
+        // Write out encodings:
+        if (encodings != null) {
+            writeEncodings(writer);
+        }
+
         if (choice != null) {
             ret = true;
+            writer.newLine();
+            writer.write(tab(1) + "//Constants:");
+            writer.newLine();
             for (Map.Entry<String, String> constant : choice.choices.entrySet()) {
-                writer.write(tab(1) + "public static final " + TypeRegistry.getJavaType(restrictedType) + " " + Utils.toJavaConstant(constant.getKey() + " = " + constant.getValue() + ";"));
+                writer.write(tab(1) + "public static final " + TypeRegistry.getJavaType(restrictedType) + " " + Utils.toJavaConstant(constant.getKey()) + " = " + constant.getValue() + ";");
                 writer.newLine();
             }
         }
         return ret;
     }
 
+    private void writeEncodings(BufferedWriter writer) throws IOException, UnknownTypeException {
+        if (encodings != null && encodings.size() == 1 && "fixed".equals(encodings.getFirst().getCategory())) {
+            writer.newLine();
+            writer.write(tab(1) + "public static final byte FORMAT_CODE = (byte) " + encodings.getFirst().getCode() + ";");
+            writer.newLine();
+        } else {
+            writer.newLine();
+            writer.write(tab(1) + "public static enum " + toJavaConstant(name) + "_ENCODING {");
+            writer.newLine();
+
+            int i = 0;
+            for (AmqpEncoding encoding : encodings) {
+                i++;
+                String eName = encoding.getName();
+                if (eName == null) {
+                    eName = name;
+                }
+                eName = toJavaConstant(eName);
+
+                writer.write(tab(2) + eName + " ((byte) " + encoding.getCode() + ", " + encoding.getWidth() + ")");
+                if (i < encodings.size()) {
+                    writer.write(",");
+                } else {
+                    writer.write(";");
+                }
+
+                if (encoding.getLabel() != null) {
+                    writer.write(" // " + encoding.getLabel());
+                }
+
+                writer.newLine();
+            }
+
+            writer.newLine();
+            writer.write(tab(2) + "private final byte formatCode;");
+            writer.newLine();
+            writer.write(tab(2) + "private final int width;");
+            writer.newLine();
+
+            // Write constructor:
+            writer.newLine();
+            writer.write(tab(2) + toJavaConstant(name) + "_ENCODING(byte formatCode, int width) {");
+            writer.newLine();
+            writer.write(tab(3) + "this.formatCode = formatCode;");
+            writer.newLine();
+            writer.write(tab(3) + "this.width = width;");
+            writer.newLine();
+            writer.write(tab(2) + "}");
+            writer.newLine();
+
+            // Write Accessors:
+            writer.newLine();
+            writer.write(tab(2) + "public final byte getFormatCode() {");
+            writer.newLine();
+            writer.write(tab(3) + "return formatCode;");
+            writer.newLine();
+            writer.write(tab(2) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(2) + "public final int getWidth() {");
+            writer.newLine();
+            writer.write(tab(3) + "return width;");
+            writer.newLine();
+            writer.write(tab(2) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(2) + "public final int getEncodedSize(" + TypeRegistry.getJavaType(name) + " val) throws IOException{");
+            writer.newLine();
+            writer.write(tab(3) + "if(width > 0) {");
+            writer.newLine();
+            writer.write(tab(4) + "return 1 + width + AmqpMarshaller.getEncodedSizeOf" + capFirst(toJavaName(name)) + "(val, this);");
+            writer.newLine();
+            writer.write(tab(3) + "}");
+            writer.newLine();
+            writer.write(tab(3) + "return 1;");
+            writer.newLine();
+            writer.write(tab(2) + "}");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+        }
+    }
+
     private boolean writeFields(BufferedWriter writer) throws IOException, UnknownTypeException {
         boolean ret = false;
+        
+        if (descriptor != null)
+        {
+            ret = true;
+            String encodingType = descriptor.getSymbolicName();
+            encodingType = encodingType.substring(encodingType.lastIndexOf(":") + 1);
+            encodingType = "Amqp" + capFirst(toJavaName(encodingType));
+            
+            writer.newLine();
+            writer.write(tab(1) + "private " + encodingType + " value;");
+            writer.newLine();
+        }
+        
         for (AmqpField field : fields.values()) {
             ret = true;
             if (field.getDoc() != null) {
@@ -203,11 +347,26 @@
             writer.write(";");
             writer.newLine();
         }
+
+        if (isPrimitive()) {
+            writer.newLine();
+            writer.write(tab(1) + "private " + TypeRegistry.getJavaType(name) + " value;");
+            writer.newLine();
+
+            // If there are multiple possible encodings store the current
+            // encoding:
+            if (encodings != null && encodings.size() > 1) {
+                writer.newLine();
+                writer.write(tab(1) + "private " + getEncodingName(true) + " encoding;");
+                writer.newLine();
+            }
+        }
         return ret;
     }
 
     private boolean writeFieldAccesors(BufferedWriter writer) throws IOException, UnknownTypeException {
         boolean ret = false;
+        
         for (AmqpField field : fields.values()) {
             ret = true;
             if (field.getDoc() != null) {
@@ -217,6 +376,7 @@
             String array = field.isMultiple() ? " []" : "";
 
             // Setter:
+            writer.newLine();
             writer.write(tab(1) + "public final void set" + capFirst(field.getJavaName()) + "(" + field.getJavaType() + array + " " + toJavaName(field.getName()) + ") {");
             writer.newLine();
             writer.write(tab(2) + "this." + field.getJavaName() + " = " + field.getJavaName() + ";");
@@ -225,16 +385,142 @@
             writer.newLine();
             writer.newLine();
             // Getter:
-
-            // Setter:
             writer.write(tab(1) + "public final " + field.getJavaType() + array + " get" + capFirst(field.getJavaName()) + "() {");
             writer.newLine();
             writer.write(tab(2) + "return " + field.getJavaName() + ";");
             writer.newLine();
             writer.write(tab(1) + "}");
             writer.newLine();
+        }
+
+        if (isPrimitive()) {
+            String valueType = TypeRegistry.getJavaType(name);
+
+            writer.newLine();
+            writer.write(tab(1) + "public final void setValue(" + valueType + " value) {");
+            writer.newLine();
+            writer.write(tab(2) + "this.value = value;");
+            if (hasMultipleEncodings()) {
+                writer.newLine();
+                writer.write(tab(2) + "this.encoding = null;");
+            }
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+            writer.newLine();
+            // Getter:
+            writer.write(tab(1) + "public final " + valueType + " getValue() {");
+            writer.newLine();
+            writer.write(tab(2) + "return value;");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+        }
+        return ret;
+    }
+
+    private boolean writeSerializers(BufferedWriter writer) throws IOException, UnknownTypeException {
+        boolean ret = false;
+
+        // Add accessors for primitive encoded sizes:
+        if (isPrimitive()) {
+            ret = true;
+            writer.newLine();
+            writer.write(tab(1) + "public final int getEncodedSize() throws IOException{");
+            writer.newLine();
+            // Handle fixed width encodings:
+            if (encodings != null && encodings.size() == 1 && "fixed".equals(encodings.getFirst().getCategory())) {
+                AmqpEncoding encoding = encodings.getFirst();
+
+                writer.write(tab(2) + "return " + (1 + new Integer(encoding.getWidth())) + ";");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void marshal(DataOutputStream dos) throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "dos.writeByte(FORMAT_CODE);");
+                writer.newLine();
+                if (Integer.parseInt(encoding.getWidth()) > 0) {
+                    writer.write(tab(2) + "AmqpMarshaller.write" + capFirst(toJavaName(name)) + "(value, dos);");
+                    writer.newLine();
+                }
+                writer.write(tab(1) + "}");
+                writer.newLine();
+            } else {
+                writer.newLine();
+                writer.write(tab(2) + "chooseEncoding();");
+                writer.newLine();
+                writer.write(tab(2) + "return encoding.getEncodedSize(value);");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void marshal(DataOutputStream dos) throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "chooseEncoding();");
+                writer.newLine();
+                writer.write(tab(2) + "dos.writeByte(encoding.getFormatCode());");
+                if (hasNonZeroEncoding()) {
+                    writer.newLine();
+                    writer.write(tab(2) + "int size = encoding.getEncodedSize(value);");
+                    writer.newLine();
+                    writer.write(tab(2) + "if(encoding.getWidth() == 1) {");
+                    writer.newLine();
+                    writer.write(tab(3) + "dos.writeByte(size);");
+                    writer.newLine();
+                    writer.write(tab(2) + "}");
+                    writer.newLine();
+                    writer.write(tab(2) + "else if(encoding.getWidth() == 4) {");
+                    writer.newLine();
+                    writer.write(tab(3) + "dos.writeInt(size);");
+                    writer.newLine();
+                    writer.write(tab(2) + "}");
+                    writer.newLine();
+                    writer.write(tab(2) + "AmqpMarshaller.write" + capFirst(toJavaName(name)) + "(value, encoding, dos);");
+                    writer.newLine();
+                }
+
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void chooseEncoding() throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "if(encoding == null) {");
+                writer.newLine();
+                writer.write(tab(3) + "encoding = AmqpMarshaller.choose" + capFirst(name) + "Encoding(value);");
+                writer.newLine();
+                writer.write(tab(2) + "}");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+            }
+        }
+
+        if (descriptor != null) {
+
+            writer.newLine();
+            writer.write(tab(1) + "public final int getEncodedSize() throws IOException {");
+            writer.newLine();
+            writer.write(tab(2) + "return CONSTRUCTOR.length + value.getEncodedSize();");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+            writer.newLine();
+            writer.write(tab(1) + "public final void marshal(DataOutputStream dos) throws IOException {");
+            writer.newLine();
+            writer.write(tab(2) + "dos.write(CONSTRUCTOR);");
+            writer.newLine();
+            writer.write(tab(2) + "value.marshal(dos);");
+            writer.newLine();
+            writer.write(tab(1) + "}");
             writer.newLine();
         }
+
         return ret;
     }
 
@@ -270,8 +556,48 @@
         this.primitive = primitive;
     }
 
+    public boolean hasMultipleEncodings() {
+        return encodings != null && encodings.size() > 1;
+    }
+
+    public boolean hasNonFixedEncoding() {
+        if (encodings == null) {
+            return false;
+        }
+
+        for (AmqpEncoding encoding : encodings) {
+            if (!encoding.isFixed()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean hasNonZeroEncoding() {
+        if (encodings == null) {
+            return false;
+        }
+
+        for (AmqpEncoding encoding : encodings) {
+            if (Integer.parseInt(encoding.getWidth()) > 0) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public String getEncodingName(boolean full) {
+        if (full) {
+            return getJavaType() + "." + getEncodingName(false);
+        } else {
+            return toJavaConstant(name) + "_ENCODING";
+        }
+    }
+
     public String toString() {
-        String ret = "Class: " + name + " [Encoding=" + encoding + ", Descriptor=" + descriptor + "]\n";
+        String ret = "Class: " + name + " [Encoding=" + encodings + ", Descriptor=" + descriptor + "]\n";
         ret += " Fields:\n";
         for (AmqpField f : fields.values()) {
             ret += " " + f.toString();

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDescriptor.java?rev=899082&r1=899081&r2=899082&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDescriptor.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDescriptor.java Thu Jan 14 06:59:34 2010
@@ -1,21 +1,60 @@
 package org.apache.activemq.amqp.generator;
 
+import java.util.StringTokenizer;
+
 import org.apache.activemq.amqp.generator.jaxb.schema.Descriptor;
 
 public class AmqpDescriptor {
 
-    String code;
-    String name;
+    String formatCode;
+    String symbolicName;
+    long category;
+    long descriptorId;
 
     public void parseFromDescriptor(Descriptor descriptor) {
 
-        code = descriptor.getCode();
-        name = descriptor.getName();
+        formatCode = descriptor.getCode();
+        symbolicName = descriptor.getName();
+        StringTokenizer tok = new StringTokenizer(formatCode, ":");
+        category = Long.parseLong(tok.nextToken().substring(2), 16);
+        descriptorId = Long.parseLong(tok.nextToken().substring(2), 16);
         // TODO descriptor.getDoc();
     }
 
+    public String getFormatCode() {
+        return formatCode;
+    }
+
+    public void setFormatCode(String formatCode) {
+        this.formatCode = formatCode;
+    }
+
+    public String getSymbolicName() {
+        return symbolicName;
+    }
+
+    public void setSymbolicName(String symbolicName) {
+        this.symbolicName = symbolicName;
+    }
+
+    public long getCategory() {
+        return category;
+    }
+
+    public void setCategory(long category) {
+        this.category = category;
+    }
+
+    public long getDescriptorId() {
+        return descriptorId;
+    }
+
+    public void setDescriptorId(long descriptorId) {
+        this.descriptorId = descriptorId;
+    }
+
     public String toString() {
-        return "{" + name + ", code=" + code + "}";
+        return "{" + symbolicName + ", code=" + formatCode + "}";
     }
 
 }

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpEncoding.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpEncoding.java?rev=899082&r1=899081&r2=899082&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpEncoding.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpEncoding.java Thu Jan 14 06:59:34 2010
@@ -8,15 +8,72 @@
     private String category;
     private String code;
     private String width;
-
+    private String label;
+    
     public void parseFromEncoding(Encoding encoding) {
         name = encoding.getName();
         category = encoding.getCategory();
         code = encoding.getCode();
         width = encoding.getWidth();
+        label = encoding.getLabel();
         //TODO: encoding.getDoc();
     }
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getCategory() {
+        return category;
+    }
+
+    public void setCategory(String category) {
+        this.category = category;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
 
+    public String getWidth() {
+        return width;
+    }
+
+    public void setWidth(String width) {
+        this.width = width;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+    
+    public boolean isFixed()
+    {
+        return "fixed".equals(getCategory());
+    }
+
+    public boolean isVariable()
+    {
+        return "variable".equals(getCategory());
+    }
+    
+    public boolean isCompound()
+    {
+        return "compound".equals(getCategory());
+    }
+    
     public String toString() {
         return "{" + name + ", cat=" + category + ", code=" + code + ", width=" + width +"}";
     }

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java?rev=899082&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java Thu Jan 14 06:59:34 2010
@@ -0,0 +1,154 @@
+package org.apache.activemq.amqp.generator;
+
+import static org.apache.activemq.amqp.generator.Utils.*;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashSet;
+
+/**
+ * Generates the AMQP marshaller
+ * 
+ * @author cmacnaug
+ */
+public class AmqpMarshallerGen {
+
+    public static final String MARSHALLER_CLASS_NAME = "AbstractAmqpMarshaller";
+
+    public static void genererate(Generator generator) throws IOException, UnknownTypeException {
+        File file = new File(generator.getOutputDirectory() + File.separator + new String(generator.getPackagePrefix() + "." + MARSHALLER_CLASS_NAME).replace(".", File.separator) + ".java");
+        file.getParentFile().mkdirs();
+        if (file.exists()) {
+            file.delete();
+        }
+        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+
+        writeJavaCopyWrite(writer);
+
+        writer.write("package " + generator.getPackagePrefix() + ";\n");
+        writer.newLine();
+
+        writeImports(writer, generator);
+
+        writer.newLine();
+        writer.write("public abstract class " + MARSHALLER_CLASS_NAME + " {");
+        writer.newLine();
+
+        // Write out encoding enums:
+        writer.newLine();
+        writer.write(tab(1) + "///////////////////////////////////////////////////////////////");
+        writer.write(tab(1) + "//Encodings:                                                 //");
+        writer.write(tab(1) + "///////////////////////////////////////////////////////////////");
+        for (AmqpClass c : TypeRegistry.getGeneratedTypes()) {
+            if (!c.isPrimitive()) {
+                continue;
+            }
+        }
+
+        writer.newLine();
+        writer.write(tab(1) + "///////////////////////////////////////////////////////////////");
+        writer.write(tab(1) + "//Marshallers:                                               //");
+        writer.write(tab(1) + "///////////////////////////////////////////////////////////////");
+
+        // Write out encoding serializers:
+        for (AmqpClass c : TypeRegistry.getGeneratedTypes()) {
+            if (!c.isPrimitive()) {
+                continue;
+            }
+            if (c.encodings != null) {
+                writeEncodingSerializers(c, writer);
+            }
+        }
+
+        writer.newLine();
+        writer.write("}");
+        writer.flush();
+        writer.close();
+    }
+
+    private static boolean writeImports(BufferedWriter writer, Generator generator) throws IOException, UnknownTypeException {
+
+        HashSet<String> imports = new HashSet<String>();
+
+        for (AmqpClass c : TypeRegistry.getGeneratedTypes()) {
+            if (!c.isPrimitive()) {
+                continue;
+            }
+            for (AmqpField field : c.fields.values()) {
+                imports.add(field.getJavaPackage());
+            }
+            imports.add(TypeRegistry.getJavaPackage(c.name));
+        }
+        imports.add("java.io");
+        imports.add(generator.getPackagePrefix() + ".types");
+        imports.remove("java.lang");
+
+        boolean ret = false;
+
+        for (String toImport : imports) {
+            ret = true;
+            writer.write("import " + toImport + ".*;");
+            writer.newLine();
+        }
+        return ret;
+    }
+
+    private static void writeEncodingSerializers(AmqpClass amqpClass, BufferedWriter writer) throws IOException, UnknownTypeException {
+
+        String javaType = TypeRegistry.getJavaType(amqpClass.name);
+        String javaTypeName = javaType;
+
+        if (javaType.endsWith(" []")) {
+            javaTypeName = javaType.substring(0, javaType.indexOf(" []")) + " Array";
+        }
+        if (amqpClass.encodings.size() > 1) {
+            writer.newLine();
+            writeJavaComment(writer, 1, "Chooses a " + amqpClass.getEncodingName(true) + " for the given " + javaType);
+            writer.write(tab(1) + "public abstract " + amqpClass.getEncodingName(true) + " choose" + capFirst(amqpClass.name) + "Encoding(" + javaType + " val) throws IOException;");
+            writer.newLine();
+
+            writer.newLine();
+            writeJavaComment(writer, 1, "Gets the encoded size of " + javaType + " with the given encoding");
+            writer.write(tab(1) + "public abstract int getEncodedSizeOf" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " value, " + amqpClass.getEncodingName(true) + " encoding) throws IOException;");
+            writer.newLine();
+
+            boolean hasNonZeroWidthEncoding = false;
+            for (AmqpEncoding encoding : amqpClass.encodings) {
+                if (Integer.parseInt(encoding.getWidth()) > 0) {
+                    hasNonZeroWidthEncoding = true;
+                }
+            }
+            if (hasNonZeroWidthEncoding) {
+                writer.newLine();
+                writeJavaComment(writer, 1, "Writes a " + javaType + " with the given encoding");
+                writer.write(tab(1) + "public abstract void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, " + amqpClass.getEncodingName(true)
+                        + " encoding, DataOutputStream dos) throws IOException;");
+                writer.newLine();
+
+                writer.newLine();
+                writeJavaComment(writer, 1, "Reads a " + javaType + " with the given encoding");
+                writer.write(tab(1) + "public abstract " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(" + amqpClass.getEncodingName(true)
+                        + " encoding, DataInputStream dis) throws IOException;");
+                writer.newLine();
+            }
+        } else {
+            AmqpEncoding encoding = amqpClass.encodings.getFirst();
+            // Don't need a serializer if the width is 0:
+            if (new Integer(encoding.getWidth()) > 0) {
+
+                writer.newLine();
+                writeJavaComment(writer, 1, "Writes a " + javaType + " encoded as " + encoding.getLabel());
+                writer.write(tab(1) + "public abstract void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, DataOutputStream dos) throws IOException;");
+                writer.newLine();
+
+                writer.newLine();
+                writeJavaComment(writer, 1, "Reads a " + javaType + " encoded as " + encoding.getLabel());
+                writer.write(tab(1) + "public abstract " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(DataInputStream dis) throws IOException;");
+                writer.newLine();
+            }
+        }
+
+    }
+}

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=899082&r1=899081&r2=899082&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 Jan 14 06:59:34 2010
@@ -1,5 +1,13 @@
 package org.apache.activemq.amqp.generator;
 
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.List;
 import javax.xml.bind.JAXBContext;
@@ -20,17 +28,17 @@
 
     private Log LOG = LogFactory.getLog(Generator.class);
 
-    private String [] inputFiles;
+    private String[] inputFiles;
     private String outputDirectory;
     private String packagePrefix;
 
     private TypeRegistry typeRegistry = new TypeRegistry();
 
-    public String [] getInputFile() {
+    public String[] getInputFile() {
         return inputFiles;
     }
 
-    public void setInputFiles(String ... inputFiles) {
+    public void setInputFiles(String... inputFiles) {
         this.inputFiles = inputFiles;
     }
 
@@ -54,8 +62,7 @@
         TypeRegistry.init(this);
         JAXBContext jc = JAXBContext.newInstance(Amqp.class.getPackage().getName());
 
-        for(String inputFile : inputFiles)
-        {
+        for (String inputFile : inputFiles) {
             // JAXB has some namespace handling problems:
             Unmarshaller unmarshaller = jc.createUnmarshaller();
             SAXParserFactory parserFactory;
@@ -67,7 +74,7 @@
             // File(inputFile)), Amqp.class).getValue();
             Amqp amqp = (Amqp) unmarshaller.unmarshal(er);
             List<Object> list = amqp.getDocOrSection();
-    
+
             // Scan document:
             for (Object docOrSection : amqp.getDocOrSection()) {
                 if (docOrSection instanceof Section) {
@@ -82,6 +89,26 @@
             }
         }
 
+        // Copy handcoded:
+        String[] handcoded = new String[] { "AmqpMarshaller", "AmqpType"};
+        for (String javaFile : handcoded) {
+            BufferedReader reader = new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/activemq/amqp/generator/handcoded/" + javaFile + ".jtemp")));
+            String line = reader.readLine();
+            line = line.replace("org.apache.activemq.amqp.generator.handcoded", packagePrefix);
+
+            File out = new File(this.outputDirectory + File.separator + packagePrefix.replace(".", File.separator) + File.separator + javaFile + ".java");
+            out.getParentFile().mkdirs();
+            BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+            while (line != null) {
+                writer.write(line);
+                writer.newLine();
+                line = reader.readLine();
+            }
+            writer.flush();
+            writer.close();
+        }
+
         // Generate Types:
         for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
             amqpClass.generate(this);

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=899082&r1=899081&r2=899082&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 Jan 14 06:59:34 2010
@@ -27,8 +27,9 @@
         JAVA_TYPE_MAP.put("binary", new JavaTypeMapping("binary", "byte []", "java.lang"));
         JAVA_TYPE_MAP.put("string", new JavaTypeMapping("string", "String", "java.lang"));
         JAVA_TYPE_MAP.put("symbol", new JavaTypeMapping("symbol", "String", "java.lang"));
-        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", "List", "java.util"));
-        JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", "HashMap", "java.util"));
+        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", "List <AmqpType>", "java.util"));
+        JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", "HashMap <AmqpType, AmqpType>", "java.util"));
+        JAVA_TYPE_MAP.put("null", new JavaTypeMapping("null", "Object", "java.lang"));
 
     }
 
@@ -36,6 +37,8 @@
         // Add in the wildcard type:
         GENERATED_TYPE_MAP.put("*", new AnyClass("*", "AmqpAny", generator.getPackagePrefix() + ".types"));
         JAVA_TYPE_MAP.put("*", new JavaTypeMapping("*", "byte []", "java.lang"));
+        
+        // Add in the compound type:
     }
 
     public static String getJavaType(AmqpField field) throws UnknownTypeException {
@@ -117,6 +120,19 @@
             super.javaType = javaType;
             super.setPrimitive(true);
             super.javaPackage = javaPackage;
+            super.handcoded = true;
         }
     }
+    
+    public static class CompoundType extends AmqpClass {
+
+        CompoundType(String name, String javaType, String javaPackage) {
+            super.name = name;
+            super.javaType = javaType;
+            super.setPrimitive(true);
+            super.javaPackage = javaPackage;
+        }
+    }
+    
+    
 }

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=899082&r1=899081&r2=899082&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 Thu Jan 14 06:59:34 2010
@@ -1,5 +1,7 @@
 package org.apache.activemq.amqp.generator;
 
+import java.io.BufferedWriter;
+import java.io.IOException;
 import java.util.StringTokenizer;
 
 public class Utils {
@@ -8,7 +10,7 @@
     public static final String NL = "\n";
 
     public static final String toJavaName(String name) {
-        StringTokenizer tok = new StringTokenizer(name, "-");
+        StringTokenizer tok = new StringTokenizer(name.trim(), "- ");
         String javaName = "";
         int i = 0;
         while (tok.hasMoreElements()) {
@@ -23,9 +25,9 @@
         }
         return javaName;
     }
-    
+
     public static final String toJavaConstant(String name) {
-        StringTokenizer tok = new StringTokenizer(name, "-");
+        StringTokenizer tok = new StringTokenizer(name.trim(), "- ");
         String javaName = "";
         int i = 0;
         while (tok.hasMoreElements()) {
@@ -54,4 +56,48 @@
         return ret;
     }
 
+    public static final String padHex(String hex, int count) {
+        while (hex.length() < count) {
+            hex = "0" + hex;
+        }
+        return hex;
+    }
+    
+    public static void writeJavaCopyWrite(BufferedWriter writer) throws IOException {
+        
+        writeJavaComment(writer, 0, 
+                "Licensed to the Apache Software Foundation (ASF) under one or more",
+                "contributor license agreements.  See the NOTICE file distributed with",
+                "his 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.");
+    }
+    
+    public static void writeJavaComment(BufferedWriter writer, int indent, String ... commentLines) throws IOException
+    {
+        if(commentLines == null)
+        {
+            return;
+        }
+        
+        writer.write(tab(indent) + "/**");
+        writer.newLine();
+        for(String s : commentLines)
+        {
+            writer.write(tab(indent) + " * " + s);
+            writer.newLine();
+        }
+        writer.write(tab(indent) + " */");
+        writer.newLine();
+    }
+
 }

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.jtemp
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.jtemp?rev=899082&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.jtemp (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.jtemp Thu Jan 14 06:59:34 2010
@@ -0,0 +1,324 @@
+package org.apache.activemq.amqp.generator.handcoded;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.activemq.amqp.v1pr2.types.AmqpBinary;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBoolean;
+import org.apache.activemq.amqp.v1pr2.types.AmqpList;
+import org.apache.activemq.amqp.v1pr2.types.AmqpMap;
+import org.apache.activemq.amqp.v1pr2.types.AmqpString;
+import org.apache.activemq.amqp.v1pr2.types.AmqpSymbol;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBinary.BINARY_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBoolean.BOOLEAN_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpList.LIST_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpMap.MAP_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpString.STRING_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpSymbol.SYMBOL_ENCODING;
+
+public class AmqpMarshaller {
+
+    public static final AmqpBinary.BINARY_ENCODING chooseBinaryEncoding(byte[] val) throws IOException {
+        if (val.length > 255) {
+            return AmqpBinary.BINARY_ENCODING.VBIN32;
+        }
+        return AmqpBinary.BINARY_ENCODING.VBIN8;
+    }
+
+    public static final AmqpBoolean.BOOLEAN_ENCODING chooseBooleanEncoding(boolean val) throws IOException {
+        if (val) {
+            return AmqpBoolean.BOOLEAN_ENCODING.TRUE;
+        }
+        return AmqpBoolean.BOOLEAN_ENCODING.FALSE;
+    }
+
+    public static final AmqpList.LIST_ENCODING chooseListEncoding(List val) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final AmqpMap.MAP_ENCODING chooseMapEncoding(HashMap val) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final AmqpString.STRING_ENCODING chooseStringEncoding(String val) throws IOException {
+        if (val.length() > 255 || val.getBytes("utf-16").length > 255) {
+            return AmqpString.STRING_ENCODING.STR32_UTF16;
+        }
+
+        return AmqpString.STRING_ENCODING.STR32_UTF16;
+    }
+
+    public static final AmqpSymbol.SYMBOL_ENCODING chooseSymbolEncoding(String val) throws IOException {
+        if (val.length() > 255 || val.getBytes("ascii").length > 255) {
+            return AmqpSymbol.SYMBOL_ENCODING.SYM32;
+        }
+        return AmqpSymbol.SYMBOL_ENCODING.SYM8;
+    }
+
+    public static final byte readByte(DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public static final byte[] readBinary(AmqpBinary.BINARY_ENCODING encoding, DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final char readChar(DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public static final double readDouble(DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public static final float readFloat(DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public static final HashMap readMap(AmqpMap.MAP_ENCODING encoding, DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final int readInt(DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return dis.readInt();
+    }
+
+    public static final List readList(AmqpList.LIST_ENCODING encoding, DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final long readLong(DataInputStream dis) throws IOException {
+        return dis.readLong();
+    }
+
+    public static final short readShort(DataInputStream dis) throws IOException {
+        return dis.readShort();
+    }
+
+    public static final String readString(AmqpString.STRING_ENCODING encoding, DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final String readSymbol(AmqpSymbol.SYMBOL_ENCODING encoding, DataInputStream dis) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static final Date readTimestamp(DataInputStream dis) throws IOException {
+        return new Date(dis.readInt());
+    }
+
+    public static final short readUbyte(DataInputStream dis) throws IOException {
+        return (short) (0xFF & (short) dis.readByte());
+    }
+
+    public static final long readUint(DataInputStream dis) throws IOException {
+        long rc = 0;
+        rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 24));
+        rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 16));
+        rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 8));
+        rc = rc | (0xFFFFFFFFL & (long) dis.readByte());
+
+        return rc;
+    }
+
+    public static final BigInteger readUlong(DataInputStream dis) throws IOException {
+        byte[] rc = new byte[9];
+        rc[0] = 0;
+        dis.readFully(rc, 1, 8);
+        return new BigInteger(rc);
+    }
+
+    public static final int readUshort(DataInputStream dis) throws IOException {
+        int rc = 0;
+        rc = rc | ((int) 0xFFFF & (((int) dis.readByte()) << 8));
+        rc = rc | ((int) 0xFFFF & (int) dis.readByte());
+
+        return rc;
+    }
+
+    public static final UUID readUuid(DataInputStream dis) throws IOException {
+        return new UUID(dis.readLong(), dis.readLong());
+    }
+
+    public static final void writeByte(byte val, DataOutputStream dos) throws IOException {
+        dos.writeByte(val);
+    }
+
+    public static final void writeBinary(byte[] val, AmqpBinary.BINARY_ENCODING encoding, DataOutputStream dos) throws IOException {
+        dos.write(val);
+    }
+
+    public static final void writeChar(char val, DataOutputStream dos) throws IOException {
+        // TODO Auto-generated method stub
+
+    }
+
+    public static final void writeDouble(double val, DataOutputStream dos) throws IOException {
+        dos.writeLong(Double.doubleToLongBits(val));
+        // dos.writeDouble(val);
+    }
+
+    public static final void writeFloat(float val, DataOutputStream dos) throws IOException {
+        dos.writeInt(Float.floatToIntBits(val));
+        // dos.writeFloat(val);
+    }
+
+    public static final void writeMap(HashMap val, AmqpMap.MAP_ENCODING encoding, DataOutputStream dos) throws IOException {
+        // TODO Auto-generated method stub
+    }
+
+    public static final void writeInt(int val, DataOutputStream dos) throws IOException {
+        // TODO Auto-generated method stub
+
+    }
+
+    public static final void writeList(List val, AmqpList.LIST_ENCODING encoding, DataOutputStream dos) throws IOException {
+        // TODO Auto-generated method stub
+
+    }
+
+    public static final void writeLong(long val, DataOutputStream dos) throws IOException {
+        dos.writeLong(val);
+    }
+
+    public static final void writeShort(short val, DataOutputStream dos) throws IOException {
+        dos.writeShort(val);
+    }
+
+    public static final void writeString(String val, AmqpString.STRING_ENCODING encoding, DataOutputStream dos) throws IOException {
+        switch (encoding) {
+        case STR32_UTF16:
+        case STR8_UTF16: {
+            dos.write(val.getBytes("utf-16"));
+        }
+        case STR32_UTF8:
+        case STR8_UTF8: {
+            dos.write(val.getBytes("utf-8"));
+        }
+        default:
+            throw new UnsupportedEncodingException(encoding.name());
+        }
+
+    }
+
+    public static final void writeTimestamp(Date val, DataOutputStream dos) throws IOException {
+        dos.writeInt((int) val.getTime());
+
+    }
+
+    public static final void writeUbyte(short val, DataOutputStream dos) throws IOException {
+        dos.write(val);
+
+    }
+
+    public static final void writeUint(long val, DataOutputStream dos) throws IOException {
+        dos.writeInt((int) val);
+
+    }
+
+    public static final void writeUlong(BigInteger val, DataOutputStream dos) throws IOException {
+        byte[] b = val.toByteArray();
+        if (b.length > 8) {
+            for (int i = 0; i < b.length - 8; i++) {
+                if (b[i] > 0) {
+                    throw new UnsupportedEncodingException("Unsigned long too large");
+                }
+            }
+        }
+        dos.write(b, b.length - 8, 8);
+    }
+
+    public static final void writeUshort(int val, DataOutputStream dos) throws IOException {
+        dos.writeShort((short) val);
+    }
+
+    public static final void writeUuid(UUID val, DataOutputStream dos) throws IOException {
+        dos.writeLong(val.getMostSignificantBits());
+        dos.writeLong(val.getLeastSignificantBits());
+    }
+
+    public static final int getEncodedSizeOfBinary(byte[] val, BINARY_ENCODING encoding) throws IOException {
+        return val.length;
+    }
+
+    public static final int getEncodedSizeOfBoolean(boolean val, BOOLEAN_ENCODING encoding) throws IOException {
+        return 0;
+    }
+
+    public static final int getEncodedSizeOfList(List val, LIST_ENCODING encoding) throws IOException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public static final int getEncodedSizeOfMap(HashMap val, MAP_ENCODING encoding) throws IOException {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public static final int getEncodedSizeOfString(String val, STRING_ENCODING encoding) throws IOException {
+        switch (encoding) {
+        case STR32_UTF16:
+        case STR8_UTF16: {
+            return val.getBytes("utf-16").length;
+        }
+        case STR32_UTF8:
+        case STR8_UTF8: {
+            return val.getBytes("utf-8").length;
+        }
+        default:
+            throw new UnsupportedEncodingException(encoding.name());
+        }
+    }
+
+    public static final int getEncodedSizeOfSymbol(String val, SYMBOL_ENCODING encoding) throws IOException {
+        return val.length();
+    }
+
+    public static final void writeSymbol(String val, SYMBOL_ENCODING encoding, DataOutputStream dos) throws IOException {
+        dos.write(val.getBytes("ascii"));
+    }
+
+    public static final void main(String[] arg) {
+        AmqpMarshaller marshaller = new AmqpMarshaller();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(30);
+        DataOutputStream dos = new DataOutputStream(baos);
+
+        try {
+            BigInteger unsigned = new BigInteger("" + Long.MAX_VALUE).multiply(new BigInteger("2"));
+            marshaller.writeUlong(unsigned, dos);
+            dos.flush();
+
+            byte[] b = baos.toByteArray();
+            ByteArrayInputStream bais = new ByteArrayInputStream(b);
+            DataInputStream dis = new DataInputStream(bais);
+            BigInteger read = marshaller.readUlong(dis);
+            if (read != unsigned) {
+                throw new Exception();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpType.jtemp
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpType.jtemp?rev=899082&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpType.jtemp (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpType.jtemp Thu Jan 14 06:59:34 2010
@@ -0,0 +1,28 @@
+package org.apache.activemq.amqp.generator.handcoded;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with his 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.
+ */
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public interface AmqpType {
+
+    public void marshal(DataOutputStream dos) throws IOException;
+    
+    public int getEncodedSize() throws IOException;
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/AmqpAny.jtemp
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/AmqpAny.jtemp?rev=899082&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/AmqpAny.jtemp (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/AmqpAny.jtemp Thu Jan 14 06:59:34 2010
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * his 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.amqp.generator.handcoded.types;
+
+import java.io.*;
+import org.apache.activemq.amqp.v1pr2.*;
+
+public class AmqpAny {
+
+    private byte [] value;
+
+    public final void setValue(byte [] value) {
+        this.value = value;
+    }
+
+    public final byte [] getValue() {
+        return value;
+    }
+
+    public final long getEncodedSize() throws IOException{
+
+        chooseEncoding();
+        return encoding.getEncodedSize(value);
+    }
+
+    public final void marshal(DataOutputStream dos, byte [] val) throws IOException {
+        chooseEncoding();
+        dos.writeByte(encoding.getFormatCode());    }
+
+    public final void chooseEncoding() throws IOException {
+        if(encoding == null) {
+            encoding = AmqpMarshaller.choose*Encoding(value);
+        }
+    }
+
+}
\ No newline at end of file



Mime
View raw message