activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r909223 - 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 Fri, 12 Feb 2010 04:24:27 GMT
Author: cmacnaug
Date: Fri Feb 12 04:24:26 2010
New Revision: 909223

URL: http://svn.apache.org/viewvc?rev=909223&view=rev
Log:
Added a TypeFactory for creating Types.
Added primitive field accessors to assist in usability. 
Updates to Map encoded types to allow copy on write checking.
Updates to equivalency checking.

Added:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpMap.java
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/AmqpType.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/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=909223&r1=909222&r2=909223&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 Fri Feb 12 04:24:26 2010
@@ -35,6 +35,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.util.buffer.Buffer;
 
 public class Encoder extends BaseEncoder {
@@ -56,13 +57,18 @@
         }
     };
 
-    static final MapDecoder DEFAULT_MAP_DECODER = new MapDecoder() {
+    static final MapDecoder<AmqpType<?,?>, AmqpType<?, ?>> DEFAULT_MAP_DECODER = new MapDecoder<AmqpType<?,?>, AmqpType<?, ?>>() {
 
-        public final void decodeToMap(EncodedBuffer key, EncodedBuffer val, Map<AmqpType<?, ?>, AmqpType<?, ?>> map) throws AmqpEncodingError {
+        public IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> createMap(int entryCount) {
+            return new IAmqpMap.AmqpWrapperMap<AmqpType<?,?>, AmqpType<?,?>>(new HashMap<AmqpType<?,?>, AmqpType<?,?>>());
+        }
+
+        public void decodeToMap(EncodedBuffer key, EncodedBuffer val, IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> map) throws AmqpEncodingError {
             map.put(MARSHALLER.decodeType(key), MARSHALLER.decodeType(key));
+            
         }
 
-        public final void unmarshalToMap(DataInput in, Map<AmqpType<?, ?>, AmqpType<?, ?>> map) throws IOException, AmqpEncodingError {
+        public void unmarshalToMap(DataInput in, IAmqpMap<AmqpType<?, ?>, AmqpType<?, ?>> map) throws IOException, AmqpEncodingError {
             map.put(MARSHALLER.unmarshalType(in), MARSHALLER.unmarshalType(in));
         }
     };
@@ -1104,10 +1110,12 @@
         AmqpType<?, ?> unmarshalType(int pos, DataInput in) throws IOException, AmqpEncodingError;
     }
 
-    public static interface MapDecoder {
-        void decodeToMap(EncodedBuffer key, EncodedBuffer val, Map<AmqpType<?, ?>, AmqpType<?, ?>> map) throws 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, Map<AmqpType<?, ?>, AmqpType<?, ?>> map) throws IOException, AmqpEncodingError;
+        public void unmarshalToMap(DataInput in, IAmqpMap<K, V> map) throws IOException, AmqpEncodingError;
+
+        IAmqpMap<K, V> createMap(int entryCount);
     }
 
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1203,7 +1211,7 @@
             return new AmqpListIterator(this);
         }
     }
