activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r900531 [2/2] - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/ handcoded/org/ handcoded/org/apache/ handcoded/org/apache/activemq/ handcoded/org/apache/activemq/amqp/ handcoded/org/apache/activemq/amqp/ge...
Date Mon, 18 Jan 2010 20:12:49 GMT
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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -8,24 +8,32 @@
 import static org.apache.activemq.amqp.generator.Utils.writeJavaCopyWrite;
 
 import java.io.BufferedWriter;
+import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.HashSet;
+import java.io.UnsupportedEncodingException;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
+import java.util.TreeSet;
 
+import org.apache.activemq.amqp.generator.TypeRegistry.JavaTypeMapping;
 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;
+import org.apache.activemq.amqp.v1pr2.messaging.AmqpDistributionMode;
+import org.apache.activemq.amqp.v1pr2.transport.AmqpConnectionErrorCode;
+import org.apache.activemq.amqp.v1pr2.types.AmqpUint;
+import org.apache.activemq.amqp.v1pr2.types.AmqpUshort;
 
 public class AmqpClass {
 
     protected String name;
+    protected String label;
     protected AmqpDoc doc;
     protected AmqpChoice choice;
     protected AmqpException exception;
@@ -37,19 +45,17 @@
     protected boolean primitive;
 
     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) {
+    // Java mapping for this class:
+    public TypeRegistry.JavaTypeMapping typeMapping;
+    // Java mapping of the value that this type holds (if any)
+    public TypeRegistry.JavaTypeMapping valueMapping;
+
+    public void parseFromType(Generator generator, String source, Type type) throws UnknownTypeException {
         this.name = type.getName();
         this.restrictedType = type.getSource();
-
-        // See if this is a restricting type (used to restrict the type of a
-        // field):
-        if (type.getClazz().equalsIgnoreCase("restricted")) {
-            this.restricted = true;
-        }
+        this.label = type.getLabel();
 
         for (Object typeAttribute : type.getEncodingOrDescriptorOrFieldOrChoiceOrExceptionOrDoc()) {
             if (typeAttribute instanceof Field) {
@@ -81,12 +87,16 @@
         }
 
         if (type.getClazz().equalsIgnoreCase("primitive")) {
-            javaType = "Amqp" + capFirst(toJavaName(name));
             setPrimitive(true);
-        } else {
-            javaType = capFirst(toJavaName(name));
         }
-        javaPackage = generator.getPackagePrefix() + "." + source;
+
+        // See if this is a restricting type (used to restrict the type of a
+        // field):
+        if (type.getClazz().equalsIgnoreCase("restricted")) {
+            this.restricted = true;
+        }
+
+        typeMapping = new JavaTypeMapping(name, generator.getPackagePrefix() + "." + source + "." + "Amqp" + capFirst(toJavaName(name)));
     }
 
     public void generate(Generator generator) throws IOException, UnknownTypeException {
@@ -95,7 +105,7 @@
         }
         String className = getJavaType();
 
-        File file = new File(generator.getOutputDirectory() + File.separator + new String(javaPackage + "." + className).replace(".", File.separator) + ".java");
+        File file = new File(generator.getOutputDirectory() + File.separator + new String(typeMapping.getFullName()).replace(".", File.separator) + ".java");
         file.getParentFile().mkdirs();
         if (file.exists()) {
             file.delete();
@@ -103,27 +113,43 @@
         BufferedWriter writer = new BufferedWriter(new FileWriter(file));
 
         writeJavaCopyWrite(writer);
-        writer.write("package " + javaPackage + ";\n");
+        writer.write("package " + typeMapping.getPackageName() + ";\n");
         writer.newLine();
         if (writeImports(writer, generator)) {
             writer.newLine();
         }
 
-        writer.write("public class " + className);
-        if (isPrimitive() || descriptor != null) {
-            writer.write(" implements AmqpType");
+        if (doc != null) {
+            doc.writeJavaDoc(writer, 0);
+        } else if (label != null) {
+            Utils.writeJavaComment(writer, 0, "Represents a " + label);
+        }
+
+        // We use enums for restricted types with a choice:
+        if (isRestricted() && choice != null) {
+            writer.write("public enum " + className);
+        } else {
+            writer.write("public class " + className);
+            if (isPrimitive() || descriptor != null) {
+                writer.write(" extends AmqpType");
+            } else if (isRestricted()) {
+                writer.write(" extends " + resolveRestrictedType().getTypeMapping().getShortName());
+            }
         }
+
         writer.write(" {");
         writer.newLine();
 
         writeConstants(writer);
-        
+
         writeFields(writer);
-        
+
+        writeConstructors(writer);
+
         writeFieldAccesors(writer);
-        
-        writeSerializers(writer); 
-        
+
+        writeSerializers(writer);
+
         writer.write("}");
         writer.flush();
         writer.close();
@@ -132,37 +158,81 @@
 
     private boolean writeImports(BufferedWriter writer, Generator generator) throws IOException, UnknownTypeException {
 
-        HashSet<String> imports = new HashSet<String>();
-
+        TreeSet<String> imports = new TreeSet<String>();
         for (AmqpField field : fields.values()) {
-            imports.add(field.getJavaPackage());
+
+            AmqpClass fieldType = field.resolveAmqpFieldType();
+            filterOrAddImport(imports, fieldType.getTypeMapping());
+            filterOrAddImport(imports, fieldType.resolveValueMapping());
+            if (fieldType.choice != null) {
+                filterOrAddImport(imports, fieldType.resolveBaseTypeMapping());
+            }
+
+            if (fieldType.getName().equals("*")) {
+                imports.add(generator.getPackagePrefix() + ".AmqpMarshaller");
+            }
+        }
+
+        if (isPrimitive() || descriptor != null) {
+
+            imports.add(generator.getPackagePrefix() + ".types.AmqpType");
+            imports.add("java.io.DataOutputStream");
+            imports.add("java.io.DataInputStream");
+            imports.add("java.io.IOException");
         }
 
         if (isPrimitive()) {
-            imports.add(TypeRegistry.getJavaPackage(name));
-            imports.add("java.io");
-            imports.add(generator.getPackagePrefix());
+            filterOrAddImport(imports, resolveValueMapping());
+            //Need the AmqpMarshaller to help with encodings:
+            if (hasNonZeroEncoding() || encodings.size() > 1) {
+                imports.add(generator.getPackagePrefix() + ".AmqpMarshaller");
+            }
+            imports.add("java.io.UnsupportedEncodingException");
         }
 
-        if (descriptor != null) {
-            imports.add(generator.getPackagePrefix());
-            imports.add(generator.getPackagePrefix() + ".types" );
-            imports.add("java.io");
+        if (isRestricted()) {
+            if (choice != null) {
+                imports.add("java.io.UnsupportedEncodingException");
+            }
+            imports.add(TypeRegistry.resolveAmqpClass(restrictedType).getTypeMapping().getImport());
         }
 
-        imports.remove(getJavaPackage());
-        imports.remove("java.lang");
+        if (descriptor != null) {
+            AmqpClass describedType = descriptor.resolveDescribedType();
+            if (describedType.getName().equals("list")) {
+                imports.add("java.util.ArrayList");
+            } else if (describedType.getName().equals("map")) {
+                // Import symbol which is used for the keys:
+                imports.add(TypeRegistry.resolveAmqpClass("symbol").getTypeMapping().getImport());
+            }
+
+            filterOrAddImport(imports, describedType.getTypeMapping());
+            // filterOrAddImport(imports, describedType.resolveValueMapping());
+        }
 
         boolean ret = false;
 
         for (String toImport : imports) {
             ret = true;
-            writer.write("import " + toImport + ".*;");
+            writer.write("import " + toImport + ";");
             writer.newLine();
         }
         return ret;
     }
 
+    private void filterOrAddImport(TreeSet<String> imports, JavaTypeMapping mapping) {
+        if (mapping == null) {
+            return;
+        }
+        if (mapping.getImport() == null) {
+            return;
+        }
+        if (mapping.getPackageName().equals(typeMapping.getPackageName())) {
+            return;
+        }
+        imports.add(mapping.getImport());
+    }
+
     private boolean writeConstants(BufferedWriter writer) throws IOException, UnknownTypeException {
         boolean ret = false;
 
@@ -211,6 +281,18 @@
             writer.newLine();
             writer.write(tab(1) + "};");
             writer.newLine();
+
+            if (descriptor.getDescribedType().equals("map")) {
+                writer.newLine();
+                writer.write(tab(1) + "//Accessor keys for field mapped fields:");
+                writer.newLine();
+                for (AmqpField field : fields.values()) {
+
+                    writer.write(tab(1) + "private static final AmqpSymbol " + toJavaConstant(field.getName()) + "_KEY = " + " new AmqpSymbol(\"" + field.getName() + "\");");
+                    writer.newLine();
+                }
+                writer.newLine();
+            }
         }
 
         // Write out encodings:
@@ -221,12 +303,110 @@
         if (choice != null) {
             ret = true;
             writer.newLine();
-            writer.write(tab(1) + "//Constants:");
+            int i = 0;
+            AmqpClass amqpType = TypeRegistry.resolveAmqpClass(restrictedType);
+            for (Choice constant : choice.choices) {
+                i++;
+                if (constant.getDoc() != null) {
+                    AmqpDoc docs = new AmqpDoc();
+                    for (Doc doc : constant.getDoc()) {
+                        docs.parseFromDoc(doc);
+                    }
+                    docs.writeJavaDoc(writer, 1);
+                }
+
+                writer.write(tab(1) + toJavaConstant(constant.getName()) + "((" + amqpType.resolveValueMapping().getJavaType() + ") " + constant.getValue() + ")");
+                if (i < choice.choices.size()) {
+                    writer.write(",");
+                } else {
+                    writer.write(";");
+                }
+                writer.newLine();
+            }
+
+            writer.newLine();
+            writer.write(tab(1) + "private final " + amqpType.getTypeMapping().getJavaType() + " value = new " + amqpType.getTypeMapping().getJavaType() + "();");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "private " + typeMapping.getShortName() + "(" + amqpType.resolveValueMapping().getJavaType() + " value) {");
+            writer.newLine();
+            writer.write(tab(2) + "this.value.setValue(value);");
             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) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "//TODO: Remove?");
+            writer.newLine();
+            writer.write(tab(1) + "public " + amqpType.getTypeMapping().getJavaType() + " getValue() {");
+            writer.newLine();
+            writer.write(tab(2) + "return value;");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "public static final " + getTypeMapping().getJavaType() + " get(" + amqpType.resolveValueMapping().getJavaType() + " value) throws UnsupportedEncodingException{");
+            if (amqpType.resolveValueMapping().getJavaType().equals("int")) {
                 writer.newLine();
+                writer.write(tab(2) + "switch (value) {");
+                writer.newLine();
+                for (Choice constant : choice.choices) {
+                    writer.write(tab(2) + "case " + constant.getValue() + ": {");
+                    writer.newLine();
+                    writer.write(tab(3) + "return " + toJavaConstant(constant.getName()) + ";");
+                    writer.newLine();
+                    writer.write(tab(2) + "}");
+                    writer.newLine();
+                }
+
+                writer.write(tab(2) + "default: {");
+                writer.newLine();
+                writer.write(tab(3) + "throw new UnsupportedEncodingException();");
+                writer.newLine();
+                writer.write(tab(2) + "}");
+                writer.newLine();
+                writer.write(tab(2) + "}");
+            } else {
+                writer.newLine();
+                i = 0;
+                for (Choice constant : choice.choices) {
+                    writer.write(tab(2));
+                    if (i > 0) {
+                        writer.write("else ");
+                    }
+                    writer.write("if (value == " + constant.getValue() + ") {");
+                    writer.newLine();
+                    writer.write(tab(3) + "return " + toJavaConstant(constant.getName()) + ";");
+                    writer.newLine();
+                    writer.write(tab(2) + "}");
+                    writer.newLine();
+                    i++;
+                }
+
+                writer.write(tab(2) + "else {");
+                writer.newLine();
+                writer.write(tab(3) + "throw new UnsupportedEncodingException();");
+                writer.newLine();
+                writer.write(tab(2) + "}");
             }
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
+            // writer.newLine();
+            // writer.write(tab(1) + "public static final  " +
+            // getTypeMapping().getJavaType() +
+            // " createFromStream(DataInputStream dis) throws IOException {");
+            // writer.newLine();
+            // writer.write(tab(2) + " return get(" +
+            // amqpType.getTypeMapping().getJavaType() +
+            // ".createFromStream(dis)).getValue();");
+            // writer.newLine();
+            // writer.write(tab(1) + "}");
+            // writer.newLine();
+
         }
         return ret;
     }
