1 7 package org.jboss.jms.util; 8 9 import javax.jms.JMSException ; 10 import javax.jms.MapMessage ; 11 import javax.jms.MessageFormatException ; 12 import java.util.Collections ; 13 import java.util.Enumeration ; 14 import java.util.HashMap ; 15 16 25 public class JMSMap implements java.io.Serializable 26 { 27 28 protected HashMap contents = new HashMap (); 29 30 public static final JMSMap createInstance(Class type) 31 { 32 if (type.equals(MapMessage .class)) 33 { 34 return new JMSMap(); 35 } 36 else 37 { 38 return new MessageProperties(); 39 } 40 } 41 42 public final void clear() 43 { 44 this.contents.clear(); 45 } 46 47 public boolean getBoolean(String name) throws JMSException 48 { 49 Object value = this.contents.get(name); 50 return JMSTypeConversions.getBoolean(value); 51 } 52 53 public byte getByte(String name) throws JMSException 54 { 55 Object value = this.contents.get(name); 56 return JMSTypeConversions.getByte(value); 57 } 58 59 public byte[] getBytes(String name) throws JMSException 60 { 61 Object value = this.contents.get(name); 62 return JMSTypeConversions.getBytes(value); 63 } 64 65 public char getChar(String name) throws JMSException 66 { 67 Object value = this.contents.get(name); 68 return JMSTypeConversions.getChar(value); 69 } 70 71 public double getDouble(String name) throws JMSException 72 { 73 Object value = this.contents.get(name); 74 return JMSTypeConversions.getDouble(value); 75 } 76 77 public float getFloat(String name) throws JMSException 78 { 79 Object value = this.contents.get(name); 80 return JMSTypeConversions.getFloat(value); 81 } 82 83 public int getInt(String name) throws JMSException 84 { 85 Object value = this.contents.get(name); 86 return JMSTypeConversions.getInt(value); 87 } 88 89 public long getLong(String name) throws JMSException 90 { 91 Object value = this.contents.get(name); 92 return JMSTypeConversions.getLong(value); 93 } 94 95 public Enumeration getMapNames() throws JMSException 96 { 97 return Collections.enumeration(this.contents.keySet()); 98 } 99 100 public Object getObject(String name) throws JMSException 101 { 102 return this.contents.get(name); 103 } 104 105 public short getShort(String name) throws JMSException 106 { 107 Object value = this.contents.get(name); 108 return JMSTypeConversions.getShort(value); 109 } 110 111 public String getString(String name) throws JMSException 112 { 113 Object value = this.contents.get(name); 114 return JMSTypeConversions.getString(value); 115 } 116 117 public boolean itemExists(String name) 118 { 119 return this.contents.containsKey(name); 120 } 121 122 public void setBoolean(String name, boolean value) throws JMSException 123 { 124 this.contents.put(name, new Boolean (value)); 125 } 126 127 public void setByte(String name, byte value) throws JMSException 128 { 129 this.contents.put(name, new Byte (value)); 130 } 131 132 public void setBytes(String name, byte[] value) throws JMSException 133 { 134 byte[] bytes = new byte[value.length]; 135 System.arraycopy(value, 0, bytes, 0, bytes.length); 136 this.contents.put(name, bytes); 137 } 138 139 public void setBytes(String name, byte[] value, int offset, int length) 140 throws JMSException 141 { 142 byte[] bytes = new byte[length]; 143 System.arraycopy(value, offset, bytes, 0, length); 144 this.contents.put(name, bytes); 145 } 146 147 public void setChar(String name, char value) throws JMSException 148 { 149 this.contents.put(name, new Character (value)); 150 } 151 152 public void setDouble(String name, double value) throws JMSException 153 { 154 this.contents.put(name, new Double (value)); 155 } 156 157 public void setFloat(String name, float value) throws JMSException 158 { 159 this.contents.put(name, new Float (value)); 160 } 161 162 public void setInt(String name, int value) throws JMSException 163 { 164 this.contents.put(name, new Integer (value)); 165 } 166 167 public void setLong(String name, long value) throws JMSException 168 { 169 this.contents.put(name, new Long (value)); 170 } 171 172 public void setObject(String name, Object value) throws JMSException 173 { 174 if (value instanceof Boolean 175 || value instanceof Byte 176 || value instanceof Character 177 || value instanceof Double 178 || value instanceof Float 179 || value instanceof Integer 180 || value instanceof Long 181 || value instanceof Short 182 || value instanceof String ) 183 { 184 this.contents.put(name, value); 185 } 186 else 187 { 188 throw new MessageFormatException (""); } 190 } 191 192 public void setShort(String name, short value) throws JMSException 193 { 194 this.contents.put(name, new Short (value)); 195 } 196 197 public void setString(String name, String value) throws JMSException 198 { 199 this.contents.put(name, value); 200 } 201 } | Popular Tags |