summaryrefslogtreecommitdiff
path: root/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java')
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java238
1 files changed, 61 insertions, 177 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
index 85d434e4eb..f69bed0fc0 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
@@ -25,6 +25,8 @@ import org.apache.qpid.framing.PropertyFieldTable;
import org.apache.qpid.framing.FieldTableFactory;
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.EncodingUtils;
+import org.apache.qpid.framing.JMSPropertyFieldTable;
+import org.apache.qpid.framing.AMQFrameDecodingException;
import org.apache.qpid.AMQException;
import org.apache.log4j.Logger;
@@ -39,7 +41,7 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa
public static final String MIME_TYPE = "jms/map-message";
- private PropertyFieldTable _map;
+ private JMSPropertyFieldTable _properties;
JMSMapMessage() throws JMSException
{
@@ -49,10 +51,9 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa
JMSMapMessage(ByteBuffer data) throws JMSException
{
super(data); // this instantiates a content header
- _map = new PropertyFieldTable();
+ _properties = new JMSPropertyFieldTable();
}
-
JMSMapMessage(long messageNbr, ContentHeaderBody contentHeader, ByteBuffer data)
throws AMQException
{
@@ -62,19 +63,33 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa
{
long tableSize = EncodingUtils.readInteger(_data);
- _map = (PropertyFieldTable) FieldTableFactory.newFieldTable(_data, tableSize);
-
+ try
+ {
+ _properties = new JMSPropertyFieldTable(_data, tableSize);
+ }
+ catch (JMSException e)
+ {
+ Exception error = e.getLinkedException();
+ if (error instanceof AMQFrameDecodingException)
+ {
+ throw(AMQFrameDecodingException) error;
+ }
+ else
+ {
+ throw new AMQException(e.getMessage(), e);
+ }
+ }
}
else
{
- _map = (PropertyFieldTable) FieldTableFactory.newFieldTable();
+ _properties = new JMSPropertyFieldTable();
}
}
public String toBodyString() throws JMSException
{
- return "MapSize:" + _map.getEncodedSize() + "\nMapData:\n" + _map.toString();
+ return _properties.toString();
}
public String getMimeType()
@@ -82,85 +97,43 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa
return MIME_TYPE;
}
- // MapMessage Interface
- public boolean getBoolean(String string) throws JMSException
+ public ByteBuffer getData()
{
- Boolean b = _map.getBoolean(string);
-
- if (b == null)
- {
- if (_map.containsKey(string))
- {
- Object str = _map.getObject(string);
+ //What if _data is null?
+ _properties.writeToBuffer(_data);
+ return super.getData();
+ }
- if (str == null || !(str instanceof String))
- {
- throw new MessageFormatException("getBoolean can't use " + string + " item.");
- }
- else
- {
- return Boolean.valueOf((String) str);
- }
- }
- else
- {
- b = Boolean.valueOf(null);
- }
- }
+ @Override
+ public void clearBodyImpl() throws JMSException
+ {
+ super.clearBodyImpl();
+ _properties.clear();
+ }
- return b;
+ public boolean getBoolean(String string) throws JMSException
+ {
+ return _properties.getBoolean(string);
}
public byte getByte(String string) throws JMSException
{
- Byte b = _map.getByte(string);
- if (b == null)
- {
- if (_map.containsKey(string))
- {
- Object str = _map.getObject(string);
-
- if (str == null || !(str instanceof String))
- {
- throw new MessageFormatException("getByte can't use " + string + " item.");
- }
- else
- {
- return Byte.valueOf((String) str);
- }
- }
- else
- {
- b = Byte.valueOf(null);
- }
- }
-
- return b;
+ return _properties.getByte(string);
}
public short getShort(String string) throws JMSException
{
- {
- Short s = _map.getShort(string);
-
- if (s == null)
- {
- s = Short.valueOf(getByte(string));
- }
-
- return s;
- }
+ return _properties.getShort(string);
}
public char getChar(String string) throws JMSException
{
-
- Character result = _map.getCharacter(string);
+ Character result = _properties.getCharacter(string);
if (result == null)
{
- throw new MessageFormatException("getChar couldn't find " + string + " item.");
+ throw new NullPointerException("getChar couldn't find " + string + " item.");
}
else
{
@@ -170,179 +143,97 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa
public int getInt(String string) throws JMSException
{
- Integer i = _map.getInteger(string);
-
- if (i == null)
- {
- i = Integer.valueOf(getShort(string));
- }
-
- return i;
+ return _properties.getInteger(string);
}
public long getLong(String string) throws JMSException
{
-
- Long l = _map.getLong(string);
-
- if (l == null)
- {
- l = Long.valueOf(getInt(string));
- }
-
- return l;
-
+ return _properties.getLong(string);
}
public float getFloat(String string) throws JMSException
{
-
- Float f = _map.getFloat(string);
-
- if (f == null)
- {
- if (_map.containsKey(string))
- {
- Object str = _map.getObject(string);
-
- if (str == null || !(str instanceof String))
- {
- throw new MessageFormatException("getFloat can't use " + string + " item.");
- }
- else
- {
- return Float.valueOf((String) str);
- }
- }
- else
- {
- f = Float.valueOf(null);
- }
-
- }
-
- return f;
-
+ return _properties.getFloat(string);
}
public double getDouble(String string) throws JMSException
{
- Double d = _map.getDouble(string);
-
- if (d == null)
- {
- d = Double.valueOf(getFloat(string));
- }
-
- return d;
+ return _properties.getDouble(string);
}
public String getString(String string) throws JMSException
{
- String s = _map.getString(string);
-
- if (s == null)
- {
- if (_map.containsKey(string))
- {
- Object o = _map.getObject(string);
- if (o instanceof byte[])
- {
- throw new MessageFormatException("getObject couldn't find " + string + " item.");
- }
- else
- {
- if (o == null)
- {
- return null;
- }
- else
- {
- s = String.valueOf(o);
- }
- }
- }
- }
-
- return s;
+ return _properties.getString(string);
}
public byte[] getBytes(String string) throws JMSException
{
-
- byte[] result = _map.getBytes(string);
-
- if (result == null)
- {
- throw new MessageFormatException("getBytes couldn't find " + string + " item.");
- }
-
- return result;
-
+ return _properties.getBytes(string);
}
public Object getObject(String string) throws JMSException
{
- return _map.getObject(string);
+ return _properties.getObject(string);
}
public Enumeration getMapNames() throws JMSException
{
- return _map.getPropertyNames();
+ return _properties.getMapNames();
}
+
public void setBoolean(String string, boolean b) throws JMSException
{
checkWritable();
- _map.setBoolean(string, b);
+ _properties.setBoolean(string, b);
}
public void setByte(String string, byte b) throws JMSException
{
checkWritable();
- _map.setByte(string, b);
+ _properties.setByte(string, b);
}
public void setShort(String string, short i) throws JMSException
{
checkWritable();
- _map.setShort(string, i);
+ _properties.setShort(string, i);
}
public void setChar(String string, char c) throws JMSException
{
checkWritable();
- _map.setChar(string, c);
+ _properties.setChar(string, c);
}
public void setInt(String string, int i) throws JMSException
{
checkWritable();
- _map.setInteger(string, i);
+ _properties.setInteger(string, i);
}
public void setLong(String string, long l) throws JMSException
{
checkWritable();
- _map.setLong(string, l);
+ _properties.setLong(string, l);
}
public void setFloat(String string, float v) throws JMSException
{
checkWritable();
- _map.setFloat(string, v);
+ _properties.setFloat(string, v);
}
public void setDouble(String string, double v) throws JMSException
{
checkWritable();
- _map.setDouble(string, v);
+ _properties.setDouble(string, v);
}
public void setString(String string, String string1) throws JMSException
{
checkWritable();
- _map.setString(string, string1);
+ _properties.setString(string, string1);
}
public void setBytes(String string, byte[] bytes) throws JMSException
@@ -353,25 +244,18 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa
public void setBytes(String string, byte[] bytes, int i, int i1) throws JMSException
{
checkWritable();
- _map.setBytes(string, bytes, i, i1);
+ _properties.setBytes(string, bytes, i, i1);
}
public void setObject(String string, Object object) throws JMSException
{
checkWritable();
- _map.setObject(string, object);
+ _properties.setObject(string, object);
}
public boolean itemExists(String string) throws JMSException
{
- return _map.itemExists(string);
- }
-
- public ByteBuffer getData()
- {
- //What if _data is null?
- _map.writeToBuffer(_data);
- return super.getData();
+ return _properties.itemExists(string);
}
}