You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ai...@apache.org on 2008/04/24 03:54:42 UTC

svn commit: r651133 [10/17] - in /incubator/qpid/trunk/qpid: gentools/ gentools/src/org/apache/qpid/gentools/ java/ java/broker/ java/broker/src/main/grammar/ java/broker/src/main/java/org/apache/qpid/server/exchange/ java/broker/src/main/java/org/apac...

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java Wed Apr 23 18:54:20 2008
@@ -1,132 +1,83 @@
-/*
- *
- * 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.framing;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.AMQChannelException;
-import org.apache.qpid.AMQConnectionException;
-import org.apache.qpid.protocol.AMQConstant;
-
-public abstract class AMQMethodBody extends AMQBody
-{
-    public static final byte TYPE = 1;
-
-    /** AMQP version */
-    protected byte major;
-    protected byte minor;
-
-    public byte getMajor()
-    {
-        return major;
-    }
-
-    public byte getMinor()
-    {
-        return minor;
-    }
-
-    public AMQMethodBody(byte major, byte minor)
-    {
-        this.major = major;
-        this.minor = minor;
-    }
-
-    /** unsigned short */
-    protected abstract int getBodySize();
-
-    /** @return unsigned short */
-    protected abstract int getClazz();
-
-    /** @return unsigned short */
-    protected abstract int getMethod();
-
-    protected abstract void writeMethodPayload(ByteBuffer buffer);
-
-    public byte getFrameType()
-    {
-        return TYPE;
-    }
-
-    protected int getSize()
-    {
-        return 2 + 2 + getBodySize();
-    }
-
-    protected void writePayload(ByteBuffer buffer)
-    {
-        EncodingUtils.writeUnsignedShort(buffer, getClazz());
-        EncodingUtils.writeUnsignedShort(buffer, getMethod());
-        writeMethodPayload(buffer);
-    }
-
-    protected abstract void populateMethodBodyFromBuffer(ByteBuffer buffer) throws AMQFrameDecodingException;
-
-    protected void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException
-    {
-        populateMethodBodyFromBuffer(buffer);
-    }
-
-    public String toString()
-    {
-        StringBuffer buf = new StringBuffer(getClass().getName());
-        buf.append("[ Class: ").append(getClazz());
-        buf.append(" Method: ").append(getMethod()).append(']');
-        return buf.toString();
-    }
-
-    /**
-     * Creates an AMQChannelException for the corresponding body type (a channel exception should include the class and
-     * method ids of the body it resulted from).
-     */
-
-    /**
-     * Convenience Method to create a channel not found exception
-     *
-     * @param channelId The channel id that is not found
-     *
-     * @return new AMQChannelException
-     */
-    public AMQChannelException getChannelNotFoundException(int channelId)
-    {
-        return getChannelException(AMQConstant.NOT_FOUND, "Channel not found for id:" + channelId);
-    }
-
-    public AMQChannelException getChannelException(AMQConstant code, String message)
-    {
-        return new AMQChannelException(code, message, getClazz(), getMethod(), major, minor, null);
-    }
-
-    public AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause)
-    {
-        return new AMQChannelException(code, message, getClazz(), getMethod(), major, minor, cause);
-    }
-
-    public AMQConnectionException getConnectionException(AMQConstant code, String message)
-    {
-        return new AMQConnectionException(code, message, getClazz(), getMethod(), major, minor, null);
-    }
-
-    public AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause)
-    {
-        return new AMQConnectionException(code, message, getClazz(), getMethod(), major, minor, cause);
-    }
-
-}
+/*
+ *
+ * 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.framing;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.AMQChannelException;
+import org.apache.qpid.AMQConnectionException;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.protocol.AMQConstant;
+
+public interface AMQMethodBody extends AMQBody
+{
+    public static final byte TYPE = 1;
+
+    /** AMQP version */
+    public byte getMajor();
+
+    public byte getMinor();
+
+
+
+    /** @return unsigned short */
+    public int getClazz();
+
+    /** @return unsigned short */
+    public int getMethod();
+
+    public void writeMethodPayload(ByteBuffer buffer);
+
+
+    public int getSize();
+
+    public void writePayload(ByteBuffer buffer);
+
+    //public abstract void populateMethodBodyFromBuffer(ByteBuffer buffer) throws AMQFrameDecodingException;
+
+    //public void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException;
+
+    public AMQFrame generateFrame(int channelId);
+
+    public String toString();
+
+
+
+    /**
+     * Convenience Method to create a channel not found exception
+     *
+     * @param channelId The channel id that is not found
+     *
+     * @return new AMQChannelException
+     */
+    public AMQChannelException getChannelNotFoundException(int channelId);
+
+    public AMQChannelException getChannelException(AMQConstant code, String message);
+
+    public AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause);
+
+    public AMQConnectionException getConnectionException(AMQConstant code, String message);
+
+
+    public AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause);
+
+
+    public boolean execute(MethodDispatcher methodDispatcher, int channelId) throws AMQException;
+}

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java Wed Apr 23 18:54:20 2008
@@ -40,7 +40,6 @@
 
     public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException
     {
-        return _protocolSession.getRegistry().get((short) in.getUnsignedShort(), (short) in.getUnsignedShort(), in,
-                bodySize);
+        return _protocolSession.getMethodRegistry().convertToBody(in, bodySize);
     }
 }

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java?rev=651133&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyImpl.java Wed Apr 23 18:54:20 2008
@@ -0,0 +1,96 @@
+package org.apache.qpid.framing;
+
+/*
+ *
+ * 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.
+ *
+ */
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.AMQChannelException;
+import org.apache.qpid.AMQConnectionException;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+
+public abstract class AMQMethodBodyImpl implements AMQMethodBody
+{
+    public static final byte TYPE = 1;
+
+    public AMQMethodBodyImpl()
+    {
+    }
+
+    public byte getFrameType()
+    {
+        return TYPE;
+    }
+
+
+    /** unsigned short */
+    abstract protected int getBodySize();
+
+
+    public AMQFrame generateFrame(int channelId)
+    {
+        return new AMQFrame(channelId, this);
+    }
+
+    /**
+     * Creates an AMQChannelException for the corresponding body type (a channel exception should include the class and
+     * method ids of the body it resulted from).
+     */
+
+    /**
+     * Convenience Method to create a channel not found exception
+     *
+     * @param channelId The channel id that is not found
+     *
+     * @return new AMQChannelException
+     */
+    public AMQChannelException getChannelNotFoundException(int channelId)
+    {
+        return getChannelException(AMQConstant.NOT_FOUND, "Channel not found for id:" + channelId);
+    }
+
+    public AMQChannelException getChannelException(AMQConstant code, String message)
+    {
+        return new AMQChannelException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), null);
+    }
+
+    public AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause)
+    {
+        return new AMQChannelException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), cause);
+    }
+
+    public AMQConnectionException getConnectionException(AMQConstant code, String message)
+    {
+        return new AMQConnectionException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), null);
+    }
+
+    public AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause)
+    {
+        return new AMQConnectionException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), cause);
+    }
+
+    public void handle(final int channelId, final AMQVersionAwareProtocolSession session) throws AMQException
+    {
+        session.methodFrameReceived(channelId, this);
+    }
+
+}

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyInstanceFactory.java Wed Apr 23 18:54:20 2008
@@ -26,6 +26,5 @@
 
 public abstract interface AMQMethodBodyInstanceFactory
 {
-    public AMQMethodBody newInstance(byte major, byte minor, ByteBuffer buffer, long size) throws AMQFrameDecodingException;
-    public AMQMethodBody newInstance(byte major, byte minor, int clazzID, int methodID, ByteBuffer buffer, long size) throws AMQFrameDecodingException;
+    public AMQMethodBody newInstance(ByteBuffer buffer, long size) throws AMQFrameDecodingException;    
 }

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java Wed Apr 23 18:54:20 2008
@@ -1,444 +1,721 @@
-/*
- *
- * 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.framing;
-
-import org.apache.mina.common.ByteBuffer;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.lang.ref.WeakReference;
-
-/**
- * A short string is a representation of an AMQ Short String
- * Short strings differ from the Java String class by being limited to on ASCII characters (0-127)
- * and thus can be held more effectively in a byte buffer.
- *
- */
-public final class AMQShortString implements CharSequence, Comparable<AMQShortString>
-{
-
-    private static final ThreadLocal<Map<AMQShortString, WeakReference<AMQShortString>>> _localInternMap =
-            new ThreadLocal<Map<AMQShortString, WeakReference<AMQShortString>>>()
-            {
-                protected Map<AMQShortString, WeakReference<AMQShortString>> initialValue()
-                {
-                    return new WeakHashMap<AMQShortString, WeakReference<AMQShortString>>();
-                };
-            };
-
-    private static final Map<AMQShortString, WeakReference<AMQShortString>> _globalInternMap =
-            new WeakHashMap<AMQShortString, WeakReference<AMQShortString>>();
-
-    private static final Logger _logger = LoggerFactory.getLogger(AMQShortString.class);
-
-    private final ByteBuffer _data;
-    private int _hashCode;
-    private final int _length;
-    private static final char[] EMPTY_CHAR_ARRAY = new char[0];
-    private char[] chars;
-    private String str;
-
-    public AMQShortString(byte[] data)
-    {
-
-        _data = ByteBuffer.wrap(data);
-        _length = data.length;
-    }
-
-    public AMQShortString(String data)
-    {
-        this((data == null) ? EMPTY_CHAR_ARRAY : data.toCharArray());
-        if (data != null)
-        {
-            _hashCode = data.hashCode();
-        }
-    }
-
-    public AMQShortString(char[] data)
-    {
-        if (data == null)
-        {
-            throw new NullPointerException("Cannot create AMQShortString with null char[]");
-        }
-
-        final int length = data.length;
-        final byte[] stringBytes = new byte[length];
-        for (int i = 0; i < length; i++)
-        {
-            stringBytes[i] = (byte) (0xFF & data[i]);
-        }
-
-        _data = ByteBuffer.wrap(stringBytes);
-        _data.rewind();
-        _length = length;
-
-    }
-
-    public AMQShortString(CharSequence charSequence)
-    {
-        final int length = charSequence.length();
-        final byte[] stringBytes = new byte[length];
-        int hash = 0;
-        for (int i = 0; i < length; i++)
-        {
-            stringBytes[i] = ((byte) (0xFF & charSequence.charAt(i)));
-            hash = (31 * hash) + stringBytes[i];
-
-        }
-
-        _data = ByteBuffer.wrap(stringBytes);
-        _data.rewind();
-        _hashCode = hash;
-        _length = length;
-
-    }
-
-    private AMQShortString(ByteBuffer data)
-    {
-        _data = data;
-        _length = data.limit();
-
-    }
-
-    /**
-     * Get the length of the short string
-     * @return length of the underlying byte array
-     */
-    public int length()
-    {
-        return _length;
-    }
-
-    public char charAt(int index)
-    {
-
-        return (char) _data.get(index);
-
-    }
-
-    public CharSequence subSequence(int start, int end)
-    {
-        return new CharSubSequence(start, end);
-    }
-
-    public int writeToByteArray(byte[] encoding, int pos)
-    {
-        final int size = length();
-        encoding[pos++] = (byte) length();
-        for (int i = 0; i < size; i++)
-        {
-            encoding[pos++] = _data.get(i);
-        }
-
-        return pos;
-    }
-
-    public static AMQShortString readFromByteArray(byte[] byteEncodedDestination, int pos)
-    {
-
-        final byte len = byteEncodedDestination[pos];
-        if (len == 0)
-        {
-            return null;
-        }
-
-        ByteBuffer data = ByteBuffer.wrap(byteEncodedDestination, pos + 1, len).slice();
-
-        return new AMQShortString(data);
-    }
-
-    public static AMQShortString readFromBuffer(ByteBuffer buffer)
-    {
-        final short length = buffer.getUnsigned();
-        if (length == 0)
-        {
-            return null;
-        }
-        else
-        {
-            ByteBuffer data = buffer.slice();
-            data.limit(length);
-            data.rewind();
-            buffer.skip(length);
-
-            return new AMQShortString(data);
-        }
-    }
-
-    public byte[] getBytes()
-    {
-
-        if (_data.buf().hasArray() && (_data.arrayOffset() == 0))
-        {
-            return _data.array();
-        }
-        else
-        {
-            final int size = length();
-            byte[] b = new byte[size];
-            ByteBuffer buf = _data.duplicate();
-            buf.rewind();
-            buf.get(b);
-
-            return b;
-        }
-
-    }
-
-    public void writeToBuffer(ByteBuffer buffer)
-    {
-
-        final int size = length();
-        if (size != 0)
-        {
-
-            buffer.put((byte) size);
-            if (_data.buf().hasArray())
-            {
-                buffer.put(_data.array(), _data.arrayOffset(), length());
-            }
-            else
-            {
-
-                for (int i = 0; i < size; i++)
-                {
-
-                    buffer.put(_data.get(i));
-                }
-            }
-        }
-        else
-        {
-            // really writing out unsigned byte
-            buffer.put((byte) 0);
-        }
-
-    }
-
-    private final class CharSubSequence implements CharSequence
-    {
-        private final int _offset;
-        private final int _end;
-
-        public CharSubSequence(final int offset, final int end)
-        {
-            _offset = offset;
-            _end = end;
-        }
-
-        public int length()
-        {
-            return _end - _offset;
-        }
-
-        public char charAt(int index)
-        {
-            return AMQShortString.this.charAt(index + _offset);
-        }
-
-        public CharSequence subSequence(int start, int end)
-        {
-            return new CharSubSequence(start + _offset, end + _offset);
-        }
-    }
-
-    public char[] asChars()
-    {
-        if (chars == null)
-        {
-            final int size = length();
-            chars = new char[size];
-
-            for (int i = 0; i < size; i++)
-            {
-                chars[i] = (char) _data.get(i);
-            }
-        }
-
-        return chars;
-    }
-
-    public String asString()
-    {
-        if (str == null)
-        {
-            str = new String(asChars());
-        }
-
-        return str;
-    }
-
-    public boolean equals(Object o)
-    {
-        if (o == null)
-        {
-            return false;
-        }
-
-        if (o == this)
-        {
-            return true;
-        }
-
-        if (o instanceof AMQShortString)
-        {
-
-            final AMQShortString otherString = (AMQShortString) o;
-
-            if ((_hashCode != 0) && (otherString._hashCode != 0) && (_hashCode != otherString._hashCode))
-            {
-                return false;
-            }
-
-            return _data.equals(otherString._data);
-
-        }
-
-        return (o instanceof CharSequence) && equals((CharSequence) o);
-
-    }
-
-    public boolean equals(CharSequence s)
-    {
-        if (s == null)
-        {
-            return false;
-        }
-
-        if (s.length() != length())
-        {
-            return false;
-        }
-
-        for (int i = 0; i < length(); i++)
-        {
-            if (charAt(i) != s.charAt(i))
-            {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    public int hashCode()
-    {
-        int hash = _hashCode;
-        if (hash == 0)
-        {
-            final int size = length();
-
-            for (int i = 0; i < size; i++)
-            {
-                hash = (31 * hash) + _data.get(i);
-            }
-
-            _hashCode = hash;
-        }
-
-        return hash;
-    }
-
-    public void setDirty()
-    {
-        _hashCode = 0;
-    }
-
-    public String toString()
-    {
-        return asString();
-    }
-
-    public int compareTo(AMQShortString name)
-    {
-        if (name == null)
-        {
-            return 1;
-        }
-        else
-        {
-
-            if (name.length() < length())
-            {
-                return -name.compareTo(this);
-            }
-
-            for (int i = 0; i < length(); i++)
-            {
-                final byte d = _data.get(i);
-                final byte n = name._data.get(i);
-                if (d < n)
-                {
-                    return -1;
-                }
-
-                if (d > n)
-                {
-                    return 1;
-                }
-            }
-
-            return (length() == name.length()) ? 0 : -1;
-        }
-    }
-
-    public AMQShortString intern()
-    {
-
-        hashCode();
-
-        Map<AMQShortString, WeakReference<AMQShortString>> localMap =
-                _localInternMap.get();
-
-        WeakReference<AMQShortString> ref = localMap.get(this);
-        AMQShortString internString;
-
-        if(ref != null)
-        {
-            internString = ref.get();
-            if(internString != null)
-            {
-                return internString;
-            }
-        }
-
-
-        synchronized(_globalInternMap)
-        {
-
-            ref = _globalInternMap.get(this);
-            if((ref == null) || ((internString = ref.get()) == null))
-            {
-                internString = new AMQShortString(getBytes());
-                ref = new WeakReference(internString);
-                _globalInternMap.put(internString, ref);
-            }
-
-        }
-        localMap.put(internString, ref);
-        return internString;
-
-    }
-}
+/*
+ *
+ * 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.framing;
+
+import org.apache.mina.common.ByteBuffer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.lang.ref.WeakReference;
+
+/**
+ * A short string is a representation of an AMQ Short String
+ * Short strings differ from the Java String class by being limited to on ASCII characters (0-127)
+ * and thus can be held more effectively in a byte buffer.
+ *
+ */
+public final class AMQShortString implements CharSequence, Comparable<AMQShortString>
+{
+    private static final byte MINUS = (byte)'-';
+    private static final byte ZERO = (byte) '0';
+
+
+
+    private final class TokenizerImpl implements AMQShortStringTokenizer
+    {
+        private final byte _delim;
+        private int _count = -1;
+        private int _pos = 0;
+
+        public TokenizerImpl(final byte delim)
+        {
+            _delim = delim;
+        }
+
+        public int countTokens()
+        {
+            if(_count == -1)
+            {
+                _count = 1 + AMQShortString.this.occurences(_delim);
+            }
+            return _count;
+        }
+
+        public AMQShortString nextToken()
+        {
+            if(_pos <= AMQShortString.this.length())
+            {
+                int nextDelim = AMQShortString.this.indexOf(_delim, _pos);
+                if(nextDelim == -1)
+                {
+                    nextDelim = AMQShortString.this.length();
+                }
+
+                AMQShortString nextToken = AMQShortString.this.substring(_pos, nextDelim++);
+                _pos = nextDelim;
+                return nextToken;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        public boolean hasMoreTokens()
+        {
+            return _pos <= AMQShortString.this.length();
+        }
+    }
+
+    private AMQShortString substring(final int from, final int to)
+    {
+        return new AMQShortString(_data, from+_offset, to+_offset);
+    }
+
+
+    private static final ThreadLocal<Map<AMQShortString, WeakReference<AMQShortString>>> _localInternMap =
+            new ThreadLocal<Map<AMQShortString, WeakReference<AMQShortString>>>()
+            {
+                protected Map<AMQShortString, WeakReference<AMQShortString>> initialValue()
+                {
+                    return new WeakHashMap<AMQShortString, WeakReference<AMQShortString>>();
+                };
+            };
+
+    private static final Map<AMQShortString, WeakReference<AMQShortString>> _globalInternMap =
+            new WeakHashMap<AMQShortString, WeakReference<AMQShortString>>();
+
+    private static final Logger _logger = LoggerFactory.getLogger(AMQShortString.class);
+
+    private final byte[] _data;
+    private final int _offset;
+    private int _hashCode;
+    private final int _length;
+    private static final char[] EMPTY_CHAR_ARRAY = new char[0];
+    
+    public static final AMQShortString EMPTY_STRING = new AMQShortString((String)null);
+
+    public AMQShortString(byte[] data)
+    {
+
+        _data = data.clone();
+        _length = data.length;
+        _offset = 0;
+    }
+
+    public AMQShortString(byte[] data, int pos)
+    {
+        final int size = data[pos++];
+        final byte[] dataCopy = new byte[size];
+        System.arraycopy(data,pos,dataCopy,0,size);
+        _length = size;
+        _data = dataCopy;
+        _offset = 0;
+    }
+
+    public AMQShortString(String data)
+    {
+        this((data == null) ? EMPTY_CHAR_ARRAY : data.toCharArray());
+
+    }
+
+    public AMQShortString(char[] data)
+    {
+        if (data == null)
+        {
+            throw new NullPointerException("Cannot create AMQShortString with null char[]");
+        }
+
+        final int length = data.length;
+        final byte[] stringBytes = new byte[length];
+        int hash = 0;
+        for (int i = 0; i < length; i++)
+        {
+            stringBytes[i] = (byte) (0xFF & data[i]);
+            hash = (31 * hash) + stringBytes[i];
+        }
+        _hashCode = hash;
+        _data = stringBytes;
+
+        _length = length;
+        _offset = 0;
+
+    }
+
+    public AMQShortString(CharSequence charSequence)
+    {
+        final int length = charSequence.length();
+        final byte[] stringBytes = new byte[length];
+        int hash = 0;
+        for (int i = 0; i < length; i++)
+        {
+            stringBytes[i] = ((byte) (0xFF & charSequence.charAt(i)));
+            hash = (31 * hash) + stringBytes[i];
+
+        }
+
+        _data = stringBytes;
+        _hashCode = hash;
+        _length = length;
+        _offset = 0;
+
+    }
+
+    private AMQShortString(ByteBuffer data, final int length)
+    {
+        if(data.isDirect() || data.isReadOnly())
+        {
+            byte[] dataBytes = new byte[length];
+            data.get(dataBytes);
+            _data = dataBytes;
+            _offset = 0;
+        }
+        else
+        {
+
+            _data = data.array();
+            _offset = data.arrayOffset() + data.position();
+            data.skip(length);
+
+        }
+        _length = length;
+
+    }
+
+    private AMQShortString(final byte[] data, final int from, final int to)
+    {
+        _offset = from;
+        _length = to - from;
+        _data = data;
+    }
+
+    public AMQShortString shrink()
+    {
+        if(_data.length != _length)
+        {
+            byte[] dataBytes = new byte[_length];
+            System.arraycopy(_data,_offset,dataBytes,0,_length);
+            return new AMQShortString(dataBytes,0,_length);
+        }
+        else
+        {
+            return this;
+        }
+    }
+
+
+    /**
+     * Get the length of the short string
+     * @return length of the underlying byte array
+     */
+    public int length()
+    {
+        return _length;
+    }
+
+    public char charAt(int index)
+    {
+
+        return (char) _data[_offset + index];
+
+    }
+
+    public CharSequence subSequence(int start, int end)
+    {
+        return new CharSubSequence(start, end);
+    }
+
+    public int writeToByteArray(byte[] encoding, int pos)
+    {
+        final int size = length();
+        encoding[pos++] = (byte) size;
+        System.arraycopy(_data,_offset,encoding,pos,size);
+        return pos+size;
+    }
+
+    public static AMQShortString readFromByteArray(byte[] byteEncodedDestination, int pos)
+    {
+
+
+        final AMQShortString shortString = new AMQShortString(byteEncodedDestination, pos);
+        if(shortString.length() == 0)
+        {
+            return null;
+        }
+        else
+        {
+            return shortString;
+        }
+    }
+
+    public static AMQShortString readFromBuffer(ByteBuffer buffer)
+    {
+        final short length = buffer.getUnsigned();
+        if (length == 0)
+        {
+            return null;
+        }
+        else
+        {
+
+            return new AMQShortString(buffer, length);
+        }
+    }
+
+    public byte[] getBytes()
+    {
+        if(_offset == 0 && _length == _data.length)
+        {
+            return _data.clone();
+        }
+        else
+        {
+            byte[] data = new byte[_length];
+            System.arraycopy(_data,_offset,data,0,_length);
+            return data;
+        }
+    }
+
+    public void writeToBuffer(ByteBuffer buffer)
+    {
+
+        final int size = length();
+        //buffer.setAutoExpand(true);
+        buffer.put((byte) size);
+        buffer.put(_data, _offset, size);
+
+    }
+
+    public boolean endsWith(String s)
+    {
+        return endsWith(new AMQShortString(s));
+    }
+
+
+    public boolean endsWith(AMQShortString otherString)
+    {
+
+        if (otherString.length() > length())
+        {
+            return false;
+        }
+
+
+        int thisLength = length();
+        int otherLength = otherString.length();
+
+        for (int i = 1; i <= otherLength; i++)
+        {
+            if (charAt(thisLength - i) != otherString.charAt(otherLength - i))
+            {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public boolean startsWith(String s)
+    {
+        return startsWith(new AMQShortString(s));
+    }
+
+    public boolean startsWith(AMQShortString otherString)
+    {
+
+        if (otherString.length() > length())
+        {
+            return false;
+        }
+
+        for (int i = 0; i < otherString.length(); i++)
+        {
+            if (charAt(i) != otherString.charAt(i))
+            {
+                return false;
+            }
+        }
+
+        return true;
+
+    }
+
+    public boolean startsWith(CharSequence otherString)
+    {
+        if (otherString.length() > length())
+        {
+            return false;
+        }
+
+        for (int i = 0; i < otherString.length(); i++)
+        {
+            if (charAt(i) != otherString.charAt(i))
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+
+    private final class CharSubSequence implements CharSequence
+    {
+        private final int _sequenceOffset;
+        private final int _end;
+
+        public CharSubSequence(final int offset, final int end)
+        {
+            _sequenceOffset = offset;
+            _end = end;
+        }
+
+        public int length()
+        {
+            return _end - _sequenceOffset;
+        }
+
+        public char charAt(int index)
+        {
+            return AMQShortString.this.charAt(index + _sequenceOffset);
+        }
+
+        public CharSequence subSequence(int start, int end)
+        {
+            return new CharSubSequence(start + _sequenceOffset, end + _sequenceOffset);
+        }
+    }
+
+    public char[] asChars()
+    {
+        final int size = length();
+        final char[] chars = new char[size];
+
+        for (int i = 0; i < size; i++)
+        {
+            chars[i] = (char) _data[i + _offset];
+        }
+
+        return chars;
+    }
+
+    public String asString()
+    {
+        return new String(asChars());
+    }
+
+    public boolean equals(Object o)
+    {
+
+
+        if(o instanceof AMQShortString)
+        {
+            return equals((AMQShortString)o);
+        }
+        if(o instanceof CharSequence)
+        {
+            return equals((CharSequence)o);
+        }
+
+        if (o == null)
+        {
+            return false;
+        }
+
+        if (o == this)
+        {
+            return true;
+        }
+
+
+        return false;
+
+    }
+
+    public boolean equals(final AMQShortString otherString)
+    {
+        if (otherString == this)
+        {
+            return true;
+        }
+
+        if (otherString == null)
+        {
+            return false;
+        }
+
+        if ((_hashCode != 0) && (otherString._hashCode != 0) && (_hashCode != otherString._hashCode))
+        {
+            return false;
+        }
+
+        return (_offset == 0 && otherString._offset == 0 && _length == _data.length && otherString._length == otherString._data.length && Arrays.equals(_data,otherString._data))
+                || Arrays.equals(getBytes(),otherString.getBytes());
+
+    }
+
+    public boolean equals(CharSequence s)
+    {
+        if(s instanceof AMQShortString)
+        {
+            return equals((AMQShortString)s);
+        }
+
+        if (s == null)
+        {
+            return false;
+        }
+
+        if (s.length() != length())
+        {
+            return false;
+        }
+
+        for (int i = 0; i < length(); i++)
+        {
+            if (charAt(i) != s.charAt(i))
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public int hashCode()
+    {
+        int hash = _hashCode;
+        if (hash == 0)
+        {
+            final int size = length();
+
+            for (int i = 0; i < size; i++)
+            {
+                hash = (31 * hash) + _data[i+_offset];
+            }
+
+            _hashCode = hash;
+        }
+
+        return hash;
+    }
+
+    public void setDirty()
+    {
+        _hashCode = 0;
+    }
+
+    public String toString()
+    {
+        return asString();
+    }
+
+    public int compareTo(AMQShortString name)
+    {
+        if (name == null)
+        {
+            return 1;
+        }
+        else
+        {
+
+            if (name.length() < length())
+            {
+                return -name.compareTo(this);
+            }
+
+            for (int i = 0; i < length(); i++)
+            {
+                final byte d = _data[i+_offset];
+                final byte n = name._data[i+name._offset];
+                if (d < n)
+                {
+                    return -1;
+                }
+
+                if (d > n)
+                {
+                    return 1;
+                }
+            }
+
+            return (length() == name.length()) ? 0 : -1;
+        }
+    }
+
+
+    public AMQShortStringTokenizer tokenize(byte delim)
+    {
+        return new TokenizerImpl(delim);
+    }
+
+
+    public AMQShortString intern()
+    {
+
+        hashCode();
+
+        Map<AMQShortString, WeakReference<AMQShortString>> localMap =
+                _localInternMap.get();
+
+        WeakReference<AMQShortString> ref = localMap.get(this);
+        AMQShortString internString;
+
+        if(ref != null)
+        {
+            internString = ref.get();
+            if(internString != null)
+            {
+                return internString;
+            }
+        }
+
+
+        synchronized(_globalInternMap)
+        {
+
+            ref = _globalInternMap.get(this);
+            if((ref == null) || ((internString = ref.get()) == null))
+            {
+                internString = shrink();
+                ref = new WeakReference(internString);
+                _globalInternMap.put(internString, ref);
+            }
+
+        }
+        localMap.put(internString, ref);
+        return internString;
+
+    }
+
+    private int occurences(final byte delim)
+    {
+        int count = 0;
+        final int end = _offset + _length;
+        for(int i = _offset ; i < end ; i++ )
+        {
+            if(_data[i] == delim)
+            {
+                count++;
+            }
+        }
+        return count;
+    }
+
+    private int indexOf(final byte val, final int pos)
+    {
+
+        for(int i = pos; i < length(); i++)
+        {
+            if(_data[_offset+i] == val)
+            {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+
+    public static AMQShortString join(final Collection<AMQShortString> terms,
+                                       final AMQShortString delim)
+    {
+        if(terms.size() == 0)
+        {
+            return EMPTY_STRING;
+        }
+
+        int size = delim.length() * (terms.size() - 1);
+        for(AMQShortString term : terms)
+        {
+            size += term.length();
+        }
+
+        byte[] data = new byte[size];
+        int pos = 0;
+        final byte[] delimData = delim._data;
+        final int delimOffset = delim._offset;
+        final int delimLength = delim._length;
+
+
+        for(AMQShortString term : terms)
+        {
+
+            if(pos!=0)
+            {
+                System.arraycopy(delimData, delimOffset,data,pos, delimLength);
+                pos+=delimLength;
+            }
+            System.arraycopy(term._data,term._offset,data,pos,term._length);
+            pos+=term._length;
+        }
+
+
+
+        return new AMQShortString(data,0,size);
+    }
+
+    public int toIntValue()
+    {
+        int pos = _offset;
+        int val = 0;
+
+
+        boolean isNegative = (_data[pos] == MINUS);
+        if(isNegative)
+        {
+            pos++;
+        }
+
+        final int end = _length + _offset;
+
+        while(pos < end)
+        {
+            int digit = (int) (_data[pos++] - ZERO);
+            if((digit < 0) || (digit > 9))
+            {
+                throw new NumberFormatException("\""+toString()+"\" is not a valid number");
+            }
+            val = val * 10;
+            val += digit;
+        }
+        if(isNegative)
+        {
+            val = val * -1;
+        }
+        return val;
+    }
+
+    public boolean contains(final byte b)
+    {
+        final int end = _length + _offset;
+        for(int i = _offset; i < end; i++)
+        {
+            if(_data[i] == b)
+            {
+                return true;
+            }
+        }
+        return false;  //To change body of created methods use File | Settings | File Templates.
+    }
+
+}

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortStringTokenizer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortStringTokenizer.java?rev=651133&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortStringTokenizer.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQShortStringTokenizer.java Wed Apr 23 18:54:20 2008
@@ -0,0 +1,31 @@
+package org.apache.qpid.framing;
+
+/*
+*
+* 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.
+*
+*/
+public interface AMQShortStringTokenizer
+{
+
+    public int countTokens();
+
+    public AMQShortString nextToken();
+
+    boolean hasMoreTokens();
+}

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java Wed Apr 23 18:54:20 2008
@@ -23,12 +23,24 @@
 import org.apache.mina.common.ByteBuffer;
 
 import java.math.BigDecimal;
-import java.math.BigInteger;
 
+/**
+ * AMQType is a type that represents the different possible AMQP field table types. It provides operations for each
+ * of the types to perform tasks such as calculating the size of an instance of the type, converting types between AMQP
+ * and Java native types, and reading and writing instances of AMQP types in binary formats to and from byte buffers.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Get the equivalent one byte identifier for a type.
+ * <tr><td> Calculate the size of an instance of an AMQP parameter type. <td> {@link EncodingUtils}
+ * <tr><td> Convert an instance of an AMQP parameter into a compatable Java object tagged with its AMQP type.
+ *     <td> {@link AMQTypedValue}
+ * <tr><td> Write an instance of an AMQP parameter type to a byte buffer. <td> {@link EncodingUtils}
+ * <tr><td> Read an instance of an AMQP parameter from a byte buffer. <td> {@link EncodingUtils}
+ * </table>
+ */
 public enum AMQType
 {
-    //AMQP FieldTable Wire Types
-
     LONG_STRING('S')
     {
         public int getEncodingSize(Object value)
@@ -36,7 +48,6 @@
             return EncodingUtils.encodedLongStringLength((String) value);
         }
 
-
         public String toNativeValue(Object value)
         {
             if (value != null)
@@ -58,12 +69,10 @@
         {
             return EncodingUtils.readLongString(buffer);
         }
-
     },
 
     INTEGER('i')
     {
-
         public int getEncodingSize(Object value)
         {
             return EncodingUtils.unsignedIntegerLength();
@@ -89,12 +98,11 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Long.valueOf((String)value);
+                return Long.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to int.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName() + ") to int.");
             }
         }
 
@@ -111,22 +119,21 @@
 
     DECIMAL('D')
     {
-
         public int getEncodingSize(Object value)
         {
-            return EncodingUtils.encodedByteLength()+ EncodingUtils.encodedIntegerLength();
+            return EncodingUtils.encodedByteLength() + EncodingUtils.encodedIntegerLength();
         }
 
         public Object toNativeValue(Object value)
         {
-            if(value instanceof BigDecimal)
+            if (value instanceof BigDecimal)
             {
                 return (BigDecimal) value;
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to BigDecimal.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to BigDecimal.");
             }
         }
 
@@ -150,7 +157,8 @@
             int unscaled = EncodingUtils.readInteger(buffer);
 
             BigDecimal bd = new BigDecimal(unscaled);
-            return bd.setScale(places);            
+
+            return bd.setScale(places);
         }
     },
 
@@ -163,14 +171,14 @@
 
         public Object toNativeValue(Object value)
         {
-            if(value instanceof Long)
+            if (value instanceof Long)
             {
                 return (Long) value;
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to timestamp.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to timestamp.");
             }
         }
 
@@ -179,37 +187,97 @@
             EncodingUtils.writeLong(buffer, (Long) value);
         }
 
-
         public Object readValueFromBuffer(ByteBuffer buffer)
         {
             return EncodingUtils.readLong(buffer);
         }
     },
 
+    /**
+     * Implements the field table type. The native value of a field table type will be an instance of
+     * {@link FieldTable}, which itself may contain name/value pairs encoded as {@link AMQTypedValue}s.
+     */
     FIELD_TABLE('F')
     {
+        /**
+         * Calculates the size of an instance of the type in bytes.
+         *
+         * @param value An instance of the type.
+         *
+         * @return The size of the instance of the type in bytes.
+         */
         public int getEncodingSize(Object value)
         {
-            // TODO : fixme
-            throw new UnsupportedOperationException();
+            // Ensure that the value is a FieldTable.
+            if (!(value instanceof FieldTable))
+            {
+                throw new IllegalArgumentException("Value is not a FieldTable.");
+            }
+
+            FieldTable ftValue = (FieldTable) value;
+
+            // Loop over all name/value pairs adding up size of each. FieldTable itself keeps track of its encoded
+            // size as entries are added, so no need to loop over all explicitly.
+            // EncodingUtils calculation of the encoded field table lenth, will include 4 bytes for its 'size' field.
+            return EncodingUtils.encodedFieldTableLength(ftValue);
         }
 
+        /**
+         * Converts an instance of the type to an equivalent Java native representation.
+         *
+         * @param value An instance of the type.
+         *
+         * @return An equivalent Java native representation.
+         */
         public Object toNativeValue(Object value)
         {
-            // TODO : fixme
-            throw new UnsupportedOperationException();
+            // Ensure that the value is a FieldTable.
+            if (!(value instanceof FieldTable))
+            {
+                throw new IllegalArgumentException("Value is not a FieldTable.");
+            }
+
+            return (FieldTable) value;
         }
 
+        /**
+         * Writes an instance of the type to a specified byte buffer.
+         *
+         * @param value  An instance of the type.
+         * @param buffer The byte buffer to write it to.
+         */
         public void writeValueImpl(Object value, ByteBuffer buffer)
         {
-            // TODO : fixme
-            throw new UnsupportedOperationException();
+            // Ensure that the value is a FieldTable.
+            if (!(value instanceof FieldTable))
+            {
+                throw new IllegalArgumentException("Value is not a FieldTable.");
+            }
+
+            FieldTable ftValue = (FieldTable) value;
+
+            // Loop over all name/values writing out into buffer.
+            ftValue.writeToBuffer(buffer);
         }
 
+        /**
+         * Reads an instance of the type from a specified byte buffer.
+         *
+         * @param buffer The byte buffer to write it to.
+         *
+         * @return An instance of the type.
+         */
         public Object readValueFromBuffer(ByteBuffer buffer)
         {
-            // TODO : fixme
-            throw new UnsupportedOperationException();
+            try
+            {
+                // Read size of field table then all name/value pairs.
+                return EncodingUtils.readFieldTable(buffer);
+            }
+            catch (AMQFrameDecodingException e)
+            {
+                throw new IllegalArgumentException("Unable to read field table from buffer.", e);
+            }
         }
     },
 
@@ -220,7 +288,6 @@
             return 0;
         }
 
-
         public Object toNativeValue(Object value)
         {
             if (value == null)
@@ -229,14 +296,13 @@
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to null String.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to null String.");
             }
         }
 
         public void writeValueImpl(Object value, ByteBuffer buffer)
-        {
-        }
+        { }
 
         public Object readValueFromBuffer(ByteBuffer buffer)
         {
@@ -244,8 +310,6 @@
         }
     },
 
-    // Extended types
-
     BINARY('x')
     {
         public int getEncodingSize(Object value)
@@ -253,21 +317,19 @@
             return EncodingUtils.encodedLongstrLength((byte[]) value);
         }
 
-
         public Object toNativeValue(Object value)
         {
-            if((value instanceof byte[]) || (value == null))
+            if ((value instanceof byte[]) || (value == null))
             {
                 return value;
             }
             else
             {
-                throw new IllegalArgumentException("Value: " + value + " (" + value.getClass().getName() +
-                                                    ") cannot be converted to byte[]");
+                throw new IllegalArgumentException("Value: " + value + " (" + value.getClass().getName()
+                    + ") cannot be converted to byte[]");
             }
         }
 
-
         public void writeValueImpl(Object value, ByteBuffer buffer)
         {
             EncodingUtils.writeLongstr(buffer, (byte[]) value);
@@ -277,7 +339,6 @@
         {
             return EncodingUtils.readLongstr(buffer);
         }
-
     },
 
     ASCII_STRING('c')
@@ -287,7 +348,6 @@
             return EncodingUtils.encodedLongStringLength((String) value);
         }
 
-
         public String toNativeValue(Object value)
         {
             if (value != null)
@@ -309,7 +369,6 @@
         {
             return EncodingUtils.readLongString(buffer);
         }
-
     },
 
     WIDE_STRING('C')
@@ -320,7 +379,6 @@
             return EncodingUtils.encodedLongStringLength((String) value);
         }
 
-
         public String toNativeValue(Object value)
         {
             if (value != null)
@@ -351,7 +409,6 @@
             return EncodingUtils.encodedBooleanLength();
         }
 
-
         public Object toNativeValue(Object value)
         {
             if (value instanceof Boolean)
@@ -360,12 +417,12 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Boolean.valueOf((String)value);
+                return Boolean.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to boolean.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to boolean.");
             }
         }
 
@@ -374,7 +431,6 @@
             EncodingUtils.writeBoolean(buffer, (Boolean) value);
         }
 
-
         public Object readValueFromBuffer(ByteBuffer buffer)
         {
             return EncodingUtils.readBoolean(buffer);
@@ -388,7 +444,6 @@
             return EncodingUtils.encodedCharLength();
         }
 
-
         public Character toNativeValue(Object value)
         {
             if (value instanceof Character)
@@ -401,8 +456,8 @@
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to char.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to char.");
             }
         }
 
@@ -415,7 +470,6 @@
         {
             return EncodingUtils.readChar(buffer);
         }
-
     },
 
     BYTE('b')
@@ -425,7 +479,6 @@
             return EncodingUtils.encodedByteLength();
         }
 
-
         public Byte toNativeValue(Object value)
         {
             if (value instanceof Byte)
@@ -434,12 +487,12 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Byte.valueOf((String)value);
+                return Byte.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to byte.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to byte.");
             }
         }
 
@@ -456,13 +509,11 @@
 
     SHORT('s')
     {
-
         public int getEncodingSize(Object value)
         {
             return EncodingUtils.encodedShortLength();
         }
 
-
         public Short toNativeValue(Object value)
         {
             if (value instanceof Short)
@@ -475,16 +526,13 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Short.valueOf((String)value);
+                return Short.valueOf((String) value);
             }
-
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to short.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to short.");
             }
-
-
         }
 
         public void writeValueImpl(Object value, ByteBuffer buffer)
