activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r946684 [1/2] - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/ main/java/org/apache/activemq/amqp/generator/
Date Thu, 20 May 2010 16:13:58 GMT
Author: cmacnaug
Date: Thu May 20 16:13:58 2010
New Revision: 946684

URL: http://svn.apache.org/viewvc?rev=946684&view=rev
Log:
Changes to encoder to better deal with lists and map (still some issues here though)

Modified:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/Encoder.java
    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/AmqpField.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

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/Encoder.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/Encoder.java?rev=946684&r1=946683&r2=946684&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/Encoder.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/Encoder.java Thu May 20 16:13:58 2010
@@ -48,7 +48,8 @@ public class Encoder extends BaseEncoder
 
     static final byte NULL_FORMAT_CODE = AmqpNullMarshaller.FORMAT_CODE;
     static final byte DESCRIBED_FORMAT_CODE = (byte) 0x00;
-
+    static final NullEncoded<?> NULL_ENCODED = new NullEncoded<Object>();
+    
     public static interface ListDecoder<E extends AmqpType<?, ?>> {
         public IAmqpList<E> decode(EncodedBuffer[] constituents) throws AmqpEncodingError;
 
@@ -1049,6 +1050,12 @@ public class Encoder extends BaseEncoder
         public abstract void marshalData(DataOutput out) throws IOException;
     }
 