-
+    
     public static final AmqpListMarshaller.LIST_ENCODING chooseListEncoding(IAmqpList val) throws AmqpEncodingError {
         if (val.getListCount() > 255) {
             return AmqpListMarshaller.LIST_ENCODING.LIST32;
@@ -1392,8 +1400,9 @@
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
     // Map ENCODINGS
     // ///////////////////////////////////////////////////////////////////////////////////////////////////
-    public static final AmqpMapMarshaller.MAP_ENCODING chooseMapEncoding(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> val) throws AmqpEncodingError {
-        for (Map.Entry<AmqpType<?, ?>, AmqpType<?, ?>> me : val.entrySet()) {
+    public static final AmqpMapMarshaller.MAP_ENCODING chooseMapEncoding(IAmqpMap<?, ?> map) throws AmqpEncodingError {
+        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;
@@ -1402,54 +1411,54 @@
         return AmqpMapMarshaller.MAP_ENCODING.MAP8;
     }
 
-    public final int getEncodedSizeOfMap(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> val, MAP_ENCODING encoding) throws AmqpEncodingError {
+    public final int getEncodedSizeOfMap(IAmqpMap<?, ?> map, MAP_ENCODING encoding) throws AmqpEncodingError {
         int size = 0;
-        for (Map.Entry<AmqpType<?, ?>, AmqpType<?, ?>> me : val.entrySet()) {
+        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : map) {
             size += me.getKey().getBuffer(MARSHALLER).getEncoded().getEncodedSize() + me.getValue().getBuffer(MARSHALLER).getEncoded().getEncodedSize();
         }
         return size;
     }
 
-    public final int getEncodedCountOfMap(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> val, MAP_ENCODING mapENCODING) throws AmqpEncodingError {
-        return val.size() * 2;
+    public final int getEncodedCountOfMap(IAmqpMap<?, ?> map, MAP_ENCODING mapENCODING) throws AmqpEncodingError {
+        return map.getEntryCount() * 2;
     }
 
-    public final void encodeMapMap32(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> value, Buffer target, int offset) throws AmqpEncodingError {
+    public final void encodeMapMap32(IAmqpMap<?, ?> value, Buffer target, int offset) throws AmqpEncodingError {
         encodeMap(value, target, offset);
     }
 
-    public final HashMap<AmqpType<?, ?>, AmqpType<?, ?>> decodeMapMap32(Buffer source, int offset, int count, int size, MapDecoder decoder) throws AmqpEncodingError {
+    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(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> val, DataOutput out) throws AmqpEncodingError, IOException {
+    public final void writeMapMap32(IAmqpMap<?, ?> val, DataOutput out) throws AmqpEncodingError, IOException {
         writeMap(val, out);
 
     }
 
-    public final HashMap<AmqpType<?, ?>, AmqpType<?, ?>> readMapMap32(int count, int size, DataInput in, MapDecoder decoder) throws AmqpEncodingError, IOException {
+    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(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> value, Buffer target, int offset) throws AmqpEncodingError {
+    public final void encodeMapMap8(IAmqpMap<?, ?> value, Buffer target, int offset) throws AmqpEncodingError {
         encodeMap(value, target, offset);
     }
 
-    public final HashMap<AmqpType<?, ?>, AmqpType<?, ?>> decodeMapMap8(Buffer source, int offset, int count, int size, MapDecoder decoder) throws AmqpEncodingError {
+    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(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> val, DataOutput out) throws AmqpEncodingError, IOException {
+    public final void writeMapMap8(IAmqpMap<?, ?> val, DataOutput out) throws AmqpEncodingError, IOException {
         writeMap(val, out);
 
     }
 
-    public final HashMap<AmqpType<?, ?>, AmqpType<?, ?>> readMapMap8(int count, int size, DataInput in, MapDecoder decoder) throws AmqpEncodingError, IOException {
+    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 HashMap<AmqpType<?, ?>, AmqpType<?, ?>> decodeMap(Buffer source, int offset, int count, int size, MapDecoder decoder) throws AmqpEncodingError {
-        HashMap<AmqpType<?, ?>, AmqpType<?, ?>> rc = new HashMap<AmqpType<?, ?>, AmqpType<?, ?>>();
+    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();
@@ -1459,9 +1468,18 @@
         }
         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(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> value, Buffer target, int offset) throws AmqpEncodingError {
-        for (Map.Entry<AmqpType<?, ?>, AmqpType<?, ?>> me : value.entrySet()) {
+    public static final void encodeMap(IAmqpMap<?, ?> value, Buffer target, int offset) throws AmqpEncodingError {
+        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : value) {
             Encoded<?> eKey = me.getKey().getBuffer(MARSHALLER).getEncoded();
             eKey.encode(target, offset);
             offset += eKey.getEncodedSize();
@@ -1472,18 +1490,10 @@
         }
     }
 
-    public static final void writeMap(HashMap<AmqpType<?, ?>, AmqpType<?, ?>> val, DataOutput out) throws IOException, AmqpEncodingError {
-        for (Map.Entry<AmqpType<?, ?>, AmqpType<?, ?>> me : val.entrySet()) {
+    public static final void writeMap(IAmqpMap<?, ?> val, DataOutput out) throws IOException, AmqpEncodingError {
+        for (Map.Entry<? extends AmqpType<?,?>, ? extends AmqpType<?,?>> me : val) {
             me.getKey().marshal(out, MARSHALLER);
             me.getValue().marshal(out, MARSHALLER);
         }
     }
-
-    public static final HashMap<AmqpType<?, ?>, AmqpType<?, ?>> readMap(int count, int size, DataInput in, MapDecoder decoder) throws IOException, AmqpEncodingError {
-        HashMap<AmqpType<?, ?>, AmqpType<?, ?>> rc = new HashMap<AmqpType<?, ?>, AmqpType<?, ?>>();
-        for (int i = 0; i < count; i += 2) {
-            decoder.unmarshalToMap(in, rc);
-        }
-        return rc;
-    }
 }
\ No newline at end of file

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java?rev=909223&r1=909222&r2=909223&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java Fri Feb 12 04:24:26 2010
@@ -26,6 +26,4 @@
     public EncodedBuffer getBuffer(AmqpMarshaller marshaller) throws AmqpEncodingError;
     
     public void marshal(DataOutput out, AmqpMarshaller marshaller) throws IOException, AmqpEncodingError;
-    
-    public boolean equivalent(AmqpType<?,?> t);
 }
\ 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=909223&r1=909222&r2=909223&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 Fri Feb 12 04:24:26 2010
@@ -17,6 +17,10 @@
 package org.apache.activemq.amqp.generator.handcoded.types;
 
 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 extends Iterable<AmqpType<?, ?>> {
 
@@ -46,4 +50,125 @@
             throw new UnsupportedOperationException();
         }
     }
+
+    public static abstract class AbstractAmqpList implements IAmqpList {
+        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) {
+            if (l1 == null ^ l2 == null) {
+                return false;
+            }
+
+            if (l1 == null) {
+                return true;
+            }
+
+            if (l1.getListCount() != l2.getListCount()) {
+                return false;
+            }
+
+            Iterator<?> i1 = l1.iterator();
+            Iterator<?> i2 = l2.iterator();
+            while (i1.hasNext()) {
+                Object e1 = i1.next();
+                Object e2 = i2.next();
+                if (!(e1 == null ? e2 == null : e1.equals(e2))) {
+                    return false;
+                }
+            }
+            return true;
+        }
+    }
+
+    public static class AmqpWrapperList extends AbstractAmqpList {
+        private final List<AmqpType<?, ?>> list;
+
+        public AmqpWrapperList(List<AmqpType<?, ?>> list) {
+            this.list = list;
+        }
+
+        public AmqpType<?, ?> get(int index) {
+            return list.get(index);
+        }
+
+        public int getListCount() {
+            return list.size();
+        }
+
+        public void set(int index, AmqpType<?, ?> value) {
+            list.set(index, value);
+        }
+
+        public Iterator<AmqpType<?, ?>> iterator() {
+            return list.iterator();
+        }
+
+        public boolean equals(Object o) {
+            if (o == null) {
+                return false;
+            }
+
+            if (o instanceof IAmqpList) {
+                return equals((IAmqpList) o);
+            }
+            return false;
+        }
+
+        public boolean equals(IAmqpList l) {
+            return checkEqual(this, l);
+        }
+
+        public int hashCode() {
+            return hashCodeFor(this);
+        }
+    }
+
+    public static class ArrayBackedList extends AbstractAmqpList {
+        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 boolean equals(Object o) {
+            if (o == null) {
+                return false;
+            }
+
+            if (o instanceof IAmqpList) {
+                return equals((IAmqpList) o);
+            }
+            return false;
+        }
+
+        public boolean equals(IAmqpList l) {
+            return checkEqual(this, l);
+        }
+
+        public int hashCode() {
+            return hashCodeFor(this);
+        }
+    }
 }
\ No newline at end of file

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpMap.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpMap.java?rev=909223&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpMap.java (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/IAmqpMap.java Fri Feb 12 04:24:26 2010
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with his work
+ * for additional information regarding copyright ownership. The ASF licenses
+ * this file to You under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.activemq.amqp.generator.handcoded.types;
+
+import java.util.Iterator;
+import java.util.Map;
+
+
+public interface IAmqpMap<K extends AmqpType<?, ?>, V extends AmqpType<?, ?>> extends Iterable<Map.Entry<K, V>> {
+
+    public void put(K key, V value);
+
+    public V get(Object key);
+    
+    public int getEntryCount();
+
+//    public void put(Object key, Object V);
+//    
+//    public V get(Object o) throws AmqpEncodingError;
+
+
+    public static abstract class AbstractAmqpMap<K extends AmqpType<?, ?>, V extends AmqpType<?, ?>> implements IAmqpMap<K, V> {
+
+        public static final int hashCodeFor(IAmqpMap<?, ?> map) {
+            int hashCode = 1;
+            for (Map.Entry<?, ?> obj : map) {
+                hashCode = 31 * hashCode + (obj.getKey() == null ? 0 : obj.getKey().hashCode());
+                hashCode = 31 * hashCode + (obj.getValue() == null ? 0 : obj.getValue().hashCode());
+            }
+            return hashCode;
+        }
+
+        public static final <K extends AmqpType<?, ?>, V extends AmqpType<?,?>> boolean checkEqual(IAmqpMap<K, V> m1, IAmqpMap<?, ?> m2) {
+            if (m1 == null ^ m2 == null) {
+                return false;
+            }
+
+            if (m2 == null) {
+                return true;
+            }
+
+            if (m1.getEntryCount() != m2.getEntryCount()) {
+                return false;
+            }
+
+            Iterator<Map.Entry<K, V>> i1 = m1.iterator();
+            while (i1.hasNext()) {
+                Map.Entry<K, V> e1 = i1.next();
+                Object v2 = m2.get(e1.getKey());
+                if (v2 == null) {
+                    return false;
+                }
+                if (!(e1.getValue() == null ? v2 == null : e1.getValue().equals(v2))) {
+                    return false;
+                }
+            }
+            return true;
+        }
+    }
+
+    public static class AmqpWrapperMap<K extends AmqpType<?, ?>, V extends AmqpType<?, ?>> extends AbstractAmqpMap<K, V> {
+        private Map<K, V> map;
+
+        public AmqpWrapperMap(Map<K, V> map) {
+            this.map = map;
+        }
+
+        public V get(Object key) {
+            return map.get(key);
+        }
+
+        public Map.Entry<K, V> getEntry(final K key) {
+            final V v = get(key);
+            if (v == null) {
+                return null;
+            }
+            return new Map.Entry<K, V>() {
+
+                public K getKey() {
+                    return key;
+                }
+
+                public V getValue() {
+                    return v;
+                }
+
+                public V setValue(V value) {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        }
+
+        public int getEntryCount() {
+            return map.size();
+        }
+
+        public void put(K key, V value) {
+            map.put(key, value);
+        }
+
+        public Iterator<Map.Entry<K, V>> iterator() {
+            return map.entrySet().iterator();
+        }
+
+        public boolean equals(Object o) {
+            if (o == null) {
+                return false;
+            }
+
+            if (o instanceof IAmqpMap<?, ?>) {
+                return checkEqual(this, (IAmqpMap<?, ?>) o);
+            }
+            return false;
+        }
+
+        public boolean equals(IAmqpMap<?, ?> m) {
+            return checkEqual(this, m);
+        }
+
+        public int hashCode() {
+            return hashCodeFor(this);
+        }
+    }
+}

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=909223&r1=909222&r2=909223&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 Fri Feb 12 04:24:26 2010
@@ -158,7 +158,11 @@
             }
 
             if (isList()) {
-                writer.write(", IAmqpList");
+                writer.write(", " + valueMapping.getJavaType());
+            }
+
+            if (isMap()) {
+                writer.write(", " + valueMapping.getJavaType());
             }
 
             if (isCommand()) {
@@ -240,8 +244,8 @@
                     imports.add(generator.getPackagePrefix() + ".types.AmqpType");
                 } else if (describedType.getName().equals("map")) {
                     imports.add(TypeRegistry.resolveAmqpClass("map").getValueMapping().getImport());
-                    imports.add("java.util.Map");
                     imports.add(generator.getPackagePrefix() + ".types.AmqpType");
+                    imports.add("java.util.HashMap");
                     // Import symbol which is used for the keys:
                     imports.add(TypeRegistry.resolveAmqpClass("symbol").getTypeMapping().getImport());
                 }
@@ -274,8 +278,18 @@
 
             imports.add(getValueMapping().getImport());
 
+            if (resolveBaseType().isList()) {
+                imports.add("java.util.Iterator");
+            }
+
             if (isList()) {
+                imports.add("java.util.ArrayList");
+            }
+
+            if (resolveBaseType().isMap()) {
                 imports.add("java.util.Iterator");
+                imports.add("java.util.Map");
+                imports.add("java.util.HashMap");
             }
 
             if (descriptor != null) {
@@ -283,7 +297,6 @@
                 AmqpClass describedType = descriptor.resolveDescribedType();
                 if (describedType.getName().equals("list")) {
                     imports.add(TypeRegistry.resolveAmqpClass("list").getValueMapping().getImport());
-                    imports.add("java.util.Iterator");
                 } else if (describedType.getName().equals("map")) {
                     imports.add(TypeRegistry.resolveAmqpClass("map").getValueMapping().getImport());
                 }
@@ -430,10 +443,9 @@
     private void writeEncodings(BufferedWriter writer) throws IOException, UnknownTypeException {
         if (isDescribed()) {
 
-            AmqpClass describedClass = descriptor.resolveDescribedType();
-            JavaTypeMapping describedType = describedClass.getTypeMapping();
+            AmqpClass describedType = descriptor.resolveDescribedType();
 
-            if (descriptor.getDescribedType().equals("list")) {
+            if (describedType.isList()) {
                 writer.newLine();
                 writer.write(tab(1) + "private static final ListDecoder DECODER = new ListDecoder() {");
                 writer.newLine();
@@ -501,12 +513,24 @@
 
                 writer.write(tab(1) + "};");
                 writer.newLine();
-            } else if (descriptor.getDescribedType().equals("map")) {
+            } else if (describedType.isMap()) {
 
                 writer.newLine();
-                writer.write(tab(1) + "private static final MapDecoder DECODER = new MapDecoder() {");
+                writer.write(tab(1) + "private static final MapDecoder<AmqpSymbol, " + TypeRegistry.any().typeMapping + "> DECODER = new MapDecoder<AmqpSymbol, " + TypeRegistry.any().typeMapping
+                        + ">() {");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(2) + "public IAmqpMap<AmqpSymbol, AmqpType<?, ?>> createMap(int entryCount) {");
+                writer.newLine();
+                writer.write(tab(3) + "return new IAmqpMap.AmqpWrapperMap<AmqpSymbol, AmqpType<?,?>>(new HashMap<AmqpSymbol, AmqpType<?,?>>());");
+                writer.newLine();
                 writer.newLine();
-                writer.write(tab(2) + "public void decodeToMap(EncodedBuffer encodedKey, EncodedBuffer encodedValue, Map<" + TypeRegistry.any().typeMapping + "," + TypeRegistry.any().typeMapping
+                writer.write(tab(2) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(2) + "public void decodeToMap(EncodedBuffer encodedKey, EncodedBuffer encodedValue, IAmqpMap<AmqpSymbol," + TypeRegistry.any().typeMapping
                         + "> map) throws AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(3) + "AmqpSymbol key = AmqpSymbol.AmqpSymbolBuffer.create(AmqpSymbolMarshaller.createEncoded(encodedKey));");
@@ -521,12 +545,12 @@
                 int f = 0;
                 for (AmqpField field : fields.values()) {
                     AmqpClass fieldType = field.resolveAmqpFieldType();
-                    writer.write(tab(3) + (f > 0 ? "else " : "") + "if (key.getValue().equals(" + toJavaConstant(field.getName()) + "_KEY.getValue())){");
+                    writer.write(tab(3) + (f > 0 ? "else " : "") + "if (key.equals(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY)){");
                     writer.newLine();
                     if (fieldType.isAny()) {
-                        writer.write(tab(4) + "map.put(" + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(buffer));");
+                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.decodeType(buffer));");
                     } else {
-                        writer.write(tab(4) + "map.put(" + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
+                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
                                 + ".createEncoded(encodedValue)));");
                     }
                     writer.newLine();
@@ -542,8 +566,8 @@
                 writer.write(tab(2) + "}");
                 writer.newLine();
 
-                writer.write(tab(2) + "public void unmarshalToMap(DataInput in, Map<" + TypeRegistry.any().typeMapping + "," + TypeRegistry.any().typeMapping
-                        + "> map) throws AmqpEncodingError, IOException {");
+                writer.newLine();
+                writer.write(tab(2) + "public void unmarshalToMap(DataInput in, IAmqpMap<AmqpSymbol," + TypeRegistry.any().typeMapping + "> map) throws IOException, AmqpEncodingError {");
                 writer.newLine();
                 writer.write(tab(3) + "AmqpSymbol key = AmqpSymbol.AmqpSymbolBuffer.create(AmqpSymbolMarshaller.createEncoded(in));");
                 writer.newLine();
@@ -557,14 +581,13 @@
                 f = 0;
                 for (AmqpField field : fields.values()) {
                     AmqpClass fieldType = field.resolveAmqpFieldType();
-                    writer.write(tab(3) + (f > 0 ? "else " : "") + "if (key.getValue().equals(" + toJavaConstant(field.getName()) + "_KEY.getValue())){");
+                    writer.write(tab(3) + (f > 0 ? "else " : "") + "if (key.equals(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY)){");
                     writer.newLine();
                     if (fieldType.isAny()) {
-                        writer.write(tab(4) + "map.put(" + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.unmarshalType(in));");
+                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, AmqpMarshaller.SINGLETON.unmarshalType(in));");
                     } else {
-                        writer
-                                .write(tab(4) + "map.put(" + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
-                                        + ".createEncoded(in)));");
+                        writer.write(tab(4) + "map.put(" + typeMapping + "." + toJavaConstant(field.getName()) + "_KEY, " + fieldType.getBufferMapping() + ".create(" + fieldType.getMarshaller()
+                                + ".createEncoded(in)));");
                     }
                     writer.newLine();
                     writer.write(tab(3) + "}");
@@ -600,7 +623,7 @@
             writer.newLine();
             writer.write(tab(2) + "public " + getJavaType() + "Encoded(" + typeMapping + " value) {");
             writer.newLine();
-            writer.write(tab(3) + "super(" + describedClass.getMarshaller() + ".encode(value));");
+            writer.write(tab(3) + "super(" + describedType.getMarshaller() + ".encode(value));");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
@@ -624,7 +647,7 @@
             writer.newLine();
             writer.write(tab(2) + "protected final Encoded<" + getValueMapping() + "> decodeDescribed(EncodedBuffer encoded) throws AmqpEncodingError {");
             writer.newLine();
-            writer.write(tab(3) + "return " + describedClass.getMarshaller() + ".createEncoded(encoded, DECODER);");
+            writer.write(tab(3) + "return " + describedType.getMarshaller() + ".createEncoded(encoded, DECODER);");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
@@ -632,7 +655,7 @@
             writer.newLine();
             writer.write(tab(2) + "protected final Encoded<" + getValueMapping() + "> unmarshalDescribed(DataInput in) throws IOException {");
             writer.newLine();
-            writer.write(tab(3) + "return " + describedClass.getMarshaller() + ".createEncoded(in, DECODER);");
+            writer.write(tab(3) + "return " + describedType.getMarshaller() + ".createEncoded(in, DECODER);");
             writer.newLine();
             writer.write(tab(2) + "}");
             writer.newLine();
@@ -1077,23 +1100,28 @@
         writer.write(tab(indent) + "private " + beanMapping.getShortName() + " bean = this;");
         writer.newLine();
         writeFields(writer, indent);
-        writer.newLine();
+
         // CONSTRUCTORS:
-        // Allow creation of empty described types:
-        if (baseType.isDescribed()) {
-            writer.write(tab(indent) + "public " + beanMapping.getShortName() + "() {");
-        } else {
-            writer.write(tab(indent) + "protected " + beanMapping.getShortName() + "() {");
+        // Allow creation of unitialized mutable types:
+        if (isMutable()) {
+            writer.newLine();
+            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.newLine();
+            } else if (!isDescribed() && baseType.isList()) {
+                writer.write(tab(indent + 1) + "this.value = new IAmqpList.AmqpWrapperList(new ArrayList<AmqpType<?,?>>());");
+                writer.newLine();
+            }
+            writer.write(tab(indent) + "}");
+            writer.newLine();
         }
-        writer.newLine();
-        writer.write(tab(indent) + "}");
-        writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "public " + beanMapping.getShortName() + "(" + baseType.getValueMapping() + " value) {");
+        writer.write(tab(indent) + beanMapping.getShortName() + "(" + baseType.getValueMapping() + " value) {");
         writer.newLine();
-        if (isDescribed() && getDescribedType().isList()) {
-            writer.write(tab(++indent) + "//TODO we should defer decoding of the described type:");
+        if (isDescribed() && baseType.isList()) {
             writer.newLine();
             writer.write(tab(indent) + "for(int i = 0; i < value.getListCount(); i++) {");
             writer.newLine();
@@ -1108,7 +1136,7 @@
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "public " + beanMapping.getShortName() + "(" + beanMapping + " other) {");
+        writer.write(tab(indent) + beanMapping.getShortName() + "(" + beanMapping + " other) {");
         writer.newLine();
         writer.write(tab(indent + 1) + "this.bean = other;");
         writer.newLine();
@@ -1184,20 +1212,20 @@
             writer.newLine();
             writer.write(tab(--indent) + "}");
             writer.newLine();
-        
+
             writer.newLine();
             writer.write(tab(indent) + "private final void copy(" + beanMapping + " other) {");
             writer.newLine();
             indent++;
-            if (baseType.isPrimitive()) {
-                writer.write(tab(indent) + "this.value = other.value;");
-                writer.newLine();
-            }
-            if (baseType.isDescribed()) {
+
+            if (isDescribed()) {
                 for (AmqpField field : baseType.fields.values()) {
                     writer.write(tab(indent) + "this." + field.getJavaName() + "= other." + field.getJavaName() + ";");
                     writer.newLine();
                 }
+            } else {
+                writer.write(tab(indent) + "this.value = other.value;");
+                writer.newLine();
             }
             writer.write(tab(indent) + "bean = this;");
             writer.newLine();
@@ -1206,91 +1234,33 @@
         }
 
         // Equivalency:
-        // Only override equals for immutable types:
-        if (baseType.isPrimitive() && !(baseType.isList() || baseType.isMap())) {
-            writer.newLine();
-            writer.write(tab(indent) + "public boolean equals(Object o){");
-            writer.newLine();
-            writer.write(tab(++indent) + "if(this == o) {");
-            writer.newLine();
-            writer.write(tab(++indent) + "return true;");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-            writer.newLine();
-            writer.write(tab(indent) + "if(o == null || !(o instanceof " + typeMapping + ")) {");
-            writer.newLine();
-            writer.write(tab(++indent) + "return false;");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-            writer.newLine();
-            writer.write(tab(indent) + "return equivalent((" + typeMapping + ") o);");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-
-            writer.newLine();
-            writer.write(tab(indent) + "public int hashCode() {");
-            writer.newLine();
-            writer.write(tab(++indent) + "if(getValue() == null) {");
-            writer.newLine();
-            writer.write(tab(++indent) + "return " + beanMapping + ".class.hashCode();");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-            writer.write(tab(indent) + "return getValue().hashCode();");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-        }
-
         writer.newLine();
-        writer.write(tab(indent) + "public boolean equivalent(AmqpType<?,?> t){");
+        writer.write(tab(indent) + "public boolean equals(Object o){");
         writer.newLine();
-        writer.write(tab(++indent) + "if(this == t) {");
+        writer.write(tab(++indent) + "if(this == o) {");
         writer.newLine();
         writer.write(tab(++indent) + "return true;");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
         writer.newLine();
-        writer.write(tab(indent) + "if(t == null || !(t instanceof " + typeMapping + ")) {");
+        writer.write(tab(indent) + "if(o == null || !(o instanceof " + typeMapping + ")) {");
         writer.newLine();
         writer.write(tab(++indent) + "return false;");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
         writer.newLine();
-        writer.write(tab(indent) + "return equivalent((" + typeMapping + ") t);");
+        writer.write(tab(indent) + "return equals((" + typeMapping + ") o);");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent++) + "public boolean equivalent(" + typeMapping + " b) {");
+        writer.write(tab(indent++) + "public boolean equals(" + typeMapping + " b) {");
         writer.newLine();
-        if (baseType.isPrimitive()) {
-            writer.write(tab(indent) + "if(b == null) {");
-            writer.newLine();
-            writer.write(tab(++indent) + "return false;");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-
-            writer.newLine();
-            writer.write(tab(indent) + "if(b.getValue() == null ^ getValue() == null) {");
-            writer.newLine();
-            writer.write(tab(++indent) + "return false;");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-            writer.newLine();
-            writer.write(tab(indent) + "return b.getValue() == null || b.getValue().equals(getValue());");
-            writer.newLine();
-        } else if (baseType.isDescribed()) {
+        if (isDescribed()) {
             for (AmqpField field : fields.values()) {
-                AmqpClass fieldClass = field.resolveAmqpFieldType();
 
                 writer.newLine();
                 writer.write(tab(indent) + "if(b.get" + capFirst(field.getJavaName()) + "() == null ^ get" + capFirst(field.getJavaName()) + "() == null) {");
@@ -1299,14 +1269,8 @@
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
-
-                if (fieldClass.isDescribed()) {
-                    writer.write(tab(indent) + "if(b.get" + capFirst(field.getJavaName()) + "() != null && !b.get" + capFirst(field.getJavaName()) + "().equivalent(get"
-                            + capFirst(field.getJavaName()) + "())){ ");
-                } else {
-                    writer.write(tab(indent) + "if(b.get" + capFirst(field.getJavaName()) + "() != null && !b.get" + capFirst(field.getJavaName()) + "().equals(get" + capFirst(field.getJavaName())
-                            + "())){ ");
-                }
+                writer.write(tab(indent) + "if(b.get" + capFirst(field.getJavaName()) + "() != null && !b.get" + capFirst(field.getJavaName()) + "().equals(get" + capFirst(field.getJavaName())
+                        + "())){ ");
 
                 writer.newLine();
                 writer.write(tab(++indent) + "return false;");
@@ -1315,9 +1279,49 @@
                 writer.newLine();
             }
             writer.write(tab(indent) + "return true;");
+        } else if (baseType.isMap()) {
+            writer.write(tab(indent) + "return AbstractAmqpMap.checkEqual(this, b);");
+        } else if (baseType.isList()) {
+            writer.write(tab(indent) + "return AbstractAmqpList.checkEqual(this, b);");
+        } else {
+            writer.write(tab(indent) + "if(b == null) {");
+            writer.newLine();
+            writer.write(tab(++indent) + "return false;");
+            writer.newLine();
+            writer.write(tab(--indent) + "}");
             writer.newLine();
+
+            writer.newLine();
+            writer.write(tab(indent) + "if(b.getValue() == null ^ getValue() == null) {");
+            writer.newLine();
+            writer.write(tab(++indent) + "return false;");
+            writer.newLine();
+            writer.write(tab(--indent) + "}");
+            writer.newLine();
+            writer.newLine();
+            writer.write(tab(indent) + "return b.getValue() == null || b.getValue().equals(getValue());");
         }
+        writer.newLine();
+        writer.write(tab(--indent) + "}");
+        writer.newLine();
 
+        writer.newLine();
+        writer.write(tab(indent) + "public int hashCode() {");
+        writer.newLine();
+        if (baseType.isMap()) {
+            writer.write(tab(++indent) + "return AbstractAmqpMap.hashCodeFor(this);");
+        } else if (baseType.isList()) {
+            writer.write(tab(++indent) + "return AbstractAmqpList.hashCodeFor(this);");
+        } else {
+            writer.write(tab(++indent) + "if(getValue() == null) {");
+            writer.newLine();
+            writer.write(tab(++indent) + "return " + beanMapping + ".class.hashCode();");
+            writer.newLine();
+            writer.write(tab(--indent) + "}");
+            writer.newLine();
+            writer.write(tab(indent) + "return getValue().hashCode();");
+        }
+        writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
 
@@ -1457,28 +1461,27 @@
         }
 
         // Equivalency:
-        if (isPrimitive() && !(isList() || isMap())) {
-            writer.newLine();
-            writer.write(tab(indent) + "public boolean equals(Object o){");
-            writer.newLine();
-            writer.write(tab(++indent) + "return bean().equals(o);");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
 
-            writer.newLine();
-            writer.write(tab(indent) + "public int hashCode() {");
-            writer.newLine();
-            writer.write(tab(++indent) + "return bean().hashCode();");
-            writer.newLine();
-            writer.write(tab(--indent) + "}");
-            writer.newLine();
-        }
+        writer.newLine();
+        writer.write(tab(indent) + "public boolean equals(Object o){");
+        writer.newLine();
+        writer.write(tab(++indent) + "return bean().equals(o);");
+        writer.newLine();
+        writer.write(tab(--indent) + "}");
+        writer.newLine();
 
         writer.newLine();
-        writer.write(tab(indent) + "public boolean equivalent(AmqpType<?, ?> t) {");
+        writer.write(tab(indent) + "public boolean equals(" + typeMapping + " o){");
         writer.newLine();
-        writer.write(tab(++indent) + "return bean().equivalent(t);");
+        writer.write(tab(++indent) + "return bean().equals(o);");
+        writer.newLine();
+        writer.write(tab(--indent) + "}");
+        writer.newLine();
+
+        writer.newLine();
+        writer.write(tab(indent) + "public int hashCode() {");
+        writer.newLine();
+        writer.write(tab(++indent) + "return bean().hashCode();");
         writer.newLine();
         writer.write(tab(--indent) + "}");
         writer.newLine();
@@ -1526,23 +1529,33 @@
             ret = true;
 
             AmqpClass fieldClass = field.resolveAmqpFieldType();
-            JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
+            AmqpClass baseType = fieldClass.resolveBaseType();
 
             if (!buffer) {
 
-                if (!fieldClass.isAny() && fieldClass.isPrimitive()) {
-                    // Setter:
+                // Setters:
+                if (baseType.isPrimitive() && !baseType.isAny() && !fieldClass.isEnumType() && !baseType.isDescribed() && !baseType.isMutable()) {
                     writer.newLine();
-                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldClass.valueMapping + " " + toJavaName(field.getName()) + ") {");
+                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.valueMapping + " " + toJavaName(field.getName()) + ") {");
                     writer.newLine();
-                    writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(new " + fieldClass.getBeanMapping() + "(" + toJavaName(field.getName()) + "));");
+                    writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(TypeFactory.create" + fieldClass.getJavaType() + "(" + toJavaName(field.getName()) + "));");
                     writer.newLine();
                     writer.write(tab(--indent) + "}");
                     writer.newLine();
                     writer.newLine();
+
+                    if (baseType.getValueMapping().hasPrimitiveType()) {
+                        writer.newLine();
+                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.getValueMapping().getPrimitiveType() + " " + toJavaName(field.getName()) + ") {");
+                        writer.newLine();
+                        writer.write(tab(++indent) + "set" + capFirst(field.getJavaName()) + "(TypeFactory.create" + fieldClass.getJavaType() + "(" + toJavaName(field.getName()) + "));");
+                        writer.newLine();
+                        writer.write(tab(--indent) + "}");
+                        writer.newLine();
+                        writer.newLine();
+                    }
                 }
 
-                // Setter:
                 writer.newLine();
                 writer.write(tab(indent) + "public final void set" + capFirst(field.getJavaName()) + "(" + fieldClass.typeMapping + " " + toJavaName(field.getName()) + ") {");
                 writer.newLine();
@@ -1553,7 +1566,9 @@
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
                 writer.newLine();
+
                 // Getter:
+                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()) {
@@ -1565,17 +1580,28 @@
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
             } else {
-                if (!fieldClass.isAny() && fieldClass.isPrimitive()) {
-                    // Setter:
+
+                // Setters:
+                if (baseType.isPrimitive() && !baseType.isAny() && !fieldClass.isEnumType() && !baseType.isDescribed() && !baseType.isMutable()) {
                     writer.newLine();
-                    writer.write(tab(1) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldClass.getValueMapping() + " " + toJavaName(field.getName()) + ") {");
+                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.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()) {
+                        writer.newLine();
+                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.getValueMapping().getPrimitiveType() + " " + 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();
+                        writer.newLine();
+                    }
                 }
-                // Setter:
                 writer.newLine();
                 writer.write(tab(indent) + "public final void set" + capFirst(field.getJavaName()) + "(" + fieldClass.getTypeMapping() + " " + toJavaName(field.getName()) + ") {");
                 writer.newLine();
@@ -1584,6 +1610,7 @@
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
                 // Getter:
+                JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
                 writer.newLine();
                 writer.write(tab(indent) + "public final " + returnType + " get" + capFirst(field.getJavaName()) + "() {");
                 writer.newLine();
@@ -1598,18 +1625,37 @@
             if (!buffer) {
                 writer.write(tab(indent) + "public void put(" + TypeRegistry.any().typeMapping + " key, " + TypeRegistry.any().typeMapping + " value) {");
                 writer.newLine();
-                writer.write(tab(++indent) + "bean.value.put(key, value);");
+                writer.write(tab(++indent) + "copyCheck();");
+                writer.newLine();
+                writer.write(tab(indent) + "bean.value.put(key, value);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(" + TypeRegistry.any().typeMapping + " key) {");
+                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(Object key) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean.value.get(key);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(indent) + "public int getEntryCount() {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean.value.getEntryCount();");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(indent) + "public Iterator<Map.Entry<" + TypeRegistry.any().getJavaType() + ", " + TypeRegistry.any().getJavaType() + ">> iterator() {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean.value.iterator();");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
+
             } else {
                 writer.write(tab(indent) + "public void put(" + TypeRegistry.any().typeMapping + " key, " + TypeRegistry.any().typeMapping + " value) {");
                 writer.newLine();
@@ -1619,12 +1665,28 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(" + TypeRegistry.any().typeMapping + " key) {");
+                writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(Object key) {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().get(key);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(indent) + "public int getEntryCount() {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean().getEntryCount();");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
+
+                writer.newLine();
+                writer.write(tab(indent) + "public Iterator<Map.Entry<" + TypeRegistry.any().getJavaType() + ", " + TypeRegistry.any().getJavaType() + ">> iterator() {");
+                writer.newLine();
+                writer.write(tab(++indent) + "return bean().iterator();");
+                writer.newLine();
+                writer.write(tab(--indent) + "}");
+                writer.newLine();
             }
 
         } else if (isList()) {
@@ -1632,7 +1694,9 @@
                 writer.newLine();
                 writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value) {");
                 writer.newLine();
-                writer.write(tab(++indent) + "bean.value.set(index, value);");
+                writer.write(tab(++indent) + "copyCheck();");
+                writer.newLine();
+                writer.write(tab(indent) + "bean.value.set(index, value);");
                 writer.newLine();
                 writer.write(tab(--indent) + "}");
                 writer.newLine();
@@ -1654,7 +1718,7 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<AmqpType<?, ?>> iterator() {");
+                writer.write(tab(indent) + "public Iterator<" + TypeRegistry.any().typeMapping + "> iterator() {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return new AmqpListIterator(bean.value);");
                 writer.newLine();
@@ -1687,7 +1751,7 @@
                 writer.newLine();
 
                 writer.newLine();
-                writer.write(tab(indent) + "public Iterator<AmqpType<?, ?>> iterator() {");
+                writer.write(tab(indent) + "public Iterator<" + TypeRegistry.any().typeMapping + "> iterator() {");
                 writer.newLine();
                 writer.write(tab(++indent) + "return bean().iterator();");
                 writer.newLine();
@@ -1829,27 +1893,53 @@
     private void writeBeanInterface(BufferedWriter writer, int indent) throws IOException, UnknownTypeException {
 
         if (isDescribed()) {
+
+            // Write out symbol constants
+            if (resolveBaseType().isMap()) {
+                writer.newLine();
+                for (AmqpField field : fields.values()) {
+
+                    AmqpClass symbolClass = TypeRegistry.resolveAmqpClass("symbol");
+                    writeJavaComment(writer, indent, "Key for: " + field.getLabel());
+                    writer.write(tab(1) + "public static final " + symbolClass.typeMapping + " " + toJavaConstant(field.getName()) + "_KEY = TypeFactory.create" + symbolClass.typeMapping + "(\""
+                            + field.getName() + "\");");
+
+                    writer.newLine();
+                }
+                writer.newLine();
+            }
+
             writer.newLine();
             for (AmqpField field : fields.values()) {
 
                 AmqpClass fieldClass = field.resolveAmqpFieldType();
-                JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
+                AmqpClass baseType = fieldClass.resolveBaseType();
 
-                if (!fieldClass.isAny() && fieldClass.isPrimitive()) {
+                if (baseType.isPrimitive() && !baseType.isAny() && !fieldClass.isEnumType() && !baseType.isDescribed() && !baseType.isMutable()) {
                     // Setter:
                     writer.newLine();
+                    field.getDoc().parseFromDoc(fieldClass.doc.docs);
                     field.writeJavaDoc(writer, indent);
-                    writer.write(tab(1) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldClass.valueMapping + " " + toJavaName(field.getName()) + ");");
+                    writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.valueMapping + " " + toJavaName(field.getName()) + ");");
                     writer.newLine();
+
+                    if (baseType.getValueMapping().hasPrimitiveType()) {
+                        writer.newLine();
+                        field.writeJavaDoc(writer, indent);
+                        writer.write(tab(indent) + "public void set" + capFirst(field.getJavaName()) + "(" + baseType.getValueMapping().getPrimitiveType() + " " + toJavaName(field.getName()) + ");");
+                        writer.newLine();
+                    }
+
                 }
 
-                // Setter:
+                // Setters:
                 writer.newLine();
                 field.writeJavaDoc(writer, indent);
                 writer.write(tab(1) + "public void set" + capFirst(field.getJavaName()) + "(" + fieldClass.typeMapping + " " + toJavaName(field.getName()) + ");");
                 writer.newLine();
 
                 // Getter:
+                JavaTypeMapping returnType = fieldClass.isPrimitive() ? fieldClass.getValueMapping() : fieldClass.typeMapping;
                 writer.newLine();
                 field.writeJavaDoc(writer, indent);
                 writer.write(tab(indent) + "public " + returnType + " get" + capFirst(field.getJavaName()) + "();");
@@ -1858,12 +1948,14 @@
         }
 
         if (isMap()) {
+            doc.writeJavaDoc(writer, indent);
             writer.write(tab(indent) + "public void put(" + TypeRegistry.any().typeMapping + " key, " + TypeRegistry.any().typeMapping + " value);");
             writer.newLine();
-            writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(" + TypeRegistry.any().typeMapping + " key);");
+            writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(Object key);");
             writer.newLine();
 
         } else if (isList()) {
+            doc.writeJavaDoc(writer, indent);
             writer.write(tab(indent) + "public void set(int index, " + TypeRegistry.any().typeMapping + " value);");
             writer.newLine();
             writer.write(tab(indent) + "public " + TypeRegistry.any().typeMapping + " get(int index);");
@@ -1953,21 +2045,9 @@
             writer.write(tab(1) + "}), 0);");
             writer.newLine();
 
-            String describedType = descriptor.getDescribedType();
-
-            if (describedType.equals("map")) {
-                writer.newLine();
-                writer.write(tab(1) + "//Accessor keys for field mapped fields:");
-                writer.newLine();
-                for (AmqpField field : fields.values()) {
+            AmqpClass describedType = descriptor.resolveDescribedType();
 
-                    AmqpClass symbolClass = TypeRegistry.resolveAmqpClass("symbol");
-                    writer.write(tab(1) + "private static final " + symbolClass.bufferMapping + " " + toJavaConstant(field.getName()) + "_KEY = new " + symbolClass.beanMapping + "(\""
-                            + field.getName() + "\").getBuffer(AmqpMarshaller.SINGLETON);");
-                    writer.newLine();
-                }
-                writer.newLine();
-            } else if (!describedType.equals("list")) {
+            if (!(describedType.isMap() || describedType.isList())) {
                 throw new UnknownTypeException("Support for " + descriptor.getDescribedType() + " as a described type isn't yet implemented");
             }
 
@@ -2462,6 +2542,8 @@
     public AmqpClass resolveBaseType() throws UnknownTypeException {
         if (isRestricted()) {
             return TypeRegistry.resolveAmqpClass(restrictedType);
+        } else if (isDescribed()) {
+            return getDescribedType();
         } else {
             return this;
         }

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java?rev=909223&r1=909222&r2=909223&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java Fri Feb 12 04:24:26 2010
@@ -116,7 +116,6 @@
                 if (docOrSection instanceof Section) {
                     Section section = (Section) docOrSection;
 
-                    System.out.println("Scanning: " + section.getName());
                     for (Object docOrDefinitionOrType : section.getDocOrDefinitionOrType()) {
                         if (docOrDefinitionOrType instanceof Type) {
                             generateClassFromType(amqp, section, (Type) docOrDefinitionOrType);
@@ -163,6 +162,7 @@
         generateCommandHandler();
         generateMarshallerInterface();
         generateMarshaller();
+        generateTypeFactory();
         writeDefinitions();
     }
 
@@ -297,6 +297,7 @@
         writer.newLine();
 
         TreeSet<String> imports = new TreeSet<String>();
+        imports.add("java.util.HashMap");
         imports.add(getMarshallerPackage() + ".Encoder.*");
         imports.add(getPackagePrefix() + ".marshaller.AmqpVersion");
         imports.add(getPackagePrefix() + ".marshaller.Encoded");
@@ -518,7 +519,7 @@
         filters.add("map");
 
         // Write out encoding serializers:
-        classLoop: for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+        for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
             if (!amqpClass.isPrimitive() || filters.contains(amqpClass.getName())) {
                 continue;
             }
@@ -571,17 +572,94 @@
         writer.close();
     }
 
-    private void writeMarshallerImports(BufferedWriter writer, boolean primitiveOnly, TreeSet<String> imports, String... packageFilters) throws IOException, UnknownTypeException {
-        HashSet<String> filters = new HashSet<String>();
-        filters.add("java.lang");
-        for (String filter : packageFilters) {
-            filters.add(filter);
+    private void generateTypeFactory() throws IOException, UnknownTypeException {
+
+        String outputPackage = getPackagePrefix() + ".types";
+        File out = new File(outputDirectory + File.separator + outputPackage.replace(".", File.separator) + File.separator + "TypeFactory.java");
+
+        BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+        writeJavaCopyWrite(writer);
+        writer.write("package " + outputPackage + ";");
+        writer.newLine();
+        writer.newLine();
+
+        TreeSet<String> imports = new TreeSet<String>();
+        writeTypeImports(writer, true, imports, getMarshallerPackage(), outputPackage);
+        writer.newLine();
+
+        writer.newLine();
+        writer.write("public class TypeFactory {");
+        writer.newLine();
+        
+        for (AmqpClass ac : TypeRegistry.getGeneratedTypes()) {
+            if (ac.isAny() || ac.isEnumType()) {
+                continue;
+            }
+            if (ac.isDescribed()) {
+                writer.newLine();
+                writeJavaComment(writer, 1, "Creates a " + ac.getTypeMapping());
+                writer.write(tab(1) + "public static final " + ac.getTypeMapping() + " create" + ac.getTypeMapping() + "() {");
+                writer.newLine();
+                writer.write(tab(2) + "return new " + ac.getBeanMapping() + "();");
+                writer.newLine();
+                writer.write(tab(1) + "};");
+                writer.newLine();
+            } else {
+                AmqpClass bt = ac.resolveBaseType();
+                writer.newLine();
+                writeJavaComment(writer, 1, "Creates a " + ac.getTypeMapping());
+                writer.write(tab(1) + "public static final " + ac.getTypeMapping() + " create" + ac.getTypeMapping() + "(" + bt.getValueMapping() + " val) {");
+                writer.newLine();
+                writer.write(tab(2) + "return new " + ac.getBeanMapping() + "(val);");
+                writer.newLine();
+                writer.write(tab(1) + "}");
+                writer.newLine();
+                
+                if(bt.getValueMapping().hasPrimitiveType())
+                {
+                    writeJavaComment(writer, 1, "Creates a " + ac.getTypeMapping());
+                    writer.write(tab(1) + "public static final " + ac.getTypeMapping() + " create" + ac.getTypeMapping() + "(" + bt.getValueMapping().getPrimitiveType() + " val) {");
+                    writer.newLine();
+                    writer.write(tab(2) + "return new " + ac.getBeanMapping() + "(val);");
+                    writer.newLine();
+                    writer.write(tab(1) + "}");
+                    writer.newLine();
+                }
+                
+                if(bt.isMutable())
+                {
+                    writeJavaComment(writer, 1, "Creates an empty " + ac.getTypeMapping());
+                    writer.write(tab(1) + "public static final " + ac.getTypeMapping() + " create" + ac.getTypeMapping() + "() {");
+                    writer.newLine();
+                    writer.write(tab(2) + "return new " + ac.getBeanMapping() + "();");
+                    writer.newLine();
+                    writer.write(tab(1) + "}");
+                    writer.newLine();
+                }
+            }
         }
+        writer.write("}");
+        writer.newLine();
+        writer.flush();
+        writer.close();
+    }
+
+    private void writeMarshallerImports(BufferedWriter writer, boolean primitiveOnly, TreeSet<String> imports, String... packageFilters) throws IOException, UnknownTypeException {
 
         imports.add("java.io.DataInput");
         imports.add("java.io.IOException");
         imports.add(getPackagePrefix() + ".marshaller.AmqpEncodingError");
 
+        writeTypeImports(writer, primitiveOnly, imports, packageFilters);
+    }
+
+    private void writeTypeImports(BufferedWriter writer, boolean primitiveOnly, TreeSet<String> imports, String... packageFilters) throws IOException, UnknownTypeException {
+        HashSet<String> filters = new HashSet<String>();
+        filters.add("java.lang");
+        for (String filter : packageFilters) {
+            filters.add(filter);
+        }
         for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
             if (primitiveOnly && (!amqpClass.isPrimitive() || amqpClass.isList() || amqpClass.isMap())) {
                 continue;
@@ -609,7 +687,6 @@
         AmqpClass amqpClass = new AmqpClass();
         amqpClass.parseFromType(this, source, section, type);
         TypeRegistry.addType(amqpClass);
-        System.out.println("Found: " + amqpClass);
     }
 
     public String getVersionPackageName() {

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=909223&r1=909222&r2=909223&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 Fri Feb 12 04:24:26 2010
@@ -33,32 +33,34 @@
     }
 
     static final void init(Generator generator) {
-        
-        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"));
+
+        // Add in the wildcard type:
+        AmqpClass any = new AmqpType("*", generator.getPackagePrefix() + ".types.AmqpType");
+        GENERATED_TYPE_MAP.put("*", any);
+        JAVA_TYPE_MAP.put("*", any.typeMapping);
+
+        //
+        JAVA_TYPE_MAP.put("boolean", new JavaTypeMapping("boolean", "java.lang.Boolean", "boolean"));
+        JAVA_TYPE_MAP.put("ubyte", new JavaTypeMapping("ubyte", "java.lang.Short", "short"));
+        JAVA_TYPE_MAP.put("ushort", new JavaTypeMapping("ushort", "java.lang.Integer", "int"));
+        JAVA_TYPE_MAP.put("uint", new JavaTypeMapping("uint", "java.lang.Long", "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("byte", new JavaTypeMapping("byte", "java.lang.Byte", "byte"));
+        JAVA_TYPE_MAP.put("short", new JavaTypeMapping("short", "java.lang.Short", "short"));
+        JAVA_TYPE_MAP.put("int", new JavaTypeMapping("int", "java.lang.Integer", "int"));
+        JAVA_TYPE_MAP.put("long", new JavaTypeMapping("long", "java.lang.Long", "long"));
+        JAVA_TYPE_MAP.put("float", new JavaTypeMapping("float", "java.lang.Float", "float"));
+        JAVA_TYPE_MAP.put("double", new JavaTypeMapping("double", "java.lang.Double", "double"));
+        JAVA_TYPE_MAP.put("char", new JavaTypeMapping("char", "java.lang.Integer", "int"));
         JAVA_TYPE_MAP.put("timestamp", new JavaTypeMapping("timestamp", "java.util.Date"));
         JAVA_TYPE_MAP.put("uuid", new JavaTypeMapping("uuid", "java.util.UUID"));
         JAVA_TYPE_MAP.put("binary", new JavaTypeMapping("binary", "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("map", new JavaTypeMapping("map", "java.util.HashMap", false, "<AmqpType<?,?>, AmqpType<?,?>>"));
+        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"));
-        
-        // Add in the wildcard type:
-        AmqpClass any = new AmqpType("*", generator.getPackagePrefix() + ".types.AmqpType");
-        GENERATED_TYPE_MAP.put("*", any);
-        JAVA_TYPE_MAP.put("*", any.typeMapping);
+
     }
 
     public static JavaTypeMapping getJavaTypeMapping(String name) throws UnknownTypeException {
@@ -76,11 +78,10 @@
         return mapping;
     }
 
-    public static AmqpClass any()
-    {
+    public static AmqpClass any() {
         return GENERATED_TYPE_MAP.get("*");
     }
-    
+
     public static AmqpClass resolveAmqpClass(AmqpField amqpField) throws UnknownTypeException {
         return resolveAmqpClass(amqpField.getType());
     }
@@ -134,9 +135,9 @@
         private String packageName;
         private String fullName;
         private String javaType;
+        private String primitiveType;
 
         boolean array;
-        private boolean inner;
         String generic;
 
         JavaTypeMapping(String amqpType, String fullName, boolean array, String generic) {
@@ -151,6 +152,15 @@
             }
         }
 
+        JavaTypeMapping(String amqpType, String fullName, String primitiveType) {
+            this.amqpType = amqpType;
+            this.fullName = fullName;
+            this.primitiveType = primitiveType;
+            this.packageName = fullName.substring(0, fullName.lastIndexOf("."));
+            this.shortName = fullName.substring(fullName.lastIndexOf(".") + 1);
+            this.javaType = shortName;
+        }
+
         JavaTypeMapping(String amqpType, String fullName) {
             this.amqpType = amqpType;
             this.fullName = fullName;
@@ -163,7 +173,6 @@
             this.amqpType = amqpType;
             this.fullName = packageName + "." + className;
             this.packageName = packageName;
-            this.inner = inner;
             this.javaType = className;
             if (inner) {
                 this.javaType = className;
@@ -171,6 +180,17 @@
             }
         }
 
+        public boolean hasPrimitiveType() {
+            return primitiveType != null;
+        }
+
+        public String getPrimitiveType() {
+            if (primitiveType == null) {
+                return javaType;
+            }
+            return primitiveType;
+        }
+
         public String getAmqpType() {
             return amqpType;
         }



Mime
View raw message