@@ -521,12 +569,11 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Integer.valueOf((String)value);
+                return Integer.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to int.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName() + ") to int.");
             }
         }
 
@@ -543,7 +590,6 @@
 
     LONG('l')
     {
-
         public int getEncodingSize(Object value)
         {
             return EncodingUtils.encodedLongLength();
@@ -551,7 +597,7 @@
 
         public Object toNativeValue(Object value)
         {
-            if(value instanceof Long)
+            if (value instanceof Long)
             {
                 return (Long) value;
             }
@@ -569,12 +615,12 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Long.valueOf((String)value);
+                return Long.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to long.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to long.");
             }
         }
 
@@ -583,7 +629,6 @@
             EncodingUtils.writeLong(buffer, (Long) value);
         }
 
-
         public Object readValueFromBuffer(ByteBuffer buffer)
         {
             return EncodingUtils.readLong(buffer);
@@ -597,7 +642,6 @@
             return EncodingUtils.encodedFloatLength();
         }
 
-
         public Float toNativeValue(Object value)
         {
             if (value instanceof Float)
@@ -606,12 +650,12 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Float.valueOf((String)value);
+                return Float.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to float.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to float.");
             }
         }
 
@@ -628,13 +672,11 @@
 
     DOUBLE('d')
     {
-
         public int getEncodingSize(Object value)
         {
             return EncodingUtils.encodedDoubleLength();
         }
 
-
         public Double toNativeValue(Object value)
         {
             if (value instanceof Double)
@@ -647,12 +689,12 @@
             }
             else if ((value instanceof String) || (value == null))
             {
-                return Double.valueOf((String)value);
+                return Double.valueOf((String) value);
             }
             else
             {
-                throw new NumberFormatException("Cannot convert: " + value + "(" +
-                                                value.getClass().getName() + ") to double.");
+                throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+                    + ") to double.");
             }
         }
 
