1 package com.ubermq.jms.client.msg; 2 3 import com.ubermq.jms.client.*; 4 import com.ubermq.jms.client.impl.*; 5 import com.ubermq.jms.common.datagram.*; 6 import java.util.*; 7 import javax.jms.*; 8 9 13 public final class LocalMapMessage 14 extends LocalMessage 15 implements javax.jms.MapMessage 16 { 17 private Map map; 18 19 public LocalMapMessage(IMessageDatagram md, IAcknowledgeHandler a) {super(md, a); map = (HashMap)super.getBody();} 20 public LocalMapMessage(IMessageDatagramFactory f) {super(f); map = new HashMap();} 21 22 public int getMessageType() {return LocalMessage.MSGTYPE_MAP;} 23 public void prepareForPublish() 24 { 25 super.prepareForPublish(); 26 super.setBody(map); 27 } 28 29 public void setChar(String str, char param) throws javax.jms.JMSException 30 { 31 checkSetOperation(str); 32 map.put(str, new Character (param)); 33 } 34 35 public void setLong(String str, long param) throws javax.jms.JMSException { 36 checkSetOperation(str); 37 map.put(str, new Long (param)); 38 } 39 40 public void setDouble(String str, double param) throws javax.jms.JMSException { 41 checkSetOperation(str); 42 map.put(str, new Double (param)); 43 } 44 45 public void setByte(String str, byte param) throws javax.jms.JMSException { 46 checkSetOperation(str); 47 map.put(str, new Byte (param)); 48 } 49 50 public String getString(String str) throws javax.jms.JMSException { 51 try { 52 return (String )map.get(str); 53 } catch(ClassCastException cce) { 54 throw new javax.jms.MessageFormatException (cce.toString()); 55 } 56 } 57 58 public int getInt(String str) throws javax.jms.JMSException { 59 try { 60 return ((Integer )map.get(str)).intValue(); 61 } catch(ClassCastException cce) { 62 throw new javax.jms.MessageFormatException (cce.toString()); 63 } 64 } 65 66 public Object getObject(String str) throws javax.jms.JMSException { 67 try { 68 return map.get(str); 69 } catch(ClassCastException cce) { 70 throw new javax.jms.MessageFormatException (cce.toString()); 71 } 72 } 73 74 public byte[] getBytes(String str) throws javax.jms.JMSException { 75 try { 76 return (byte[])map.get(str); 77 } catch(ClassCastException cce) { 78 throw new javax.jms.MessageFormatException (cce.toString()); 79 } 80 } 81 82 public float getFloat(String str) throws javax.jms.JMSException { 83 try { 84 return ((Float )map.get(str)).floatValue(); 85 } catch(ClassCastException cce) { 86 throw new javax.jms.MessageFormatException (cce.toString()); 87 } 88 } 89 90 public java.util.Enumeration getMapNames() throws javax.jms.JMSException { 91 try { 92 Vector v = new Vector(); 93 v.addAll(map.keySet()); 94 return v.elements(); 95 } catch(Exception cce) { 96 throw new javax.jms.MessageFormatException (cce.toString()); 97 } 98 } 99 100 public void setObject(String str, Object obj) throws javax.jms.JMSException { 101 checkSetOperation(str); 102 map.put(str, obj); 103 } 104 105 public void setBoolean(String str, boolean param) throws javax.jms.JMSException { 106 checkSetOperation(str); 107 map.put(str, new Boolean (param)); 108 } 109 110 public boolean itemExists(String str) throws javax.jms.JMSException { 111 return (map.get(str) != null); 112 } 113 114 public char getChar(String str) throws javax.jms.JMSException { 115 try { 116 return ((Character )map.get(str)).charValue(); 117 } catch(ClassCastException cce) { 118 throw new javax.jms.MessageFormatException (cce.toString()); 119 } 120 } 121 122 public void setInt(String str, int param) throws javax.jms.JMSException { 123 checkSetOperation(str); 124 map.put(str, new Integer (param)); 125 } 126 127 public void setBytes(String str, byte[] values) throws javax.jms.JMSException { 128 checkSetOperation(str); 129 map.put(str, values); 130 } 131 132 public void setShort(String str, short param) throws javax.jms.JMSException { 133 checkSetOperation(str); 134 map.put(str, new Short (param)); 135 } 136 137 public void setFloat(String str, float param) throws javax.jms.JMSException { 138 checkSetOperation(str); 139 map.put(str, new Float (param)); 140 } 141 142 public void setBytes(String str, byte[] values, int param, int param3) throws javax.jms.JMSException { 143 checkSetOperation(str); 144 145 try { 146 byte[] a = new byte[param3]; 147 for(int i = 0;i < param3;i++) 148 { 149 a[i] = values[i + param]; 150 } 151 map.put(str, a); 152 } catch(Exception x) { 153 throw new javax.jms.JMSException (x.toString()); 154 } 155 } 156 157 public short getShort(String str) throws javax.jms.JMSException { 158 try { 159 return ((Short )map.get(str)).shortValue(); 160 } catch(ClassCastException cce) { 161 throw new javax.jms.MessageFormatException (cce.toString()); 162 } 163 } 164 165 public double getDouble(String str) throws javax.jms.JMSException { 166 try { 167 return ((Double )map.get(str)).doubleValue(); 168 } catch(ClassCastException cce) { 169 throw new javax.jms.MessageFormatException (cce.toString()); 170 } 171 } 172 173 public byte getByte(String str) throws javax.jms.JMSException { 174 try { 175 return ((Byte )map.get(str)).byteValue(); 176 } catch(ClassCastException cce) { 177 throw new javax.jms.MessageFormatException (cce.toString()); 178 } 179 } 180 181 public long getLong(String str) throws javax.jms.JMSException { 182 try { 183 return ((Long )map.get(str)).longValue(); 184 } catch(ClassCastException cce) { 185 throw new javax.jms.MessageFormatException (cce.toString()); 186 } 187 } 188 189 public boolean getBoolean(String str) throws javax.jms.JMSException { 190 try { 191 return ((Boolean )map.get(str)).booleanValue(); 192 } catch(ClassCastException cce) { 193 throw new javax.jms.MessageFormatException (cce.toString()); 194 } 195 } 196 197 public void setString(String str, String str1) throws javax.jms.JMSException { 198 checkSetOperation(str); 199 map.put(str, str1); 200 } 201 202 private void checkSetOperation(String str) 203 throws IllegalArgumentException , MessageNotWriteableException 204 { 205 if (!isWriteable()) 206 throw new MessageNotWriteableException("not writeable"); 207 if (str == null || 208 str.length() == 0) 209 throw new IllegalArgumentException ("invalid key"); 210 } 211 212 } 213 | Popular Tags |