{
throw new MessageFormatException("Attempting to do AMQPMessage.getList() on null Message");
}
else if (message instanceof BytesMessage)
{
BytesMessage msg = (BytesMessage)message;
//only handles responses up to 2^31-1 bytes long
byte[] data = new byte[(int) msg.getBodyLength()];
msg.readBytes(data);
BBDecoder decoder = new BBDecoder();
decoder.init(ByteBuffer.wrap(data));
return (List<T>)decoder.readList();
}
else if (message instanceof MapMessage)
{ /*
* In Qpid version 0.20 instead of exposing amqp/list as a BytesMessage as above rather it is exposed
* as a MapMessage!!??? the Object Keys are the indices into the List. We create a java.util.List
* out of this by iterating through the getMapNames() Enumeration and copying the Objects into the List.
* This amount of copying doesn't feel healthy and we can't even work out the capacity for the List
* a priori, but I'm not sure of a better way at present. I can't say I much like how amqp/list or indeed
* amqp/map are currently encoded. I'd *much* prefer to see them exposed as JMS ObjectMessage.
*/
MapMessage msg = (MapMessage)message;
List resultList = new ArrayList(50); // Initial capacity of 50, can we better estimate this?
for (Enumeration e = msg.getMapNames(); e.hasMoreElements();)
{
String key = (String)e.nextElement();
resultList.add(msg.getObject(key));
}
return resultList;
}
else
{