throw new XBException("internal", "Convert: The passed 'msg' attribute is null.");
// first strip all qos properties which are specific
Destination dest = msg.getJMSDestination();
if (!(dest instanceof XBDestination))
throw new XBException("client.configuration", "destination is not an xmlblaster destination. Do not know how to handle it");
PublishQos qos = null;
PublishKey key = null;
if (dest != null) {
XBDestination xbDest = (XBDestination)dest;
String ptpCompleteName = xbDest.getQueueName();
if (ptpCompleteName != null) {
String[] ptpNames = StringPairTokenizer.parseLine(ptpCompleteName, ',');
org.xmlBlaster.util.qos.address.Destination ptpDest = new org.xmlBlaster.util.qos.address.Destination(global, new SessionName(global, ptpNames[0]));
if (xbDest.getForceQueuing())
ptpDest.forceQueuing(true);
qos = new PublishQos(global, ptpDest);
for (int i=1; i < ptpNames.length; i++) {
org.xmlBlaster.util.qos.address.Destination additionalDest = new org.xmlBlaster.util.qos.address.Destination(global, new SessionName(global, ptpNames[i]));
qos.addDestination(additionalDest);
}
}
else {
qos = new PublishQos(global);
}
String tmp = xbDest.getTopicName();
if (tmp == null && ptpCompleteName == null)
throw new XBException("client.configuration", "A Topic must be specified in the message to be sent");
// determine if it is a complete key
if (tmp != null && tmp.indexOf('<') > -1) { // complete key
MsgKeySaxFactory keyFactory = new MsgKeySaxFactory(global);
key = new PublishKey(global, keyFactory.readObject(tmp));
}
else { // then it is a simple oid
if (tmp != null)
key = new PublishKey(global, tmp);
else
key = new PublishKey(global);
}
}
else
throw new XBException("client.configuration", "A destination must be specified in the message to be sent");
String corrId = msg.getJMSCorrelationID();
if (corrId != null)
qos.addClientProperty(XBMessage.addToKeyAndCheck(XBPropertyNames.JMS_CORRELATION_ID), corrId);
int deliveryMode = msg.getJMSDeliveryMode();
if (deliveryMode == DeliveryMode.PERSISTENT)
qos.setPersistent(true);
long expiration = msg.getJMSExpiration();
if (expiration > -1)
qos.setLifeTime(expiration);
int prio = msg.getJMSPriority();
if (prio > -1)
qos.setPriority(PriorityEnum.toPriorityEnum(prio));
String mimeType = msg.getJMSType(); // is this correct ?
if (mimeType != null)
key.setContentMime(mimeType);
Enumeration eNum = msg.getPropertyNames();
while (eNum.hasMoreElements()) {
String propKey = (String)eNum.nextElement();
Object obj = msg.getObjectProperty(propKey);
qos.addClientProperty(XBMessage.addToKeyAndCheck(propKey), obj);
}
byte[] content = null;
if (msg instanceof TextMessage) {
qos.addClientProperty(XBMessage.addToKeyAndCheck(XBPropertyNames.JMS_MESSAGE_TYPE), XBMessage.TEXT);
content = ((TextMessage)msg).getText().getBytes();
}
else if (msg instanceof StreamMessage) {
qos.addClientProperty(XBMessage.addToKeyAndCheck(XBPropertyNames.JMS_MESSAGE_TYPE), XBMessage.STREAM);
StreamMessage streamMsg = (StreamMessage)msg;
if (streamMsg instanceof XBStreamMessage) {
long length = ((XBStreamMessage)streamMsg).getBodyLength();
if (length >= Integer.MAX_VALUE)
throw new XBException("feature.missing", "Handling of big message not implemented");
content = new byte[(int)length];
streamMsg.readBytes(content);
}
else
throw new XBException("feature.missing", "Handling of non XBStreamMessage types not implemented");
}
else if (msg instanceof BytesMessage) {
qos.addClientProperty(XBMessage.addToKeyAndCheck(XBPropertyNames.JMS_MESSAGE_TYPE), XBMessage.BYTES);
BytesMessage bytesMsg = (BytesMessage)msg;
long length = bytesMsg.getBodyLength();
if (length >= Integer.MAX_VALUE)
throw new XBException("feature.missing", "Handling of big message not implemented");
content = new byte[(int)length];
bytesMsg.readBytes(content);
}
else if (msg instanceof ObjectMessage) {
qos.addClientProperty(XBMessage.addToKeyAndCheck(XBPropertyNames.JMS_MESSAGE_TYPE), XBMessage.OBJECT);
ObjectMessage objMsg = (ObjectMessage)msg;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
Object object = objMsg.getObject();
oos.writeObject(object);