Source Code Cross Referenced for Converter.java in  » Workflow-Engines » Dalma » dalma » endpoints » jms » impl » 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 » Workflow Engines » Dalma » dalma.endpoints.jms.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package dalma.endpoints.jms.impl;
002:
003:        import javax.jms.MessageFormatException;
004:        import javax.jms.JMSException;
005:        import java.util.Map;
006:        import java.util.HashMap;
007:
008:        /**
009:         * Converts the type of a value according to the following table in JMS:
010:         *
011:         * <pre>
012:         * |        | boolean byte short char int long float double String byte[]
013:         * |----------------------------------------------------------------------
014:         * |boolean |    X                                            X
015:         * |byte    |          X     X         X   X                  X
016:         * |short   |                X         X   X                  X
017:         * |char    |                     X                           X
018:         * |int     |                          X   X                  X
019:         * |long    |                              X                  X
020:         * |float   |                                    X     X      X
021:         * |double  |                                          X      X
022:         * |String  |    X     X     X         X   X     X     X      X
023:         * |byte[]  |                                                        X
024:         * |----------------------------------------------------------------------
025:         * </pre>
026:         *
027:         * @author Kohsuke Kawaguchi
028:         */
029:        abstract class Converter<T> {
030:            private final Class<T> sourceType;
031:
032:            private Converter(Class<T> sourceType) {
033:                this .sourceType = sourceType;
034:                convs.put(sourceType, this ); // register
035:            }
036:
037:            //
038:            // conversion methods
039:            //
040:            boolean asBoolean(T source) throws JMSException {
041:                throw error("boolean");
042:            }
043:
044:            byte asByte(T source) throws JMSException {
045:                throw error("byte");
046:            }
047:
048:            short asShort(T source) throws JMSException {
049:                throw error("short");
050:            }
051:
052:            char asChar(T source) throws JMSException {
053:                throw error("char");
054:            }
055:
056:            int asInt(T source) throws JMSException {
057:                throw error("int");
058:            }
059:
060:            long asLong(T source) throws JMSException {
061:                throw error("long");
062:            }
063:
064:            float asFloat(T source) throws JMSException {
065:                throw error("float");
066:            }
067:
068:            double asDouble(T source) throws JMSException {
069:                throw error("double");
070:            }
071:
072:            String asString(T source) throws JMSException {
073:                //        throw error("string");
074:                return source.toString();
075:            }
076:
077:            byte[] asByteArray(T source) throws JMSException {
078:                throw error("byte[]");
079:            }
080:
081:            // table
082:            private static Map<Class, Converter> convs = new HashMap<Class, Converter>();
083:
084:            /**
085:             * Gets the converter for the given class.
086:             */
087:            public static <T> Converter<T> get(Class<T> type) {
088:                return (Converter<T>) convs.get(type);
089:            }
090:
091:            public static Converter get(Object o) {
092:                if (o == null)
093:                    return NULL;
094:                return convs.get(o.getClass());
095:            }
096:
097:            //
098:            // converters
099:            //
100:            static final Converter<Boolean> BOOLEAN = new Converter<Boolean>(
101:                    Boolean.class) {
102:                boolean asBoolean(Boolean source) {
103:                    return source;
104:                }
105:            };
106:
107:            static final Converter<Byte> BYTE = new Converter<Byte>(Byte.class) {
108:                byte asByte(Byte source) {
109:                    return source;
110:                }
111:
112:                short asShort(Byte source) {
113:                    return source;
114:                }
115:
116:                int asInt(Byte source) {
117:                    return source;
118:                }
119:
120:                long asLong(Byte source) {
121:                    return source;
122:                }
123:            };
124:
125:            static final Converter<Short> SHORT = new Converter<Short>(
126:                    Short.class) {
127:                short asShort(Short source) {
128:                    return source;
129:                }
130:
131:                int asInt(Short source) {
132:                    return source;
133:                }
134:
135:                long asLong(Short source) {
136:                    return source;
137:                }
138:            };
139:
140:            static final Converter<Character> CHARACTER = new Converter<Character>(
141:                    Character.class) {
142:                char asChar(Character source) {
143:                    return source;
144:                }
145:            };
146:
147:            static final Converter<Integer> INTEGER = new Converter<Integer>(
148:                    Integer.class) {
149:                int asInt(Integer source) {
150:                    return source;
151:                }
152:
153:                long asLong(Integer source) {
154:                    return source;
155:                }
156:            };
157:
158:            static final Converter<Long> LONG = new Converter<Long>(Long.class) {
159:                long asLong(Long source) {
160:                    return source;
161:                }
162:            };
163:
164:            static final Converter<Float> FLOAT = new Converter<Float>(
165:                    Float.class) {
166:                float asFloat(Float source) {
167:                    return source;
168:                }
169:
170:                double asDouble(Float source) {
171:                    return source;
172:                }
173:            };
174:
175:            static final Converter<Double> DOUBLE = new Converter<Double>(
176:                    Double.class) {
177:                double asDouble(Double source) {
178:                    return source;
179:                }
180:            };
181:
182:            static final Converter<String> STRING = new Converter<String>(
183:                    String.class) {
184:                boolean asBoolean(String source) {
185:                    return Boolean.parseBoolean(source);
186:                }
187:
188:                byte asByte(String source) {
189:                    return Byte.parseByte(source);
190:                }
191:
192:                short asShort(String source) {
193:                    return Short.parseShort(source);
194:                }
195:
196:                int asInt(String source) {
197:                    return Integer.parseInt(source);
198:                }
199:
200:                long asLong(String source) {
201:                    return Long.parseLong(source);
202:                }
203:
204:                float asFloat(String source) {
205:                    return Float.parseFloat(source);
206:                }
207:
208:                double asDouble(String source) {
209:                    return Double.parseDouble(source);
210:                }
211:            };
212:
213:            static final Converter<byte[]> BYTE_ARRAY = new Converter<byte[]>(
214:                    byte[].class) {
215:                String asString(byte[] source) throws JMSException {
216:                    throw error("byte[]");
217:                }
218:
219:                byte[] asByteArray(byte[] source) {
220:                    return source;
221:                }
222:            };
223:
224:            static final Converter<?> NULL = new Converter<Object>(Object.class) {
225:                boolean asBoolean(Object source) {
226:                    return false;
227:                }
228:
229:                byte asByte(Object source) {
230:                    return 0;
231:                }
232:
233:                short asShort(Object source) {
234:                    return 0;
235:                }
236:
237:                char asChar(Object source) {
238:                    return 0;
239:                }
240:
241:                int asInt(Object source) {
242:                    return 0;
243:                }
244:
245:                long asLong(Object source) {
246:                    return 0;
247:                }
248:
249:                float asFloat(Object source) {
250:                    return 0;
251:                }
252:
253:                double asDouble(Object source) {
254:                    return 0;
255:                }
256:
257:                String asString(Object source) {
258:                    return null;
259:                }
260:
261:                byte[] asByteArray(Object source) {
262:                    return null;
263:                }
264:            };
265:
266:            //
267:            // impl
268:            //
269:            protected final JMSException error(String name)
270:                    throws MessageFormatException {
271:                throw new MessageFormatException(sourceType.getName()
272:                        + " cannot be converted to " + name);
273:            }
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.