@@ -236,9 +416,12 @@
             writer.newLine();
             writer.write(tab(1) + "public static final byte FORMAT_CODE = (byte) " + encodings.getFirst().getCode() + ";");
             writer.newLine();
+            writer.write(tab(1) + "public static final FormatSubCategory FORMAT_CATEGORY  = FormatSubCategory.getCategory(FORMAT_CODE);");
+            writer.newLine();
         } else {
+            String encodingName = getEncodingName(false);
             writer.newLine();
-            writer.write(tab(1) + "public static enum " + toJavaConstant(name) + "_ENCODING {");
+            writer.write(tab(1) + "public static enum " + encodingName + " {");
             writer.newLine();
 
             int i = 0;
@@ -250,7 +433,7 @@
                 }
                 eName = toJavaConstant(eName);
 
-                writer.write(tab(2) + eName + " ((byte) " + encoding.getCode() + ", " + encoding.getWidth() + ")");
+                writer.write(tab(2) + eName + " ((byte) " + encoding.getCode() + ")");
                 if (i < encodings.size()) {
                     writer.write(",");
                 } else {
@@ -265,52 +448,67 @@
             }
 
             writer.newLine();
-            writer.write(tab(2) + "private final byte formatCode;");
+            writer.write(tab(2) + "public final byte FORMAT_CODE;");
             writer.newLine();
-            writer.write(tab(2) + "private final int width;");
+            writer.write(tab(2) + "public final FormatSubCategory CATEGORY;");
             writer.newLine();
 
             // Write constructor:
             writer.newLine();
-            writer.write(tab(2) + toJavaConstant(name) + "_ENCODING(byte formatCode, int width) {");
+            writer.write(tab(2) + encodingName + "(byte formatCode) {");
             writer.newLine();
