MessageImpl message;
List<Section> payload = msg.getPayload();
Header header = null;
MessageAnnotations messageAnnotations = null;
Properties properties = null;
ApplicationProperties appProperties = null;
Footer footer;
Iterator<Section> iter = payload.iterator();
List<Section> body = new ArrayList<Section>();
Section section = iter.hasNext() ? iter.next() : null;
if(section instanceof Header)
{
header = (Header) section;
section = iter.hasNext() ? iter.next() : null;
}
if(section instanceof DeliveryAnnotations)
{
section = iter.hasNext() ? iter.next() : null;
}
if(section instanceof MessageAnnotations)
{
messageAnnotations = (MessageAnnotations) section;
section = iter.hasNext() ? iter.next() : null;
}
if(section instanceof Properties)
{
properties = (Properties) section;
section = iter.hasNext() ? iter.next() : null;
}
if(section instanceof ApplicationProperties)
{
appProperties = (ApplicationProperties) section;
section = iter.hasNext() ? iter.next() : null;
}
while(section != null && !(section instanceof Footer))
{
body.add(section);
section = iter.hasNext() ? iter.next() : null;
}
footer = (Footer) section;
if(body.size() == 1)
{
Section bodySection = body.get(0);
if(bodySection instanceof AmqpValue && ((AmqpValue)bodySection).getValue() instanceof Map)
{
message = new MapMessageImpl(header, messageAnnotations, properties, appProperties, (Map) ((AmqpValue)bodySection).getValue(), footer, _session);
}
else if(bodySection instanceof AmqpValue && ((AmqpValue)bodySection).getValue() instanceof List)
{
message = new StreamMessageImpl(header, messageAnnotations, properties, appProperties,
(List) ((AmqpValue)bodySection).getValue(), footer, _session);
}
else if(bodySection instanceof AmqpValue && ((AmqpValue)bodySection).getValue() instanceof String)
{
message = new TextMessageImpl(header, messageAnnotations, properties, appProperties,
(String) ((AmqpValue)bodySection).getValue(), footer, _session);
}
else if(bodySection instanceof AmqpValue && ((AmqpValue)bodySection).getValue() instanceof Binary)
{
Binary value = (Binary) ((AmqpValue) bodySection).getValue();
message = new BytesMessageImpl(header, messageAnnotations, properties, appProperties,
new Data(value), footer, _session);
}
else if(bodySection instanceof Data)
{
if(properties != null && ObjectMessageImpl.CONTENT_TYPE.equals(properties.getContentType()))
{
message = new ObjectMessageImpl(header, messageAnnotations, properties, appProperties,
(Data) bodySection,