ConnectionState connectionState = (ConnectionState)sessionState.getParent();
long id =
connectionState.getIdGenerator().getId((ConnectionDelegate)connectionState.getDelegate());
JBossMessage messageToSend;
boolean foreign = false;
if (!(m instanceof MessageProxy))
{
// it's a foreign message
foreign = true;
// JMS 1.1 Sect. 3.11.4: A provider must be prepared to accept, from a client,
// a message whose implementation is not one of its own.
// create a matching JBossMessage Type from JMS Type
if(m instanceof BytesMessage)
{
messageToSend = new JBossBytesMessage((BytesMessage)m,0);
}
else if(m instanceof MapMessage)
{
messageToSend = new JBossMapMessage((MapMessage)m,0);
}
else if(m instanceof ObjectMessage)
{
messageToSend = new JBossObjectMessage((ObjectMessage)m,0);
}
else if(m instanceof StreamMessage)
{
messageToSend = new JBossStreamMessage((StreamMessage)m,0);
}
else if(m instanceof TextMessage)
{
messageToSend = new JBossTextMessage((TextMessage)m,0);
}
else
{
messageToSend = new JBossMessage(m, 0);
}
messageToSend.setJMSMessageID(null);
}
else
{
// get the actual message
MessageProxy proxy = (MessageProxy)m;
//The following line executed on the proxy should cause a copy to occur
//if it is necessary
proxy.setJMSMessageID(null);
//Get the underlying message
messageToSend = proxy.getMessage();
proxy.beforeSend();
}
// Set the new id
messageToSend.setMessageId(id);
// This only really used for BytesMessages and StreamMessages to reset their state
messageToSend.doBeforeSend();
// now that we know the messageID, set it also on the foreign message, if is the case
if (foreign)
{
m.setJMSMessageID(messageToSend.getJMSMessageID());
}
// we now invoke the send(Message) method on the session, which will eventually be fielded
// by connection endpoint
((SessionDelegate)sessionState.getDelegate()).send(messageToSend, false);