throws JMSException {
if (message instanceof ActiveMQMessage) {
return (ActiveMQMessage)message;
} else {
ActiveMQMessage activeMessage = null;
if (message instanceof BytesMessage) {
BytesMessage bytesMsg = (BytesMessage)message;
bytesMsg.reset();
ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
msg.setConnection(connection);
try {
for (;;) {
// Reads a byte from the message stream until the stream
// is empty
msg.writeByte(bytesMsg.readByte());
}
} catch (MessageEOFException e) {
// if an end of message stream as expected
} catch (JMSException e) {
}
activeMessage = msg;
} else if (message instanceof MapMessage) {
MapMessage mapMsg = (MapMessage)message;
ActiveMQMapMessage msg = new ActiveMQMapMessage();
msg.setConnection(connection);
Enumeration iter = mapMsg.getMapNames();
while (iter.hasMoreElements()) {
String name = iter.nextElement().toString();
msg.setObject(name, mapMsg.getObject(name));
}
activeMessage = msg;
} else if (message instanceof ObjectMessage) {
ObjectMessage objMsg = (ObjectMessage)message;
ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
msg.setConnection(connection);
msg.setObject(objMsg.getObject());
msg.storeContent();
activeMessage = msg;
} else if (message instanceof StreamMessage) {
StreamMessage streamMessage = (StreamMessage)message;
streamMessage.reset();
ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
msg.setConnection(connection);
Object obj = null;
try {
while ((obj = streamMessage.readObject()) != null) {
msg.writeObject(obj);
}
} catch (MessageEOFException e) {
// if an end of message stream as expected
} catch (JMSException e) {
}
activeMessage = msg;
} else if (message instanceof TextMessage) {
TextMessage textMsg = (TextMessage)message;
ActiveMQTextMessage msg = new ActiveMQTextMessage();
msg.setConnection(connection);
msg.setText(textMsg.getText());
activeMessage = msg;
} else {
activeMessage = new ActiveMQMessage();
activeMessage.setConnection(connection);
}
copyProperties(message, activeMessage);
return activeMessage;