public static Message createMessage(Session session, Class messageClazz) throws JMSException { if (session == null) { throw new JMSException("session cannot be null"); } if (Message.class.isAssignableFrom(messageClazz)) { throw new JMSException("cannot create message of type: " + messageClazz.getName()); } if (TextMessage.class.equals(messageClazz)) { return session.createTextMessage(); } else if (StreamMessage.class.equals(messageClazz)) { return session.createStreamMessage(); } else if (MapMessage.class.equals(messageClazz)) { return session.createMapMessage(); } else if (ObjectMessage.class.equals(messageClazz)) { return session.createObjectMessage(); } else if (BytesMessage.class.equals(messageClazz)) { return session.createBytesMessage(); } else if (Message.class.equals(messageClazz)) { return session.createMessage(); } else { throw new JMSException("cannot create message of type: " + messageClazz.getName()); } }