Source Code Cross Referenced for PrimitiveMap.java in  » Testing » MockEJB » org » mockejb » jms » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » MockEJB » org.mockejb.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.mockejb.jms;
002:
003:        import java.util.*;
004:        import javax.jms.*;
005:
006:        /**
007:         * Map that sotre name-value pairs, where the values are <code>null</code> or
008:         * instances of String, Boolean, Byte, Character, Short, Integer, Long, Float,
009:         * Double or byte[]. 
010:         * <p>
011:         * Conversion between types is supported as specified in
012:         * <code>javax.jms.StreamMessage</code>
013:         * @author Dimitar Gospodinov
014:         */
015:        class PrimitiveMap {
016:
017:            private final Map map = new HashMap();
018:
019:            private byte[] copyBytes(byte[] source) {
020:                if (source == null) {
021:                    return null;
022:                } else {
023:                    return (byte[]) source.clone();
024:                }
025:            }
026:
027:            public boolean getBoolean(String name) throws JMSException {
028:                checkName(name);
029:                Object value = map.get(name);
030:
031:                if (value instanceof  Boolean) {
032:                    return ((Boolean) value).booleanValue();
033:                }
034:                if (value == null || value instanceof  String) {
035:                    return Boolean.valueOf((String) value).booleanValue();
036:                }
037:                throw new MessageFormatException(name
038:                        + " does not represent valid Boolean value!");
039:            }
040:
041:            public byte getByte(String name) throws JMSException {
042:                checkName(name);
043:                Object value = map.get(name);
044:
045:                if (value instanceof  Byte) {
046:                    return ((Byte) value).byteValue();
047:                }
048:                if (value == null || value instanceof  String) {
049:                    return Byte.valueOf((String) value).byteValue();
050:                }
051:                throw new MessageFormatException(name
052:                        + " does not represent valid Byte value!");
053:            }
054:
055:            public byte[] getBytes(String name) throws JMSException {
056:                checkName(name);
057:                Object value = map.get(name);
058:                if (value == null || value instanceof  byte[]) {
059:                    return copyBytes((byte[]) value);
060:                }
061:                throw new MessageFormatException(name
062:                        + " does not represent valid byte[] value!");
063:            }
064:
065:            public char getChar(String name) throws JMSException {
066:                checkName(name);
067:                Object value = map.get(name);
068:                if (value == null) {
069:                    throw new NullPointerException();
070:                }
071:                if (value instanceof  Character) {
072:                    return ((Character) value).charValue();
073:                }
074:                throw new MessageFormatException(name
075:                        + " does not represent valid Char value!");
076:            }
077:
078:            public short getShort(String name) throws JMSException {
079:                checkName(name);
080:                Object value = map.get(name);
081:
082:                if (value instanceof  Byte || value instanceof  Short) {
083:                    return ((Number) value).shortValue();
084:                }
085:                if (value == null || value instanceof  String) {
086:                    return Short.valueOf((String) value).shortValue();
087:                }
088:                throw new MessageFormatException(name
089:                        + " does not represent valid Short value!");
090:            }
091:
092:            public int getInt(String name) throws JMSException {
093:                checkName(name);
094:                Object value = map.get(name);
095:
096:                if (value instanceof  Byte || value instanceof  Short
097:                        || value instanceof  Integer) {
098:                    return ((Number) value).intValue();
099:                }
100:                if (value == null || value instanceof  String) {
101:                    return Integer.valueOf((String) value).intValue();
102:                }
103:                throw new MessageFormatException(name
104:                        + " does not represent valid Integer value!");
105:            }
106:
107:            public long getLong(String name) throws JMSException {
108:                checkName(name);
109:                Object value = map.get(name);
110:
111:                if (value instanceof  Byte || value instanceof  Short
112:                        || value instanceof  Integer || value instanceof  Long) {
113:
114:                    return ((Number) value).longValue();
115:                }
116:                if (value == null || value instanceof  String) {
117:                    return Long.valueOf((String) value).longValue();
118:                }
119:                throw new MessageFormatException(name
120:                        + " does not represent valid Long value!");
121:            }
122:
123:            public float getFloat(String name) throws JMSException {
124:                checkName(name);
125:                Object value = map.get(name);
126:
127:                if (value instanceof  Float) {
128:                    return ((Float) value).floatValue();
129:                }
130:                if (value == null || value instanceof  String) {
131:                    return Float.valueOf((String) value).floatValue();
132:                }
133:                throw new MessageFormatException(name
134:                        + " does not represent valid Float value!");
135:            }
136:
137:            public double getDouble(String name) throws JMSException {
138:                checkName(name);
139:                Object value = map.get(name);
140:
141:                if (value instanceof  Float || value instanceof  Double) {
142:                    return ((Number) value).doubleValue();
143:                }
144:                if (value == null || value instanceof  String) {
145:                    return Double.valueOf((String) value).doubleValue();
146:                }
147:                throw new MessageFormatException(name
148:                        + " does not represent valid Double value!");
149:            }
150:
151:            public String getString(String name) throws JMSException {
152:                checkName(name);
153:                Object value = map.get(name);
154:                if (value == null) {
155:                    return null;
156:                }
157:                if (value instanceof  Boolean || value instanceof  Byte
158:                        || value instanceof  Short || value instanceof  Character
159:                        || value instanceof  Integer || value instanceof  Long
160:                        || value instanceof  Float || value instanceof  Double
161:                        || value instanceof  String) {
162:
163:                    return value.toString();
164:                }
165:                throw new MessageFormatException(name
166:                        + " does not represent valid String value!");
167:            }
168:
169:            public Object getObject(String name) throws JMSException {
170:                checkName(name);
171:                Object result = map.get(name);
172:                if (result instanceof  byte[]) {
173:                    result = copyBytes((byte[]) result);
174:                }
175:                return result;
176:            }
177:
178:            public void setBoolean(String name, boolean value)
179:                    throws JMSException {
180:
181:                checkName(name);
182:                map.put(name, new Boolean(value));
183:            }
184:
185:            public void setByte(String name, byte value) throws JMSException {
186:                checkName(name);
187:                map.put(name, new Byte(value));
188:            }
189:
190:            public void setBytes(String name, byte[] value) {
191:                checkName(name);
192:                map.put(name, copyBytes(value));
193:            }
194:
195:            public void setChar(String name, char value) {
196:                checkName(name);
197:                map.put(name, new Character(value));
198:            }
199:
200:            public void setShort(String name, short value) throws JMSException {
201:                checkName(name);
202:                map.put(name, new Short(value));
203:            }
204:
205:            public void setInt(String name, int value) throws JMSException {
206:                checkName(name);
207:                map.put(name, new Integer(value));
208:            }
209:
210:            public void setLong(String name, long value) throws JMSException {
211:                checkName(name);
212:                map.put(name, new Long(value));
213:            }
214:
215:            public void setFloat(String name, float value) throws JMSException {
216:                checkName(name);
217:                map.put(name, new Float(value));
218:            }
219:
220:            public void setDouble(String name, double value)
221:                    throws JMSException {
222:
223:                checkName(name);
224:                map.put(name, new Double(value));
225:            }
226:
227:            public void setString(String name, String value)
228:                    throws JMSException {
229:
230:                checkName(name);
231:                map.put(name, value);
232:            }
233:
234:            /* (non-Javadoc)
235:             * @see javax.jms.Message#setObjectProperty(java.lang.String, java.lang.Object)
236:             */
237:            public void setObject(String name, Object value)
238:                    throws JMSException {
239:
240:                checkName(name);
241:                if (!(value == null || value instanceof  byte[]
242:                        || value instanceof  Boolean || value instanceof  Byte
243:                        || value instanceof  Character || value instanceof  Short
244:                        || value instanceof  Integer || value instanceof  Long
245:                        || value instanceof  Float || value instanceof  Double || value instanceof  String)) {
246:
247:                    throw new MessageFormatException("Incorrect object type!");
248:                }
249:                if (value instanceof  byte[]) {
250:                    value = copyBytes((byte[]) value);
251:                }
252:                map.put(name, value);
253:            }
254:
255:            private void checkName(String name) {
256:                if (name == null || name.length() == 0) {
257:                    throw new IllegalArgumentException(
258:                            "Name must be non-empty string!");
259:                }
260:            }
261:
262:            public void clear() {
263:                map.clear();
264:            }
265:
266:            public boolean containsKey(String key) {
267:                checkName(key);
268:                return map.containsKey(key);
269:            }
270:
271:            public Enumeration getNames() {
272:                return new CollectionEnumeration(map.keySet().iterator());
273:            }
274:
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.