-            writer.write(tab(3) + "this.formatCode = formatCode;");
+            writer.write(tab(3) + "this.FORMAT_CODE = formatCode;");
             writer.newLine();
-            writer.write(tab(3) + "this.width = width;");
+            writer.write(tab(3) + "this.CATEGORY = FormatSubCategory.getCategory(formatCode);");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
 
-            // Write Accessors:
             writer.newLine();
-            writer.write(tab(2) + "public final byte getFormatCode() {");
+            writer.write(tab(2) + "public final int getEncodedSize(" + TypeRegistry.getJavaType(name) + " val) throws IOException {");
+            writer.newLine();
+            writer.write(tab(3) + "if(CATEGORY.WIDTH > 0) {");
+            writer.newLine();
+            writer.write(tab(4) + "return 1 + CATEGORY.WIDTH + AmqpMarshaller.getEncodedSizeOf" + capFirst(toJavaName(name)) + "(val, this);");
             writer.newLine();
-            writer.write(tab(3) + "return formatCode;");
+            writer.write(tab(3) + "}");
+            writer.newLine();
+            writer.write(tab(3) + "return 1;");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public final int getWidth() {");
+            writer.write(tab(2) + "public final int getEncodedCount(" + TypeRegistry.getJavaType(name) + " val) throws IOException {");
             writer.newLine();
-            writer.write(tab(3) + "return width;");
+            if (hasCompoundEncoding() || hasArrayEncoding()) {
+                writer.write(tab(3) + "return AmqpMarshaller.getEncodedCounfOf" + capFirst(toJavaName(name)) + "(val, this);");
+            } else {
+                writer.write(tab(3) + "return 1;");
+            }
             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.write(tab(2) + "public static " + encodingName + " getEncoding(byte formatCode) throws UnsupportedEncodingException {");
             writer.newLine();
-            writer.write(tab(3) + "if(width > 0) {");
+            writer.write(tab(3) + "for(" + encodingName + " e: " + encodingName + ".values()) {");
             writer.newLine();
-            writer.write(tab(4) + "return 1 + width + AmqpMarshaller.getEncodedSizeOf" + capFirst(toJavaName(name)) + "(val, this);");
+            writer.write(tab(4) + "if(e.FORMAT_CODE == formatCode) {");
+            writer.newLine();
+            writer.write(tab(5) + "return e;");
+            writer.newLine();
+            writer.write(tab(4) + "}");
             writer.newLine();
             writer.write(tab(3) + "}");
             writer.newLine();
-            writer.write(tab(3) + "return 1;");
+            writer.write(tab(3) + "throw new UnsupportedEncodingException(\"Unexpected format code for " + capFirst(name) + ": \" + formatCode);");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
+
             writer.write(tab(1) + "}");
             writer.newLine();
         }
@@ -318,27 +516,24 @@
 
     private boolean writeFields(BufferedWriter writer) throws IOException, UnknownTypeException {
         boolean ret = false;
-        
-        if (descriptor != null)
-        {
+
+        if (descriptor != null) {
             ret = true;
-            String encodingType = descriptor.getSymbolicName();
-            encodingType = encodingType.substring(encodingType.lastIndexOf(":") + 1);
-            encodingType = "Amqp" + capFirst(toJavaName(encodingType));
-            
+            String encodingType = TypeRegistry.resolveAmqpClass(descriptor.getDescribedType()).getJavaType();
             writer.newLine();
             writer.write(tab(1) + "private " + encodingType + " value;");
             writer.newLine();
         }
-        
+
         for (AmqpField field : fields.values()) {
             ret = true;
             if (field.getDoc() != null) {
                 // TODO
             }
 
-            String array = field.isMultiple() ? " []" : "";
-            writer.write(tab(1) + "private " + field.getJavaType() + array + " " + field.getJavaName());
+            AmqpClass amqpType = field.resolveAmqpFieldType();
+
+            writer.write(tab(1) + "private " + amqpType.getJavaType() + " " + field.getJavaName());
 
             if (field.getDefaultValue() != null) {
                 writer.write(" = " + field.getDefaultValue());
@@ -364,30 +559,66 @@
         return ret;
     }
 
+    private boolean writeConstructors(BufferedWriter writer) throws IOException, UnknownTypeException {
+        boolean ret = false;
+
+        if (isPrimitive()) {
+            writer.newLine();
+            writer.write(tab(1) + "public " + typeMapping.getShortName() + "() {");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "public " + typeMapping.getShortName() + "(" + valueMapping.getJavaType() + " value) {");
+            writer.newLine();
+            writer.write(tab(2) + "this.value = value;");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            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) {
                 // TODO
             }
 
-            String array = field.isMultiple() ? " []" : "";
+            AmqpClass amqpType = field.resolveAmqpFieldType();
 
             // Setter:
             writer.newLine();
-            writer.write(tab(1) + "public final void set" + capFirst(field.getJavaName()) + "(" + field.getJavaType() + array + " " + toJavaName(field.getName()) + ") {");
+            if (field.getDoc() != null) {
+                field.getDoc().writeJavaDoc(writer, 1);
+            }
+            writer.write(tab(1) + "public final void set" + capFirst(field.getJavaName()) + "(" + amqpType.resolveValueType() + " " + toJavaName(field.getName()) + ") {");
             writer.newLine();
-            writer.write(tab(2) + "this." + field.getJavaName() + " = " + field.getJavaName() + ";");
+            if (amqpType.isPrimitive() && !amqpType.getName().equals("*")) {
+                writer.write(tab(2) + "this." + field.getJavaName() + ".setValue(" + toJavaName(field.getName()) + ");");
+            } else {
+                writer.write(tab(2) + "this." + field.getJavaName() + " = " + toJavaName(field.getName()) + ";");
+            }
             writer.newLine();
             writer.write(tab(1) + "}");
             writer.newLine();
             writer.newLine();
             // Getter:
-            writer.write(tab(1) + "public final " + field.getJavaType() + array + " get" + capFirst(field.getJavaName()) + "() {");
+            if (field.getDoc() != null) {
+                field.getDoc().writeJavaDoc(writer, 1);
+            }
+            writer.write(tab(1) + "public final " + amqpType.resolveValueType() + " get" + capFirst(field.getJavaName()) + "() {");
             writer.newLine();
-            writer.write(tab(2) + "return " + field.getJavaName() + ";");
+            if (amqpType.isPrimitive() && !amqpType.getName().equals("*")) {
+                writer.write(tab(2) + "return " + field.getJavaName() + ".getValue();");
+            } else {
+                writer.write(tab(2) + "return " + field.getJavaName() + ";");
+            }
             writer.newLine();
             writer.write(tab(1) + "}");
             writer.newLine();
@@ -403,6 +634,10 @@
             if (hasMultipleEncodings()) {
                 writer.newLine();
                 writer.write(tab(2) + "this.encoding = null;");
+                writer.newLine();
+                writer.write(tab(2) + "encodedSize = -1;");
+                writer.newLine();
+                writer.write(tab(2) + "encodedCount = -1;");
             }
             writer.newLine();
             writer.write(tab(1) + "}");
@@ -422,82 +657,195 @@
     private boolean writeSerializers(BufferedWriter writer) throws IOException, UnknownTypeException {
         boolean ret = false;
 
+        if (!(isPrimitive() || descriptor != null)) {
+            return false;
+        }
+
+        ret = true;
+
+        writer.newLine();
+        writer.write(tab(1) + "public static final " + typeMapping.javaType + " createFromStream(DataInputStream dis) throws IOException {");
+        writer.newLine();
+        writer.write(tab(2) + typeMapping.javaType + " rc = new " + typeMapping.javaType + "();");
+        writer.newLine();
+        writer.write(tab(2) + "rc.unmarshal(dis);");
+        writer.newLine();
+        writer.write(tab(2) + "return rc;");
+        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) + "marshalConstructor(dos);");
+        writer.newLine();
+        writer.write(tab(2) + "marshalData(dos);");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(1) + "public final void unmarshal(DataInputStream dis) throws IOException {");
+        writer.newLine();
+        writer.write(tab(2) + "unmarshalConstructor(dis);");
+        writer.newLine();
+        writer.write(tab(2) + "unmarshalData(dis);");
+        writer.newLine();
+        writer.write(tab(1) + "}");
+        writer.newLine();
+
         // 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(1) + "public final int getEncodedSize() throws IOException{");
+                writer.newLine();
                 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.write(tab(1) + "public final int getEncodedCount() throws IOException{");
+                writer.newLine();
+                writer.write(tab(2) + "return 1;");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void marshalConstructor(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(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void unmarshalConstructor(DataInputStream dis) throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "byte fc = dis.readByte();");
+                writer.newLine();
+                writer.write(tab(2) + "if(fc != FORMAT_CODE) {");
+                writer.newLine();
+                writer.write(tab(3) + "throw new UnsupportedEncodingException(\"Unexpected format code for " + capFirst(toJavaName(name)) + "\" + fc + \" expected: \" + FORMAT_CODE);");
+                writer.newLine();
+                writer.write(tab(2) + "}");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void marshalData(DataOutputStream dos) throws IOException {");
+                writer.newLine();
+                if (hasNonZeroEncoding()) {
+
                     writer.write(tab(2) + "AmqpMarshaller.write" + capFirst(toJavaName(name)) + "(value, dos);");
-                    writer.newLine();
                 }
+                writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void unmarshalData(DataInputStream dis) throws IOException {");
+                writer.newLine();
+                if (hasNonZeroEncoding()) {
+                    writer.write(tab(2) + "value = AmqpMarshaller.read" + capFirst(toJavaName(name)) + "(dis);");
+                }
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
             } else {
+                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();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final int getEncodedSize() throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "if(encodedSize == -1) {");
+                writer.newLine();
+                writer.write(tab(3) + "chooseEncoding();");
+                writer.newLine();
+                writer.write(tab(3) + "encodedSize = encoding.getEncodedSize(value);");
+                writer.newLine();
+                writer.write(tab(2) + "}");
+                writer.newLine();
+                writer.write(tab(2) + "return encodedSize;");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final int getEncodedCount() throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "if(encodedCount == -1) {");
+                writer.newLine();
+                writer.write(tab(3) + "chooseEncoding();");
+                writer.newLine();
+                writer.write(tab(3) + "encodedCount = encoding.getEncodedCount(value);");
+                writer.newLine();
+                writer.write(tab(2) + "}");
                 writer.newLine();
                 writer.write(tab(2) + "chooseEncoding();");
                 writer.newLine();
-                writer.write(tab(2) + "return encoding.getEncodedSize(value);");
+                writer.write(tab(2) + "return encoding.getEncodedCount(value);");
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "public final void marshal(DataOutputStream dos) throws IOException {");
+                writer.write(tab(1) + "public final void marshalConstructor(DataOutputStream dos) throws IOException {");
                 writer.newLine();
                 writer.write(tab(2) + "chooseEncoding();");
                 writer.newLine();
-                writer.write(tab(2) + "dos.writeByte(encoding.getFormatCode());");
+                writer.write(tab(2) + "dos.writeByte(encoding.FORMAT_CODE);");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void unmarshalConstructor(DataInputStream dis) throws IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "encoding = " + getEncodingName(false) + ".getEncoding(dis.readByte());");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(1) + "public final void marshalData(DataOutputStream dos) throws IOException {");
                 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.write(tab(2) + "encoding.CATEGORY.marshalFormatHeader(this, dos);");
                     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) + "public final void unmarshalData(DataInputStream dis) throws IOException {");