@@ -667,35 +709,87 @@
         }
     };
 
+    /** Holds the defined one byte identifier for the type. */
     private final byte _identifier;
 
+    /**
+     * Creates an instance of an AMQP type from its defined one byte identifier.
+     *
+     * @param identifier The one byte identifier for the type.
+     */
     AMQType(char identifier)
     {
         _identifier = (byte) identifier;
     }
 
+    /**
+     * Extracts the byte identifier for the typ.
+     *
+     * @return The byte identifier for the typ.
+     */
     public final byte identifier()
     {
         return _identifier;
     }
 
-
+    /**
+     * Calculates the size of an instance of the type in bytes.
+     *
+     * @param value An instance of the type.
+     *
+     * @return The size of the instance of the type in bytes.
+     */
     public abstract int getEncodingSize(Object value);
 
+    /**
+     * Converts an instance of the type to an equivalent Java native representation.
+     *
+     * @param value An instance of the type.
+     *
+     * @return An equivalent Java native representation.
+     */
     public abstract Object toNativeValue(Object value);
 
+    /**
+     * Converts an instance of the type to an equivalent Java native representation, packaged as an
+     * {@link AMQTypedValue} tagged with its AMQP type.
+     *
+     * @param value An instance of the type.
+     *
+     * @return An equivalent Java native representation, tagged with its AMQP type.
+     */
     public AMQTypedValue asTypedValue(Object value)
     {
         return new AMQTypedValue(this, toNativeValue(value));
     }
 