+    @SuppressWarnings("unchecked")
+    static final <V> Encoded<V> getNullEncoded()
+    {
+        return (Encoded<V>) NULL_ENCODED;
+    }
+    
     static class NullEncoded<V> extends AbstractEncoded<V> {
 
         private static FixedBuffer nb = new FixedBuffer(new Buffer(new byte[] { NULL_FORMAT_CODE }), 0);

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=946684&r1=946683&r2=946684&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 May 20 16:13:58 2010
@@ -45,14 +45,19 @@ public class AmqpClass {
     LinkedHashMap<String, AmqpField> fields = new LinkedHashMap<String, AmqpField>();
     public boolean handcoded;
 
+    boolean mappingsResolved = false;
     // Java mapping for this class:
     protected TypeRegistry.JavaTypeMapping typeMapping;
     // Java mapping of the value that this type holds (if any)
+    protected AmqpClass valueType;
     protected TypeRegistry.JavaTypeMapping valueMapping;
     // Java mapping of the bean for this type (if any)
     protected TypeRegistry.JavaTypeMapping beanMapping;
     // Java mapping of the buffer for this type (if any)
     protected TypeRegistry.JavaTypeMapping bufferMapping;
+    // Java mapping of the type that this extends (if any)
+    protected AmqpClass baseType;
+    protected TypeRegistry.JavaTypeMapping baseMapping;
 
     protected String mapKeyType = "AmqpType<?,?>";
     protected String mapValueType = "AmqpType<?,?>";
@@ -108,17 +113,11 @@ public class AmqpClass {
             this.restricted = true;
         }
 
-        typeMapping = new JavaTypeMapping(name, generator.getPackagePrefix() + ".types." + "Amqp" + capFirst(toJavaName(name)));
+        typeMapping = new JavaTypeMapping(name, generator.getPackagePrefix() + ".types", "Amqp" + capFirst(toJavaName(name)));
 
         if (isMarshallable()) {
-            beanMapping = new JavaTypeMapping(name + "-bean", generator.getPackagePrefix() + ".types", typeMapping + "." + typeMapping + "Bean", true);
-            bufferMapping = new JavaTypeMapping(name + "-bean", generator.getPackagePrefix() + ".types", typeMapping + "." + typeMapping + "Buffer", true);
-        }
-
-        if (isPrimitive()) {
-            valueMapping = TypeRegistry.getJavaTypeMapping(name);
-        } else if (isRestricted()) {
-            valueMapping = typeMapping;
+            beanMapping = new JavaTypeMapping(name + "-bean", generator.getPackagePrefix() + ".types", typeMapping + "." + typeMapping + "Bean");
+            bufferMapping = new JavaTypeMapping(name + "-bean", generator.getPackagePrefix() + ".types", typeMapping + "." + typeMapping + "Buffer");
         }
     }
 
@@ -127,6 +126,8 @@ public class AmqpClass {
             return;
         }
 
+        resolveMappings();
+
         File file = new File(generator.getOutputDirectory() + File.separator + new String(typeMapping.getFullName()).replace(".", File.separator) + ".java");
         file.getParentFile().mkdirs();
         if (file.exists()) {
@@ -146,7 +147,7 @@ public class AmqpClass {
         } else if (label != null) {
             writeJavaComment(writer, 0, "Represents a " + label);
         }
-        
+
         Utils.writeAutoGeneratedWarning(writer, 0);
 
         // We use enums for restricted types with a choice:
@@ -154,16 +155,14 @@ public class AmqpClass {
             writer.write("public enum " + typeMapping);
         } else if (isMarshallable()) {
 
-            if (isRestricted()) {
-                writer.write("public interface " + typeMapping + " extends " + resolveRestrictedType().getTypeMapping());
-            } else if (isDescribed()) {
-                writer.write("public interface " + typeMapping + " extends " + descriptor.resolveDescribedType().getTypeMapping());
+            if (isRestricted() || isDescribed()) {
+                writer.write("public interface " + typeMapping + " extends " + baseMapping);
             } else {
-                writer.write("public interface " + typeMapping + " extends AmqpType<" + beanMapping + ", " + bufferMapping + ">");
+                writer.write("public interface " + typeMapping + " extends AmqpType<" + beanMapping.parameterized() + ", " + bufferMapping.parameterized() + ">");
             }
 
             if (isList() || isMap()) {
-                writer.write(", " + valueMapping.getJavaType());
+                writer.write(", " + valueMapping);
             }
 
             if (isCommand()) {
@@ -208,7 +207,7 @@ public class AmqpClass {
                 if (!marshaller) {
                     filterOrAddImport(imports, fieldType.getTypeMapping(), marshaller);
                 }
-                filterOrAddImport(imports, fieldType.resolveBaseType().getTypeMapping(), marshaller);
+                filterOrAddImport(imports, fieldType.getBaseType().getTypeMapping(), marshaller);
             } else {
                 filterOrAddImport(imports, fieldType.getTypeMapping(), marshaller);
             }
@@ -279,7 +278,7 @@ public class AmqpClass {
 
             imports.add(getValueMapping().getImport());
 
-            if (resolveBaseType().isList()) {
+            if (getBaseType().isList()) {
                 imports.add("java.util.Iterator");
             }
 
@@ -287,7 +286,7 @@ public class AmqpClass {
                 imports.add("java.util.ArrayList");
             }
 
-            if (resolveBaseType().isMap()) {
+            if (getBaseType().isMap()) {
                 imports.add("java.util.Iterator");
                 imports.add("java.util.Map");
                 imports.add("java.util.HashMap");
@@ -474,7 +473,7 @@ public class AmqpClass {
                     if (fieldType.isAny()) {
                         writer.write(tab(4) + "rc.set(" + f + ", AmqpMarshaller.SINGLETON.unmarshalType(in));");
                     } else {
-                        writer.write(tab(4) + "rc.set(" + f + ", " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller() + ".createEncoded(in)));");
+                        writer.write(tab(4) + "rc.set(" + f + ", " + fieldType.getBufferMapping().getClassName() + ".create(" + fieldType.getMarshaller() + ".createEncoded(in)));");
                     }
                     writer.newLine();
                     writer.write(tab(4) + "dataCount--;");
@@ -522,7 +521,7 @@ public class AmqpClass {
                     if (fieldType.isAny()) {
                         writer.write(tab(4) + "rc.set(" + f + ", AmqpMarshaller.SINGLETON.decodeType(constituents[" + f + "]));");
                     } else {
-                        writer.write(tab(4) + "rc.set(" + f + ", " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller() + ".createEncoded(constituents[" + f + "])));");
+                        writer.write(tab(4) + "rc.set(" + f + ", " + fieldType.getBufferMapping().getClassName() + ".create(" + fieldType.getMarshaller() + ".createEncoded(constituents[" + f + "])));");
                     }
                     writer.newLine();
                     writer.write(tab(4) + "dataCount--;");
@@ -591,11 +590,11 @@ public class AmqpClass {
                         writer.write(tab(5) + "saw" + capFirst(field.getName()) + " = true;");
                         writer.newLine();
                     }
-                    
+
                     if (fieldType.isAny()) {
                         writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(constituents[i + 1]));");
                     } else {
-                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
+                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping().getClassName() + ".create(" + fieldType.getMarshaller()
                                 + ".createEncoded(constituents[i + 1])));");
                     }
                     writer.newLine();
@@ -667,7 +666,7 @@ public class AmqpClass {
                     if (fieldType.isAny()) {
                         writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(in));");
                     } else {
-                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
+                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping().getClassName() + ".create(" + fieldType.getMarshaller()
                                 + ".createEncoded(in)));");
                     }
                     writer.newLine();
@@ -704,7 +703,7 @@ public class AmqpClass {
             }
 
             writer.newLine();
-            writer.write(tab(1) + "public static class " + getJavaType() + "Encoded extends DescribedEncoded<" + getValueMapping() + "> {");
+            writer.write(tab(1) + "public static class " + getJavaType() + "Encoded extends DescribedEncoded<" + getValueMapping().parameterized() + "> {");
             writer.newLine();
 
             writer.newLine();
@@ -716,7 +715,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public " + getJavaType() + "Encoded(" + typeMapping + " value) {");
+            writer.write(tab(2) + "public " + getJavaType() + "Encoded(" + typeMapping.parameterized() + " value) {");
             writer.newLine();
             writer.write(tab(3) + "super(" + describedType.getMarshaller() + ".encode(value));");
             writer.newLine();
@@ -740,7 +739,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "protected final Encoded<" + getValueMapping() + "> decodeDescribed(EncodedBuffer encoded) throws AmqpEncodingError {");
+            writer.write(tab(2) + "protected final Encoded<" + getValueMapping().parameterized() + "> decodeDescribed(EncodedBuffer encoded) throws AmqpEncodingError {");
             writer.newLine();
             writer.write(tab(3) + "return " + describedType.getMarshaller() + ".createEncoded(encoded, DECODER);");
             writer.newLine();
@@ -748,7 +747,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "protected final Encoded<" + getValueMapping() + "> unmarshalDescribed(DataInput in) throws IOException {");
+            writer.write(tab(2) + "protected final Encoded<" + getValueMapping().parameterized() + "> unmarshalDescribed(DataInput in) throws IOException {");
             writer.newLine();
             writer.write(tab(3) + "return " + describedType.getMarshaller() + ".createEncoded(in, DECODER);");
             writer.newLine();
@@ -780,7 +779,7 @@ public class AmqpClass {
             // writer.newLine();
 
             writer.newLine();
-            writer.write(tab(1) + "public static class " + getJavaType() + "Encoded  extends AbstractEncoded<" + getValueMapping().getJavaType() + "> {");
+            writer.write(tab(1) + "public static class " + getJavaType() + "Encoded  extends AbstractEncoded<" + getValueMapping().parameterized() + "> {");
             writer.newLine();
 
             writer.newLine();
@@ -792,7 +791,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public " + getJavaType() + "Encoded (" + getValueMapping().getJavaType() + " value) throws AmqpEncodingError {");
+            writer.write(tab(2) + "public " + getJavaType() + "Encoded (" + getValueMapping().parameterized() + " value) throws AmqpEncodingError {");
             writer.newLine();
             writer.write(tab(3) + "super(FORMAT_CODE, value);");
             writer.newLine();
@@ -800,7 +799,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public final void encode(" + getValueMapping().getJavaType() + " value, Buffer encoded, int offset) throws AmqpEncodingError{");
+            writer.write(tab(2) + "public final void encode(" + getValueMapping().parameterized() + " value, Buffer encoded, int offset) throws AmqpEncodingError{");
             writer.newLine();
             if (hasNonZeroEncoding()) {
                 writer.write(tab(3) + "ENCODER.encode" + capFirst(toJavaName(name)) + "(value, encoded, offset);");
@@ -810,7 +809,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " decode(EncodedBuffer encoded) throws AmqpEncodingError{");
+            writer.write(tab(2) + "public final " + getValueMapping().parameterized() + " decode(EncodedBuffer encoded) throws AmqpEncodingError{");
             writer.newLine();
             if (hasNonZeroEncoding()) {
                 writer.write(tab(3) + "return ENCODER.decode" + capFirst(toJavaName(name)) + "(encoded.getBuffer(), encoded.getDataOffset());");
@@ -832,7 +831,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " unmarshalData(DataInput in) throws IOException {");
+            writer.write(tab(2) + "public final " + getValueMapping().parameterized() + " unmarshalData(DataInput in) throws IOException {");
             writer.newLine();
             if (hasNonZeroEncoding()) {
                 writer.write(tab(3) + "return ENCODER.read" + capFirst(toJavaName(name)) + "(in);");
@@ -939,14 +938,14 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "static final " + getJavaType() + "Encoded createEncoded(EncodedBuffer buffer) throws AmqpEncodingError {");
+            writer.write(tab(2) + "static final " + getTypeMapping().getGeneric(" ") + getJavaType() + "Encoded " + getTypeMapping().parameterized().getGeneric("") + "createEncoded(EncodedBuffer buffer) throws AmqpEncodingError {");
             writer.newLine();
             writer.write(tab(3) + "switch(buffer.getEncodingFormatCode()) {");
             writer.newLine();
             for (AmqpEncoding encoding : encodings) {
                 writer.write(tab(3) + "case " + toJavaConstant(encoding.getName()) + "_FORMAT_CODE: {");
                 writer.newLine();
-                writer.write(tab(4) + "return new " + getJavaType() + capFirst(toJavaName(encoding.getName())) + "Encoded(buffer);");
+                writer.write(tab(4) + "return new " + getJavaType() + capFirst(toJavaName(encoding.getName())) + "Encoded" + getTypeMapping().parameterized().getGeneric("") + "(buffer);");
                 writer.newLine();
                 writer.write(tab(3) + "}");
                 writer.newLine();
@@ -962,14 +961,14 @@ public class AmqpClass {
             writer.write(tab(2) + "}");
             writer.newLine();
 
-            writer.write(tab(2) + "static final " + getJavaType() + "Encoded createEncoded(byte formatCode, " + getValueMapping().getJavaType() + " value) throws AmqpEncodingError {");
+            writer.write(tab(2) + "static final " + getTypeMapping().getGeneric(" ") + getJavaType() + "Encoded" + getTypeMapping().parameterized().getGeneric("") + " createEncoded(byte formatCode, " + getValueMapping().parameterized() + " value) throws AmqpEncodingError {");
             writer.newLine();
             writer.write(tab(3) + "switch(formatCode) {");
             writer.newLine();
             for (AmqpEncoding encoding : encodings) {
                 writer.write(tab(3) + "case " + toJavaConstant(encoding.getName()) + "_FORMAT_CODE: {");
                 writer.newLine();
-                writer.write(tab(4) + "return new " + getJavaType() + capFirst(toJavaName(encoding.getName())) + "Encoded(value);");
+                writer.write(tab(4) + "return new " + getJavaType() + capFirst(toJavaName(encoding.getName())) + "Encoded" + getValueMapping().parameterized().getGeneric("") + "(value);");
                 writer.newLine();
                 writer.write(tab(3) + "}");
                 writer.newLine();
@@ -988,16 +987,16 @@ public class AmqpClass {
             writer.write(tab(1) + "}");
             writer.newLine();
 
-            writer.write(tab(1) + "public static abstract class " + getJavaType() + "Encoded extends AbstractEncoded <" + getValueMapping().getJavaType() + "> {");
+            writer.write(tab(1) + "public static abstract class " + getJavaType() + "Encoded" + typeMapping.getGeneric("") + " extends AbstractEncoded <" + getValueMapping().parameterized() + "> {");
             if (isList()) {
                 writer.newLine();
-                writer.write(tab(2) + "ListDecoder decoder = Encoder.DEFAULT_LIST_DECODER;");
+                writer.write(tab(2) + "ListDecoder<V> decoder;");
                 writer.newLine();
             }
 
             if (isMap()) {
                 writer.newLine();
-                writer.write(tab(2) + "MapDecoder decoder = Encoder.DEFAULT_MAP_DECODER;");
+                writer.write(tab(2) + "MapDecoder<K, V> decoder;");
                 writer.newLine();
             }
 
@@ -1010,7 +1009,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(2) + "public " + getJavaType() + "Encoded(byte formatCode, " + getValueMapping().getJavaType() + " value) throws AmqpEncodingError {");
+            writer.write(tab(2) + "public " + getJavaType() + "Encoded(byte formatCode, " + getValueMapping().parameterized() + " value) throws AmqpEncodingError {");
             writer.newLine();
             writer.write(tab(3) + "super(formatCode, value);");
             writer.newLine();
@@ -1019,7 +1018,7 @@ public class AmqpClass {
 
             if (isList()) {
                 writer.newLine();
-                writer.write(tab(2) + "final void setDecoder(ListDecoder decoder) {");
+                writer.write(tab(2) + "final void setDecoder(ListDecoder<V> decoder) {");
                 writer.newLine();
                 writer.write(tab(3) + "this.decoder = decoder;");
                 writer.newLine();
@@ -1029,7 +1028,7 @@ public class AmqpClass {
 
             if (isMap()) {
                 writer.newLine();
-                writer.write(tab(2) + "final void setDecoder(MapDecoder decoder) {");
+                writer.write(tab(2) + "final void setDecoder(MapDecoder<K, V> decoder) {");
                 writer.newLine();
                 writer.write(tab(3) + "this.decoder = decoder;");
                 writer.newLine();
@@ -1045,7 +1044,7 @@ public class AmqpClass {
 
                 writer.newLine();
                 writeJavaComment(writer, 1, encoding.getLabel());
-                writer.write(tab(1) + "private static class " + getJavaType() + eName + "Encoded extends " + getJavaType() + "Encoded {");
+                writer.write(tab(1) + "private static class " + getJavaType() + eName + "Encoded " + typeMapping.getGeneric(" ") + "extends " + getJavaType() + "Encoded" + typeMapping.parameterized().getGeneric("") + " {");
                 writer.newLine();
                 writer.newLine();
                 writer.write(tab(2) + "private final " + encodingName + " encoding = " + encodingName + "." + toJavaConstant(encoding.getName()) + ";");
@@ -1059,7 +1058,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public " + getJavaType() + eName + "Encoded(" + getValueMapping().getJavaType() + " value) throws AmqpEncodingError {");
+                writer.write(tab(2) + "public " + getJavaType() + eName + "Encoded(" + getValueMapping().parameterized() + " value) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(3) + "super(" + encodingName + "." + toJavaConstant(encoding.getName()) + ".FORMAT_CODE, value);");
                 writer.newLine();
@@ -1087,7 +1086,7 @@ public class AmqpClass {
                 }
 
                 writer.newLine();
-                writer.write(tab(2) + "public final void encode(" + getValueMapping().getJavaType() + " value, Buffer encoded, int offset) throws AmqpEncodingError {");
+                writer.write(tab(2) + "public final void encode(" + getValueMapping().parameterized() + " value, Buffer encoded, int offset) throws AmqpEncodingError {");
                 writer.newLine();
                 if (hasNonZeroEncoding()) {
                     writer.write(tab(3) + "ENCODER.encode" + capFirst(toJavaName(name)) + eName + "(value, encoded, offset);");
@@ -1107,7 +1106,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " decode(EncodedBuffer encoded) throws AmqpEncodingError {");
+                writer.write(tab(2) + "public final " + getValueMapping().parameterized() + " decode(EncodedBuffer encoded) throws AmqpEncodingError {");
                 writer.newLine();
                 if (isList() || isMap()) {
                     writer.write(tab(3) + "return decoder.decode(encoded.asCompound().constituents());");
@@ -1124,7 +1123,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " unmarshalData(DataInput in) throws IOException {");
+                writer.write(tab(2) + "public final " + getValueMapping().parameterized() + " unmarshalData(DataInput in) throws IOException {");
                 writer.newLine();
 
                 if (isList() || isMap()) {
@@ -1151,10 +1150,8 @@ public class AmqpClass {
 
         for (AmqpField field : fields.values()) {
             ret = true;
-            AmqpClass fieldClass = field.resolveAmqpFieldType();
-            JavaTypeMapping valueType = fieldClass.getTypeMapping();
 
-            writer.write(tab(indent) + "private " + valueType + " " + field.getJavaName());
+            writer.write(tab(indent) + "private " + field.resolveAccessorMapping().parameterized() + " " + field.getJavaName());
 
             if (field.getDefaultValue() != null) {
                 writer.write(" = " + field.getDefaultValue());
@@ -1164,19 +1161,17 @@ public class AmqpClass {
             writer.newLine();
         }
 
-        if (isDescribed()) {
-            AmqpClass describedType = descriptor.resolveDescribedType();
-            if (!describedType.isList()) {
-                describedType.writeFields(writer, indent);
+        if (baseType != this) {
+            if (baseType.isMap()) {
+                writer.write(tab(indent) + "private " + getValueMapping().parameterized() + " value;");
+                writer.newLine();
+            } else if (!baseType.isList()) {
+                baseType.writeFields(writer, indent);
             }
         }
 
-        if (isRestricted()) {
-            resolveRestrictedType().writeFields(writer, indent);
-        }
-
         if (isPrimitive()) {
-            writer.write(tab(indent) + "private " + getValueMapping().getJavaType() + " value;");
+            writer.write(tab(indent) + "private " + getValueMapping().parameterized() + " value;");
             writer.newLine();
         }
         return ret;
@@ -1184,16 +1179,16 @@ public class AmqpClass {
 
     private void writeBeanImpl(BufferedWriter writer, int indent) throws IOException, UnknownTypeException {
 
-        AmqpClass baseType = resolveBaseType();
+        AmqpClass baseType = getBaseType();
 
         writer.newLine();
-        writer.write(tab(indent++) + "public static class " + beanMapping.getShortName() + " implements " + typeMapping + "{");
+        writer.write(tab(indent++) + "public static class " + beanMapping.shortName() + " implements " + typeMapping.parameterized() + "{");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "private " + bufferMapping.getShortName() + " buffer;");
+        writer.write(tab(indent) + "private " + bufferMapping.shortName().parameterized() + " buffer;");
         writer.newLine();
-        writer.write(tab(indent) + "private " + beanMapping.getShortName() + " bean = this;");
+        writer.write(tab(indent) + "private " + beanMapping.shortName().parameterized() + " bean = this;");
         writer.newLine();
         writeFields(writer, indent);
 
@@ -1201,14 +1196,14 @@ public class AmqpClass {
         // Allow creation of unitialized mutable types:
         if (isMutable()) {
             writer.newLine();
-            writer.write(tab(indent) + "" + beanMapping.getShortName() + "() {");
+            writer.write(tab(indent) + "" + beanMapping.shortName().nonGeneric() + "() {");
             writer.newLine();
             if (baseType.isMap()) {
                 writer.write(tab(indent + 1) + "this.value = new IAmqpMap.AmqpWrapperMap<" + getMapKeyType() + "," + getMapValueType() + ">(new HashMap<" + getMapKeyType() + "," + getMapValueType()
                         + ">());");
                 writer.newLine();
             } else if (!isDescribed() && baseType.isList()) {
-                writer.write(tab(indent + 1) + "this.value = new IAmqpList.AmqpWrapperList(new ArrayList<AmqpType<?,?>>());");
+                writer.write(tab(indent + 1) + "this.value = new IAmqpList.AmqpWrapperList<V>(new ArrayList<V>());");
                 writer.newLine();
             }
             writer.write(tab(indent) + "}");
@@ -1216,7 +1211,7 @@ public class AmqpClass {
         }
 
         writer.newLine();
-        writer.write(tab(indent) + beanMapping.getShortName() + "(" + baseType.getValueMapping().getJavaType() + " value) {");
+        writer.write(tab(indent) + beanMapping.shortName().nonGeneric() + "(" + getValueMapping().parameterized() + " value) {");
         writer.newLine();
         if (isDescribed() && baseType.isList()) {
             writer.newLine();
@@ -1233,7 +1228,7 @@ public class AmqpClass {
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + beanMapping.getShortName() + "(" + beanMapping + " other) {");
+        writer.write(tab(indent) + beanMapping.shortName().nonGeneric() + "(" + beanMapping.parameterized() + " other) {");
         writer.newLine();
         writer.write(tab(indent + 1) + "this.bean = other;");
         writer.newLine();
@@ -1243,10 +1238,10 @@ public class AmqpClass {
 
         // METHODS:
         writer.newLine();
-        writer.write(tab(indent) + "public final " + beanMapping.getShortName() + " copy() {");
+        writer.write(tab(indent) + "public final " + beanMapping.shortName().parameterized() + " copy() {");
         writer.newLine();
         if (isMutable()) {
-            writer.write(tab(++indent) + "return new " + beanMapping + "(bean);");
+            writer.write(tab(++indent) + "return new " + beanMapping.parameterized() + "(bean);");
         } else {
             writer.write(tab(++indent) + "return bean;");
         }
@@ -1265,11 +1260,11 @@ public class AmqpClass {
         }
 
         writer.newLine();
-        writer.write(tab(indent) + "public final " + bufferMapping + " getBuffer(AmqpMarshaller marshaller) throws AmqpEncodingError{");
+        writer.write(tab(indent) + "public final " + bufferMapping.shortName().parameterized() + " getBuffer(AmqpMarshaller marshaller) throws AmqpEncodingError{");
         writer.newLine();
         writer.write(tab(++indent) + "if(buffer == null) {");
         writer.newLine();
-        writer.write(tab(++indent) + "buffer = new " + bufferMapping.getShortName() + "(marshaller.encode(this));");
+        writer.write(tab(++indent) + "buffer = new " + bufferMapping.shortName().nonGeneric() + "(marshaller.encode(this));");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
@@ -1311,7 +1306,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "private final void copy(" + beanMapping + " other) {");
+            writer.write(tab(indent) + "private final void copy(" + beanMapping.parameterized() + " other) {");
             writer.newLine();
             indent++;
 
@@ -1341,20 +1336,20 @@ public class AmqpClass {
         writer.write(tab(--indent) + "}");
         writer.newLine();
         writer.newLine();
-        writer.write(tab(indent) + "if(o == null || !(o instanceof " + typeMapping + ")) {");
+        writer.write(tab(indent) + "if(o == null || !(o instanceof " + typeMapping.wildcard() + ")) {");
         writer.newLine();
         writer.write(tab(++indent) + "return false;");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
         writer.newLine();
-        writer.write(tab(indent) + "return equals((" + typeMapping + ") o);");
+        writer.write(tab(indent) + "return equals((" + typeMapping.wildcard() + ") o);");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent++) + "public boolean equals(" + typeMapping + " b) {");
+        writer.write(tab(indent++) + "public boolean equals(" + typeMapping.parameterized() + " b) {");
         writer.newLine();
         if (isDescribed()) {
             for (AmqpField field : fields.values()) {
@@ -1412,7 +1407,7 @@ public class AmqpClass {
         } else {
             writer.write(tab(++indent) + "if(getValue() == null) {");
             writer.newLine();
-            writer.write(tab(++indent) + "return " + beanMapping + ".class.hashCode();");
+            writer.write(tab(++indent) + "return " + beanMapping.shortName().nonGeneric() + ".class.hashCode();");
             writer.newLine();
             writer.write(tab(--indent) + "}");
             writer.newLine();
@@ -1429,19 +1424,19 @@ public class AmqpClass {
 
     private void writeBufferImpl(BufferedWriter writer, int indent) throws IOException, UnknownTypeException {
         if (isDescribed()) {
-            AmqpClass describedType = descriptor.resolveDescribedType();
 
             writer.newLine();
-            writer.write(tab(indent++) + "public static class " + bufferMapping.getClassName() + " extends " + describedType.bufferMapping + " implements " + typeMapping + "{");
+            writer.write(tab(indent++) + "public static class " + bufferMapping.shortName() + " extends " + baseType.bufferMapping.parameterized(baseMapping.getGenerics()).parameterized()
+                    + " implements " + typeMapping.parameterized() + "{");
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "private " + beanMapping.getShortName() + " bean;");
+            writer.write(tab(indent) + "private " + beanMapping.shortName().nonGeneric() + " bean;");
             writer.newLine();
 
             // CONSTRUCTORS:
             writer.newLine();
-            writer.write(tab(indent) + "protected " + bufferMapping.getShortName() + "(Encoded<" + getValueMapping() + "> encoded) {");
+            writer.write(tab(indent) + "protected " + bufferMapping.shortName().nonGeneric() + "(Encoded<" + getValueMapping() + "> encoded) {");
             writer.newLine();
             writer.write(tab(++indent) + "super(encoded);");
             writer.newLine();
@@ -1451,24 +1446,25 @@ public class AmqpClass {
         } else if (isPrimitive()) {
 
             writer.newLine();
-            writer.write(tab(indent++) + "public static class " + bufferMapping.getShortName() + " implements " + typeMapping + ", AmqpBuffer< " + getValueMapping() + "> {");
+            writer.write(tab(indent++) + "public static class " + bufferMapping.shortName() + " implements " + typeMapping.parameterized() + ", AmqpBuffer<" + getValueMapping().parameterized()
+                    + "> {");
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "private " + beanMapping.getShortName() + " bean;");
+            writer.write(tab(indent) + "private " + beanMapping.shortName().parameterized() + " bean;");
             writer.newLine();
-            writer.write(tab(indent) + "protected Encoded<" + valueMapping + "> encoded;");
+            writer.write(tab(indent) + "protected Encoded<" + valueMapping.parameterized() + "> encoded;");
             writer.newLine();
 
             // CONSTRUCTORS:
             writer.newLine();
-            writer.write(tab(indent) + "protected " + bufferMapping.getShortName() + "() {");
+            writer.write(tab(indent) + "protected " + bufferMapping.shortName().nonGeneric() + "() {");
             writer.newLine();
             writer.write(tab(indent) + "}");
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "protected " + bufferMapping.getShortName() + "(Encoded<" + getValueMapping() + "> encoded) {");
+            writer.write(tab(indent) + "protected " + bufferMapping.shortName().nonGeneric() + "(Encoded<" + getValueMapping().parameterized() + "> encoded) {");
             writer.newLine();
             writer.write(tab(++indent) + "this.encoded = encoded;");
             writer.newLine();
@@ -1476,7 +1472,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "public final Encoded<" + getValueMapping() + "> getEncoded() throws AmqpEncodingError{");
+            writer.write(tab(indent) + "public final Encoded<" + getValueMapping().parameterized() + "> getEncoded() throws AmqpEncodingError{");
             writer.newLine();
             writer.write(tab(++indent) + "return encoded;");
             writer.newLine();
@@ -1492,19 +1488,19 @@ public class AmqpClass {
             writer.newLine();
 
         } else if (isRestricted()) {
-            AmqpClass restrictedType = resolveRestrictedType();
 
             writer.newLine();
-            writer.write(tab(indent++) + "public static class " + bufferMapping.getShortName() + " extends " + restrictedType.bufferMapping + " implements " + typeMapping + "{");
+            writer.write(tab(indent++) + "public static class " + bufferMapping.shortName().parameterized() + " extends "
+                    + baseType.bufferMapping.parameterized(baseMapping.getGenerics()).parameterized() + " implements " + typeMapping + "{");
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "private " + beanMapping.getShortName() + " bean;");
+            writer.write(tab(indent) + "private " + beanMapping.shortName().parameterized() + " bean;");
             writer.newLine();
 
             // CONSTRUCTORS:
             writer.newLine();
-            writer.write(tab(indent) + "protected " + bufferMapping.getShortName() + "() {");
+            writer.write(tab(indent) + "protected " + bufferMapping.shortName().nonGeneric() + "() {");
             writer.newLine();
             writer.write(tab(++indent) + "super();");
             writer.newLine();
@@ -1512,7 +1508,7 @@ public class AmqpClass {
             writer.newLine();
 
             writer.newLine();
-            writer.write(tab(indent) + "protected " + bufferMapping.getShortName() + "(Encoded<" + restrictedType.getValueMapping() + "> encoded) {");
+            writer.write(tab(indent) + "protected " + bufferMapping.shortName().nonGeneric() + "(Encoded<" + getValueMapping().parameterized() + "> encoded) {");
             writer.newLine();
             writer.write(tab(++indent) + "super(encoded);");
             writer.newLine();
@@ -1524,7 +1520,7 @@ public class AmqpClass {
         writeFieldAccesors(writer, indent, true);
 
         writer.newLine();
-        writer.write(tab(indent) + "public " + bufferMapping + " getBuffer(AmqpMarshaller marshaller) throws AmqpEncodingError{");
+        writer.write(tab(indent) + "public " + bufferMapping.shortName().parameterized() + " getBuffer(AmqpMarshaller marshaller) throws AmqpEncodingError{");
         writer.newLine();
         writer.write(tab(++indent) + "return this;");
         writer.newLine();
@@ -1532,11 +1528,11 @@ public class AmqpClass {
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "protected " + typeMapping + " bean() {");
+        writer.write(tab(indent) + "protected " + typeMapping.shortName().parameterized() + " bean() {");
         writer.newLine();
         writer.write(tab(++indent) + "if(bean == null) {");
         writer.newLine();
-        writer.write(tab(++indent) + "bean = new " + beanMapping + "(encoded.getValue());");
+        writer.write(tab(++indent) + "bean = new " + beanMapping.shortName().parameterized() + "(encoded.getValue());");
         writer.newLine();
         writer.write(tab(indent) + "bean.buffer = this;");
         writer.newLine();
@@ -1568,7 +1564,7 @@ public class AmqpClass {
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "public boolean equals(" + typeMapping + " o){");
+        writer.write(tab(indent) + "public boolean equals(" + typeMapping.wildcard() + " o){");
         writer.newLine();
         writer.write(tab(++indent) + "return bean().equals(o);");
         writer.newLine();
@@ -1585,7 +1581,7 @@ public class AmqpClass {
 
         // Factory methods:
         writer.newLine();
-        writer.write(tab(indent) + "public static " + bufferMapping + " create(Encoded<" + getEncodedType().valueMapping + "> encoded) {");
+        writer.write(tab(indent) + "public static " + bufferMapping.getGeneric(" ") + bufferMapping.parameterized() + " create(Encoded<" + getValueMapping().parameterized() + "> encoded) {");
         writer.newLine();
         writer.write(tab(++indent) + "if(encoded.isNull()) {");
         writer.newLine();
@@ -1593,23 +1589,29 @@ public class AmqpClass {
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
-        writer.write(tab(indent) + "return new " + bufferMapping + "(encoded);");
+        writer.write(tab(indent) + "return new " + bufferMapping.parameterized() + "(encoded);");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "public static " + bufferMapping + " create(DataInput in, AmqpMarshaller marshaller) throws IOException, AmqpEncodingError {");
+        writer.write(tab(indent) + "public static " + bufferMapping.getGeneric(" ") + bufferMapping.shortName().parameterized()
+                + " create(DataInput in, AmqpMarshaller marshaller) throws IOException, AmqpEncodingError {");
         writer.newLine();
-        writer.write(tab(++indent) + "return create(marshaller.unmarshal" + getEncodedType().typeMapping + "(in));");
+        writer.write(tab(++indent) + "Encoded<" + getValueMapping().parameterized() + "> e = marshaller.unmarshal" + baseMapping.shortName().nonGeneric() + "(in);");
+        writer.newLine();
+        writer.write(tab(indent) + "return create(e);");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "public static " + bufferMapping + " create(Buffer buffer, int offset, AmqpMarshaller marshaller) throws AmqpEncodingError {");
+        writer.write(tab(indent) + "public static " + bufferMapping.getGeneric(" ") + bufferMapping.shortName().parameterized()
+                + " create(Buffer buffer, int offset, AmqpMarshaller marshaller) throws AmqpEncodingError {");
+        writer.newLine();
+        writer.write(tab(++indent) + "Encoded<" + getValueMapping().parameterized() + "> e = marshaller.decode" + baseMapping.shortName().nonGeneric() + "(buffer, offset);");
         writer.newLine();
-        writer.write(tab(++indent) + "return create(marshaller.decode" + getEncodedType().typeMapping + "(buffer, offset));");
+        writer.write(tab(indent) + "return create(e);");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
@@ -1626,14 +1628,14 @@ public class AmqpClass {
             ret = true;
 
             AmqpClass fieldClass = field.resolveAmqpFieldType();
-            AmqpClass baseType = fieldClass.resolveBaseType();
+            AmqpClass fieldBaseType = fieldClass.getBaseType();
 
             if (!buffer) {
 
                 // Setters:
-                if (baseType.isPrimitive() && !baseType.isAny() && !fieldClass.isEnumType() && !baseType.isDescribed() && !baseType.isMutable()) {
+                if (fieldBaseType.isPrimitive() && !fieldBaseType.isAny() && !fieldClass.isEnumType() && !fieldBaseType.isDescribed() && !fieldBaseType.isMutable()) {
                     writer.newLine();
-                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.valueMapping + " " + toJavaName(field.getName()) + ") {");
+                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldBaseType.getValueMapping().parameterized() + " " + toJavaName(field.getName()) + ") {");
                     writer.newLine();
                     writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(TypeFactory.create" + fieldClass.getJavaType() + "(" + toJavaName(field.getName()) + "));");
                     writer.newLine();
@@ -1641,11 +1643,13 @@ public class AmqpClass {
                     writer.newLine();
                     writer.newLine();
 
-                    if (baseType.getValueMapping().hasPrimitiveType()) {
+                    if (fieldBaseType.getValueMapping().hasPrimitiveType()) {
                         writer.newLine();
-                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.getValueMapping().getPrimitiveType() + " " + toJavaName(field.getName()) + ") {");
+                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldBaseType.getValueMapping().getPrimitiveType() + " " + toJavaName(field.getName())
+                                + ") {");
                         writer.newLine();
-                        writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(TypeFactory.create" + fieldClass.getJavaType() + "(" + toJavaName(field.getName()) + "));");
+                        writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(TypeFactory.create" + fieldClass.getTypeMapping().nonGeneric() + "(" + toJavaName(field.getName())
+                                + "));");
                         writer.newLine();
                         writer.write(tab(--indent) + "}");
                         writer.newLine();
@@ -1653,8 +1657,10 @@ public class AmqpClass {
                     }
                 }
 
+                JavaTypeMapping returnType = field.resolveAccessorMapping().parameterized();
+
                 writer.newLine();
-                writer.write(tab(indent) + "public final void set" + capFirst(field.getJavaName()) + "(" + fieldClass.typeMapping + " " + toJavaName(field.getName()) + ") {");
+                writer.write(tab(indent) + "public final void set" + capFirst(field.getJavaName()) + "(" + returnType + " " + toJavaName(field.getName()) + ") {");
                 writer.newLine();
                 writer.write(tab(++indent) + "copyCheck();");
                 writer.newLine();
@@ -1665,10 +1671,12 @@ public class AmqpClass {
                 writer.newLine();
 
                 // Getter:
-                JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
+                if (fieldClass.isPrimitive() && !field.isMultiple() && !fieldClass.isMutable()) {
+                    returnType = fieldClass.getValueMapping().parameterized();
+                }
                 writer.write(tab(indent) + "public final " + returnType + " get" + capFirst(field.getJavaName()) + "() {");
                 writer.newLine();
-                if (!fieldClass.isAny() && fieldClass.isPrimitive() && !fieldClass.isMutable()) {
+                if (!fieldClass.isAny() && fieldClass.isPrimitive() && !fieldClass.isMutable() && !field.isMultiple()) {
                     writer.write(tab(++indent) + "return bean." + field.getJavaName() + ".getValue();");
                 } else {
                     writer.write(tab(++indent) + "return bean." + field.getJavaName() + ";");
@@ -1679,18 +1687,19 @@ public class AmqpClass {
             } else {
 
                 // Setters:
-                if (baseType.isPrimitive() && !baseType.isAny() && !fieldClass.isEnumType() && !baseType.isDescribed() && !baseType.isMutable()) {
+                if (fieldBaseType.isPrimitive() && !fieldBaseType.isAny() && !fieldClass.isEnumType() && !fieldBaseType.isDescribed() && !fieldBaseType.isMutable()) {
                     writer.newLine();
-                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.getValueMapping() + " " + toJavaName(field.getName()) + ") {");
+                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldBaseType.getValueMapping() + " " + toJavaName(field.getName()) + ") {");
                     writer.newLine();
                     writer.write(tab(++indent) + "bean().set" + capFirst(field.getJavaName()) + "(" + toJavaName(field.getName()) + ");");
                     writer.newLine();
                     writer.write(tab(--indent) + "}");
                     writer.newLine();
 
-                    if (baseType.getValueMapping().hasPrimitiveType()) {
+                    if (fieldBaseType.getValueMapping().hasPrimitiveType()) {
                         writer.newLine();
-                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.getValueMapping().getPrimitiveType() + " " + toJavaName(field.getName()) + ") {");
+                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldBaseType.getValueMapping().getPrimitiveType() + " " + toJavaName(field.getName())
+                                + ") {");
                         writer.newLine();
                         writer.write(tab(++indent) + "bean().set" + capFirst(field.getJavaName()) + "(" + toJavaName(field.getName()) + ");");
                         writer.newLine();
@@ -1699,17 +1708,22 @@ public class AmqpClass {
                         writer.newLine();
                     }
                 }
+
+                JavaTypeMapping returnType = field.resolveAccessorMapping().parameterized();
                 writer.newLine();
-                writer.write(tab(indent) + "public final void set" + capFirst(field.getJavaName()) + "(" + fieldClass.getTypeMapping() + " " + toJavaName(field.getName()) + ") {");
+                writer.write(tab(indent) + "public final void set" + capFirst(field.getJavaName()) + "(" + returnType.parameterized() + " " + toJavaName(field.getName()) + ") {");
                 writer.newLine();
                 writer.write(tab(++indent) + "bean().set" + capFirst(field.getJavaName()) + "(" + toJavaName(field.getName()) + ");");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
+
+                if (fieldClass.isPrimitive() && !field.isMultiple() && !fieldClass.isMutable()) {
+                    returnType = fieldClass.getValueMapping().parameterized();
+                }
                 // Getter:
-                JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
                 writer.newLine();
-                writer.write(tab(indent) + "public final " + returnType + " get" + capFirst(field.getJavaName()) + "() {");
+                writer.write(tab(indent) + "public final " + returnType.parameterized() + " get" + capFirst(field.getJavaName()) + "() {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().get" + capFirst(field.getJavaName()) + "();");
                 writer.newLine();
@@ -1718,7 +1732,7 @@ public class AmqpClass {
             }
         }
 
-        if (isMap()) {
+        if (isMap() || baseType.isMap()) {
             if (!buffer) {
                 writer.write(tab(indent) + "public void put(" + getMapKeyType() + " key, " + getMapValueType() + " value) {");
                 writer.newLine();
@@ -1789,7 +1803,7 @@ public class AmqpClass {
         } else if (isList()) {
             if (!buffer) {
                 writer.newLine();
-                writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value) {");
+                writer.write(tab(indent) + "public void set(int index, V value) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "copyCheck();");
                 writer.newLine();
@@ -1799,7 +1813,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(int index) {");
+                writer.write(tab(indent) + "public V get(int index) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean.value.get(index);");
                 writer.newLine();
@@ -1815,16 +1829,16 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<" + TypeRegistry.any().typeMapping + "> iterator() {");
+                writer.write(tab(indent) + "public Iterator<V> iterator() {");
                 writer.newLine();
-                writer.write(tab(++indent) + "return new AmqpListIterator<" + TypeRegistry.any().typeMapping + ">(bean.value);");
+                writer.write(tab(++indent) + "return new AmqpListIterator<V>(bean.value);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
 
             } else {
                 writer.newLine();
-                writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value) {");
+                writer.write(tab(indent) + "public void set(int index, V value) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "bean().set(index, value);");
                 writer.newLine();
@@ -1832,7 +1846,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(int index) {");
+                writer.write(tab(indent) + "public V get(int index) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().get(index);");
                 writer.newLine();
@@ -1848,7 +1862,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<" + TypeRegistry.any().typeMapping + "> iterator() {");
+                writer.write(tab(indent) + "public Iterator<V> iterator() {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().iterator();");
                 writer.newLine();
@@ -1858,8 +1872,8 @@ public class AmqpClass {
 
         }
 
-        if (isDescribed()) {
-            if (descriptor.resolveDescribedType().isList() && !buffer) {
+        if (isDescribed() && baseType.isList()) {
+            if (!buffer) {
 
                 writer.newLine();
                 writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value) {");
@@ -1874,7 +1888,7 @@ public class AmqpClass {
                     if (fieldClass.isEnumType()) {
                         writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(" + fieldClass.typeMapping + ".get((" + fieldClass.resolveRestrictedType().typeMapping + ")value));");
                     } else {
-                        writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "((" + fieldClass.typeMapping + ") value);");
+                        writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "((" + field.resolveAccessorMapping().parameterized() + ") value);");
                     }
                     writer.newLine();
                     writer.write(tab(indent) + "break;");
@@ -1941,27 +1955,49 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + descriptor.resolveDescribedType().getValueMapping() + " getValue() {");
+                writer.write(tab(indent) + "public Iterator<AmqpType<?, ?>> iterator() {");
                 writer.newLine();
-                writer.write(tab(++indent) + "return bean;");
+                writer.write(tab(++indent) + "return new AmqpListIterator<" + TypeRegistry.any().typeMapping + ">(bean);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
 
+            } else {
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<AmqpType<?, ?>> iterator() {");
+                writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value) {");
                 writer.newLine();
-                writer.write(tab(++indent) + "return new AmqpListIterator<" + TypeRegistry.any().typeMapping + ">(bean);");
+                writer.write(tab(++indent) + "bean().set(index, value);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
 
-            } else {
-                descriptor.resolveDescribedType().writeFieldAccesors(writer, indent, buffer);
+                writer.newLine();
+                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(int index) {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean().get(index);");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(indent) + "public int getListCount() {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean().getListCount();");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(indent) + "public Iterator<" + TypeRegistry.any().typeMapping + "> iterator() {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean().iterator();");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
             }
         }
 
-        if (isRestricted()) {
+        if (isRestricted() && !baseType.isMap()) {
             resolveRestrictedType().writeFieldAccesors(writer, indent, buffer);
         }
 
@@ -1992,7 +2028,7 @@ public class AmqpClass {
         if (isDescribed()) {
 
             // Write out symbol constants
-            if (resolveBaseType().isMap()) {
+            if (getBaseType().isMap()) {
                 writer.newLine();
                 for (AmqpField field : fields.values()) {
 
@@ -2010,7 +2046,7 @@ public class AmqpClass {
             for (AmqpField field : fields.values()) {
 
                 AmqpClass fieldClass = field.resolveAmqpFieldType();
-                AmqpClass baseType = fieldClass.resolveBaseType();
+                AmqpClass baseType = fieldClass.getBaseType();
 
                 if (baseType.isPrimitive() && !baseType.isAny() && !fieldClass.isEnumType() && !baseType.isDescribed() && !baseType.isMutable()) {
                     // Setter:
@@ -2030,13 +2066,16 @@ public class AmqpClass {
                 }
 
                 // Setters:
+                JavaTypeMapping returnType = field.resolveAccessorMapping().parameterized();
+
                 writer.newLine();
                 field.writeJavaDoc(writer, indent);
-                writer.write(tab(1) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldClass.typeMapping + " " + toJavaName(field.getName()) + ");");
+                writer.write(tab(1) + "public void set" + capFirst(field.getJavaName()) + "(" + returnType + " " + toJavaName(field.getName()) + ");");
                 writer.newLine();
 
-                // Getter:
-                JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
+                if (fieldClass.isPrimitive() && !field.isMultiple() && !fieldClass.isMutable()) {
+                    returnType = fieldClass.getValueMapping().parameterized();
+                }
                 writer.newLine();
                 field.writeJavaDoc(writer, indent);
                 writer.write(tab(indent) + "public " + returnType + " get" + capFirst(field.getJavaName()) + "();");
@@ -2053,9 +2092,9 @@ public class AmqpClass {
 
         } else if (isList()) {
             doc.writeJavaDoc(writer, indent);
-            writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value);");
+            writer.write(tab(indent) + "public void set(int index, V value);");
             writer.newLine();
-            writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(int index);");
+            writer.write(tab(indent) + "public V get(int index);");
             writer.newLine();
             writer.write(tab(indent) + "public int getListCount();");
             writer.newLine();
@@ -2064,7 +2103,7 @@ public class AmqpClass {
         if (isPrimitive() && !isMutable()) {
             // Getter:
             writer.newLine();
-            writer.write(tab(1) + "public " + valueMapping + " getValue();");
+            writer.write(tab(1) + "public " + valueMapping.parameterized() + " getValue();");
             writer.newLine();
         }
     }
@@ -2093,15 +2132,13 @@ public class AmqpClass {
 
         // Write out the descriptor (for compound types):
         if (descriptor != null) {
-            writer.write("public class " + typeMapping.getShortName() + "Marshaller implements DescribedTypeMarshaller<" + typeMapping + ">{");
+            writer.write("public class " + typeMapping.shortName().nonGeneric() + "Marshaller implements DescribedTypeMarshaller<" + typeMapping + ">{");
             writer.newLine();
 
             writer.newLine();
             writer.write(tab(1) + "static final " + typeMapping + "Marshaller SINGLETON = new " + typeMapping + "Marshaller();");
             writer.newLine();
-            writer.write(tab(1) + "private static final Encoded<" + getValueMapping() + "> NULL_ENCODED = new Encoder.NullEncoded<" + getValueMapping() + ">();");
-            writer.newLine();
-
+            
             writer.newLine();
             writer.write(tab(1) + "public static final String SYMBOLIC_ID = \"" + descriptor.getSymbolicName() + "\";");
             writer.newLine();
@@ -2152,7 +2189,7 @@ public class AmqpClass {
             writeEncodings(writer);
 
             writer.newLine();
-            writer.write(tab(1) + "public static final Encoded<" + getValueMapping() + "> encode(" + typeMapping + " value) throws AmqpEncodingError {");
+            writer.write(tab(1) + "public static final Encoded<" + getValueMapping() + "> encode(" + typeMapping.parameterized() + " value) throws AmqpEncodingError {");
             writer.newLine();
             writer.write(tab(2) + "return new " + typeMapping.getJavaType() + "Encoded(value);");
             writer.newLine();
@@ -2182,7 +2219,7 @@ public class AmqpClass {
             writer.newLine();
             writer.write(tab(2) + "if (fc == Encoder.NULL_FORMAT_CODE) {");
             writer.newLine();
-            writer.write(tab(3) + "return NULL_ENCODED;");
+            writer.write(tab(3) + "return Encoder.getNullEncoded();");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
@@ -2216,15 +2253,12 @@ public class AmqpClass {
         // Add accessors for primitive encoded sizes:
         else if (isPrimitive()) {
 
-            writer.write("public class " + typeMapping.getShortName() + "Marshaller {");
+            writer.write("public class " + typeMapping.shortName().nonGeneric() + "Marshaller {");
             writer.newLine();
 
             writer.newLine();
             writer.write(tab(1) + "private static final Encoder ENCODER = Encoder.SINGLETON;");
             writer.newLine();
-            writer.write(tab(1) + "private static final Encoded<" + getValueMapping() + "> NULL_ENCODED = new Encoder.NullEncoded<" + getValueMapping() + ">();");
-
-            writer.newLine();
 
             writeEncodings(writer);
 
@@ -2232,11 +2266,11 @@ public class AmqpClass {
             // Handle fixed width encodings:
             if (!hasMultipleEncodings() && !hasNonFixedEncoding()) {
                 writer.newLine();
-                writer.write(tab(1) + "public static final Encoded<" + getValueMapping() + "> encode(" + getJavaType() + " data) throws AmqpEncodingError {");
+                writer.write(tab(1) + "public static final Encoded<" + getValueMapping().parameterized() + "> encode(" + typeMapping.parameterized() + " data) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "if(data == null) {");
                 writer.newLine();
-                writer.write(tab(3) + "return NULL_ENCODED;");
+                writer.write(tab(3) + "return Encoder.getNullEncoded();");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
@@ -2246,7 +2280,7 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(Buffer source, int offset) throws AmqpEncodingError {");
+                writer.write(tab(1) + "static final Encoded<" + getValueMapping().parameterized() + "> createEncoded(Buffer source, int offset) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return createEncoded(FormatCategory.createBuffer(source, offset));");
                 writer.newLine();
@@ -2254,25 +2288,24 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(DataInput in) throws IOException, AmqpEncodingError {");
+                writer.write(tab(1) + "static final Encoded<" + getValueMapping().parameterized() + "> createEncoded(DataInput in) throws IOException, AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return createEncoded(FormatCategory.createBuffer(in.readByte(), in));");
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
 
-                writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(EncodedBuffer buffer) throws AmqpEncodingError {");
+                writer.write(tab(1) + "static final Encoded<" + getValueMapping().parameterized() + "> createEncoded(EncodedBuffer buffer) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "if(buffer.getEncodingFormatCode() == AmqpNullMarshaller.FORMAT_CODE) {");
                 writer.newLine();
-                writer.write(tab(3) + "return new Encoder.NullEncoded<" + getValueMapping() + ">();");
+                writer.write(tab(3) + "return Encoder.getNullEncoded();");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
                 writer.write(tab(2) + "if(buffer.getEncodingFormatCode() != FORMAT_CODE) {");
                 writer.newLine();
-                writer.write(tab(3) + "throw new AmqpEncodingError(\"Unexpected format for " + typeMapping.getShortName() + " expected: \" + FORMAT_CODE);");
+                writer.write(tab(3) + "throw new AmqpEncodingError(\"Unexpected format for " + typeMapping.shortName().nonGeneric() + " expected: \" + FORMAT_CODE);");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
@@ -2284,7 +2317,8 @@ public class AmqpClass {
             } else {
 
                 writer.newLine();
-                writer.write(tab(1) + "private static final " + getEncodingName(false) + " chooseEncoding(" + getJavaType() + " val) throws AmqpEncodingError {");
+                writer.write(tab(1) + "private static final " + getTypeMapping().getGeneric(" ") + getEncodingName(false) + " chooseEncoding(" + typeMapping.parameterized()
+                        + " val) throws AmqpEncodingError {");
                 writer.newLine();
                 if (isMutable()) {
                     writer.write(tab(2) + "return Encoder.choose" + capFirst(name) + "Encoding(val);");
@@ -2296,7 +2330,8 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "private static final " + getEncodingName(false) + " chooseEncoding(" + valueMapping + " val) throws AmqpEncodingError {");
+                writer.write(tab(1) + "private static final " + getTypeMapping().getGeneric(" ") + getEncodingName(false) + " chooseEncoding(" + valueMapping.parameterized()
+                        + " val) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return Encoder.choose" + capFirst(name) + "Encoding(val);");
                 writer.newLine();
@@ -2304,11 +2339,12 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> encode(" + getJavaType() + " data) throws AmqpEncodingError {");
+                writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized() + "> encode(" + typeMapping.parameterized()
+                        + " data) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "if(data == null) {");
                 writer.newLine();
-                writer.write(tab(3) + "return NULL_ENCODED;");
+                writer.write(tab(3) + "return Encoder.getNullEncoded();");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
@@ -2322,7 +2358,8 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(Buffer source, int offset) throws AmqpEncodingError {");
+                writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                        + "> createEncoded(Buffer source, int offset) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return createEncoded(FormatCategory.createBuffer(source, offset));");
                 writer.newLine();
@@ -2330,7 +2367,8 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(" + getValueMapping() + " val) throws AmqpEncodingError {");
+                writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized() + "> createEncoded(" + getValueMapping()
+                        + " val) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return " + getEncodingName(false) + ".createEncoded(chooseEncoding(val).FORMAT_CODE, val);");
                 writer.newLine();
@@ -2338,7 +2376,8 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(DataInput in) throws IOException, AmqpEncodingError {");
+                writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                        + "> createEncoded(DataInput in) throws IOException, AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "return createEncoded(FormatCategory.createBuffer(in.readByte(), in));");
                 writer.newLine();
@@ -2346,22 +2385,43 @@ public class AmqpClass {
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(EncodedBuffer buffer) throws AmqpEncodingError {");
+                writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                        + "> createEncoded(EncodedBuffer buffer) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(2) + "if(buffer.getEncodingFormatCode() == AmqpNullMarshaller.FORMAT_CODE) {");
                 writer.newLine();
-                writer.write(tab(3) + "return NULL_ENCODED;");
+                writer.write(tab(3) + "return Encoder.getNullEncoded();");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
-                writer.write(tab(2) + "return " + getEncodingName(false) + ".createEncoded(buffer);");
+                if(isMap())
+                {
+                    writer.write(tab(2) + getJavaType() + "Encoded" + getTypeMapping().parameterized().getGeneric("") + " rc = " + getEncodingName(false) + ".createEncoded(buffer);");
+                    writer.newLine();
+                    writer.write(tab(2) + "rc.setDecoder(Encoder.DEFAULT_MAP_DECODER);");
+                    writer.newLine();
+                    writer.write(tab(2) + "return rc;");
+                }
+                else if(isList())
+                {
+                    writer.write(tab(2) + getJavaType() + "Encoded" + getTypeMapping().parameterized().getGeneric("") + " rc = " + getEncodingName(false) + ".createEncoded(buffer);");
+                    writer.newLine();
+                    writer.write(tab(2) + "rc.setDecoder(Encoder.DEFAULT_LIST_DECODER);");
+                    writer.newLine();
+                    writer.write(tab(2) + "return rc;");
+                }
+                else
+                {
+                    writer.write(tab(2) + "return " + getEncodingName(false) + ".createEncoded(buffer);");
+                }
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
 
                 if (isList()) {
                     writer.newLine();
-                    writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(DataInput in, ListDecoder decoder) throws IOException, AmqpEncodingError {");
+                    writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                            + "> createEncoded(DataInput in, ListDecoder<V> decoder) throws IOException, AmqpEncodingError {");
                     writer.newLine();
                     writer.write(tab(2) + "return createEncoded(FormatCategory.createBuffer(in.readByte(), in), decoder);");
                     writer.newLine();
@@ -2369,15 +2429,16 @@ public class AmqpClass {
                     writer.newLine();
 
                     writer.newLine();
-                    writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(EncodedBuffer buffer, ListDecoder decoder) throws AmqpEncodingError {");
+                    writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                            + "> createEncoded(EncodedBuffer buffer, ListDecoder<V> decoder) throws AmqpEncodingError {");
                     writer.newLine();
                     writer.write(tab(2) + "if(buffer.getEncodingFormatCode() == AmqpNullMarshaller.FORMAT_CODE) {");
                     writer.newLine();
-                    writer.write(tab(3) + "return NULL_ENCODED;");
+                    writer.write(tab(3) + "return Encoder.getNullEncoded();");
                     writer.newLine();
                     writer.write(tab(2) + "}");
                     writer.newLine();
-                    writer.write(tab(2) + getJavaType() + "Encoded rc = " + getEncodingName(false) + ".createEncoded(buffer);");
+                    writer.write(tab(2) + getJavaType() + "Encoded" + getTypeMapping().parameterized().getGeneric("") + " rc = " + getEncodingName(false) + ".createEncoded(buffer);");
                     writer.newLine();
                     writer.write(tab(2) + "rc.setDecoder(decoder);");
                     writer.newLine();
@@ -2389,7 +2450,8 @@ public class AmqpClass {
 
                 if (isMap()) {
                     writer.newLine();
-                    writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(DataInput in, MapDecoder decoder) throws IOException, AmqpEncodingError {");
+                    writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                            + "> createEncoded(DataInput in, MapDecoder<K, V> decoder) throws IOException, AmqpEncodingError {");
                     writer.newLine();
                     writer.write(tab(2) + "return createEncoded(FormatCategory.createBuffer(in.readByte(), in), decoder);");
                     writer.newLine();
@@ -2397,15 +2459,16 @@ public class AmqpClass {
                     writer.newLine();
 
                     writer.newLine();
-                    writer.write(tab(1) + "static final Encoded<" + getValueMapping() + "> createEncoded(EncodedBuffer buffer, MapDecoder decoder) throws AmqpEncodingError {");
+                    writer.write(tab(1) + "static final " + getTypeMapping().getGeneric(" ") + "Encoded<" + getValueMapping().parameterized()
+                            + "> createEncoded(EncodedBuffer buffer, MapDecoder<K, V> decoder) throws AmqpEncodingError {");
                     writer.newLine();
                     writer.write(tab(2) + "if(buffer.getEncodingFormatCode() == AmqpNullMarshaller.FORMAT_CODE) {");
                     writer.newLine();
-                    writer.write(tab(3) + "return NULL_ENCODED;");
+                    writer.write(tab(3) + "return Encoder.getNullEncoded();");
                     writer.newLine();
                     writer.write(tab(2) + "}");
                     writer.newLine();
-                    writer.write(tab(2) + getJavaType() + "Encoded rc = " + getEncodingName(false) + ".createEncoded(buffer);");
+                    writer.write(tab(2) + getJavaType() + "Encoded" + getTypeMapping().parameterized().getGeneric("") + " rc = " + getEncodingName(false) + ".createEncoded(buffer);");
                     writer.newLine();
                     writer.write(tab(2) + "rc.setDecoder(decoder);");
                     writer.newLine();
@@ -2422,6 +2485,66 @@ public class AmqpClass {
         writer.flush();
     }
 
+    private void resolveMappings() throws UnknownTypeException {
+        if (mappingsResolved) {
+            return;
+        }
+        mappingsResolved = true;
+
+        if (isRestricted()) {
+            baseType = TypeRegistry.resolveAmqpClass(restrictedType);
+        } else if (isDescribed()) {
+            baseType = descriptor.resolveDescribedType();
+        } else {
+            baseType = this;
+        }
+        baseMapping = baseType.getTypeMapping();
+
+        // ValueMapping:
+        if (isPrimitive()) {
+            valueMapping = TypeRegistry.getJavaTypeMapping(name);
+        } else if (isRestricted()) {
+            if (isEnumType()) {
+                valueMapping = typeMapping;
+            } else {
+                valueMapping = baseType.getValueMapping();
+            }
+        } else if (isDescribed()) {
+            valueMapping = baseType.getValueMapping();
+        } else {
+            valueMapping = this.typeMapping;
+        }
+
+        if (isList()) {
+            typeMapping.setGenerics("V extends " + TypeRegistry.any().getTypeMapping());
+            beanMapping.setGenerics(typeMapping.getGenerics());
+            bufferMapping.setGenerics(typeMapping.getGenerics());
+            valueMapping = valueMapping.parameterized("V");
+        }
+
+        if (isMap()) {
+            mapKeyType = "K";
+            mapValueType = "V";
+            typeMapping.setGenerics("K extends " + TypeRegistry.any().getTypeMapping(), "V extends " + TypeRegistry.any().getTypeMapping());
+            beanMapping.setGenerics(typeMapping.getGenerics());
+            bufferMapping.setGenerics(typeMapping.getGenerics());
+            valueMapping = valueMapping.parameterized(mapKeyType, mapValueType);
+
+        }
+
+        if (isDescribed() || isRestricted()) {
+            if (baseType.isList()) {
+                baseMapping = baseMapping.parameterized(TypeRegistry.any().getTypeMapping().toString());
+                valueMapping = valueMapping.parameterized(TypeRegistry.any().getTypeMapping().toString());
+            }
+            if (baseType.isMap()) {
+                mapKeyType = TypeRegistry.resolveAmqpClass("symbol").getJavaType();
+                baseMapping = baseMapping.parameterized(mapKeyType, mapValueType);
+                valueMapping = valueMapping.parameterized(mapKeyType, mapValueType);
+            }
+        }
+    }
+
     public String getJavaType() {
         return typeMapping.getJavaType();
     }
@@ -2443,7 +2566,7 @@ public class AmqpClass {
     }
 
     public boolean isMutable() throws UnknownTypeException {
-        AmqpClass baseType = resolveBaseType();
+        resolveMappings();
         if (baseType.isPrimitive() && !(baseType.isList() || baseType.isMap())) {
             return false;
         } else {
@@ -2479,9 +2602,9 @@ public class AmqpClass {
         if (isAny()) {
             return "AmqpMarshaller.SINGLETON";
         } else if (isRestricted()) {
-            return resolveRestrictedType().getTypeMapping() + "Marshaller";
+            return resolveRestrictedType().getTypeMapping().shortName().nonGeneric() + "Marshaller";
         } else {
-            return getTypeMapping() + "Marshaller";
+            return getTypeMapping().shortName().nonGeneric() + "Marshaller";
         }
     }
 
@@ -2496,6 +2619,7 @@ public class AmqpClass {
     }
 
     public AmqpClass getDescribedType() throws UnknownTypeException {
+        resolveMappings();
         return descriptor.resolveDescribedType();
     }
 
@@ -2515,10 +2639,6 @@ public class AmqpClass {
         return name.equals("list");
     }
 
-    public final String getListElementType() {
-        return listElementType;
-    }
-
     public boolean isMarshallable() {
         return isDescribed() || isPrimitive() || (isRestricted() && !isEnumType());
     }
@@ -2642,12 +2762,7 @@ public class AmqpClass {
      * @throws UnknownTypeException
      */
     public JavaTypeMapping getValueMapping() throws UnknownTypeException {
-        if (valueMapping == null) {
-            if (isDescribed()) {
-                valueMapping = descriptor.resolveDescribedType().getValueMapping();
-            }
-        }
-
+        resolveMappings();
         return valueMapping;
     }
 
@@ -2657,14 +2772,10 @@ public class AmqpClass {
      * @return
      * @throws UnknownTypeException
      */
-    public AmqpClass resolveBaseType() throws UnknownTypeException {
-        if (isRestricted()) {
-            return TypeRegistry.resolveAmqpClass(restrictedType);
-        } else if (isDescribed()) {
-            return getDescribedType();
-        } else {
-            return this;
-        }
+    public AmqpClass getBaseType() throws UnknownTypeException {
+        resolveMappings();
+        return baseType;
+
     }
 
     public JavaTypeMapping getTypeMapping() {

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=946684&r1=946683&r2=946684&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 Thu May 20 16:13:58 2010
@@ -5,6 +5,7 @@ import static org.apache.activemq.amqp.g
 import java.io.BufferedWriter;
 import java.io.IOException;
 
+import org.apache.activemq.amqp.generator.TypeRegistry.JavaTypeMapping;
 import org.apache.activemq.amqp.generator.jaxb.schema.Doc;
 import org.apache.activemq.amqp.generator.jaxb.schema.Field;
 
@@ -26,7 +27,7 @@ public class AmqpField {
         required = new Boolean(field.getRequired()).booleanValue();
         type = field.getType();
         doc.setLabel(label);
-        
+
         for (Object object : field.getDocOrException()) {
             if (object instanceof Doc) {
                 doc.parseFromDoc((Doc) object);
@@ -101,6 +102,18 @@ public class AmqpField {
         return ampqClass;
     }
 
+    public JavaTypeMapping resolveAccessorMapping() throws UnknownTypeException {
+        AmqpClass amqpClass = TypeRegistry.resolveAmqpClass(this);
+        if (isMultiple()) {
+            // Swap with the value type for enum types:
+            if (amqpClass.isEnumType()) {
+                return TypeRegistry.resolveAmqpClass("list").getTypeMapping().parameterized(amqpClass.getBaseType().getTypeMapping().toString());
+            }
+            return TypeRegistry.resolveAmqpClass("list").getTypeMapping().parameterized(amqpClass.getTypeMapping().toString());
+        }
+        return amqpClass.getTypeMapping().wildcard();
+    }
+
     public void writeJavaDoc(BufferedWriter writer, int indent) throws IOException {
         doc.writeJavaDoc(writer, indent);
     }



Mime
View raw message