001: package dalma.endpoints.jms.impl;
002:
003: import javax.jms.JMSException;
004: import javax.jms.MapMessage;
005: import java.io.Serializable;
006: import java.util.Collections;
007: import java.util.Enumeration;
008: import java.util.HashMap;
009: import java.util.Map;
010:
011: /**
012: * {@link Serializable} {@link MapMessage}.
013: *
014: * @author Kohsuke Kawaguchi
015: */
016: public class MapMessageImpl extends MessageImpl<MapMessage> implements
017: MapMessage {
018:
019: private Map<String, Object> data = new HashMap<String, Object>();
020:
021: public MapMessageImpl() {
022: }
023:
024: public MapMessageImpl wrap(MapMessage s) throws JMSException {
025: super .wrap(s);
026: Enumeration e = s.getMapNames();
027: while (e.hasMoreElements()) {
028: String key = (String) e.nextElement();
029: data.put(key, s.getObject(key));
030: }
031: return this ;
032: }
033:
034: public void writeTo(MapMessage d) throws JMSException {
035: super .writeTo(d);
036: Enumeration e = getMapNames();
037: while (e.hasMoreElements()) {
038: String key = (String) e.nextElement();
039: d.setObject(key, getObject(key));
040: }
041: }
042:
043: public void clearBody() throws JMSException {
044: data.clear();
045: }
046:
047: public Enumeration getMapNames() throws JMSException {
048: return Collections.enumeration(data.keySet());
049: }
050:
051: public boolean itemExists(String name) throws JMSException {
052: return data.containsKey(name);
053: }
054:
055: public boolean getBoolean(String name) throws JMSException {
056: Object v = getObject(name);
057: return Converter.get(v).asBoolean(v);
058: }
059:
060: public byte getByte(String name) throws JMSException {
061: Object v = getObject(name);
062: return Converter.get(v).asByte(v);
063: }
064:
065: public short getShort(String name) throws JMSException {
066: Object v = getObject(name);
067: return Converter.get(v).asShort(v);
068: }
069:
070: public char getChar(String name) throws JMSException {
071: Object v = getObject(name);
072: return Converter.get(v).asChar(v);
073: }
074:
075: public int getInt(String name) throws JMSException {
076: Object v = getObject(name);
077: return Converter.get(v).asInt(v);
078: }
079:
080: public long getLong(String name) throws JMSException {
081: Object v = getObject(name);
082: return Converter.get(v).asLong(v);
083: }
084:
085: public float getFloat(String name) throws JMSException {
086: Object v = getObject(name);
087: return Converter.get(v).asFloat(v);
088: }
089:
090: public double getDouble(String name) throws JMSException {
091: Object v = getObject(name);
092: return Converter.get(v).asDouble(v);
093: }
094:
095: public String getString(String name) throws JMSException {
096: Object v = getObject(name);
097: return Converter.get(v).asString(v);
098: }
099:
100: public byte[] getBytes(String name) throws JMSException {
101: Object v = getObject(name);
102: return Converter.get(v).asByteArray(v);
103: }
104:
105: public Object getObject(String name) throws JMSException {
106: return data.get(name);
107: }
108:
109: public void setBoolean(String name, boolean value)
110: throws JMSException {
111: preWrite();
112: data.put(name, value);
113: }
114:
115: public void setByte(String name, byte value) throws JMSException {
116: preWrite();
117: data.put(name, value);
118: }
119:
120: public void setShort(String name, short value) throws JMSException {
121: preWrite();
122: data.put(name, value);
123: }
124:
125: public void setChar(String name, char value) throws JMSException {
126: preWrite();
127: data.put(name, value);
128: }
129:
130: public void setInt(String name, int value) throws JMSException {
131: preWrite();
132: data.put(name, value);
133: }
134:
135: public void setLong(String name, long value) throws JMSException {
136: preWrite();
137: data.put(name, value);
138: }
139:
140: public void setFloat(String name, float value) throws JMSException {
141: preWrite();
142: data.put(name, value);
143: }
144:
145: public void setDouble(String name, double value)
146: throws JMSException {
147: preWrite();
148: data.put(name, value);
149: }
150:
151: public void setString(String name, String value)
152: throws JMSException {
153: preWrite();
154: data.put(name, value);
155: }
156:
157: public void setBytes(String name, byte[] value) throws JMSException {
158: preWrite();
159: data.put(name, value);
160: }
161:
162: public void setBytes(String name, byte[] value, int offset,
163: int length) throws JMSException {
164: byte[] exact = new byte[length];
165: System.arraycopy(value, offset, exact, 0, length);
166: setBytes(name, exact);
167: }
168:
169: public void setObject(String name, Object value)
170: throws JMSException {
171: preWrite();
172: data.put(name, value);
173: }
174:
175: private void preWrite() {
176: // TODO: read-only mode check
177: }
178:
179: private static final long serialVersionUID = 1L;
180: }
|