package org.mockejb.jms;
import java.util.*;
import javax.jms.*;
public class MessageImpl implements Message {
private static final int MODE_READ_ONLY = 100;
private static final int MODE_WRITE_ONLY = 200;
private int bodyMode = MODE_WRITE_ONLY;
private boolean propertiesWriteable = true;
private String jmsType;
private long jmsTimestamp;
private Destination jmsReplyTo;
private int jmsPriority;
private String jmsMessageId;
private long jmsExpiration;
private Destination jmsDestination;
private int jmsDeliveryMode;
private String jmsCorrelationId;
private final PrimitiveMap properties = new PrimitiveMap();
public MessageImpl() {
super();
}
public MessageImpl(Message msg) throws JMSException {
setJMSMessageID(msg.getJMSMessageID());
setJMSTimestamp(msg.getJMSTimestamp());
setJMSCorrelationID(msg.getJMSCorrelationID());
setJMSReplyTo(msg.getJMSReplyTo());
setJMSDestination(msg.getJMSDestination());
setJMSDeliveryMode(msg.getJMSDeliveryMode());
setJMSRedelivered(msg.getJMSRedelivered());
setJMSType(msg.getJMSType());
setJMSExpiration(msg.getJMSExpiration());
setJMSPriority(msg.getJMSPriority());
Enumeration e = msg.getPropertyNames();
while (e.hasMoreElements()) {
String propertyName = (String) e.nextElement();
setObjectProperty(
propertyName,
msg.getObjectProperty(propertyName));
}
}
public String getJMSMessageID() throws JMSException {
return jmsMessageId;
}
public void setJMSMessageID(String messageId) throws JMSException {
jmsMessageId = messageId;
}
public long getJMSTimestamp() throws JMSException {
return jmsTimestamp;
}
public void setJMSTimestamp(long timestamp) throws JMSException {
jmsTimestamp = timestamp;
}
public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
throw new UnsupportedOperationException();
}
public void setJMSCorrelationIDAsBytes(byte[] arg0) throws JMSException {
throw new UnsupportedOperationException();
}
public void setJMSCorrelationID(String correlationId) throws JMSException {
jmsCorrelationId = correlationId;
}
public String getJMSCorrelationID() throws JMSException {
return jmsCorrelationId;
}
public Destination getJMSReplyTo() throws JMSException {
return jmsReplyTo;
}
public void setJMSReplyTo(Destination replyTo) throws JMSException {
jmsReplyTo = replyTo;
}
public Destination getJMSDestination() throws JMSException {
return jmsDestination;
}
public void setJMSDestination(Destination destination)
throws JMSException {
jmsDestination = destination;
}
public int getJMSDeliveryMode() throws JMSException {
return jmsDeliveryMode;
}
public void setJMSDeliveryMode(int deliveryMode) throws JMSException {
jmsDeliveryMode = deliveryMode;
}
public boolean getJMSRedelivered() throws JMSException {
return false;
}
public void setJMSRedelivered(boolean redelivered) throws JMSException {
}
public String getJMSType() throws JMSException {
return jmsType;
}
public void setJMSType(String type) throws JMSException {
jmsType = type;
}
public long getJMSExpiration() throws JMSException {
return jmsExpiration;
}
public void setJMSExpiration(long expiration) throws JMSException {
jmsExpiration = expiration;
}
public int getJMSPriority() throws JMSException {
return jmsPriority;
}
public void setJMSPriority(int priority) throws JMSException {
jmsPriority = priority;
}
public void clearProperties() throws JMSException {
propertiesWriteable = true;
properties.clear();
}
public boolean propertyExists(String propertyName) throws JMSException {
return properties.containsKey(propertyName);
}
public boolean getBooleanProperty(String name) throws JMSException {
return properties.getBoolean(name);
}
public byte getByteProperty(String name) throws JMSException {
return properties.getByte(name);
}
public short getShortProperty(String name) throws JMSException {
return properties.getShort(name);
}
public int getIntProperty(String name) throws JMSException {
return properties.getInt(name);
}
public long getLongProperty(String name) throws JMSException {
return properties.getLong(name);
}
public float getFloatProperty(String name) throws JMSException {
return properties.getFloat(name);
}
public double getDoubleProperty(String name) throws JMSException {
return properties.getDouble(name);
}
public String getStringProperty(String name) throws JMSException {
return properties.getString(name);
}
public Object getObjectProperty(String name) throws JMSException {
return properties.getObject(name);
}
public Enumeration getPropertyNames() throws JMSException {
return properties.getNames();
}
public void setBooleanProperty(String name, boolean value)
throws JMSException {
checkPropertiesWriteable();
properties.setBoolean(name, value);
}
public void setByteProperty(String name, byte value) throws JMSException {
checkPropertiesWriteable();
properties.setByte(name, value);
}
public void setShortProperty(String name, short value)
throws JMSException {
checkPropertiesWriteable();
properties.setShort(name, value);
}
public void setIntProperty(String name, int value) throws JMSException {
checkPropertiesWriteable();
properties.setInt(name, value);
}
public void setLongProperty(String name, long value) throws JMSException {
checkPropertiesWriteable();
properties.setLong(name, value);
}
public void setFloatProperty(String name, float value)
throws JMSException {
checkPropertiesWriteable();
properties.setFloat(name, value);
}
public void setDoubleProperty(String name, double value)
throws JMSException {
checkPropertiesWriteable();
properties.setDouble(name, value);
}
public void setStringProperty(String name, String value)
throws JMSException {
checkPropertiesWriteable();
properties.setString(name, value);
}
public void setObjectProperty(String name, Object value)
throws JMSException {
checkPropertiesWriteable();
properties.setObject(name, value);
}
public void acknowledge() throws JMSException {
}
public void clearBody() throws JMSException {
bodyMode = MODE_WRITE_ONLY;
}
private boolean propertiesWriteable() {
return propertiesWriteable;
}
public void setPropertiesNotWriteable() {
propertiesWriteable = false;
}
private void checkPropertiesWriteable()
throws MessageNotWriteableException {
if (!propertiesWriteable()) {
throw new MessageNotWriteableException("Message is in read-only mode!");
}
}
void setBodyReadOnly() {
bodyMode = MODE_READ_ONLY;
}
void checkBodyReadable() throws JMSException {
if (bodyMode == MODE_WRITE_ONLY) {
throw new MessageNotReadableException("Message is not in Read-Only mode!");
}
}
void checkBodyWriteable() throws JMSException {
if (bodyMode == MODE_READ_ONLY) {
throw new MessageNotWriteableException("Message is not in Write-Only mode!");
}
}
void resetBody() throws JMSException {
}
}