+                if (hasNonZeroEncoding()) {
+                    writer.newLine();
+                    writer.write(tab(2) + "value = AmqpMarshaller.read" + capFirst(toJavaName(name)) + "(encoding, encodedSize, encodedCount, dis);");
+                    writer.newLine();
+                }
                 writer.write(tab(1) + "}");
                 writer.newLine();
-
             }
         }
 
@@ -510,26 +858,118 @@
             writer.newLine();
             writer.write(tab(1) + "}");
             writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "public final int getEncodedCount() throws IOException {");
+            writer.newLine();
+            writer.write(tab(2) + "return 1;");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
             writer.newLine();
-            writer.write(tab(1) + "public final void marshal(DataOutputStream dos) throws IOException {");
+            writer.write(tab(1) + "public final void marshalConstructor(DataOutputStream dos) throws IOException {");
             writer.newLine();
             writer.write(tab(2) + "dos.write(CONSTRUCTOR);");
             writer.newLine();
-            writer.write(tab(2) + "value.marshal(dos);");
+            writer.write(tab(2) + "value.marshalConstructor(dos);");
             writer.newLine();
             writer.write(tab(1) + "}");
             writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "public final void marshalData(DataOutputStream dos) throws IOException {");
+            writer.newLine();
+            writer.write(tab(2) + "value.marshalData(dos);");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "public final void unmarshalConstructor(DataInputStream dos) throws IOException {");
+            writer.newLine();
+            writer.write(tab(2) + "//TODO");
+            writer.newLine();
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(1) + "public final void unmarshalData(DataInputStream dis) throws IOException {");
+            writer.newLine();
+            if (descriptor.getDescribedType().equals("list")) {
+                writer.write(tab(2) + "value = new " + TypeRegistry.resolveAmqpClass(descriptor.getDescribedType()).getJavaType() + "();");
+                writer.newLine();
+                writer.write(tab(2) + "value.setValue(new ArrayList<AmqpType>(" + fields.size() + "));");
+                writer.newLine();
+                writer.newLine();
+                writer.write(tab(2) + "//Deserialize the values and add them to the list:");
+                writer.newLine();
+            } else if (descriptor.getDescribedType().equals("map")) {
+                writer.write(tab(2) + "value = " + TypeRegistry.resolveAmqpClass(descriptor.getDescribedType()).getJavaType() + ".createFromStream(dis);");
+                writer.newLine();
+                writer.newLine();
+                writer.write(tab(2) + "//Get the values from the map:");
+                writer.newLine();
+            } else {
+                throw new UnknownTypeException("Support for " + descriptor.getDescribedType() + " as a described type isn't yet implemented");
+            }
+
+            int f = 0;
+            for (AmqpField field : fields.values()) {
+
+                AmqpClass fieldType = field.resolveAmqpFieldType();
+                if (descriptor.getDescribedType().equals("list")) {
+                    if (fieldType.isRestricted() && fieldType.choice != null) {
+                        writer.write(tab(2) + field.getJavaName() + " = " + fieldType.getJavaType() + ".get(" + fieldType.resolveRestrictedType().getTypeMapping().getShortName()
+                                + ".createFromStream(dis).getValue());");
+                        writer.newLine();
+                        writer.write(tab(2) + "value.getValue().set(" + f + ", " + field.getJavaName() + ".getValue());");
+                    } else if (field.getType().equals("*")) {
+                        writer.newLine();
+                        writer.write(tab(2) + field.getJavaName() + " = " + "AmqpMarshaller.readType(dis);");
+                        writer.newLine();
+                        writer.write(tab(2) + "value.getValue().set(" + f + ", " + field.getJavaName() + ");");
+                        writer.newLine();
+                    } else {
+                        writer.newLine();
+                        writer.write(tab(2) + field.getJavaName() + " = new " + fieldType.getTypeMapping().getShortName() + "();");
+                        writer.newLine();
+                        writer.write(tab(2) + field.getJavaName() + ".unmarshal(dis);");
+                        writer.newLine();
+                        writer.write(tab(2) + "value.getValue().set(" + f + ", " + field.getJavaName() + ");");
+                    }
+                    writer.newLine();
+                } else if (descriptor.getDescribedType().equals("map")) {
+                    if (fieldType.isRestricted() && fieldType.choice != null) {
+                        // e.g. value =
+                        // AmqpDistributionMode.get(((AmqpUint)value.getValue().get(DISTRIBUTION_MODE_KEY)).getValue());
+                        writer.write(tab(2) + field.getJavaName() + " = " + fieldType.getJavaType() + ".get(((" + fieldType.resolveBaseTypeMapping().getJavaType() + ") value.getValue().get("
+                                + toJavaConstant(field.getName()) + "_KEY)).getValue());");
+
+                    } else {
+                        writer.write(tab(2) + field.getJavaName() + " = (" + fieldType.getJavaType() + ") value.getValue().get(" + toJavaConstant(field.getName()) + "_KEY);");
+                    }
+                    writer.newLine();
+                } else {
+                    throw new UnknownTypeException("Support for " + descriptor.getDescribedType() + " as a described type isn't yet implemented");
+                }
+                f++;
+            }
+
+            writer.write(tab(1) + "}");
+            writer.newLine();
+
         }
 
         return ret;
     }
 
     public String getJavaType() {
-        return javaType;
+        return typeMapping.getJavaType();
     }
 
     public String getJavaPackage() {
-        return javaPackage;
+        return typeMapping.getPackageName();
     }
 
     public String getName() {
@@ -552,6 +992,10 @@
         return restrictedType;
     }
 
