You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2011/08/14 19:15:08 UTC

svn commit: r1157566 [8/23] - in /qpid: branches/rg-amqp-1-0-sandbox/qpid/java/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/s...

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class ShortTypeConstructor implements TypeConstructor
+{
+    private static final ShortTypeConstructor INSTANCE = new ShortTypeConstructor();
+
+
+    public static ShortTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private ShortTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=2)
+        {
+            return in.getShort();
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct short: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ShortWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,55 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+public class ShortWriter extends FixedTwoWriter<Short>
+{
+
+    private static final byte FORMAT_CODE = (byte)0x61;
+
+
+    @Override
+    short convertValueToShort(Short value)
+    {
+        return value.shortValue();
+    }
+
+    @Override
+    byte getFormatCode()
+    {
+        return FORMAT_CODE;
+    }
+
+    private static Factory<Short> FACTORY = new Factory<Short>()
+                                            {
+
+                                                public ValueWriter<Short> newInstance(Registry registry)
+                                                {
+                                                    return new ShortWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Short.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SimpleVariableWidthWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SimpleVariableWidthWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SimpleVariableWidthWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SimpleVariableWidthWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,68 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class SimpleVariableWidthWriter<V> extends VariableWidthWriter<V>
+{
+    private byte[] _buf;
+
+
+    public void setValue(V value)
+    {
+        _buf = getByteArray(value);
+        super.setValue(value);
+    }
+
+    protected int getLength()
+    {
+        return _buf.length;
+    }
+
+    protected void writeBytes(ByteBuffer buf, int offset, int length)
+    {
+        buf.put(_buf, getOffset()+offset, length);
+    }
+
+    @Override
+    protected void clearValue()
+    {
+        _buf = null;
+    }
+
+    @Override
+    protected boolean hasValue()
+    {
+        return _buf != null;
+    }
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    protected abstract byte[] getByteArray(V value);
+
+    protected abstract int getOffset();
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallIntConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallIntConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallIntConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallIntConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class SmallIntConstructor implements TypeConstructor
+{
+    private static final SmallIntConstructor INSTANCE = new SmallIntConstructor();
+
+
+    public static SmallIntConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private SmallIntConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.hasRemaining())
+        {
+            byte b = in.get();
+            return (int) b;
+        }
+        else
+        {
+            Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct int: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallLongConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallLongConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallLongConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallLongConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class SmallLongConstructor implements TypeConstructor
+{
+    private static final SmallLongConstructor INSTANCE = new SmallLongConstructor();
+
+
+    public static SmallLongConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private SmallLongConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.hasRemaining())
+        {
+            byte b = in.get();
+            return (long) b;
+        }
+        else
+        {
+            Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct long: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallUIntConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallUIntConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallUIntConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallUIntConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class SmallUIntConstructor implements TypeConstructor
+{
+    private static final SmallUIntConstructor INSTANCE = new SmallUIntConstructor();
+
+
+    public static SmallUIntConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private SmallUIntConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.hasRemaining())
+        {
+            byte b = in.get();
+            return UnsignedInteger.valueOf(((int) b) & 0xff);
+        }
+        else
+        {
+            Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct uint: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallULongConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallULongConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallULongConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SmallULongConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.UnsignedLong;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class SmallULongConstructor implements TypeConstructor
+{
+    private static final SmallULongConstructor INSTANCE = new SmallULongConstructor();
+
+
+    public static SmallULongConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private SmallULongConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.hasRemaining())
+        {
+            byte b = in.get();
+            return UnsignedLong.valueOf(((long) b) & 0xffL);
+        }
+        else
+        {
+            Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct ulong: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,128 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class StringTypeConstructor extends VariableWidthTypeConstructor
+{
+    private Charset _charSet;
+
+    private BinaryString _defaultBinaryString = new BinaryString();
+    private ValueCache<BinaryString, String> _cachedValues = new ValueCache<BinaryString, String>(10);
+
+    private static final class ValueCache<K,V> extends LinkedHashMap<K,V>
+    {
+        private final int _cacheSize;
+
+        public ValueCache(int cacheSize)
+        {
+            _cacheSize = cacheSize;
+        }
+
+        @Override
+        protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
+        {
+            return size() > _cacheSize;
+        }
+
+        public boolean isFull()
+        {
+            return size() == _cacheSize;
+        }
+    }
+
+
+    public static StringTypeConstructor getInstance(int i, Charset c)
+    {
+        return new StringTypeConstructor(i, c);
+    }
+
+
+    private StringTypeConstructor(int size, Charset c)
+    {
+        super(size);
+        _charSet = c;
+    }
+
+    @Override
+    public Object construct(final ByteBuffer in, boolean isCopy, ValueHandler handler) throws AmqpErrorException
+    {
+        int size;
+
+        if(getSize() == 1)
+        {
+            size = in.get() & 0xFF;
+        }
+        else
+        {
+            size = in.getInt();
+        }
+
+        int origPosition = in.position();
+        _defaultBinaryString.setData(in.array(), in.arrayOffset()+ origPosition, size);
+
+        BinaryString binaryStr = _defaultBinaryString;
+
+        boolean isFull = _cachedValues.isFull();
+
+        String str = isFull ? _cachedValues.remove(binaryStr) : _cachedValues.get(binaryStr);
+
+        if(str == null)
+        {
+
+            ByteBuffer dup = in.duplicate();
+            try
+            {
+                dup.limit(dup.position()+size);
+            }
+            catch(IllegalArgumentException e)
+            {
+                throw new IllegalArgumentException("position: " + dup.position() + "size: " + size + " capacity: " + dup.capacity());
+            }
+            CharBuffer charBuf = _charSet.decode(dup);
+
+            str = charBuf.toString();
+
+            byte[] data = new byte[size];
+            in.get(data);
+            binaryStr = new BinaryString(data, 0, size);
+
+            _cachedValues.put(binaryStr, str);
+        }
+        else if(isFull)
+        {
+            _cachedValues.put(binaryStr, str);
+        }
+
+        in.position(origPosition+size);
+
+        return str;
+
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/StringWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,146 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class StringWriter extends SimpleVariableWidthWriter<String>
+{
+    private static final Charset ENCODING_CHARSET;
+    private static final byte ONE_BYTE_CODE;
+    private static final byte FOUR_BYTE_CODE;
+    static
+    {
+        Charset defaultCharset = Charset.defaultCharset();
+        if(defaultCharset.name().equals("UTF-16") || defaultCharset.name().equals("UTF-16BE"))
+        {
+            ENCODING_CHARSET = defaultCharset;
+            ONE_BYTE_CODE = (byte) 0xa2;
+            FOUR_BYTE_CODE = (byte) 0xb2;
+        }
+        else
+        {
+            ENCODING_CHARSET = Charset.forName("UTF-8");
+            ONE_BYTE_CODE = (byte) 0xa1;
+            FOUR_BYTE_CODE = (byte) 0xb1;
+        }
+    }
+
+    private static final class ValueCache<K,V> extends LinkedHashMap<K,V>
+    {
+        private final int _cacheSize;
+
+        public ValueCache(int cacheSize)
+        {
+            _cacheSize = cacheSize;
+        }
+
+        @Override
+        protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
+        {
+            return size() > _cacheSize;
+        }
+
+        public boolean isFull()
+        {
+            return size() == _cacheSize;
+        }
+    }
+
+    private final ValueCache<String, byte[]> _cachedEncodings = new ValueCache<String, byte[]>(10);
+
+
+    @Override
+    protected byte getFourOctetEncodingCode()
+    {
+        return FOUR_BYTE_CODE;
+    }
+
+    @Override
+    protected byte getSingleOctetEncodingCode()
+    {
+        return ONE_BYTE_CODE;
+    }
+
+    @Override
+    protected byte[] getByteArray(String value)
+    {
+
+        byte[] encoding;
+        boolean isFull = _cachedEncodings.isFull();
+        if(isFull)
+        {
+            encoding = _cachedEncodings.remove(value);
+        }
+        else
+        {
+            encoding = _cachedEncodings.get(value);
+        }
+
+
+        if(encoding == null)
+        {
+            ByteBuffer buf = ENCODING_CHARSET.encode(value);
+            if(buf.hasArray() && buf.arrayOffset() == 0 && buf.limit()==buf.capacity())
+            {
+                encoding = buf.array();
+            }
+            else
+            {
+                byte[] bufArray = new byte[buf.limit()-buf.position()];
+                buf.get(bufArray);
+                encoding = bufArray;
+            }
+            _cachedEncodings.put(value,encoding);
+
+        }
+        else if(isFull)
+        {
+            _cachedEncodings.put(value,encoding);
+        }
+
+        return encoding;
+    }
+
+    @Override
+    protected int getOffset()
+    {
+        return 0;
+    }
+
+    private static Factory<String> FACTORY = new Factory<String>()
+                                            {
+
+                                                public ValueWriter<String> newInstance(Registry registry)
+                                                {
+                                                    return new StringWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(String.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolArrayWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolArrayWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolArrayWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolArrayWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.Symbol;
+
+import java.nio.ByteBuffer;
+
+public class SymbolArrayWriter extends VariableWidthWriter<Symbol[]>
+{
+
+    private int _length;
+    private byte[] _encodedVal;
+
+    @Override protected void clearValue()
+    {
+        _encodedVal = null;
+    }
+
+    @Override protected boolean hasValue()
+    {
+        return _encodedVal != null;
+    }
+
+    @Override protected byte getFourOctetEncodingCode()
+    {
+        return (byte) 0xf0;
+    }
+
+    @Override protected byte getSingleOctetEncodingCode()
+    {
+        return (byte) 0xe0;
+    }
+
+    @Override protected int getLength()
+    {
+        return _length;
+    }
+
+    @Override protected void writeBytes(final ByteBuffer buf, final int offset, final int length)
+    {
+        buf.put(_encodedVal,offset,length);
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+    public void setValue(final Symbol[] value)
+    {
+
+        boolean useSmallConstructor = useSmallConstructor(value);
+        boolean isSmall = useSmallConstructor && canFitInSmall(value);
+        if(isSmall)
+        {
+            _length = 2;
+        }
+        else
+        {
+            _length = 5;
+        }
+        for(Symbol symbol : value)
+        {
+            _length += symbol.length() ;
+        }
+        _length += value.length * (useSmallConstructor ? 1 : 4);
+
+
+        _encodedVal = new byte[_length];
+
+        ByteBuffer buf = ByteBuffer.wrap(_encodedVal);
+        if(isSmall)
+        {
+            buf.put((byte)value.length);
+            buf.put(SymbolWriter.SMALL_ENCODING_CODE);
+        }
+        else
+        {
+            buf.putInt(value.length);
+            buf.put(SymbolWriter.LARGE_ENCODING_CODE);
+        }
+
+        for(Symbol symbol : value)
+        {
+                if(isSmall)
+                {
+                    buf.put((byte)symbol.length());
+                }
+                else
+                {
+                    buf.putInt(symbol.length());
+                }
+
+
+            for(int i = 0; i < symbol.length(); i++)
+            {
+                buf.put((byte)symbol.charAt(i));
+            }
+        }
+
+
+
+        super.setValue(value);
+    }
+
+    private boolean useSmallConstructor(final Symbol[] value)
+    {
+        for(Symbol sym : value)
+        {
+            if(sym.length()>255)
+            {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean canFitInSmall(final Symbol[] value)
+    {
+        if(value.length>=127)
+        {
+            return false;
+        }
+
+        int remaining = 253 - value.length;
+        for(Symbol symbol : value)
+        {
+
+            if((remaining -= symbol.length()) < 0)
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+
+    private static Factory<Symbol[]> FACTORY = new Factory<Symbol[]>()
+                                            {
+
+                                                public ValueWriter<Symbol[]> newInstance(Registry registry)
+                                                {
+                                                    return new SymbolArrayWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Symbol[].class, FACTORY);
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,96 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.Symbol;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class SymbolTypeConstructor extends VariableWidthTypeConstructor
+{
+    private static final Charset ASCII = Charset.forName("US-ASCII");
+
+    private BinaryString _defaultBinaryString = new BinaryString();
+
+    private static final ConcurrentHashMap<BinaryString, Symbol> SYMBOL_MAP =
+            new ConcurrentHashMap<BinaryString, Symbol>(2048);
+
+    public static SymbolTypeConstructor getInstance(int i)
+    {
+        return new SymbolTypeConstructor(i);
+    }
+
+
+    private SymbolTypeConstructor(int size)
+    {
+        super(size);
+    }
+
+    @Override
+    public Object construct(final ByteBuffer in, boolean isCopy, ValueHandler handler) throws AmqpErrorException
+    {
+        int size;
+
+        if(getSize() == 1)
+        {
+            size = in.get() & 0xFF;
+        }
+        else
+        {
+            size = in.getInt();
+        }
+
+        _defaultBinaryString.setData(in.array(), in.arrayOffset()+in.position(), size);
+
+        BinaryString binaryStr = _defaultBinaryString;
+
+        Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
+        if(symbolVal == null)
+        {
+            ByteBuffer dup = in.duplicate();
+            dup.limit(in.position()+size);
+            CharBuffer charBuf = ASCII.decode(dup);
+
+
+            symbolVal = Symbol.getSymbol(charBuf.toString());
+
+
+
+
+            byte[] data = new byte[size];
+            in.get(data);
+            binaryStr = new BinaryString(data, 0, size);
+            SYMBOL_MAP.putIfAbsent(binaryStr, symbolVal);
+        }
+        else
+        {
+            in.position(in.position()+size);
+        }
+
+        return symbolVal;
+
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/SymbolWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,102 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.Symbol;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+public class SymbolWriter extends VariableWidthWriter<Symbol>
+{
+    private static final Charset ENCODING_CHARSET = Charset.forName("US-ASCII");
+    public static final byte LARGE_ENCODING_CODE = (byte) 0xb3;
+    public static final byte SMALL_ENCODING_CODE = (byte) 0xa3;
+    private Symbol _value;
+
+
+    @Override
+    protected byte getFourOctetEncodingCode()
+    {
+        return LARGE_ENCODING_CODE;
+    }
+
+    @Override
+    protected byte getSingleOctetEncodingCode()
+    {
+        return SMALL_ENCODING_CODE;
+    }
+
+    @Override
+    public void setValue(Symbol value)
+    {
+        _value = value;
+        super.setValue(value);
+    }
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    @Override
+    protected void clearValue()
+    {
+        _value = null;
+    }
+
+    @Override
+    protected boolean hasValue()
+    {
+        return _value != null;
+    }
+
+    @Override
+    protected int getLength()
+    {
+        return _value.length();
+    }
+
+    @Override
+    protected void writeBytes(ByteBuffer buf, int offset, int length)
+    {
+        int end = offset + length;
+        for(int i = offset; i < end; i++)
+        {
+            buf.put((byte)_value.charAt(i));
+        }
+    }
+
+    private static Factory<Symbol> FACTORY = new Factory<Symbol>()
+                                            {
+
+                                                public ValueWriter<Symbol> newInstance(Registry registry)
+                                                {
+                                                    return new SymbolWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Symbol.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,60 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+public class TimestampTypeConstructor implements TypeConstructor
+{
+    private static final TimestampTypeConstructor INSTANCE = new TimestampTypeConstructor();
+
+
+    public static TimestampTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private TimestampTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=8)
+        {
+            long l = in.getLong();
+            return new Date(l);
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct timestamp: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TimestampWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,57 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import java.util.Date;
+
+public class TimestampWriter extends FixedEightWriter<Date>
+{
+    private static final byte FORMAT_CODE = (byte) 0x83;
+
+
+    @Override
+    byte getFormatCode()
+    {
+        return FORMAT_CODE;
+    }
+
+    @Override
+    long convertValueToLong(Date value)
+    {
+        return value.getTime();
+    }
+
+    private static Factory<Date> FACTORY = new Factory<Date>()
+                                            {
+
+                                                public ValueWriter<Date> newInstance(Registry registry)
+                                                {
+                                                    return new TimestampWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Date.class, FACTORY);
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/TypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,32 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+
+public interface TypeConstructor<T>
+{
+
+    public T construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException;
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UByteTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UByteTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UByteTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UByteTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,59 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class UByteTypeConstructor implements TypeConstructor
+{
+    private static final UByteTypeConstructor INSTANCE = new UByteTypeConstructor();
+
+
+    public static UByteTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private UByteTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.hasRemaining())
+        {
+            byte b = in.get();
+            return UnsignedByte.valueOf(b);
+        }
+        else
+        {
+            Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct ubyte: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UIntTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UIntTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UIntTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UIntTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,59 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class UIntTypeConstructor implements TypeConstructor
+{
+    private static final UIntTypeConstructor INSTANCE = new UIntTypeConstructor();
+
+
+    public static UIntTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private UIntTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=4)
+        {
+            final int i = in.getInt();
+            return UnsignedInteger.valueOf(i);
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct uint: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ULongTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ULongTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ULongTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ULongTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,61 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class ULongTypeConstructor implements TypeConstructor
+{
+    private static final ULongTypeConstructor INSTANCE = new ULongTypeConstructor();
+
+
+    public static ULongTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private ULongTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=8)
+        {
+            long l = in.getLong();
+
+            return UnsignedLong.valueOf(l);
+
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct ulong: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UShortTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UShortTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UShortTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UShortTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,60 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class UShortTypeConstructor implements TypeConstructor
+{
+    private static final UShortTypeConstructor INSTANCE = new UShortTypeConstructor();
+
+
+    public static UShortTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private UShortTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=2)
+        {
+            short s = in.getShort();
+            return UnsignedShort.valueOf(s);
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct ushort: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,62 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+public class UUIDTypeConstructor implements TypeConstructor
+{
+    private static final UUIDTypeConstructor INSTANCE = new UUIDTypeConstructor();
+
+
+    public static UUIDTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private UUIDTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=16)
+        {
+            long msb = in.getLong();
+            long lsb = in.getLong();
+            return new UUID(msb, lsb);
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct UUID: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UUIDWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,63 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import java.util.UUID;
+
+public class UUIDWriter extends FixedSixteenWriter<UUID>
+{
+    private static final byte FORMAT_CODE = (byte) 0x98;
+
+
+    @Override
+    byte getFormatCode()
+    {
+        return FORMAT_CODE;
+    }
+
+    @Override
+    long convertValueToMSB(UUID value)
+    {
+        return value.getMostSignificantBits();
+    }
+
+    @Override
+    long convertValueToLSB(UUID value)
+    {
+        return value.getLeastSignificantBits();
+    }
+
+    private static Factory<UUID> FACTORY = new Factory<UUID>()
+                                            {
+
+                                                public ValueWriter<UUID> newInstance(Registry registry)
+                                                {
+                                                    return new UUIDWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(UUID.class, FACTORY);
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedByteWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedByteWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedByteWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedByteWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,92 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.UnsignedByte;
+
+import java.nio.ByteBuffer;
+
+public class UnsignedByteWriter implements ValueWriter<UnsignedByte>
+{
+    private int _written;
+    private byte _value;
+
+    public int writeToBuffer(ByteBuffer buffer)
+    {
+
+        switch(_written)
+        {
+            case 0:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put((byte)0x50);
+                }
+                else
+                {
+                    break;
+                }
+            case 1:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put(_value);
+                    _written = 2;
+                }
+                else
+                {
+                    _written = 1;
+                }
+
+        }
+
+        return 2;
+    }
+
+    public void setValue(UnsignedByte value)
+    {
+        _written = 0;
+        _value = value.byteValue();
+    }
+
+    public boolean isComplete()
+    {
+        return _written == 2;
+    }
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    private static Factory<UnsignedByte> FACTORY = new Factory<UnsignedByte>()
+                                            {
+
+                                                public ValueWriter<UnsignedByte> newInstance(Registry registry)
+                                                {
+                                                    return new UnsignedByteWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(UnsignedByte.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedIntegerWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedIntegerWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedIntegerWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedIntegerWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,148 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
+
+import java.nio.ByteBuffer;
+
+public class UnsignedIntegerWriter implements ValueWriter<UnsignedInteger>
+{
+    private static final byte EIGHT_BYTE_FORMAT_CODE = (byte)0x70;
+    private static final byte ONE_BYTE_FORMAT_CODE = (byte) 0x52;
+    private static final byte ZERO_BYTE_FORMAT_CODE = (byte) 0x43;
+
+    private ValueWriter<UnsignedInteger> _delegate;
+
+    private final FixedFourWriter<UnsignedInteger> _eightByteWriter = new FixedFourWriter<UnsignedInteger>()
+    {
+
+        @Override
+        byte getFormatCode()
+        {
+            return EIGHT_BYTE_FORMAT_CODE;
+        }
+
+        @Override
+        int convertValueToInt(UnsignedInteger value)
+        {
+            return value.intValue();
+        }
+    };
+
+    private final ValueWriter<UnsignedInteger> _oneByteWriter = new FixedOneWriter<UnsignedInteger>()
+    {
+
+        @Override protected byte getFormatCode()
+        {
+            return ONE_BYTE_FORMAT_CODE;
+        }
+
+        @Override protected byte convertToByte(final UnsignedInteger value)
+        {
+            return value.byteValue();
+        }
+    };
+
+    private final ValueWriter<UnsignedInteger> _zeroByteWriter = new ValueWriter<UnsignedInteger>()
+        {
+            private boolean _complete;
+
+
+            public int writeToBuffer(ByteBuffer buffer)
+            {
+
+                if(!_complete && buffer.hasRemaining())
+                {
+                    buffer.put(ZERO_BYTE_FORMAT_CODE);
+                    _complete = true;
+                }
+
+                return 1;
+            }
+
+            public void setValue(UnsignedInteger uint)
+            {
+                _complete = false;
+            }
+
+            public boolean isCacheable()
+            {
+                return true;
+            }
+
+            public boolean isComplete()
+            {
+                return _complete;
+            }
+
+        };
+
+
+
+    public int writeToBuffer(final ByteBuffer buffer)
+    {
+        return _delegate.writeToBuffer(buffer);
+    }
+
+    public void setValue(final UnsignedInteger uint)
+    {
+        if(uint.equals(UnsignedInteger.ZERO))
+        {
+            _delegate = _zeroByteWriter;
+        }
+        else if(uint.compareTo(UnsignedInteger.valueOf(256))<0)
+        {
+            _delegate = _oneByteWriter;
+        }
+        else
+        {
+            _delegate = _eightByteWriter;
+        }
+        _delegate.setValue(uint);
+    }
+
+    public boolean isComplete()
+    {
+        return _delegate.isComplete();
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+
+    private static Factory<UnsignedInteger> FACTORY = new Factory<UnsignedInteger>()
+                                            {
+
+                                                public ValueWriter<UnsignedInteger> newInstance(Registry registry)
+                                                {
+                                                    return new UnsignedIntegerWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(UnsignedInteger.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedLongWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedLongWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedLongWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedLongWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,152 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.UnsignedLong;
+
+import java.nio.ByteBuffer;
+
+public class UnsignedLongWriter implements ValueWriter<UnsignedLong>
+{
+
+
+    private static final byte EIGHT_BYTE_FORMAT_CODE = (byte) 0x80;
+    private static final byte ONE_BYTE_FORMAT_CODE = (byte) 0x53;
+    private static final byte ZERO_BYTE_FORMAT_CODE = (byte) 0x44;
+
+    private ValueWriter<UnsignedLong> _delegate;
+
+    private final FixedEightWriter<UnsignedLong> _eightByteWriter = new FixedEightWriter<UnsignedLong>()
+    {
+
+        @Override
+        byte getFormatCode()
+        {
+            return EIGHT_BYTE_FORMAT_CODE;
+        }
+
+        @Override
+        long convertValueToLong(UnsignedLong value)
+        {
+            return value.longValue();
+        }
+
+    };
+
+    private final ValueWriter<UnsignedLong> _oneByteWriter = new FixedOneWriter<UnsignedLong>()
+    {
+
+        @Override protected byte getFormatCode()
+        {
+            return ONE_BYTE_FORMAT_CODE;
+        }
+
+        @Override protected byte convertToByte(final UnsignedLong value)
+        {
+            return value.byteValue();
+        }
+    };
+
+    private final ValueWriter<UnsignedLong> _zeroByteWriter = new ValueWriter<UnsignedLong>()
+    {
+        private boolean _complete;
+
+
+        public int writeToBuffer(ByteBuffer buffer)
+        {
+
+            if(!_complete && buffer.hasRemaining())
+            {
+                buffer.put(ZERO_BYTE_FORMAT_CODE);
+                _complete = true;
+            }
+
+            return 1;
+        }
+
+        public void setValue(UnsignedLong ulong)
+        {
+            _complete = false;
+        }
+
+        public boolean isCacheable()
+        {
+            return true;
+        }
+
+        public boolean isComplete()
+        {
+            return _complete;
+        }
+
+    };
+
+
+
+    private static Factory<UnsignedLong> FACTORY = new Factory<UnsignedLong>()
+                                            {
+
+                                                public ValueWriter<UnsignedLong> newInstance(Registry registry)
+                                                {
+                                                    return new UnsignedLongWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(UnsignedLong.class, FACTORY);
+    }
+
+    public int writeToBuffer(final ByteBuffer buffer)
+    {
+        return _delegate.writeToBuffer(buffer);
+    }
+
+    public void setValue(final UnsignedLong ulong)
+    {
+        if(ulong.equals(UnsignedLong.ZERO))
+        {
+            _delegate = _zeroByteWriter;
+        }
+        else if(ulong.compareTo(UnsignedLong.valueOf(256))<0)
+        {
+            _delegate = _oneByteWriter;
+        }
+        else
+        {
+            _delegate = _eightByteWriter;
+        }
+
+        _delegate.setValue(ulong);
+    }
+
+    public boolean isComplete()
+    {
+        return _delegate.isComplete();
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedShortWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedShortWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedShortWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/UnsignedShortWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,56 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.UnsignedShort;
+
+public class UnsignedShortWriter extends FixedTwoWriter<UnsignedShort>
+{
+    private static final byte FORMAT_CODE = (byte)0x60;
+
+
+    @Override
+    short convertValueToShort(UnsignedShort value)
+    {
+        return value.shortValue();
+    }
+
+    @Override
+    byte getFormatCode()
+    {
+        return FORMAT_CODE;
+    }
+
+    private static Factory<UnsignedShort> FACTORY = new Factory<UnsignedShort>()
+                                            {
+
+                                                public ValueWriter<UnsignedShort> newInstance(Registry registry)
+                                                {
+                                                    return new UnsignedShortWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(UnsignedShort.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ValueHandler.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ValueHandler.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ValueHandler.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ValueHandler.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,159 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this 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.qpid.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.AmqpError;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+public class ValueHandler implements DescribedTypeConstructorRegistry.Source
+{
+    private static final byte DESCRIBED_TYPE = (byte)0;
+
+    private final DescribedTypeConstructorRegistry _describedTypeConstructorRegistry;
+
+
+    private static final TypeConstructor[][] TYPE_CONSTRUCTORS =
+            {
+                    {},
+                    {},
+                    {},
+                    {},
+                    { NullTypeConstructor.getInstance(),   BooleanConstructor.getTrueInstance(),
+                      BooleanConstructor.getFalseInstance(), ZeroUIntConstructor.getInstance(),
+                      ZeroULongConstructor.getInstance(),  ZeroListConstructor.getInstance()       },
+                    { UByteTypeConstructor.getInstance(),  ByteTypeConstructor.getInstance(),
+                      SmallUIntConstructor.getInstance(),  SmallULongConstructor.getInstance(),
+                      SmallIntConstructor.getInstance(),   SmallLongConstructor.getInstance(),
+                      BooleanConstructor.getByteInstance()},
+                    { UShortTypeConstructor.getInstance(), ShortTypeConstructor.getInstance()      },
+                    { UIntTypeConstructor.getInstance(),   IntTypeConstructor.getInstance(),
+                      FloatTypeConstructor.getInstance(),  CharTypeConstructor.getInstance(),
+                      DecimalConstructor.getDecimal32Instance()},
+                    { ULongTypeConstructor.getInstance(),  LongTypeConstructor.getInstance(),
+                      DoubleTypeConstructor.getInstance(), TimestampTypeConstructor.getInstance(),
+                      DecimalConstructor.getDecimal64Instance()},
+                    { null,                                null,
+                      null,                                null,
+                      DecimalConstructor.getDecimal128Instance(), null,
+                      null,                                null,
+                      UUIDTypeConstructor.getInstance()                                            },
+                    { BinaryTypeConstructor.getInstance(1),
+                      StringTypeConstructor.getInstance(1, Charset.forName("UTF8")),
+                      StringTypeConstructor.getInstance(1, Charset.forName("UTF16")),
+                      SymbolTypeConstructor.getInstance(1)                                         },
+                    { BinaryTypeConstructor.getInstance(4),
+                      StringTypeConstructor.getInstance(4, Charset.forName("UTF8")),
+                      StringTypeConstructor.getInstance(4, Charset.forName("UTF16")),
+                      SymbolTypeConstructor.getInstance(4)                                         },
+                    { CompoundTypeConstructor.getInstance(1, CompoundTypeConstructor.LIST_ASSEMBLER_FACTORY),
+                      CompoundTypeConstructor.getInstance(1, CompoundTypeConstructor.MAP_ASSEMBLER_FACTORY)  },
+                    { CompoundTypeConstructor.getInstance(4, CompoundTypeConstructor.LIST_ASSEMBLER_FACTORY),
+                      CompoundTypeConstructor.getInstance(4, CompoundTypeConstructor.MAP_ASSEMBLER_FACTORY)  },
+                    {
+                      ArrayTypeConstructor.getOneByteSizeTypeConstructor()
+                    },
+                    {
+                      ArrayTypeConstructor.getFourByteSizeTypeConstructor()
+                    }
+            };
+
+
+    public ValueHandler(DescribedTypeConstructorRegistry registry)
+    {
+        _describedTypeConstructorRegistry = registry;
+    }
+
+    public Object parse(final ByteBuffer in) throws AmqpErrorException
+    {
+        TypeConstructor constructor = readConstructor(in);
+        return constructor.construct(in, this);
+    }
+
+
+    public TypeConstructor readConstructor(ByteBuffer in) throws AmqpErrorException
+    {
+        if(!in.hasRemaining())
+        {
+            throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data - expected type, no data remaining");
+        }
+        byte formatCode = in.get();
+
+        if(formatCode == DESCRIBED_TYPE)
+        {
+            Object descriptor = parse(in);
+            DescribedTypeConstructor describedTypeConstructor = _describedTypeConstructorRegistry.getConstructor(descriptor);
+            if(describedTypeConstructor==null)
+            {
+                describedTypeConstructor=new DefaultDescribedTypeConstructor(descriptor);
+            }
+            TypeConstructor typeConstructor = readConstructor(in);
+
+            return describedTypeConstructor.construct(typeConstructor);
+
+        }
+        else
+        {
+            int subCategory = (formatCode >> 4) & 0x0F;
+            int subtype =  formatCode & 0x0F;
+
+            TypeConstructor tc;
+            try
+            {
+                tc = TYPE_CONSTRUCTORS[subCategory][subtype];
+            }
+            catch(IndexOutOfBoundsException e)
+            {
+                tc = null;
+            }
+
+            if(tc == null)
+            {
+                throw new AmqpErrorException(ConnectionError.FRAMING_ERROR,"Unknown type format-code 0x%02x", formatCode);
+            }
+
+            return tc;
+        }
+    }
+
+
+
+
+
+    @Override
+    public String toString()
+    {
+        return "ValueHandler{" +
+              ", _describedTypeConstructorRegistry=" + _describedTypeConstructorRegistry +
+               '}';
+    }
+
+
+    public DescribedTypeConstructorRegistry getDescribedTypeRegistry()
+    {
+        return _describedTypeConstructorRegistry;
+    }
+
+
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org