+    /**
+     * Writes an instance of the type to a specified byte buffer, preceded by its one byte identifier. As the type and
+     * value are both written, this provides a fully encoded description of a parameters type and value.
+     *
+     * @param value  An instance of the type.
+     * @param buffer The byte buffer to write it to.
+     */
     public void writeToBuffer(Object value, ByteBuffer buffer)
     {
-        buffer.put((byte)identifier());
+        buffer.put(identifier());
         writeValueImpl(value, buffer);
     }
 
+    /**
+     * Writes an instance of the type to a specified byte buffer.
+     *
+     * @param value  An instance of the type.
+     * @param buffer The byte buffer to write it to.
+     */
     abstract void writeValueImpl(Object value, ByteBuffer buffer);
 
+    /**
+     * Reads an instance of the type from a specified byte buffer.
+     *
+     * @param buffer The byte buffer to write it to.
+     *
+     * @return An instance of the type.
+     */
     abstract Object readValueFromBuffer(ByteBuffer buffer);
 }

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java Wed Apr 23 18:54:20 2008
@@ -18,23 +18,40 @@
  * under the License.
  *
  */
-
 package org.apache.qpid.framing;
 
 import org.apache.mina.common.ByteBuffer;
 
+/**
+ * AMQTypedValue combines together a native Java Object value, and an {@link AMQType}, as a fully typed AMQP parameter
+ * value. It provides the ability to read and write fully typed parameters to and from byte buffers. It also provides
+ * the ability to create such parameters from Java native value and a type tag or to extract the native value and type
+ * from one.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Create a fully typed AMQP value from a native type and a type tag. <td> {@link AMQType}
+ * <tr><td> Create a fully typed AMQP value from a binary representation in a byte buffer. <td> {@link AMQType}
+ * <tr><td> Write a fully typed AMQP value to a binary representation in a byte buffer. <td> {@link AMQType}
+ * <tr><td> Extract the type from a fully typed AMQP value.
+ * <tr><td> Extract the value from a fully typed AMQP value.
+ * </table>
+ */
 public class AMQTypedValue
 {
+    /** The type of the value. */
     private final AMQType _type;
-    private final Object _value;
 
+    /** The Java native representation of the AMQP typed value. */
+    private final Object _value;
 
     public AMQTypedValue(AMQType type, Object value)
     {
-        if(type == null)
+        if (type == null)
         {
             throw new NullPointerException("Cannot create a typed value with null type");
         }
+
         _type = type;
         _value = type.toNativeValue(value);
     }
@@ -42,10 +59,9 @@
     private AMQTypedValue(AMQType type, ByteBuffer buffer)
     {
         _type = type;
-        _value = type.readValueFromBuffer( buffer );
+        _value = type.readValueFromBuffer(buffer);
     }
 
-
     public AMQType getType()
     {
         return _type;
@@ -56,10 +72,9 @@
         return _value;
     }
 
-
     public void writeToBuffer(ByteBuffer buffer)
     {
-        _type.writeToBuffer(_value,buffer);
+        _type.writeToBuffer(_value, buffer);
     }
 
     public int getEncodingSize()
@@ -70,11 +85,12 @@
     public static AMQTypedValue readFromBuffer(ByteBuffer buffer)
     {
         AMQType type = AMQTypeMap.getType(buffer.get());
+
         return new AMQTypedValue(type, buffer);
     }
 
     public String toString()
     {
-        return "["+getType()+": "+getValue()+"]";
+        return "[" + getType() + ": " + getValue() + "]";
     }
 }

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java Wed Apr 23 18:54:20 2008
@@ -24,7 +24,6 @@
 
 public class CompositeAMQDataBlock extends AMQDataBlock implements EncodableAMQDataBlock
 {
-    private ByteBuffer _encodedBlock;
 
     private AMQDataBlock[] _blocks;
 
@@ -33,27 +32,12 @@
         _blocks = blocks;
     }
 
