activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r909703 - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/org/apache/activemq/amqp/generator/handcoded/marshaller/v1_0_0/ handcoded/org/apache/activemq/amqp/generator/handcoded/types/ main/java/org/apache/a...
Date Sat, 13 Feb 2010 03:20:03 GMT
Author: cmacnaug
Date: Sat Feb 13 03:19:48 2010
New Revision: 909703

URL: http://svn.apache.org/viewvc?rev=909703&view=rev
Log:
Modified Map and List decoding to perform additional validation. Changes in support of array encodings. 

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/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpList.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/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=909703&r1=909702&r2=909703&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 Sat Feb 13 03:19:48 2010
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.activemq.amqp.generator.handcoded.marshaller.AmqpVersion;
@@ -35,7 +34,7 @@
 import org.apache.activemq.amqp.generator.handcoded.BitUtils;
 import org.apache.activemq.amqp.generator.handcoded.types.AmqpType;
 import org.apache.activemq.amqp.generator.handcoded.types.IAmqpList;
-import org.apache.activemq.amqp.protocol.types.IAmqpMap;
+import org.apache.activemq.amqp.generator.handcoded.types.IAmqpMap;
 import org.apache.activemq.util.buffer.Buffer;
 
 public class Encoder extends BaseEncoder {
@@ -46,30 +45,61 @@
     static final byte NULL_FORMAT_CODE = AmqpNullMarshaller.FORMAT_CODE;
     static final byte DESCRIBED_FORMAT_CODE = (byte) 0x00;
 
-    static final ListDecoder DEFAULT_LIST_DECODER = new ListDecoder() {
+    public static interface ListDecoder<E extends AmqpType<?, ?>> {
+        public IAmqpList<E> decode(EncodedBuffer[] constituents) throws AmqpEncodingError;
 
-        public final AmqpType<?, ?> unmarshalType(int pos, DataInput in) throws IOException, AmqpEncodingError {
-            return MARSHALLER.unmarshalType(in);
+        public IAmqpList<E> unmarshalType(int dataCount, int dataSize, DataInput in) throws IOException, AmqpEncodingError;
+    }
+
+    public static interface MapDecoder<K extends AmqpType<?, ?>, V extends AmqpType<?, ?>> {
+        public IAmqpMap<K, V> decode(EncodedBuffer[] constituents) throws AmqpEncodingError;
+
+        public IAmqpMap<K, V> unmarshalType(int dataCount, int dataSize, DataInput in) throws IOException, AmqpEncodingError;
+    }
+
+    static final ListDecoder<AmqpType<?, ?>> DEFAULT_LIST_DECODER = new ListDecoder<AmqpType<?, ?>>() {
+
+        public IAmqpList<AmqpType<?, ?>> decode(EncodedBuffer[] constituents) {
+            IAmqpList<AmqpType<?, ?>> rc = new IAmqpList.ArrayBackedList<AmqpType<?, ?>>(new AmqpType<?, ?>[constituents.length]);
+            for (int i = 0; i < constituents.length; i++) {
+                rc.set(i, MARSHALLER.decodeType(constituents[i]));
+            }
+            return rc;
         }
 
-        public final AmqpType<?, ?> decodeType(int pos, EncodedBuffer buffer) throws AmqpEncodingError {
-            return MARSHALLER.decodeType(buffer);
+        public final IAmqpList<AmqpType<?, ?>> unmarshalType(int dataCount, int dataSize, DataInput in) throws IOException, AmqpEncodingError {
+            IAmqpList<AmqpType<?, ?>> rc = new IAmqpList.ArrayBackedList<AmqpType<?, ?>>(new AmqpType<?, ?>[dataCount]);
+            for (int i = 0; i < dataCount; i++) {
+                rc.set(i, MARSHALLER.unmarshalType(in));
+            }
+            return rc;
         }
     };
 
-    static final MapDecoder<AmqpType<?,?>, AmqpType<?, ?>> DEFAULT_MAP_DECODER = new MapDecoder<AmqpType<?,?>, AmqpType<?, ?>>() {
+    static final MapDecoder<AmqpType<?, ?>, AmqpType<?, ?>> DEFAULT_MAP_DECODER = new MapDecoder<AmqpType<?, ?>, AmqpType<?, ?>>() {
 
-        public IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> createMap(int entryCount) {
-            return new IAmqpMap.AmqpWrapperMap<AmqpType<?,?>, AmqpType<?,?>>(new HashMap<AmqpType<?,?>, AmqpType<?,?>>());
-        }
+        public IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> decode(EncodedBuffer[] constituents) {
+            IAmqpMap.AmqpWrapperMap<AmqpType<?, ?>, AmqpType<?, ?>> rc = new IAmqpMap.AmqpWrapperMap<AmqpType<?, ?>, AmqpType<?, ?>>(new HashMap<AmqpType<?, ?>, AmqpType<?, ?>>());
+            if (constituents.length % 2 != 0) {
+                throw new AmqpEncodingError("Invalid number of compound constituents: " + constituents.length);
+            }
 
-        public void decodeToMap(EncodedBuffer key, EncodedBuffer val, IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> map) throws AmqpEncodingError {
-            map.put(MARSHALLER.decodeType(key), MARSHALLER.decodeType(key));
-            
+            for (int i = 0; i < constituents.length; i += 2) {
+                rc.put(MARSHALLER.decodeType(constituents[i]), MARSHALLER.decodeType(constituents[i + 1]));
+            }
+            return rc;
         }
 
-        public void unmarshalToMap(DataInput in, IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> map) throws IOException, AmqpEncodingError {
-            map.put(MARSHALLER.unmarshalType(in), MARSHALLER.unmarshalType(in));
+        public IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> unmarshalType(int dataCount, int dataSize, DataInput in) throws IOException, AmqpEncodingError {
+            IAmqpMap.AmqpWrapperMap<AmqpType<?, ?>, AmqpType<?, ?>> rc = new IAmqpMap.AmqpWrapperMap<AmqpType<?, ?>, AmqpType<?, ?>>(new HashMap<AmqpType<?, ?>, AmqpType<?, ?>>());
+            if (dataCount % 2 != 0) {
+                throw new AmqpEncodingError("Invalid number of compound constituents: " + dataCount);
+            }
+
+            for (int i = 0; i < dataCount; i += 2) {
+                rc.put(MARSHALLER.unmarshalType(in), MARSHALLER.unmarshalType(in));
+            }
+            return rc;
         }
     };
 
@@ -578,7 +608,7 @@
             }
 
             Buffer rc = new Buffer(1 + category.WIDTH + dataSize);
-            System.arraycopy(source, offset, rc, 0, rc.length);
+            System.arraycopy(source.data, offset, rc.data, 0, rc.length);
             return rc;
         }
 
@@ -707,8 +737,9 @@
                 EncodedBuffer[] cb = new EncodedBuffer[getDataCount()];
                 Buffer b = getBuffer();
                 int offset = getDataOffset();
-                for (int i = 0; i < constituents.length; i++) {
-                    constituents[i] = FormatCategory.createBuffer(b, offset);
+                for (int i = 0; i < cb.length; i++) {
+                    cb[i] = FormatCategory.createBuffer(b, offset);
+                    offset += cb[i].getEncodedSize();
                 }
                 this.constituents = cb;
             }
@@ -881,7 +912,7 @@
         protected V value;
 
         // TODO make configurable.
-        //private boolean cacheEncoded = true;
+        // private boolean cacheEncoded = true;
 
         AbstractEncoded(EncodedBuffer encoded) {
             this.encoded = encoded;
@@ -1016,7 +1047,7 @@
 
     static class NullEncoded<V> extends AbstractEncoded<V> {
 
-        private static FixedBuffer nb = new FixedBuffer(new Buffer(new byte [] {NULL_FORMAT_CODE}), 0);
+        private static FixedBuffer nb = new FixedBuffer(new Buffer(new byte[] { NULL_FORMAT_CODE }), 0);
 
         NullEncoded() {
             super(nb);
@@ -1104,20 +1135,6 @@
         protected abstract Encoded<V> unmarshalDescribed(DataInput in) throws IOException, AmqpEncodingError;
     }
 
-    public static interface ListDecoder {
-        AmqpType<?, ?> decodeType(int pos, EncodedBuffer buffer) throws AmqpEncodingError;
-
-        AmqpType<?, ?> unmarshalType(int pos, DataInput in) throws IOException, AmqpEncodingError;
-    }
-
-    public static interface MapDecoder<K extends AmqpType<?, ?>, V extends AmqpType<?, ?>> {
-        void decodeToMap(EncodedBuffer key, EncodedBuffer val, IAmqpMap<K, V> map) throws AmqpEncodingError;
-
-        public void unmarshalToMap(DataInput in, IAmqpMap<K, V> map) throws IOException, AmqpEncodingError;
-
-        IAmqpMap<K, V> createMap(int entryCount);
-    }
-
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
     // Encoding Helpers:
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1187,37 +1204,12 @@
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
     // LIST ENCODINGS
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    private static class ArrayBackedList implements IAmqpList {
-        AmqpType<?, ?>[] list;
-
-        ArrayBackedList(int size) {
-            list = new AmqpType<?, ?>[size];
-        }
-
-        public AmqpType<?, ?> get(int index) {
-            return list[index];
-        }
-
-        public int getListCount() {
-            return list.length;
-        }
-
-        public void set(int index, AmqpType<?, ?> value) {
-            list[index] = value;
-        }
-
-        public Iterator<AmqpType<?, ?>> iterator() {
-            return new AmqpListIterator(this);
-        }
-    }
-    
-    public static final AmqpListMarshaller.LIST_ENCODING chooseListEncoding(IAmqpList val) throws AmqpEncodingError {
+    public static final <E extends AmqpType<?, ?>> AmqpListMarshaller.LIST_ENCODING chooseListEncoding(IAmqpList<E> val) throws AmqpEncodingError {
         if (val.getListCount() > 255) {
             return AmqpListMarshaller.LIST_ENCODING.LIST32;
         }
         int size = 1;
-        for (AmqpType<?, ?> le : val) {
+        for (E le : val) {
             if (le == null) {
                 size += 1;
             } else {
@@ -1230,7 +1222,7 @@
         return AmqpListMarshaller.LIST_ENCODING.LIST8;
     }
 
-    public final int getEncodedSizeOfList(IAmqpList val, LIST_ENCODING encoding) throws AmqpEncodingError {
+    public final <E extends AmqpType<?, ?>> int getEncodedSizeOfList(IAmqpList<E> val, LIST_ENCODING encoding) throws AmqpEncodingError {
         int size = 0;
         switch (encoding) {
         // TODO for arrays we need to choose an encoding that is compatible for
@@ -1242,7 +1234,7 @@
         }
         case LIST32:
         case LIST8: {
-            for (AmqpType<?, ?> le : val) {
+            for (E le : val) {
                 if (le == null) {
                     size += 1;
                 } else {
@@ -1257,107 +1249,57 @@
         }
     }
 
-    public final int getEncodedCountOfList(IAmqpList val, LIST_ENCODING listENCODING) throws AmqpEncodingError {
+    public final <E extends AmqpType<?, ?>> int getEncodedCountOfList(IAmqpList<E> val, LIST_ENCODING listENCODING) throws AmqpEncodingError {
         return val.getListCount();
     }
 
     // List 8 encoding
-    public void encodeListList8(IAmqpList value, Buffer encoded, int offset) throws AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void encodeListList8(IAmqpList<E> value, Buffer encoded, int offset) throws AmqpEncodingError {
         encodeList(value, encoded, offset);
     }
 
-    public IAmqpList decodeListList8(Buffer encoded, int offset, int count, int size, ListDecoder decoder) throws AmqpEncodingError {
-        return decodeList(encoded, offset, count, size, decoder);
-    }
-
-    public void writeListList8(IAmqpList val, DataOutput out) throws IOException, AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void writeListList8(IAmqpList<E> val, DataOutput out) throws IOException, AmqpEncodingError {
         writeList(val, out);
     }
 
-    public IAmqpList readListList8(int count, int size, DataInput in, ListDecoder decoder) throws IOException, AmqpEncodingError {
-        return readList(count, size, in, decoder);
-    }
-
     // List 32 encoding:
-    public void encodeListList32(IAmqpList value, Buffer encoded, int offset) throws AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void encodeListList32(IAmqpList<E> value, Buffer encoded, int offset) throws AmqpEncodingError {
         encodeList(value, encoded, offset);
     }
 
-    public IAmqpList decodeListList32(Buffer encoded, int offset, int count, int size, ListDecoder decoder) throws AmqpEncodingError {
-        return decodeList(encoded, offset, count, size, decoder);
-    }
-
-    public void writeListList32(IAmqpList val, DataOutput out) throws IOException, AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void writeListList32(IAmqpList<E> val, DataOutput out) throws IOException, AmqpEncodingError {
         writeList(val, out);
     }
 
-    public IAmqpList readListList32(int count, int size, DataInput in, ListDecoder decoder) throws IOException, AmqpEncodingError {
-        return readList(count, size, in, decoder);
-    }
-
     // Array 8 encoding
-    public void encodeListArray8(IAmqpList value, Buffer encoded, int offset) throws AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void encodeListArray8(IAmqpList<E> value, Buffer encoded, int offset) throws AmqpEncodingError {
         encodeArray(value, encoded, offset);
     }
 
-    public IAmqpList decodeListArray8(Buffer encoded, int offset, int count, int size, ListDecoder decoder) throws AmqpEncodingError {
-        return decodeArray(encoded, offset, count, size, decoder);
-    }
-
-    public void writeListArray8(IAmqpList val, DataOutput out) throws IOException, AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void writeListArray8(IAmqpList<E> val, DataOutput out) throws IOException, AmqpEncodingError {
         writeArray(val, out);
     }
 
-    public IAmqpList readListArray8(int count, int size, DataInput in, ListDecoder decoder) throws IOException, AmqpEncodingError {
-        return readArray(count, size, in, decoder);
-    }
-
     // List 32 encoding:
-    public void encodeListArray32(IAmqpList value, Buffer encoded, int offset) throws AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void encodeListArray32(IAmqpList<E> value, Buffer encoded, int offset) throws AmqpEncodingError {
         encodeArray(value, encoded, offset);
     }
 
-    public IAmqpList decodeListArray32(Buffer encoded, int offset, int count, int size, ListDecoder decoder) throws AmqpEncodingError {
-        return decodeArray(encoded, offset, count, size, decoder);
-    }
-
-    public void writeListArray32(IAmqpList val, DataOutput out) throws IOException, AmqpEncodingError {
+    public <E extends AmqpType<?, ?>> void writeListArray32(IAmqpList<E> val, DataOutput out) throws IOException, AmqpEncodingError {
         writeArray(val, out);
     }
 
-    public IAmqpList readListArray32(int count, int size, DataInput in, ListDecoder decoder) throws IOException, AmqpEncodingError {
-        return readArray(count, size, in, decoder);
-    }
-
     // Generic versions:
-    public static final void encodeList(IAmqpList value, Buffer target, int offset) throws AmqpEncodingError {
-        for (AmqpType<?, ?> le : value) {
+    public static final <E extends AmqpType<?, ?>> void encodeList(IAmqpList<E> value, Buffer target, int offset) throws AmqpEncodingError {
+        for (E le : value) {
             Encoded<?> encoded = le.getBuffer(MARSHALLER).getEncoded();
             encoded.encode(target, offset);
             offset = encoded.getDataSize();
         }
     }
 
-    public static final IAmqpList decodeList(Buffer source, int offset, int count, int size, ListDecoder decoder) throws AmqpEncodingError {
-        IAmqpList rc = new ArrayBackedList(count);
-        for (int i = 0; i < count; i++) {
-            EncodedBuffer encoded = FormatCategory.createBuffer(source, offset);
-            offset += encoded.getEncodedSize();
-            rc.set(i, decoder.decodeType(i, encoded));
-        }
-        return rc;
-    }
-
-    public static final IAmqpList readList(int count, int size, DataInput in, ListDecoder decoder) throws IOException, AmqpEncodingError {
-        IAmqpList rc = new ArrayBackedList(count);
-        for (int i = 0; i < count; i++) {
-            rc.set(i, decoder.unmarshalType(i, in));
-        }
-        return rc;
-    }
-
-    public static final void writeList(IAmqpList val, DataOutput out) throws IOException, AmqpEncodingError {
-        for (AmqpType<?, ?> le : val) {
+    public static final <E extends AmqpType<?, ?>> void writeList(IAmqpList<E> val, DataOutput out) throws IOException, AmqpEncodingError {
+        for (E le : val) {
             if (le == null) {
                 out.writeByte(NULL_FORMAT_CODE);
             } else {
@@ -1366,7 +1308,7 @@
         }
     }
 
-    public static final void encodeArray(IAmqpList value, Buffer target, int offset) throws AmqpEncodingError {
+    public static final <E extends AmqpType<?, ?>> void encodeArray(IAmqpList<E> value, Buffer target, int offset) throws AmqpEncodingError {
         Encoded<?> first = value.get(0).getBuffer(MARSHALLER).getEncoded();
         first.encode(target, offset);
         offset += first.getEncodedSize();
@@ -1379,17 +1321,17 @@
         // }
     }
 
-    public static final IAmqpList decodeArray(Buffer encoded, int offset, int count, int size, ListDecoder decoder) {
+    public static final <E extends AmqpType<?, ?>> IAmqpList<E> decodeArray(Buffer encoded, int offset, int count, int size, ListDecoder<E> decoder) {
         // TODO
         throw new UnsupportedOperationException();
     }
 
-    public static final IAmqpList readArray(int count, int size, DataInput dis, ListDecoder decoder) throws IOException, AmqpEncodingError {
+    public static final <E extends AmqpType<?, ?>> IAmqpList<E> readArray(int count, int size, DataInput dis, ListDecoder<E> decoder) throws IOException, AmqpEncodingError {
         // TODO
         throw new UnsupportedOperationException();
     }
 
-    public static final void writeArray(IAmqpList val, DataOutput out) throws IOException, AmqpEncodingError {
+    public static final <E extends AmqpType<?, ?>> void writeArray(IAmqpList<E> val, DataOutput out) throws IOException, AmqpEncodingError {
         Encoded<?> first = val.get(0).getBuffer(MARSHALLER).getEncoded();
         first.marshal(out);
         for (int i = 1; i < val.getListCount(); i++) {
@@ -1401,8 +1343,8 @@
     // Map ENCODINGS
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
     public static final AmqpMapMarshaller.MAP_ENCODING chooseMapEncoding(IAmqpMap<?, ?> map) throws AmqpEncodingError {
-        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : map) {
-            
+        for (Map.Entry<? extends AmqpType<?, ?>, ? extends AmqpType<?, ?>> me : map) {
+
             int size = me.getKey().getBuffer(MARSHALLER).getEncoded().getEncodedSize() + me.getValue().getBuffer(MARSHALLER).getEncoded().getEncodedSize();
             if (size > 255) {
                 return AmqpMapMarshaller.MAP_ENCODING.MAP32;
@@ -1413,7 +1355,7 @@
 
     public final int getEncodedSizeOfMap(IAmqpMap<?, ?> map, MAP_ENCODING encoding) throws AmqpEncodingError {
         int size = 0;
-        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : map) {
+        for (Map.Entry<? extends AmqpType<?, ?>, ? extends AmqpType<?, ?>> me : map) {
             size += me.getKey().getBuffer(MARSHALLER).getEncoded().getEncodedSize() + me.getValue().getBuffer(MARSHALLER).getEncoded().getEncodedSize();
         }
         return size;
@@ -1427,59 +1369,21 @@
         encodeMap(value, target, offset);
     }
 
-    public final <K extends AmqpType<?,?>, V extends AmqpType<?,?>> IAmqpMap<K, V> decodeMapMap32(Buffer source, int offset, int count, int size, MapDecoder<K, V> decoder) throws AmqpEncodingError {
-        return decodeMap(source, offset, count, size, decoder);
-    }
-
     public final void writeMapMap32(IAmqpMap<?, ?> val, DataOutput out) throws AmqpEncodingError, IOException {
         writeMap(val, out);
-
-    }
-
-    public final <K extends AmqpType<?,?>, V extends AmqpType<?,?>> IAmqpMap<K, V> readMapMap32(int count, int size, DataInput in, MapDecoder<K, V> decoder) throws AmqpEncodingError, IOException {
-        return readMap(count, size, in, decoder);
     }
 
     public final void encodeMapMap8(IAmqpMap<?, ?> value, Buffer target, int offset) throws AmqpEncodingError {
         encodeMap(value, target, offset);
     }
 
-    public final <K extends AmqpType<?,?>, V extends AmqpType<?,?>> IAmqpMap<K, V> decodeMapMap8(Buffer source, int offset, int count, int size, MapDecoder<K, V> decoder) throws AmqpEncodingError {
-        return decodeMap(source, offset, count, size, decoder);
-    }
-
     public final void writeMapMap8(IAmqpMap<?, ?> val, DataOutput out) throws AmqpEncodingError, IOException {
         writeMap(val, out);
 
     }
 
-    public final <K extends AmqpType<?,?>, V extends AmqpType<?,?>> IAmqpMap<K, V> readMapMap8(int count, int size, DataInput in, MapDecoder<K, V> decoder) throws AmqpEncodingError, IOException {
-        return readMap(count, size, in, decoder);
-    }
-
-    public static final <K extends AmqpType<?,?>, V extends AmqpType<?,?>> IAmqpMap<K, V> decodeMap(Buffer source, int offset, int count, int size, MapDecoder<K, V> decoder) throws AmqpEncodingError {
-        IAmqpMap<K, V> rc = decoder.createMap(count / 2);
-        for (int i = 0; i < count; i += 2) {
-            EncodedBuffer encodedKey = FormatCategory.createBuffer(source, offset);
-            offset += encodedKey.getEncodedSize();
-            EncodedBuffer encodedVal = FormatCategory.createBuffer(source, offset);
-            offset += encodedVal.getEncodedSize();
-            decoder.decodeToMap(encodedKey, encodedVal, rc);
-        }
-        return rc;
-    }
-    
-
-    public static final <K extends AmqpType<?,?>, V extends AmqpType<?,?>> IAmqpMap<K, V> readMap(int count, int size, DataInput in, MapDecoder<K, V> decoder) throws IOException, AmqpEncodingError {
-        IAmqpMap<K, V> rc = decoder.createMap(count / 2);
-        for (int i = 0; i < count; i += 2) {
-            decoder.unmarshalToMap(in, rc);
-        }
-        return rc;
-    }
-
     public static final void encodeMap(IAmqpMap<?, ?> value, Buffer target, int offset) throws AmqpEncodingError {
-        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : value) {
+        for (Map.Entry<? extends AmqpType<?, ?>, ? extends AmqpType<?, ?>> me : value) {
             Encoded<?> eKey = me.getKey().getBuffer(MARSHALLER).getEncoded();
             eKey.encode(target, offset);
             offset += eKey.getEncodedSize();
@@ -1491,9 +1395,9 @@
     }
 
     public static final void writeMap(IAmqpMap<?, ?> val, DataOutput out) throws IOException, AmqpEncodingError {
-        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : val) {
+        for (Map.Entry<? extends AmqpType<?, ?>, ? extends AmqpType<?, ?>> me : val) {
             me.getKey().marshal(out, MARSHALLER);
             me.getValue().marshal(out, MARSHALLER);
         }
     }
-}
\ No newline at end of file
+}

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpList.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpList.java?rev=909703&r1=909702&r2=909703&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpList.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpList.java Sat Feb 13 03:19:48 2010
@@ -19,22 +19,19 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.activemq.amqp.protocol.types.AmqpType;
-import org.apache.activemq.amqp.protocol.types.IAmqpList;
+public interface IAmqpList<E extends AmqpType<?, ?>> extends Iterable<E> {
 
-public interface IAmqpList extends Iterable<AmqpType<?, ?>> {
+    public E get(int index);
 
-    public AmqpType<?, ?> get(int index);
-
-    public void set(int index, AmqpType<?, ?> value);
+    public void set(int index, E value);
 
     public int getListCount();
 
-    public static class AmqpListIterator implements Iterator<AmqpType<?, ?>> {
+    public static class AmqpListIterator<E extends AmqpType<?, ?>> implements Iterator<E> {
         int next = 0;
-        final IAmqpList list;
+        final IAmqpList<E> list;
 
-        public AmqpListIterator(IAmqpList list) {
+        public AmqpListIterator(IAmqpList<E> list) {
             this.list = list;
         }
 
@@ -42,7 +39,7 @@
             return next < list.getListCount();
         }
 
-        public AmqpType<?, ?> next() {
+        public E next() {
             return list.get(next++);
         }
 
@@ -51,16 +48,16 @@
         }
     }
 
-    public static abstract class AbstractAmqpList implements IAmqpList {
-        public static final int hashCodeFor(IAmqpList l) {
+    public static abstract class AbstractAmqpList<E extends AmqpType<?, ?>> implements IAmqpList<E> {
+        public static final int hashCodeFor(IAmqpList<?> l) {
             int hashCode = 1;
             for (Object obj : l) {
                 hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
             }
             return hashCode;
         }
-        
-        public static final boolean checkEqual(IAmqpList l1, IAmqpList l2) {
+
+        public static final boolean checkEqual(IAmqpList<?> l1, IAmqpList<?> l2) {
             if (l1 == null ^ l2 == null) {
                 return false;
             }
@@ -86,14 +83,14 @@
         }
     }
 
-    public static class AmqpWrapperList extends AbstractAmqpList {
-        private final List<AmqpType<?, ?>> list;
+    public static class AmqpWrapperList<E extends AmqpType<?, ?>> extends AbstractAmqpList<E> {
+        private final List<E> list;
 
-        public AmqpWrapperList(List<AmqpType<?, ?>> list) {
+        public AmqpWrapperList(List<E> list) {
             this.list = list;
         }
 
-        public AmqpType<?, ?> get(int index) {
+        public E get(int index) {
             return list.get(index);
         }
 
@@ -101,11 +98,11 @@
             return list.size();
         }
 
-        public void set(int index, AmqpType<?, ?> value) {
+        public void set(int index, E value) {
             list.set(index, value);
         }
 
-        public Iterator<AmqpType<?, ?>> iterator() {
+        public Iterator<E> iterator() {
             return list.iterator();
         }
 
@@ -114,13 +111,13 @@
                 return false;
             }
 
-            if (o instanceof IAmqpList) {
-                return equals((IAmqpList) o);
+            if (o instanceof IAmqpList<?>) {
+                return equals((IAmqpList<?>) o);
             }
             return false;
         }
 
-        public boolean equals(IAmqpList l) {
+        public boolean equals(IAmqpList<?> l) {
             return checkEqual(this, l);
         }
 
@@ -129,14 +126,14 @@
         }
     }
 
-    public static class ArrayBackedList extends AbstractAmqpList {
-        AmqpType<?, ?>[] list;
+    public static class ArrayBackedList<E extends AmqpType<?, ?>> extends AbstractAmqpList<E> {
+        E[] list;
 
-        ArrayBackedList(int size) {
-            list = new AmqpType<?, ?>[size];
+        public ArrayBackedList(E[] list) {
+            this.list = list;
         }
 
-        public AmqpType<?, ?> get(int index) {
+        public E get(int index) {
             return list[index];
         }
 
@@ -144,12 +141,12 @@
             return list.length;
         }
 
-        public void set(int index, AmqpType<?, ?> value) {
+        public void set(int index, E value) {
             list[index] = value;
         }
 
-        public Iterator<AmqpType<?, ?>> iterator() {
-            return new AmqpListIterator(this);
+        public Iterator<E> iterator() {
+            return new AmqpListIterator<E>(this);
         }
 
         public boolean equals(Object o) {
@@ -157,13 +154,13 @@
                 return false;
             }
 
-            if (o instanceof IAmqpList) {
-                return equals((IAmqpList) o);
+            if (o instanceof IAmqpList<?>) {
+                return equals((IAmqpList<?>) o);
             }
             return false;
         }
 
-        public boolean equals(IAmqpList l) {
+        public boolean equals(IAmqpList<?> l) {
             return checkEqual(this, l);
         }
 

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=909703&r1=909702&r2=909703&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 Sat Feb 13 03:19:48 2010
@@ -54,6 +54,10 @@
     // Java mapping of the buffer for this type (if any)
     protected TypeRegistry.JavaTypeMapping bufferMapping;
 
+    protected String mapKeyType = "AmqpType<?,?>";
+    protected String mapValueType = "AmqpType<?,?>";
+    protected String listElementType = "AmqpType<?,?>";
+
     public TypeRegistry.JavaTypeMapping versionMarshaller;
 
     public void parseFromType(Generator generator, Amqp source, Section section, Type type) throws UnknownTypeException {
@@ -122,7 +126,6 @@
         if (handcoded) {
             return;
         }
-        String className = getJavaType();
 
         File file = new File(generator.getOutputDirectory() + File.separator + new String(typeMapping.getFullName()).replace(".", File.separator) + ".java");
         file.getParentFile().mkdirs();
@@ -146,22 +149,18 @@
 
         // We use enums for restricted types with a choice:
         if (isEnumType()) {
-            writer.write("public enum " + className);
+            writer.write("public enum " + typeMapping);
         } else if (isMarshallable()) {
 
             if (isRestricted()) {
-                writer.write("public interface " + className + " extends " + resolveRestrictedType().getTypeMapping());
+                writer.write("public interface " + typeMapping + " extends " + resolveRestrictedType().getTypeMapping());
             } else if (isDescribed()) {
-                writer.write("public interface " + className + " extends " + descriptor.resolveDescribedType().getTypeMapping());
+                writer.write("public interface " + typeMapping + " extends " + descriptor.resolveDescribedType().getTypeMapping());
             } else {
-                writer.write("public interface " + className + " extends AmqpType<" + beanMapping + ", " + bufferMapping + ">");
-            }
-
-            if (isList()) {
-                writer.write(", " + valueMapping.getJavaType());
+                writer.write("public interface " + typeMapping + " extends AmqpType<" + beanMapping + ", " + bufferMapping + ">");
             }
-
-            if (isMap()) {
+            
+            if (isList() || isMap()) {
                 writer.write(", " + valueMapping.getJavaType());
             }
 
@@ -222,8 +221,8 @@
             // Add the marshalled type:
             filterOrAddImport(imports, typeMapping, marshaller);
 
-            if (isMap()) {
-                filterOrAddImport(imports, TypeRegistry.resolveAmqpClass("*").getTypeMapping(), marshaller);
+            if (isMap() || isList()) {
+                filterOrAddImport(imports, TypeRegistry.any().getTypeMapping(), marshaller);
             }
 
             imports.add("java.io.DataInput");
@@ -447,66 +446,98 @@
 
             if (describedType.isList()) {
                 writer.newLine();
-                writer.write(tab(1) + "private static final ListDecoder DECODER = new ListDecoder() {");
+                writer.write(tab(1) + "private static final ListDecoder<" + TypeRegistry.any().typeMapping + "> DECODER = new ListDecoder<" + TypeRegistry.any().typeMapping + ">() {");
+                writer.newLine();
+                writer
+                        .write(tab(2) + "public final IAmqpList<" + TypeRegistry.any().typeMapping
+                                + "> unmarshalType(int dataCount, int dataSize, DataInput in) throws AmqpEncodingError, IOException {");
                 writer.newLine();
-                writer.write(tab(2) + "public final " + TypeRegistry.any().typeMapping + " unmarshalType(int pos, DataInput in) throws IOException {");
+                writer.write(tab(3) + "if (dataCount > " + fields.size() + ") {");
                 writer.newLine();
-                writer.write(tab(3) + "switch(pos) {");
+                writer.write(tab(4) + "throw new AmqpEncodingError(\"Too many fields for \" + SYMBOLIC_ID + \": \" + dataCount);");
+                writer.newLine();
+                writer.write(tab(3) + "}");
+
                 writer.newLine();
+                writer.write(tab(3) + "IAmqpList<" + TypeRegistry.any().typeMapping + "> rc = new IAmqpList.ArrayBackedList<" + TypeRegistry.any().typeMapping + ">(new "
+                        + TypeRegistry.any().typeMapping + "[" + fields.size() + "]);");
                 int f = 0;
                 for (AmqpField field : fields.values()) {
                     AmqpClass fieldType = field.resolveAmqpFieldType();
-
-                    writer.write(tab(3) + "case " + f++ + ": {");
+                    writer.newLine();
+                    writer.write(tab(3) + "//" + field.getName() + ":");
+                    writer.newLine();
+                    writer.write(tab(3) + "if(dataCount > 0) {");
                     writer.newLine();
                     if (fieldType.isAny()) {
-                        writer.write(tab(4) + "return AmqpMarshaller.SINGLETON.unmarshalType(in);");
+                        writer.write(tab(4) + "rc.set(" + f + ", AmqpMarshaller.SINGLETON.unmarshalType(in));");
                     } else {
-                        writer.write(tab(4) + "return " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller() + ".createEncoded(in));");
+                        writer.write(tab(4) + "rc.set(" + f + ", " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller() + ".createEncoded(in)));");
                     }
                     writer.newLine();
+                    writer.write(tab(4) + "dataCount--;");
+                    writer.newLine();
                     writer.write(tab(3) + "}");
                     writer.newLine();
+                    if (field.isRequired()) {
+                        writer.write(tab(3) + "else {");
+                        writer.newLine();
+                        writer.write(tab(4) + "throw new AmqpEncodingError(\"Missing required field for \" + SYMBOLIC_ID + \": " + field.getName() + "\");");
+                        writer.newLine();
+                        writer.write(tab(3) + "}");
+                        writer.newLine();
+                    }
+                    f++;
                 }
-                writer.write(tab(3) + "default: {");
-                writer.newLine();
-                writer.write(tab(4) + "return AmqpMarshaller.SINGLETON.unmarshalType(in);");
-                writer.newLine();
-                writer.write(tab(3) + "}");
-                writer.newLine();
-                writer.write(tab(3) + "}");
+
+                writer.write(tab(3) + "return rc;");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public final " + TypeRegistry.any().typeMapping + " decodeType(int pos, EncodedBuffer buffer) throws AmqpEncodingError {");
+                writer.write(tab(2) + "public IAmqpList<" + TypeRegistry.any().typeMapping + "> decode(EncodedBuffer[] constituents) {");
+                writer.newLine();
+                writer.write(tab(3) + "if (constituents.length > " + fields.size() + ") {");
                 writer.newLine();
-                writer.write(tab(3) + "switch(pos) {");
+                writer.write(tab(4) + "throw new AmqpEncodingError(\"Too many fields for \" + SYMBOLIC_ID + \":\" + constituents.length);");
                 writer.newLine();
+                writer.write(tab(3) + "}");
 
+                writer.newLine();
+                writer.write(tab(3) + "int dataCount = constituents.length;");
+                writer.newLine();
+                writer.write(tab(3) + "IAmqpList<" + TypeRegistry.any().typeMapping + "> rc = new IAmqpList.ArrayBackedList<" + TypeRegistry.any().typeMapping + ">(new "
+                        + TypeRegistry.any().typeMapping + "[" + fields.size() + "]);");
                 f = 0;
                 for (AmqpField field : fields.values()) {
                     AmqpClass fieldType = field.resolveAmqpFieldType();
-
-                    writer.write(tab(3) + "case " + f++ + ": {");
+                    writer.newLine();
+                    writer.write(tab(3) + "//" + field.getName() + ":");
+                    writer.newLine();
+                    writer.write(tab(3) + "if(dataCount > 0) {");
                     writer.newLine();
                     if (fieldType.isAny()) {
-                        writer.write(tab(4) + "return " + fieldType.getMarshaller() + ".decodeType(buffer);");
+                        writer.write(tab(4) + "rc.set(" + f + ", AmqpMarshaller.SINGLETON.decodeType(constituents[" + f + "]));");
                     } else {
-                        writer.write(tab(4) + "return " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller() + ".createEncoded(buffer));");
+                        writer.write(tab(4) + "rc.set(" + f + ", " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller() + ".createEncoded(constituents[" + f + "])));");
                     }
                     writer.newLine();
+                    writer.write(tab(4) + "dataCount--;");
+                    writer.newLine();
                     writer.write(tab(3) + "}");
                     writer.newLine();
+                    if (field.isRequired()) {
+                        writer.write(tab(3) + "else {");
+                        writer.newLine();
+                        writer.write(tab(4) + "throw new AmqpEncodingError(\"Missing required field for \" + SYMBOLIC_ID + \": " + field.getName() + "\");");
+                        writer.newLine();
+                        writer.write(tab(3) + "}");
+                        writer.newLine();
+                    }
+                    f++;
                 }
-                writer.write(tab(3) + "default: {");
-                writer.newLine();
-                writer.write(tab(4) + "return AmqpMarshaller.SINGLETON.decodeType(buffer);");
-                writer.newLine();
-                writer.write(tab(3) + "}");
-                writer.newLine();
-                writer.write(tab(3) + "}");
+                writer.write(tab(3) + "return rc;");
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
@@ -521,84 +552,104 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public IAmqpMap<AmqpSymbol, AmqpType<?, ?>> createMap(int entryCount) {");
+                writer.write(tab(2) + "public IAmqpMap<AmqpSymbol, AmqpType<?, ?>> decode(EncodedBuffer[] constituents) throws AmqpEncodingError {");
                 writer.newLine();
-                writer.write(tab(3) + "return new IAmqpMap.AmqpWrapperMap<AmqpSymbol, AmqpType<?,?>>(new HashMap<AmqpSymbol, AmqpType<?,?>>());");
+                writer.write(tab(3) + "IAmqpMap<AmqpSymbol, AmqpType<?, ?>> rc = new IAmqpMap.AmqpWrapperMap<AmqpSymbol, AmqpType<?,?>>(new HashMap<AmqpSymbol, AmqpType<?,?>>());");
                 writer.newLine();
+                writer.write(tab(3) + "if (constituents.length % 2 != 0) {");
                 writer.newLine();
-                writer.write(tab(2) + "}");
+                writer.write(tab(4) + "throw new AmqpEncodingError(\"Invalid number of compound constituents for \" + SYMBOLIC_ID + \": \" + constituents.length);");
                 writer.newLine();
-
+                writer.write(tab(3) + "}");
                 writer.newLine();
-                writer.write(tab(2) + "public void decodeToMap(EncodedBuffer encodedKey, EncodedBuffer encodedValue, IAmqpMap<AmqpSymbol," + TypeRegistry.any().typeMapping
-                        + "> map) throws AmqpEncodingError {");
+
+                writer.write(tab(3) + "for (int i = 0; i < constituents.length; i += 2) {");
                 writer.newLine();
-                writer.write(tab(3) + "AmqpSymbol key = AmqpSymbol.AmqpSymbolBuffer.create(AmqpSymbolMarshaller.createEncoded(encodedKey));");
+                writer.write(tab(4) + "AmqpSymbol key = AmqpSymbol.AmqpSymbolBuffer.create(AmqpSymbolMarshaller.createEncoded(constituents[i]));");
                 writer.newLine();
-                writer.write(tab(3) + "if (key == null) {");
+                writer.write(tab(4) + "if (key == null) {");
                 writer.newLine();
-                writer.write(tab(4) + "throw new AmqpEncodingError(\"Null Key for \" + SYMBOLIC_ID);");
+                writer.write(tab(5) + "throw new AmqpEncodingError(\"Null Key for \" + SYMBOLIC_ID);");
                 writer.newLine();
-                writer.write(tab(3) + "}");
+                writer.write(tab(4) + "}");
                 writer.newLine();
                 writer.newLine();
                 int f = 0;
                 for (AmqpField field : fields.values()) {
                     AmqpClass fieldType = field.resolveAmqpFieldType();
-                    writer.write(tab(3) + (f > 0 ? "else " : "") + "if (key.equals(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY)){");
+                    writer.write(tab(4) + (f > 0 ? "else " : "") + "if (key.equals(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY)){");
                     writer.newLine();
                     if (fieldType.isAny()) {
-                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(buffer));");
+                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(constituents[i + 1]));");
                     } else {
-                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
-                                + ".createEncoded(encodedValue)));");
+                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
+                                + ".createEncoded(constituents[i + 1])));");
                     }
                     writer.newLine();
-                    writer.write(tab(3) + "}");
+                    writer.write(tab(4) + "}");
                     writer.newLine();
                 }
-                writer.write(tab(3) + "else {");
+                writer.write(tab(4) + "else {");
+                writer.newLine();
+                writer.write(tab(5) + "throw new UnexpectedTypeException(\"Invalid field key for \" + SYMBOLIC_ID + \" : \" + key);");
                 writer.newLine();
-                writer.write(tab(4) + "throw new UnexpectedTypeException(\"Invalid Key for \" + SYMBOLIC_ID + \" : \" + key);");
+                writer.write(tab(4) + "}");
                 writer.newLine();
                 writer.write(tab(3) + "}");
                 writer.newLine();
+                writer.write(tab(3) + "return rc;");
+                writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public void unmarshalToMap(DataInput in, IAmqpMap<AmqpSymbol," + TypeRegistry.any().typeMapping + "> map) throws IOException, AmqpEncodingError {");
+                writer.write(tab(2) + "public IAmqpMap<AmqpSymbol, AmqpType<?, ?>> unmarshalType(int dataCount, int dataSize, DataInput in) throws IOException, AmqpEncodingError {");
                 writer.newLine();
-                writer.write(tab(3) + "AmqpSymbol key = AmqpSymbol.AmqpSymbolBuffer.create(AmqpSymbolMarshaller.createEncoded(in));");
+                writer.write(tab(3) + "IAmqpMap<AmqpSymbol, AmqpType<?, ?>> rc = new IAmqpMap.AmqpWrapperMap<AmqpSymbol, AmqpType<?,?>>(new HashMap<AmqpSymbol, AmqpType<?,?>>());");
                 writer.newLine();
-                writer.write(tab(3) + "if (key == null) {");
+                writer.write(tab(3) + "if (dataCount % 2 != 0) {");
                 writer.newLine();
-                writer.write(tab(4) + "throw new AmqpEncodingError(\"Null Key for \" + SYMBOLIC_ID);");
+                writer.write(tab(4) + "throw new AmqpEncodingError(\"Invalid number of compound constituents for \" + SYMBOLIC_ID + \": \" + dataCount);");
                 writer.newLine();
                 writer.write(tab(3) + "}");
                 writer.newLine();
+
+                writer.write(tab(3) + "for (int i = 0; i < dataCount; i += 2) {");
+                writer.newLine();
+                writer.write(tab(4) + "AmqpSymbol key = AmqpSymbol.AmqpSymbolBuffer.create(AmqpSymbolMarshaller.createEncoded(in));");
+                writer.newLine();
+                writer.write(tab(4) + "if (key == null) {");
+                writer.newLine();
+                writer.write(tab(5) + "throw new AmqpEncodingError(\"Null Key for \" + SYMBOLIC_ID);");
+                writer.newLine();
+                writer.write(tab(4) + "}");
+                writer.newLine();
                 writer.newLine();
                 f = 0;
                 for (AmqpField field : fields.values()) {
                     AmqpClass fieldType = field.resolveAmqpFieldType();
-                    writer.write(tab(3) + (f > 0 ? "else " : "") + "if (key.equals(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY)){");
+                    writer.write(tab(4) + (f > 0 ? "else " : "") + "if (key.equals(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY)){");
                     writer.newLine();
                     if (fieldType.isAny()) {
-                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.unmarshalType(in));");
+                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(in));");
                     } else {
-                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
+                        writer.write(tab(5) + "rc.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
                                 + ".createEncoded(in)));");
                     }
                     writer.newLine();
-                    writer.write(tab(3) + "}");
+                    writer.write(tab(4) + "}");
                     writer.newLine();
                 }
-                writer.write(tab(3) + "else {");
+                writer.write(tab(4) + "else {");
+                writer.newLine();
+                writer.write(tab(5) + "throw new UnexpectedTypeException(\"Invalid field key for \" + SYMBOLIC_ID + \" : \" + key);");
                 writer.newLine();
-                writer.write(tab(4) + "throw new UnexpectedTypeException(\"Invalid Key for \" + SYMBOLIC_ID + \" : \" + key);");
+                writer.write(tab(4) + "}");
                 writer.newLine();
                 writer.write(tab(3) + "}");
                 writer.newLine();
+                writer.write(tab(3) + "return rc;");
+                writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
 
@@ -893,20 +944,17 @@
             writer.write(tab(1) + "}");
             writer.newLine();
 
-            String decoderArg = "";
             writer.write(tab(1) + "public static abstract class " + getJavaType() + "Encoded extends AbstractEncoded <" + getValueMapping().getJavaType() + "> {");
             if (isList()) {
                 writer.newLine();
                 writer.write(tab(2) + "ListDecoder decoder = Encoder.DEFAULT_LIST_DECODER;");
                 writer.newLine();
-                decoderArg = ", decoder";
             }
 
             if (isMap()) {
                 writer.newLine();
                 writer.write(tab(2) + "MapDecoder decoder = Encoder.DEFAULT_MAP_DECODER;");
                 writer.newLine();
-                decoderArg = ", decoder";
             }
 
             writer.newLine();
@@ -1005,25 +1053,27 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " decode(EncodedBuffer encoded) throws AmqpEncodingError {");
+                writer.write(tab(2) + "public final void marshalData(DataOutput out) throws IOException {");
                 writer.newLine();
-                if (hasCompoundEncoding()) {
-                    writer.write(tab(3) + "return ENCODER.decode" + capFirst(toJavaName(name)) + eName + "(encoded.getBuffer(), encoded.getDataOffset(), encoded.getDataCount(), encoded.getDataSize()"
-                            + decoderArg + ");");
-                } else if (hasNonZeroEncoding()) {
-                    writer.write(tab(3) + "return ENCODER.decode" + capFirst(toJavaName(name)) + eName + "(encoded.getBuffer(), encoded.getDataOffset(), encoded.getDataSize()" + decoderArg + ");");
-                } else {
-                    writer.write(tab(3) + "return ENCODER.valueOf" + capFirst(toJavaName(name)) + "(encoding);");
+                if (hasNonZeroEncoding()) {
+                    writer.write(tab(3) + "ENCODER.write" + capFirst(toJavaName(name)) + eName + "(value, out);");
                 }
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(2) + "public final void marshalData(DataOutput out) throws IOException {");
+                writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " decode(EncodedBuffer encoded) throws AmqpEncodingError {");
                 writer.newLine();
-                if (hasNonZeroEncoding()) {
-                    writer.write(tab(3) + "ENCODER.write" + capFirst(toJavaName(name)) + eName + "(value, out);");
+                if (isList() || isMap()) {
+                    writer.write(tab(3) + "return decoder.decode(encoded.asCompound().constituents());");
+                } else if (hasCompoundEncoding()) {
+                    writer.write(tab(3) + "return ENCODER.decode" + capFirst(toJavaName(name)) + eName
+                            + "(encoded.getBuffer(), encoded.getDataOffset(), encoded.getDataCount(), encoded.getDataSize());");
+                } else if (hasNonZeroEncoding()) {
+                    writer.write(tab(3) + "return ENCODER.decode" + capFirst(toJavaName(name)) + eName + "(encoded.getBuffer(), encoded.getDataOffset(), encoded.getDataSize());");
+                } else {
+                    writer.write(tab(3) + "return ENCODER.valueOf" + capFirst(toJavaName(name)) + "(encoding);");
                 }
                 writer.newLine();
                 writer.write(tab(2) + "}");
@@ -1033,12 +1083,14 @@
                 writer.write(tab(2) + "public final " + getValueMapping().getJavaType() + " unmarshalData(DataInput in) throws IOException {");
                 writer.newLine();
 
-                if (hasCompoundEncoding()) {
-                    writer.write(tab(3) + "return ENCODER.read" + capFirst(toJavaName(name)) + eName + "(getDataCount(), getDataSize(), in" + decoderArg + ");");
+                if (isList() || isMap()) {
+                    writer.write(tab(3) + "return decoder.unmarshalType(getDataCount(), getDataSize(), in);");
+                } else if (hasCompoundEncoding()) {
+                    writer.write(tab(3) + "return ENCODER.read" + capFirst(toJavaName(name)) + eName + "(getDataCount(), getDataSize(), in);");
                 } else if (hasNonZeroEncoding()) {
-                    writer.write(tab(3) + "return ENCODER.read" + capFirst(toJavaName(name)) + eName + "(getDataSize(), in" + decoderArg + ");");
+                    writer.write(tab(3) + "return ENCODER.read" + capFirst(toJavaName(name)) + eName + "(getDataSize(), in);");
                 } else {
-                    writer.write(tab(3) + "return ENCODER.valueOf" + capFirst(toJavaName(name)) + "(encoding" + decoderArg + ");");
+                    writer.write(tab(3) + "return ENCODER.valueOf" + capFirst(toJavaName(name)) + "(encoding);");
                 }
                 writer.newLine();
                 writer.write(tab(2) + "}");
@@ -1091,7 +1143,7 @@
         AmqpClass baseType = resolveBaseType();
 
         writer.newLine();
-        writer.write(tab(indent++) + "public static class " + getJavaType() + "Bean implements " + getJavaType() + "{");
+        writer.write(tab(indent++) + "public static class " + beanMapping.getShortName() + " implements " + typeMapping + "{");
         writer.newLine();
 
         writer.newLine();
@@ -1108,7 +1160,8 @@
             writer.write(tab(indent) + "" + beanMapping.getShortName() + "() {");
             writer.newLine();
             if (baseType.isMap()) {
-                writer.write(tab(indent + 1) + "this.value = new IAmqpMap.AmqpWrapperMap<AmqpType<?,?>, AmqpType<?,?>>(new HashMap<AmqpType<?,?>, AmqpType<?,?>>());");
+                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<?,?>>());");
@@ -1119,11 +1172,11 @@
         }
 
         writer.newLine();
-        writer.write(tab(indent) + beanMapping.getShortName() + "(" + baseType.getValueMapping() + " value) {");
+        writer.write(tab(indent) + beanMapping.getShortName() + "(" + baseType.getValueMapping().getJavaType() + " value) {");
         writer.newLine();
         if (isDescribed() && baseType.isList()) {
             writer.newLine();
-            writer.write(tab(indent) + "for(int i = 0; i < value.getListCount(); i++) {");
+            writer.write(tab(++indent) + "for(int i = 0; i < value.getListCount(); i++) {");
             writer.newLine();
             writer.write(tab(++indent) + "set(i, value.get(i));");
             writer.newLine();
@@ -1335,7 +1388,7 @@
             AmqpClass describedType = descriptor.resolveDescribedType();
 
             writer.newLine();
-            writer.write(tab(indent++) + "public static class " + bufferMapping.getShortName() + " extends " + describedType.bufferMapping + " implements " + typeMapping + "{");
+            writer.write(tab(indent++) + "public static class " + bufferMapping.getClassName() + " extends " + describedType.bufferMapping + " implements " + typeMapping + "{");
             writer.newLine();
 
             writer.newLine();
@@ -1571,7 +1624,7 @@
                 JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
                 writer.write(tab(indent) + "public final " + returnType + " get" + capFirst(field.getJavaName()) + "() {");
                 writer.newLine();
-                if (!fieldClass.isAny() && fieldClass.isPrimitive()) {
+                if (!fieldClass.isAny() && fieldClass.isPrimitive() && !fieldClass.isMutable()) {
                     writer.write(tab(++indent) + "return bean." + field.getJavaName() + ".getValue();");
                 } else {
                     writer.write(tab(++indent) + "return bean." + field.getJavaName() + ";");
@@ -1623,7 +1676,7 @@
 
         if (isMap()) {
             if (!buffer) {
-                writer.write(tab(indent) + "public void put(" + TypeRegistry.any().typeMapping + " key, " + TypeRegistry.any().typeMapping + " value) {");
+                writer.write(tab(indent) + "public void put(" + getMapKeyType() + " key, " + getMapValueType() + " value) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "copyCheck();");
                 writer.newLine();
@@ -1633,7 +1686,7 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(Object key) {");
+                writer.write(tab(indent) + "public " + getMapValueType() + " get(Object key) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean.value.get(key);");
                 writer.newLine();
@@ -1649,7 +1702,7 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<Map.Entry<" + TypeRegistry.any().getJavaType() + ", " + TypeRegistry.any().getJavaType() + ">> iterator() {");
+                writer.write(tab(indent) + "public Iterator<Map.Entry<" + getMapKeyType() + ", " + getMapValueType() + ">> iterator() {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean.value.iterator();");
                 writer.newLine();
@@ -1657,7 +1710,7 @@
                 writer.newLine();
 
             } else {
-                writer.write(tab(indent) + "public void put(" + TypeRegistry.any().typeMapping + " key, " + TypeRegistry.any().typeMapping + " value) {");
+                writer.write(tab(indent) + "public void put(" + getMapKeyType() + " key, " + getMapValueType() + " value) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "bean().put(key, value);");
                 writer.newLine();
@@ -1665,7 +1718,7 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(Object key) {");
+                writer.write(tab(indent) + "public " + getMapValueType() + " get(Object key) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().get(key);");
                 writer.newLine();
@@ -1681,7 +1734,7 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<Map.Entry<" + TypeRegistry.any().getJavaType() + ", " + TypeRegistry.any().getJavaType() + ">> iterator() {");
+                writer.write(tab(indent) + "public Iterator<Map.Entry<" + getMapKeyType() + ", " + getMapValueType() + ">> iterator() {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().iterator();");
                 writer.newLine();
@@ -1720,7 +1773,7 @@
                 writer.newLine();
                 writer.write(tab(indent) + "public Iterator<" + TypeRegistry.any().typeMapping + "> iterator() {");
                 writer.newLine();
-                writer.write(tab(++indent) + "return new AmqpListIterator(bean.value);");
+                writer.write(tab(++indent) + "return new AmqpListIterator<" + TypeRegistry.any().typeMapping + ">(bean.value);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
@@ -1854,7 +1907,7 @@
                 writer.newLine();
                 writer.write(tab(indent) + "public Iterator<AmqpType<?, ?>> iterator() {");
                 writer.newLine();
-                writer.write(tab(++indent) + "return new AmqpListIterator(bean);");
+                writer.write(tab(++indent) + "return new AmqpListIterator<" + TypeRegistry.any().typeMapping + ">(bean);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
@@ -1868,7 +1921,7 @@
             resolveRestrictedType().writeFieldAccesors(writer, indent, buffer);
         }
 
-        if (isPrimitive()) {
+        if (isPrimitive() && !isMutable()) {
 
             // Getter:
             writer.newLine();
@@ -1949,9 +2002,9 @@
 
         if (isMap()) {
             doc.writeJavaDoc(writer, indent);
-            writer.write(tab(indent) + "public void put(" + TypeRegistry.any().typeMapping + " key, " + TypeRegistry.any().typeMapping + " value);");
+            writer.write(tab(indent) + "public void put(" + getMapKeyType() + " key, " + getMapValueType() + " value);");
             writer.newLine();
-            writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(Object key);");
+            writer.write(tab(indent) + "public " + getMapValueType() + " get(Object key);");
             writer.newLine();
 
         } else if (isList()) {
@@ -1964,7 +2017,7 @@
             writer.newLine();
         }
 
-        if (isPrimitive()) {
+        if (isPrimitive() && !isMutable()) {
             // Getter:
             writer.newLine();
             writer.write(tab(1) + "public " + valueMapping + " getValue();");
@@ -1979,7 +2032,7 @@
 
         String packageName = generator.getMarshallerPackage();
 
-        File file = new File(generator.getOutputDirectory() + File.separator + new String(packageName).replace(".", File.separator) + File.separator + typeMapping + "Marshaller.java");
+        File file = new File(generator.getOutputDirectory() + File.separator + new String(packageName).replace(".", File.separator) + File.separator + typeMapping.getClassName() + "Marshaller.java");
         file.getParentFile().mkdirs();
         if (file.exists()) {
             file.delete();
@@ -2188,7 +2241,11 @@
                 writer.newLine();
                 writer.write(tab(1) + "private static final " + getEncodingName(false) + " chooseEncoding(" + getJavaType() + " val) throws AmqpEncodingError {");
                 writer.newLine();
-                writer.write(tab(2) + "return Encoder.choose" + capFirst(name) + "Encoding(val.getValue());");
+                if (isMutable()) {
+                    writer.write(tab(2) + "return Encoder.choose" + capFirst(name) + "Encoding(val);");
+                } else {
+                    writer.write(tab(2) + "return Encoder.choose" + capFirst(name) + "Encoding(val.getValue());");
+                }
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
@@ -2210,7 +2267,11 @@
                 writer.newLine();
                 writer.write(tab(2) + "}");
                 writer.newLine();
-                writer.write(tab(2) + "return " + getEncodingName(false) + ".createEncoded(chooseEncoding(data).FORMAT_CODE, data.getValue());");
+                if (isMutable()) {
+                    writer.write(tab(2) + "return " + getEncodingName(false) + ".createEncoded(chooseEncoding(data).FORMAT_CODE, data);");
+                } else {
+                    writer.write(tab(2) + "return " + getEncodingName(false) + ".createEncoded(chooseEncoding(data).FORMAT_CODE, data.getValue());");
+                }
                 writer.newLine();
                 writer.write(tab(1) + "}");
                 writer.newLine();
@@ -2397,10 +2458,22 @@
         return name.equals("map");
     }
 
+    public final String getMapKeyType() {
+        return mapKeyType;
+    }
+
+    public final String getMapValueType() {
+        return mapValueType;
+    }
+
     public boolean isList() {
         return name.equals("list");
     }
 
+    public final String getListElementType() {
+        return listElementType;
+    }
+
     public boolean isMarshallable() {
         return isDescribed() || isPrimitive() || (isRestricted() && !isEnumType());
     }

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=909703&r1=909702&r2=909703&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java Sat Feb 13 03:19:48 2010
@@ -8,30 +8,6 @@
     private static final HashMap<String, JavaTypeMapping> JAVA_TYPE_MAP = new HashMap<String, JavaTypeMapping>();
     private static final HashMap<String, AmqpClass> GENERATED_TYPE_MAP = new HashMap<String, AmqpClass>();
 
-    static {
-        JAVA_TYPE_MAP.put("boolean", new JavaTypeMapping("boolean", "java.lang.Boolean"));
-        JAVA_TYPE_MAP.put("ubyte", new JavaTypeMapping("ubyte", "java.lang.Short"));
-        JAVA_TYPE_MAP.put("ushort", new JavaTypeMapping("ushort", "java.lang.Integer"));
-        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "java.lang.Long"));
-        JAVA_TYPE_MAP.put("ulong", new JavaTypeMapping("ulong", "java.math.BigInteger"));
-        JAVA_TYPE_MAP.put("byte", new JavaTypeMapping("byte", "java.lang.Byte"));
-        JAVA_TYPE_MAP.put("short", new JavaTypeMapping("short", "java.lang.Short"));
-        JAVA_TYPE_MAP.put("int", new JavaTypeMapping("int", "java.lang.Integer"));
-        JAVA_TYPE_MAP.put("long", new JavaTypeMapping("long", "java.lang.Long"));
-        JAVA_TYPE_MAP.put("float", new JavaTypeMapping("float", "java.lang.Float"));
-        JAVA_TYPE_MAP.put("double", new JavaTypeMapping("double", "java.lang.Double"));
-        JAVA_TYPE_MAP.put("char", new JavaTypeMapping("char", "java.lang.Integer"));
-        JAVA_TYPE_MAP.put("timestamp", new JavaTypeMapping("timestamp", "java.util.Date"));
-        JAVA_TYPE_MAP.put("uuid", new JavaTypeMapping("uuid", "java.util.UUID"));
-        JAVA_TYPE_MAP.put("binary", new JavaTypeMapping("binary", "org.apache.activemq.util.buffer.Buffer"));
-        JAVA_TYPE_MAP.put("string", new JavaTypeMapping("string", "java.lang.String"));
-        JAVA_TYPE_MAP.put("symbol", new JavaTypeMapping("symbol", "java.lang.String"));
-        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", "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:
@@ -57,7 +33,7 @@
         JAVA_TYPE_MAP.put("binary", new JavaTypeMapping("binary", "org.apache.activemq.util.buffer.Buffer"));
         JAVA_TYPE_MAP.put("string", new JavaTypeMapping("string", "java.lang.String"));
         JAVA_TYPE_MAP.put("symbol", new JavaTypeMapping("symbol", "java.lang.String"));
-        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", generator.getPackagePrefix() + ".types.IAmqpList"));
+        JAVA_TYPE_MAP.put("list", new JavaTypeMapping("list", generator.getPackagePrefix() + ".types.IAmqpList", false, "<" + any.getJavaType() + ">"));
         JAVA_TYPE_MAP.put("map", new JavaTypeMapping("map", generator.getPackagePrefix() + ".types.IAmqpMap", false, "<" + any.getJavaType() + ", " + any.getJavaType() + ">"));
         JAVA_TYPE_MAP.put("null", new JavaTypeMapping("null", "java.lang.Object"));
 
@@ -143,10 +119,7 @@
         JavaTypeMapping(String amqpType, String fullName, boolean array, String generic) {
             this(amqpType, fullName);
             this.array = array;
-            this.generic = generic;
-            if (generic != null) {
-                javaType = javaType + generic;
-            }
+            setGeneric(generic);
             if (array) {
                 javaType = javaType + " []";
             }
@@ -199,6 +172,10 @@
             this.amqpType = amqpType;
         }
 
+        public String getClassName() {
+            return shortName;
+        }
+
         public String getShortName() {
             return shortName;
         }
@@ -227,6 +204,28 @@
             return javaType;
         }
 
+        private String parameratize(String str, String... generics) {
+            if (generic != null) {
+                if (generics != null && generics.length > 0) {
+                    boolean first = true;
+                    for (String g : generics) {
+                        if (!first) {
+                            str += ", " + g;
+                        } else {
+                            first = false;
+                            str += "<" + g;
+                        }
+                    }
+                    return str + ">";
+
+                } else {
+                    return javaType + generic;
+                }
+
+            }
+            return str;
+        }
+
         public void setJavaType(String javaType) {
             this.javaType = javaType;
         }
@@ -245,6 +244,7 @@
 
         public void setGeneric(String generic) {
             this.generic = generic;
+            javaType = shortName + generic;
         }
 
         public String getFullVersionMarshallerName(Generator generator) {
@@ -256,7 +256,7 @@
         }
 
         public String toString() {
-            return javaType;
+            return getJavaType();
         }
     }
 



Mime
View raw message