+    public AmqpClass resolveRestrictedType() throws UnknownTypeException {
+        return TypeRegistry.resolveAmqpClass(restrictedType);
+    }
+
     public void setPrimitive(boolean primitive) {
         this.primitive = primitive;
     }
@@ -588,6 +1032,48 @@
         return false;
     }
 
+    public boolean hasVariableEncoding() {
+        if (encodings == null) {
+            return false;
+        }
+
+        for (AmqpEncoding encoding : encodings) {
+            if (encoding.isVariable()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean hasCompoundEncoding() {
+        if (encodings == null) {
+            return false;
+        }
+
+        for (AmqpEncoding encoding : encodings) {
+            if (encoding.isCompound()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean hasArrayEncoding() {
+        if (encodings == null) {
+            return false;
+        }
+
+        for (AmqpEncoding encoding : encodings) {
+            if (encoding.isArray()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     public String getEncodingName(boolean full) {
         if (full) {
             return getJavaType() + "." + getEncodingName(false);
@@ -596,6 +1082,63 @@
         }
     }
 
+    /**
+     * Resolves the JavaTypeMapping that will be exposed via the class' api.
+     * 
+     * @return
+     * @throws UnknownTypeException
+     */
+    public JavaTypeMapping resolveValueMapping() throws UnknownTypeException {
+        if (valueMapping != null) {
+            return valueMapping;
+        }
+
+        if (isPrimitive()) {
+            valueMapping = TypeRegistry.getJavaTypeMapping(name);
+            return valueMapping;
+        }
+
+        if (descriptor != null) {
+            String encodingType = descriptor.getSymbolicName();
+            encodingType = encodingType.substring(encodingType.lastIndexOf(":") + 1);
+            valueMapping = TypeRegistry.resolveAmqpClass(encodingType).typeMapping;
+            return valueMapping;
+        }
+
+        if (isRestricted()) {
+            return typeMapping;
+        }
+
+        return null;
+    }
+
+    /**
+     * Resolves the TypeMapping of this class' base class
+     * 
+     * @return
+     * @throws UnknownTypeException
+     */
+    public JavaTypeMapping resolveBaseTypeMapping() throws UnknownTypeException {
+        if (isRestricted()) {
+            return TypeRegistry.resolveAmqpClass(restrictedType).typeMapping;
+        } else {
+            // Return the any type:
+            return TypeRegistry.resolveAmqpClass("*").typeMapping;
+        }
+    }
+
+    public JavaTypeMapping getTypeMapping() {
+        return typeMapping;
+    }
+
+    public String resolveValueType() throws UnknownTypeException {
+        if (isRestricted()) {
+            return typeMapping.getJavaType();
+        } else {
+            return TypeRegistry.getJavaType(name);
+        }
+    }
+
     public String toString() {
         String ret = "Class: " + name + " [Encoding=" + encodings + ", Descriptor=" + descriptor + "]\n";
         ret += " Fields:\n";

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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -53,6 +53,14 @@
         this.descriptorId = descriptorId;
     }
 
+    public AmqpClass resolveDescribedType() throws UnknownTypeException {
+        return TypeRegistry.resolveAmqpClass(getDescribedType());
+    }
+
+    public String getDescribedType() {
+        return symbolicName.substring(symbolicName.lastIndexOf(":") + 1);
+    }
+
     public String toString() {
         return "{" + symbolicName + ", code=" + formatCode + "}";
     }

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java?rev=900531&r1=900530&r2=900531&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java Mon Jan 18 20:12:47 2010
@@ -1,12 +1,100 @@
 package org.apache.activemq.amqp.generator;
 
-import org.apache.activemq.amqp.generator.jaxb.schema.Doc;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.activemq.amqp.generator.jaxb.schema.*;
 
 public class AmqpDoc {
 
-    
-    public void parseFromDoc(Doc doc)
-    {
-        //TODO
+    List<Doc> docs = new LinkedList<Doc>();
+
+    public void parseFromDoc(Doc doc) {
+
+        this.docs.add(doc);
+    }
+
+    public void writeJavaDoc(BufferedWriter writer, int indent) throws IOException {
+        String comment = "";
+        for (Doc doc : docs) {
+            for (Object docType : doc.getPOrUlOrOlOrDlOrPicture()) {
+
+                if (docType instanceof P) {
+                    comment += handleP((P) docType);
+                } else if (docType instanceof Ul) {
+                    comment += handleUl((Ul) docType);
+                } else if (docType instanceof Ol) {
+                    comment += handleOl((Ol) docType);
+                } else if (docType instanceof Dl) {
+                    comment += handleDl((Dl) docType);
+                } else if (docType instanceof Picture) {
+                    comment += "\n<pre>\n" + ((Picture) docType).getvalue() + "</pre>\n";
+                }
+            }
+            comment += "\n";
+        }
+
+        if (comment.length() > 0) {
+            Utils.writeJavaComment(writer, indent, Utils.convertToLines(comment, 80));
+        }
+    }
+
+    private static final String handleP(P p) {
+        return "<p>\n" + p.getvalue() + "\n</p>\n";
+    }
+
+    private static final String handleUl(Ul ul) {
+        String comment = "";
+        comment += "<ul>\n";
+        for (Li li : ul.getLi()) {
+            comment += "<li>\n";
+            for (Object uType : li.getPOrUl()) {
+                if (uType instanceof P) {
+                    comment += handleP((P) uType);
+                } else {
+                    comment += handleUl((Ul) uType);
+                }
+            }
+            comment += "<\n></li>\n";
+        }
+        comment += "<\n></ul>\n";
+        return comment;
+    }
+
+    private static final String handleOl(Ol ol) {
+        String comment = "";
+        comment += "<ol>\n";
+        for (Li li : ol.getLi()) {
+            comment += "<li>\n";
+            for (Object uType : li.getPOrUl()) {
+                if (uType instanceof P) {
+                    comment += handleP((P) uType);
+                } else {
+                    comment += handleUl((Ul) uType);
+                }
+            }
+            comment += "\n</li>\n";
+        }
+        comment += "\n</ol>\n";
+        return comment;
+    }
+
+    private static final String handleDl(Dl dl) {
+        String comment = "";
+        comment += "<dl>\n";
+        for (Object dType : dl.getDtOrDd()) {
+            if (dType instanceof Dt) {
+                comment += "<dt>\n" + ((Dt) dType).getvalue() + "\n</dt>\n";
+            } else {
+                for (P p : ((Dd) dType).getP()) {
+                    comment += handleP(p);
+                }
+            }
+        }
+        comment += "\n</dl>\n";
+        return comment;
     }
+
 }

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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -74,6 +74,11 @@
         return "compound".equals(getCategory());
     }
     
+    public boolean isArray()
+    {
+        return "array".equals(getCategory());
+    }
+    
     public String toString() {
         return "{" + name + ", cat=" + category + ", code=" + code + ", width=" + width +"}";
     }

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java?rev=900531&r1=900530&r2=900531&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java Mon Jan 18 20:12:47 2010
@@ -1,11 +1,13 @@
 package org.apache.activemq.amqp.generator;
 
-import org.apache.activemq.amqp.generator.jaxb.schema.*;
-import static org.apache.activemq.amqp.generator.Utils.*;
+import static org.apache.activemq.amqp.generator.Utils.toJavaName;
+
+import org.apache.activemq.amqp.generator.jaxb.schema.Doc;
+import org.apache.activemq.amqp.generator.jaxb.schema.Field;
 
 public class AmqpField {
 
-    String doc;
+    AmqpDoc doc;
     String name;
     String defaultValue;
     String label;
@@ -22,7 +24,14 @@
         type = field.getType();
 
         for (Object object : field.getDocOrException()) {
-            // TODO;
+            if (object instanceof Doc) {
+                if (doc == null) {
+                    doc = new AmqpDoc();
+                }
+                doc.parseFromDoc((Doc) object);
+            } else {
+                // TODO handle exception:
+            }
         }
     }
 
@@ -34,11 +43,11 @@
         this.name = name;
     }
 
-    public String getDoc() {
+    public AmqpDoc getDoc() {
         return doc;
     }
 
-    public void setDoc(String doc) {
+    public void setDoc(AmqpDoc doc) {
         this.doc = doc;
     }
 
@@ -82,14 +91,15 @@
         this.required = required;
     }
 
-    public String getJavaType() throws UnknownTypeException {
-        return TypeRegistry.getJavaType(this);
-    }
-    
-    public String getJavaPackage() throws UnknownTypeException {
-        return TypeRegistry.getJavaPackage(this);
+    public AmqpClass resolveAmqpFieldType() throws UnknownTypeException {
+        if (isMultiple()) {
+            return TypeRegistry.resolveAmqpClass("list");
+        }
+
+        AmqpClass ampqClass = TypeRegistry.resolveAmqpClass(this);
+        return ampqClass;
     }
-    
+
     public String getJavaName() {
         return toJavaName(name);
     }

Modified: 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=900531&r1=900530&r2=900531&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java Mon Jan 18 20:12:47 2010
@@ -1,6 +1,10 @@
 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.tab;
+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.BufferedWriter;
 import java.io.File;
@@ -9,7 +13,7 @@
 import java.util.HashSet;
 
 /**
- * Generates the AMQP marshaller
+ * Generates the AMQPMarshaller template:
  * 
  * @author cmacnaug
  */
@@ -33,7 +37,7 @@
         writeImports(writer, generator);
 
         writer.newLine();
-        writer.write("public abstract class " + MARSHALLER_CLASS_NAME + " {");
+        writer.write("public class " + MARSHALLER_CLASS_NAME + " {");
         writer.newLine();
 
         // Write out encoding enums:
@@ -76,10 +80,13 @@
             if (!c.isPrimitive()) {
                 continue;
             }
+            
             for (AmqpField field : c.fields.values()) {
-                imports.add(field.getJavaPackage());
+                
+                AmqpClass fieldType = field.resolveAmqpFieldType();
+                imports.add(fieldType.resolveValueMapping().getPackageName());
             }
-            imports.add(TypeRegistry.getJavaPackage(c.name));
+            imports.add(c.getTypeMapping().getPackageName());
         }
         imports.add("java.io");
         imports.add(generator.getPackagePrefix() + ".types");
@@ -98,57 +105,71 @@
     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.write(tab(1) + "public static final " + amqpClass.getEncodingName(true) + " choose" + capFirst(amqpClass.name) + "Encoding(" + javaType + " val) throws IOException {");
+            writeUnimplementedMethodBody(writer, 1);
 
             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.write(tab(1) + "public static final int getEncodedSizeOf" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " value, " + amqpClass.getEncodingName(true)
+                    + " encoding) throws IOException {");
+            writeUnimplementedMethodBody(writer, 1);
             writer.newLine();
 
-            boolean hasNonZeroWidthEncoding = false;
-            for (AmqpEncoding encoding : amqpClass.encodings) {
-                if (Integer.parseInt(encoding.getWidth()) > 0) {
-                    hasNonZeroWidthEncoding = true;
-                }
-            }
-            if (hasNonZeroWidthEncoding) {
+            if (amqpClass.hasNonZeroEncoding()) {
                 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.write(tab(1) + "public static final void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, " + amqpClass.getEncodingName(true)
+                        + " encoding, DataOutputStream dos) throws IOException {");
+                writeUnimplementedMethodBody(writer, 1);
 
                 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();
+                if(amqpClass.hasCompoundEncoding() || amqpClass.hasArrayEncoding() ||  amqpClass.hasVariableEncoding())
+                {
+                    writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(" + amqpClass.getEncodingName(true)
+                            + " encoding, int size, int count, DataInputStream dis) throws IOException {");
+                }
+                else {
+                    writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(" + amqpClass.getEncodingName(true)
+                            + " encoding, DataInputStream dis) throws IOException {");
+                }
+                writeUnimplementedMethodBody(writer, 1);
             }
         } else {
             AmqpEncoding encoding = amqpClass.encodings.getFirst();
             // Don't need a serializer if the width is 0:
-            if (new Integer(encoding.getWidth()) > 0) {
+            if (amqpClass.hasNonZeroEncoding()) {
 
                 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.write(tab(1) + "public static final void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, DataOutputStream dos) throws IOException {");
+                writeUnimplementedMethodBody(writer, 1);
 
                 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();
+                if (amqpClass.hasNonFixedEncoding()) {
+                    writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(int size, int count, DataInputStream dis) throws IOException {");
+                } else {
+                    writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(DataInputStream dis) throws IOException {");
+                }
+                writeUnimplementedMethodBody(writer, 1);
+                
             }
         }
-
     }
+    
+    private static void writeUnimplementedMethodBody(BufferedWriter writer, int indent) throws IOException
+    {
+        writer.newLine();
+        writer.write(tab(indent + 1) + "//TODO: Implement");
+        writer.newLine();
+        writer.write(tab(indent + 1) + "throw new UnsupportedOperationException(\"not implemented\");");
+        writer.newLine();
+        writer.write(tab(indent) + "}");
+    }
+    
 }

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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -1,15 +1,11 @@
 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.FileReader;
 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;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.SAXParserFactory;
@@ -19,21 +15,16 @@
 import org.apache.activemq.amqp.generator.jaxb.schema.Amqp;
 import org.apache.activemq.amqp.generator.jaxb.schema.Section;
 import org.apache.activemq.amqp.generator.jaxb.schema.Type;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
 public class Generator {
 
-    private Log LOG = LogFactory.getLog(Generator.class);
-
     private String[] inputFiles;
     private String outputDirectory;
+    private String sourceDirectory;
     private String packagePrefix;
 
-    private TypeRegistry typeRegistry = new TypeRegistry();
-
     public String[] getInputFile() {
         return inputFiles;
     }
@@ -50,6 +41,10 @@
         this.outputDirectory = outputDirectory;
     }
 
+    public void setSourceDirectory(String sourceDirectory) {
+        this.sourceDirectory = sourceDirectory;
+    }
+    
     public String getPackagePrefix() {
         return packagePrefix;
     }
@@ -73,8 +68,7 @@
             // Amqp amqp = (Amqp) unmarshaller.unmarshal(new StreamSource(new
             // 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) {
@@ -90,17 +84,19 @@
         }
 
         // 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");
+        String handCodedSource = "org/apache/activemq/amqp/generator/handcoded";
+        String outputPackage = packagePrefix.replace(".", File.separator);
+        File sourceDir = new File(sourceDirectory + File.separator + handCodedSource);
+        for (File javaFile : Utils.findFiles(sourceDir)) {
+            javaFile.setWritable(true);
+            BufferedReader reader = new BufferedReader(new FileReader(javaFile));
+            File out = new File(outputDirectory + File.separator + outputPackage + File.separator + javaFile.getCanonicalPath().substring((int)sourceDir.getCanonicalPath().length()));
             out.getParentFile().mkdirs();
+            String line = reader.readLine();
             BufferedWriter writer = new BufferedWriter(new FileWriter(out));
 
             while (line != null) {
+                line = line.replace("org.apache.activemq.amqp.generator.handcoded", packagePrefix);
                 writer.write(line);
                 writer.newLine();
                 line = reader.readLine();
@@ -122,4 +118,6 @@
         TypeRegistry.addType(amqpClass);
         System.out.println("Found: " + amqpClass);
     }
+
+    
 }

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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -1,6 +1,5 @@
 package org.apache.activemq.amqp.generator;
 
-import javax.xml.bind.JAXBException;
 
 public class Main {
 
@@ -10,6 +9,7 @@
                 "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.v1pr2");
         gen.setOutputDirectory("C:/dev/fuse/amq6.0/activemq-amqp-generator/src/main/java");
+        gen.setSourceDirectory("C:/dev/fuse/amq6.0/activemq-amqp-generator/src/handcoded");
         try {
             gen.generate();
         } catch (Exception e) {

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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -9,69 +9,68 @@
     private static final HashMap<String, AmqpClass> GENERATED_TYPE_MAP = new HashMap<String, AmqpClass>();
 
     static {
-        JAVA_TYPE_MAP.put("boolean", new JavaTypeMapping("boolean", "boolean", "java.lang"));
-        JAVA_TYPE_MAP.put("ubyte", new JavaTypeMapping("ubyte", "short", "java.lang"));
-        JAVA_TYPE_MAP.put("ushort", new JavaTypeMapping("ushort", "int", "java.lang"));
-        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "long", "java.lang"));
-        JAVA_TYPE_MAP.put("ulong", new JavaTypeMapping("ulong", "BigInteger", "java.math"));
-        JAVA_TYPE_MAP.put("byte", new JavaTypeMapping("byte", "byte", "java.lang"));
-        JAVA_TYPE_MAP.put("short", new JavaTypeMapping("short", "short", "java.lang"));
-        JAVA_TYPE_MAP.put("int", new JavaTypeMapping("int", "int", "java.lang"));
-        JAVA_TYPE_MAP.put("long", new JavaTypeMapping("long", "long", "java.lang"));
-        JAVA_TYPE_MAP.put("float", new JavaTypeMapping("float", "float", "java.lang"));
-        JAVA_TYPE_MAP.put("double", new JavaTypeMapping("double", "double", "java.lang"));
-        JAVA_TYPE_MAP.put("char", new JavaTypeMapping("char", "char", "java.lang"));
-        JAVA_TYPE_MAP.put("timestamp", new JavaTypeMapping("timestamp", "Date", "java.util"));
-        JAVA_TYPE_MAP.put("uuid", new JavaTypeMapping("uuid", "UUID", "java.util"));
-        JAVA_TYPE_MAP.put("byte", new JavaTypeMapping("byte", "byte", "java.lang"));
-        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 <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"));
+        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("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("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("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("null", new JavaTypeMapping("null", "java.lang.Object"));
 
     }
 
     static final void init(Generator generator) {
         // 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:
+        AmqpClass any = new AmqpType("*", generator.getPackagePrefix() + ".types.AmqpType");
+        GENERATED_TYPE_MAP.put("*", any);
+        JAVA_TYPE_MAP.put("*", any.typeMapping);
     }
 
-    public static String getJavaType(AmqpField field) throws UnknownTypeException {
-        return getJavaType(field.getType());
+    public static JavaTypeMapping getJavaTypeMapping(String name) throws UnknownTypeException {
+        JavaTypeMapping mapping = JAVA_TYPE_MAP.get(name);
+        if (mapping == null) {
+            // Try to find a class that defines it:
+            AmqpClass amqpClass = GENERATED_TYPE_MAP.get(name);
+            if (amqpClass != null) {
+                mapping = amqpClass.typeMapping;
+            }
+            if (mapping == null) {
+                throw new UnknownTypeException(name);
+            }
+        }
+        return mapping;
     }
 
-    public static String getJavaType(String type) throws UnknownTypeException {
+    public static AmqpClass resolveAmqpClass(AmqpField amqpField) throws UnknownTypeException {
+        return resolveAmqpClass(amqpField.getType());
+    }
+
+    public static AmqpClass resolveAmqpClass(String type) throws UnknownTypeException {
         AmqpClass amqpClass = GENERATED_TYPE_MAP.get(type);
         if (amqpClass == null) {
             throw new UnknownTypeException("Type " + type + " not found");
         }
-
-        // Replace with restricted type:
-        if (amqpClass.isRestricted()) {
-            return getJavaType(amqpClass.getRestrictedType());
-        }
-
-        if (amqpClass.isPrimitive()) {
-            JavaTypeMapping mapping = JAVA_TYPE_MAP.get(amqpClass.getName());
-            if (mapping == null) {
-                throw new UnknownTypeException("Primitive Type " + type + " not found");
-            }
-            return mapping.javaType;
-        }
-
-        return amqpClass.getJavaType();
+        return amqpClass;
     }
 
-    public static String getJavaPackage(AmqpField field) throws UnknownTypeException {
-        return getJavaPackage(field.getType());
+    public static String getJavaType(AmqpField field) throws UnknownTypeException {
+        return getJavaType(field.getType());
     }
 
-    public static String getJavaPackage(String type) throws UnknownTypeException {
+    public static String getJavaType(String type) throws UnknownTypeException {
         AmqpClass amqpClass = GENERATED_TYPE_MAP.get(type);
         if (amqpClass == null) {
             throw new UnknownTypeException("Type " + type + " not found");
@@ -79,7 +78,7 @@
 
         // Replace with restricted type:
         if (amqpClass.isRestricted()) {
-            return getJavaPackage(amqpClass.getRestrictedType());
+            return getJavaType(amqpClass.getRestrictedType());
         }
 
         if (amqpClass.isPrimitive()) {
@@ -87,9 +86,10 @@
             if (mapping == null) {
                 throw new UnknownTypeException("Primitive Type " + type + " not found");
             }
-            return mapping.javaPackage;
+            return mapping.javaType;
         }
-        return amqpClass.getJavaPackage();
+
+        return amqpClass.getJavaType();
     }
 
     public static Collection<AmqpClass> getGeneratedTypes() {
@@ -102,37 +102,108 @@
 
     public static class JavaTypeMapping {
 
-        String name;
+        String amqpType;
+        String shortName;
+        String packageName;
+        String fullName;
         String javaType;
-        String javaPackage;
 
-        JavaTypeMapping(String name, String javaType, String javaPackage) {
-            this.name = name;
+        boolean array;
+        String generic;
+
+        JavaTypeMapping(String amqpType, String fullName, boolean array, String generic) {
+            this(amqpType, fullName);
+            this.array = array;
+            this.generic = generic;
+            if (generic != null) {
+                javaType = javaType + generic;
+            }
+            if (array) {
+                javaType = javaType + " []";
+            }
+        }
+
+        JavaTypeMapping(String amqpType, String fullName) {
+            this.amqpType = amqpType;
+            this.fullName = fullName;
+            this.packageName = fullName.substring(0, fullName.lastIndexOf("."));
+            this.shortName = fullName.substring(fullName.lastIndexOf(".") + 1);
+            this.javaType = shortName;
+        }
+
+        public String getAmqpType() {
+            return amqpType;
+        }
+
+        public void setAmqpType(String amqpType) {
+            this.amqpType = amqpType;
+        }
+
+        public String getShortName() {
+            return shortName;
+        }
+
+        public void setShortName(String shortName) {
+            this.shortName = shortName;
+        }
+
+        public String getPackageName() {
+            return packageName;
+        }
+
+        public void setPackageName(String packageName) {
+            this.packageName = packageName;
+        }
+
+        public String getFullName() {
+            return fullName;
+        }
+
+        public void setFullName(String fullName) {
+            this.fullName = fullName;
+        }
+
+        public String getJavaType() {
+            return javaType;
+        }
+
+        public void setJavaType(String javaType) {
             this.javaType = javaType;
-            this.javaPackage = javaPackage;
         }
-    }
 
-    public static class AnyClass extends AmqpClass {
+        public boolean isArray() {
+            return array;
+        }
 
-        AnyClass(String name, String javaType, String javaPackage) {
-            super.name = name;
-            super.javaType = javaType;
-            super.setPrimitive(true);
-            super.javaPackage = javaPackage;
-            super.handcoded = true;
+        public void setArray(boolean array) {
+            this.array = array;
+        }
+
+        public String getGeneric() {
+            return generic;
+        }
+
+        public void setGeneric(String generic) {
+            this.generic = generic;
+        }
+
+        public String getImport() {
+            if (packageName.startsWith("java.lang")) {
+                return null;
+            } else {
+                return fullName;
+            }
         }
     }
-    
-    public static class CompoundType extends AmqpClass {
 
-        CompoundType(String name, String javaType, String javaPackage) {
-            super.name = name;
-            super.javaType = javaType;
+    public static class AmqpType extends AmqpClass {
+
+        AmqpType(String amqpName, String fullName) {
+            super.typeMapping = new JavaTypeMapping(amqpName, fullName);
+            super.name = amqpName;
             super.setPrimitive(true);
-            super.javaPackage = javaPackage;
+            super.handcoded = true;
         }
     }
-    
-    
+
 }

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/UnknownTypeException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/UnknownTypeException.java?rev=900531&r1=900530&r2=900531&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/UnknownTypeException.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/UnknownTypeException.java Mon Jan 18 20:12:47 2010
@@ -2,6 +2,8 @@
 
 public class UnknownTypeException extends Exception {
 
+    private static final long serialVersionUID = 4106181403332534392L;
+
     public UnknownTypeException(String message) {
         super(message);
     }

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=900531&r1=900530&r2=900531&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 Mon Jan 18 20:12:47 2010
@@ -1,7 +1,10 @@
 package org.apache.activemq.amqp.generator;
 
 import java.io.BufferedWriter;
+import java.io.File;
 import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.StringTokenizer;
 
 public class Utils {
@@ -62,37 +65,25 @@
         }
         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)
-        {
+
+        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)
-        {
+        for (String s : commentLines) {
             writer.write(tab(indent) + " * " + s);
             writer.newLine();
         }
@@ -100,4 +91,55 @@
         writer.newLine();
     }
 
+    public static String[] convertToLines(String s, int charsPerLine) {
+        LinkedList<String> rc = new LinkedList<String>();
+        String line = "";
+        StringTokenizer lines = new StringTokenizer(s, "\r\n");
+        while (lines.hasMoreElements()) {
+            StringTokenizer tok = new StringTokenizer(lines.nextToken(), " ");
+            int chars = 0;
+
+            while (tok.hasMoreTokens()) {
+                String word = tok.nextToken();
+                chars += word.length();
+                if (chars > charsPerLine) {
+                    if (line.length() == 0) {
+                        rc.add(word);
+                    } else {
+                        rc.add(line);
+                        line = word;
+                        chars = word.length();
+                        continue;
+                    }
+                }
+
+                if (line.length() > 0) {
+                    line += " ";
+                }
+
+                line += word;
+
+            }
+            if (line.length() > 0) {
+                rc.add(line);
+            }
+            line = "";
+        }
+
+        return rc.toArray(new String[] {});
+    }
+
+    public static final List<File> findFiles(File dir) {
+        LinkedList<File> rc = new LinkedList<File>();
+        for (File file : dir.listFiles()) {
+            if (file.isFile()) {
+                rc.add(file);
+            } else {
+                rc.addAll(findFiles(file));
+            }
+        }
+        
+        return rc;
+    }
+
 }



Mime
View raw message