-    /**
-     * The encoded block will be logically first before the AMQDataBlocks which are encoded
-     * into the buffer afterwards.
-     * @param encodedBlock already-encoded data
-     * @param blocks some blocks to be encoded.
-     */
-    public CompositeAMQDataBlock(ByteBuffer encodedBlock, AMQDataBlock[] blocks)
-    {
-        this(blocks);
-        _encodedBlock = encodedBlock;
-    }
 
     public AMQDataBlock[] getBlocks()
     {
         return _blocks;
     }
 
-    public ByteBuffer getEncodedBlock()
-    {
-        return _encodedBlock;
-    }
 
     public long getSize()
     {
@@ -62,20 +46,11 @@
         {
             frameSize += _blocks[i].getSize();
         }
-        if (_encodedBlock != null)
-        {
-            _encodedBlock.rewind();
-            frameSize += _encodedBlock.remaining();
-        }
         return frameSize;
     }
 
     public void writePayload(ByteBuffer buffer)
     {
-        if (_encodedBlock != null)
-        {
-            buffer.put(_encodedBlock);
-        }
         for (int i = 0; i < _blocks.length; i++)
         {
             _blocks[i].writePayload(buffer);
@@ -91,7 +66,7 @@
         else
         {
             StringBuilder buf = new StringBuilder(this.getClass().getName());
-            buf.append("{encodedBlock=").append(_encodedBlock);
+            buf.append("{");
             for (int i = 0 ; i < _blocks.length; i++)
             {
                 buf.append(" ").append(i).append("=[").append(_blocks[i].toString()).append("]");

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java Wed Apr 23 18:54:20 2008
@@ -21,8 +21,10 @@
 package org.apache.qpid.framing;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+import org.apache.qpid.AMQException;
 
-public class ContentBody extends AMQBody
+public class ContentBody implements AMQBody
 {
     public static final byte TYPE = 3;
 
@@ -63,9 +65,22 @@
     {
         if (payload != null)
         {
-            ByteBuffer copy = payload.duplicate();
-            buffer.put(copy.rewind());
+            if(payload.isDirect() || payload.isReadOnly())
+            {            
+                ByteBuffer copy = payload.duplicate();
+                buffer.put(copy.rewind());
+            }
+            else
+            {
+                buffer.put(payload.array(),payload.arrayOffset(),payload.limit());
+            }
         }
+    }
+
+    public void handle(final int channelId, final AMQVersionAwareProtocolSession session)
+            throws AMQException
+    {
+        session.contentBodyReceived(channelId, this);
     }
 
     protected void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java Wed Apr 23 18:54:20 2008
@@ -21,8 +21,10 @@
 package org.apache.qpid.framing;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+import org.apache.qpid.AMQException;
 
-public class ContentHeaderBody extends AMQBody
+public class ContentHeaderBody implements AMQBody
 {
     public static final byte TYPE = 2;
 
@@ -108,6 +110,12 @@
         buffer.putLong(bodySize);
         EncodingUtils.writeUnsignedShort(buffer, properties.getPropertyFlags());
         properties.writePropertyListPayload(buffer);
+    }
+
+    public void handle(final int channelId, final AMQVersionAwareProtocolSession session)
+            throws AMQException
+    {
+        session.contentHeaderReceived(channelId, this);
     }
 
     public static AMQFrame createAMQFrame(int channelId, int classId, int weight, BasicContentHeaderProperties properties,

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java Wed Apr 23 18:54:20 2008
@@ -22,6 +22,8 @@
 
 import org.apache.mina.common.ByteBuffer;
 
+import org.apache.qpid.framing.amqp_8_0.BasicConsumeBodyImpl;
+
 public class ContentHeaderPropertiesFactory
 {
     private static final ContentHeaderPropertiesFactory _instance = new ContentHeaderPropertiesFactory();
@@ -43,7 +45,7 @@
         // AMQP version change: "Hardwired" version to major=8, minor=0
         // TODO: Change so that the actual version is obtained from
         // the ProtocolInitiation object for this session.
-        if (classId == BasicConsumeBody.getClazz((byte)8, (byte)0))
+        if (classId == BasicConsumeBodyImpl.CLASS_ID)
         {
         	properties = new BasicContentHeaderProperties();
         }

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/DeferredDataBlock.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/DeferredDataBlock.java?rev=651133&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/DeferredDataBlock.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/DeferredDataBlock.java Wed Apr 23 18:54:20 2008
@@ -0,0 +1,50 @@
+package org.apache.qpid.framing;
+
+import org.apache.mina.common.ByteBuffer;
+
+/*
+*
+* 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.
+*
+*/
+public abstract class DeferredDataBlock extends AMQDataBlock
+{
+    private AMQDataBlock _underlyingDataBlock;
+
+
+    public long getSize()
+    {
+        if(_underlyingDataBlock == null)
+        {
+            _underlyingDataBlock = createAMQDataBlock();
+        }
+        return _underlyingDataBlock.getSize();
+    }
+
+    public void writePayload(ByteBuffer buffer)
+    {
+        if(_underlyingDataBlock == null)
+        {
+            _underlyingDataBlock = createAMQDataBlock();
+        }
+        _underlyingDataBlock.writePayload(buffer);
+    }
+
+    abstract protected AMQDataBlock createAMQDataBlock();
+
+}

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java Wed Apr 23 18:54:20 2008
@@ -229,7 +229,11 @@
                 encodedString[i] = (byte) cha[i];
             }
 
-            writeBytes(buffer, encodedString);
+            // TODO: check length fits in an unsigned byte
+            writeUnsignedByte(buffer,  (short)encodedString.length);
+            buffer.put(encodedString);
+
+
         }
         else
         {
@@ -928,15 +932,15 @@
 
     public static byte[] readBytes(ByteBuffer buffer)
     {
-        short length = buffer.getUnsigned();
+        long length = buffer.getUnsignedInt();
         if (length == 0)
         {
             return null;
         }
         else
         {
-            byte[] dataBytes = new byte[length];
-            buffer.get(dataBytes, 0, length);
+            byte[] dataBytes = new byte[(int)length];
+            buffer.get(dataBytes, 0, (int)length);
 
             return dataBytes;
         }
@@ -947,13 +951,14 @@
         if (data != null)
         {
             // TODO: check length fits in an unsigned byte
-            writeUnsignedByte(buffer, (short) data.length);
+            writeUnsignedInteger(buffer,  (long)data.length);
             buffer.put(data);
         }
         else
-        {
+        {                                                    
             // really writing out unsigned byte
-            buffer.put((byte) 0);
+            //buffer.put((byte) 0);
+            writeUnsignedInteger(buffer, 0L);
         }
     }
 

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java Wed Apr 23 18:54:20 2008
@@ -18,7 +18,6 @@
  * under the License.
  *
  */
-
 package org.apache.qpid.framing;
 
 import org.apache.mina.common.ByteBuffer;
@@ -360,6 +359,41 @@
         }
     }
 
+    /**
+     * Extracts a value from the field table that is itself a FieldTable associated with the specified parameter name.
+     *
+     * @param string The name of the parameter to get the associated FieldTable value for.
+     *
+     * @return The associated FieldTable value, or <tt>null</tt> if the associated value is not of FieldTable type or
+     *         not present in the field table at all.
+     */
+    public FieldTable getFieldTable(String string)
+    {
+        return getFieldTable(new AMQShortString(string));
+    }
+
+    /**
+     * Extracts a value from the field table that is itself a FieldTable associated with the specified parameter name.
+     *
+     * @param string The name of the parameter to get the associated FieldTable value for.
+     *
+     * @return The associated FieldTable value, or <tt>null</tt> if the associated value is not of FieldTable type or
+     *         not present in the field table at all.
+     */
+    public FieldTable getFieldTable(AMQShortString string)
+    {
+        AMQTypedValue value = getProperty(string);
+
+        if ((value != null) && (value.getType() == AMQType.FIELD_TABLE))
+        {
+            return (FieldTable) value.getValue();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
     public Object getObject(String string)
     {
         return getObject(new AMQShortString(string));
@@ -568,6 +602,32 @@
         return setProperty(string, AMQType.VOID.asTypedValue(null));
     }
 
+    /**
+     * Associates a nested field table with the specified parameter name.
+     *
+     * @param string  The name of the parameter to store in the table.
+     * @param ftValue The field table value to associate with the parameter name.
+     *
+     * @return The stored value.
+     */
+    public Object setFieldTable(String string, FieldTable ftValue)
+    {
+        return setFieldTable(new AMQShortString(string), ftValue);
+    }
+
+    /**
+     * Associates a nested field table with the specified parameter name.
+     *
+     * @param string  The name of the parameter to store in the table.
+     * @param ftValue The field table value to associate with the parameter name.
+     *
+     * @return The stored value.
+     */
+    public Object setFieldTable(AMQShortString string, FieldTable ftValue)
+    {
+        return setProperty(string, AMQType.FIELD_TABLE.asTypedValue(ftValue));
+    }
+
     public Object setObject(AMQShortString string, Object object)
     {
         if (object instanceof Boolean)
@@ -706,12 +766,15 @@
 
     public void writeToBuffer(ByteBuffer buffer)
     {
-        final boolean trace = _logger.isTraceEnabled();
+        final boolean trace = _logger.isDebugEnabled();
 
         if (trace)
         {
-            _logger.trace("FieldTable::writeToBuffer: Writing encoded length of " + getEncodedSize() + "...");
-            _logger.trace(_properties.toString());
+            _logger.debug("FieldTable::writeToBuffer: Writing encoded length of " + getEncodedSize() + "...");
+            if (_properties != null)
+            {
+                _logger.debug(_properties.toString());
+            }
         }
 
         EncodingUtils.writeUnsignedInteger(buffer, getEncodedSize());
@@ -894,14 +957,21 @@
 
         if (_encodedForm != null)
         {
+            if(buffer.isDirect() || buffer.isReadOnly())
+            {
+                ByteBuffer encodedForm = _encodedForm.duplicate();
 
-            if (_encodedForm.position() != 0)
+                if (encodedForm.position() != 0)
+                {
+                    encodedForm.flip();
+                }
+
+                buffer.put(encodedForm);
+            }
+            else
             {
-                _encodedForm.flip();
+                buffer.put(_encodedForm.array(),_encodedForm.arrayOffset(),(int)_encodedSize);
             }
-            // _encodedForm.limit((int)getEncodedSize());
-
-            buffer.put(_encodedForm);
         }
         else if (_properties != null)
         {
@@ -915,11 +985,11 @@
                 final Map.Entry<AMQShortString, AMQTypedValue> me = it.next();
                 try
                 {
-                    if (_logger.isTraceEnabled())
+                    if (_logger.isDebugEnabled())
                     {
-                        _logger.trace("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:"
+                        _logger.debug("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:"
                             + me.getValue().getValue());
-                        _logger.trace("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining());
+                        _logger.debug("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining());
                     }
 
                     // Write the actual parameter name
@@ -928,12 +998,12 @@
                 }
                 catch (Exception e)
                 {
-                    if (_logger.isTraceEnabled())
+                    if (_logger.isDebugEnabled())
                     {
-                        _logger.trace("Exception thrown:" + e);
-                        _logger.trace("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:"
+                        _logger.debug("Exception thrown:" + e);
+                        _logger.debug("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:"
                             + me.getValue().getValue());
-                        _logger.trace("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining());
+                        _logger.debug("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining());
                     }
 
                     throw new RuntimeException(e);
@@ -945,7 +1015,7 @@
     private void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException
     {
 
-        final boolean trace = _logger.isTraceEnabled();
+        final boolean trace = _logger.isDebugEnabled();
         if (length > 0)
         {
 
@@ -961,7 +1031,7 @@
 
                 if (trace)
                 {
-                    _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType()
+                    _logger.debug("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType()
                         + "', key '" + key + "', value '" + value.getValue() + "'");
                 }
 
@@ -976,7 +1046,7 @@
 
         if (trace)
         {
-            _logger.trace("FieldTable::FieldTable(buffer," + length + "): Done.");
+            _logger.debug("FieldTable::FieldTable(buffer," + length + "): Done.");
         }
     }
 

Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java?rev=651133&r1=651132&r2=651133&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java Wed Apr 23 18:54:20 2008
@@ -21,8 +21,10 @@
 package org.apache.qpid.framing;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
+import org.apache.qpid.AMQException;
 
-public class HeartbeatBody extends AMQBody
+public class HeartbeatBody implements AMQBody
 {
     public static final byte TYPE = 8;
     public static AMQFrame FRAME = new HeartbeatBody().toFrame();
@@ -46,13 +48,19 @@
         return TYPE;
     }
 
-    protected int getSize()
+    public int getSize()
     {
         return 0;//heartbeats we generate have no payload
     }
 
-    protected void writePayload(ByteBuffer buffer)
+    public void writePayload(ByteBuffer buffer)
     {
+    }
+
+    public void handle(final int channelId, final AMQVersionAwareProtocolSession session)
+            throws AMQException
+    {
+        session.heartbeatBodyReceived(channelId, this);
     }
 
     protected void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException