Source Code Cross Referenced for BasicDeserializer.java in  » EJB-Server-resin-3.1.5 » hessian » com » caucho » hessian » io » 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 » EJB Server resin 3.1.5 » hessian » com.caucho.hessian.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001-2004 Caucho Technology, Inc.  All rights reserved.
003:         *
004:         * The Apache Software License, Version 1.1
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution, if
019:         *    any, must include the following acknowlegement:
020:         *       "This product includes software developed by the
021:         *        Caucho Technology (http://www.caucho.com/)."
022:         *    Alternately, this acknowlegement may appear in the software itself,
023:         *    if and wherever such third-party acknowlegements normally appear.
024:         *
025:         * 4. The names "Burlap", "Resin", and "Caucho" must not be used to
026:         *    endorse or promote products derived from this software without prior
027:         *    written permission. For written permission, please contact
028:         *    info@caucho.com.
029:         *
030:         * 5. Products derived from this software may not be called "Resin"
031:         *    nor may "Resin" appear in their names without prior written
032:         *    permission of Caucho Technology.
033:         *
034:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037:         * DISCLAIMED.  IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
038:         * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
039:         * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
040:         * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
041:         * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
042:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
043:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
044:         * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
045:         *
046:         * @author Scott Ferguson
047:         */
048:
049:        package com.caucho.hessian.io;
050:
051:        import java.io.IOException;
052:        import java.util.ArrayList;
053:        import java.util.Date;
054:
055:        /**
056:         * Serializing an object for known object types.
057:         */
058:        public class BasicDeserializer extends AbstractDeserializer {
059:            public static final int NULL = BasicSerializer.NULL;
060:            public static final int BOOLEAN = BasicSerializer.BOOLEAN;
061:            public static final int BYTE = BasicSerializer.BYTE;
062:            public static final int SHORT = BasicSerializer.SHORT;
063:            public static final int INTEGER = BasicSerializer.INTEGER;
064:            public static final int LONG = BasicSerializer.LONG;
065:            public static final int FLOAT = BasicSerializer.FLOAT;
066:            public static final int DOUBLE = BasicSerializer.DOUBLE;
067:            public static final int CHARACTER = BasicSerializer.CHARACTER;
068:            public static final int CHARACTER_OBJECT = BasicSerializer.CHARACTER_OBJECT;
069:            public static final int STRING = BasicSerializer.STRING;
070:            public static final int DATE = BasicSerializer.DATE;
071:            public static final int NUMBER = BasicSerializer.NUMBER;
072:            public static final int OBJECT = BasicSerializer.OBJECT;
073:
074:            public static final int BOOLEAN_ARRAY = BasicSerializer.BOOLEAN_ARRAY;
075:            public static final int BYTE_ARRAY = BasicSerializer.BYTE_ARRAY;
076:            public static final int SHORT_ARRAY = BasicSerializer.SHORT_ARRAY;
077:            public static final int INTEGER_ARRAY = BasicSerializer.INTEGER_ARRAY;
078:            public static final int LONG_ARRAY = BasicSerializer.LONG_ARRAY;
079:            public static final int FLOAT_ARRAY = BasicSerializer.FLOAT_ARRAY;
080:            public static final int DOUBLE_ARRAY = BasicSerializer.DOUBLE_ARRAY;
081:            public static final int CHARACTER_ARRAY = BasicSerializer.CHARACTER_ARRAY;
082:            public static final int STRING_ARRAY = BasicSerializer.STRING_ARRAY;
083:            public static final int OBJECT_ARRAY = BasicSerializer.OBJECT_ARRAY;
084:
085:            private int _code;
086:
087:            public BasicDeserializer(int code) {
088:                _code = code;
089:            }
090:
091:            public Class getType() {
092:                switch (_code) {
093:                case NULL:
094:                    return void.class;
095:                case BOOLEAN:
096:                    return Boolean.class;
097:                case BYTE:
098:                    return Byte.class;
099:                case SHORT:
100:                    return Short.class;
101:                case INTEGER:
102:                    return Integer.class;
103:                case LONG:
104:                    return Long.class;
105:                case FLOAT:
106:                    return Float.class;
107:                case DOUBLE:
108:                    return Double.class;
109:                case CHARACTER:
110:                    return Character.class;
111:                case CHARACTER_OBJECT:
112:                    return Character.class;
113:                case STRING:
114:                    return String.class;
115:                case DATE:
116:                    return Date.class;
117:                case NUMBER:
118:                    return Number.class;
119:                case OBJECT:
120:                    return Object.class;
121:
122:                case BOOLEAN_ARRAY:
123:                    return boolean[].class;
124:                case BYTE_ARRAY:
125:                    return byte[].class;
126:                case SHORT_ARRAY:
127:                    return short[].class;
128:                case INTEGER_ARRAY:
129:                    return int[].class;
130:                case LONG_ARRAY:
131:                    return long[].class;
132:                case FLOAT_ARRAY:
133:                    return float[].class;
134:                case DOUBLE_ARRAY:
135:                    return double[].class;
136:                case CHARACTER_ARRAY:
137:                    return char[].class;
138:                case STRING_ARRAY:
139:                    return String[].class;
140:                case OBJECT_ARRAY:
141:                    return Object[].class;
142:                default:
143:                    throw new UnsupportedOperationException();
144:                }
145:            }
146:
147:            public Object readObject(AbstractHessianInput in)
148:                    throws IOException {
149:                switch (_code) {
150:                case NULL:
151:                    // hessian/3490
152:                    in.readObject();
153:
154:                    return null;
155:
156:                case BOOLEAN:
157:                    return Boolean.valueOf(in.readBoolean());
158:
159:                case BYTE:
160:                    return Byte.valueOf((byte) in.readInt());
161:
162:                case SHORT:
163:                    return Short.valueOf((short) in.readInt());
164:
165:                case INTEGER:
166:                    return Integer.valueOf(in.readInt());
167:
168:                case LONG:
169:                    return Long.valueOf(in.readLong());
170:
171:                case FLOAT:
172:                    return Float.valueOf((float) in.readDouble());
173:
174:                case DOUBLE:
175:                    return Double.valueOf(in.readDouble());
176:
177:                case STRING:
178:                    return in.readString();
179:
180:                case OBJECT:
181:                    return in.readObject();
182:
183:                case CHARACTER: {
184:                    String s = in.readString();
185:                    if (s == null || s.equals(""))
186:                        return new Character((char) 0);
187:                    else
188:                        return new Character(s.charAt(0));
189:                }
190:
191:                case CHARACTER_OBJECT: {
192:                    String s = in.readString();
193:                    if (s == null || s.equals(""))
194:                        return null;
195:                    else
196:                        return new Character(s.charAt(0));
197:                }
198:
199:                case DATE:
200:                    return new Date(in.readUTCDate());
201:
202:                case NUMBER:
203:                    return in.readObject();
204:
205:                case BYTE_ARRAY:
206:                    return in.readBytes();
207:
208:                case CHARACTER_ARRAY: {
209:                    String s = in.readString();
210:
211:                    if (s == null)
212:                        return null;
213:                    else {
214:                        int len = s.length();
215:                        char[] chars = new char[len];
216:                        s.getChars(0, len, chars, 0);
217:                        return chars;
218:                    }
219:                }
220:
221:                case BOOLEAN_ARRAY:
222:                case SHORT_ARRAY:
223:                case INTEGER_ARRAY:
224:                case LONG_ARRAY:
225:                case FLOAT_ARRAY:
226:                case DOUBLE_ARRAY:
227:                case STRING_ARRAY: {
228:                    int code = in.readListStart();
229:
230:                    switch (code) {
231:                    case 'N':
232:                        return null;
233:
234:                    case 0x10:
235:                    case 0x11:
236:                    case 0x12:
237:                    case 0x13:
238:                    case 0x14:
239:                    case 0x15:
240:                    case 0x16:
241:                    case 0x17:
242:                    case 0x18:
243:                    case 0x19:
244:                    case 0x1a:
245:                    case 0x1b:
246:                    case 0x1c:
247:                    case 0x1d:
248:                    case 0x1e:
249:                    case 0x1f:
250:                        int length = code - 0x10;
251:                        in.readInt();
252:
253:                        return readLengthList(in, length);
254:
255:                    default:
256:                        String type = in.readType();
257:                        length = in.readLength();
258:
259:                        return readList(in, length);
260:                    }
261:                }
262:
263:                default:
264:                    throw new UnsupportedOperationException();
265:                }
266:            }
267:
268:            public Object readList(AbstractHessianInput in, int length)
269:                    throws IOException {
270:                switch (_code) {
271:                case BOOLEAN_ARRAY: {
272:                    if (length >= 0) {
273:                        boolean[] data = new boolean[length];
274:
275:                        in.addRef(data);
276:
277:                        for (int i = 0; i < data.length; i++)
278:                            data[i] = in.readBoolean();
279:
280:                        in.readEnd();
281:
282:                        return data;
283:                    } else {
284:                        ArrayList list = new ArrayList();
285:
286:                        while (!in.isEnd())
287:                            list.add(new Boolean(in.readBoolean()));
288:
289:                        in.readEnd();
290:
291:                        boolean[] data = new boolean[list.size()];
292:
293:                        in.addRef(data);
294:
295:                        for (int i = 0; i < data.length; i++)
296:                            data[i] = ((Boolean) list.get(i)).booleanValue();
297:
298:                        return data;
299:                    }
300:                }
301:
302:                case SHORT_ARRAY: {
303:                    if (length >= 0) {
304:                        short[] data = new short[length];
305:
306:                        in.addRef(data);
307:
308:                        for (int i = 0; i < data.length; i++)
309:                            data[i] = (short) in.readInt();
310:
311:                        in.readEnd();
312:
313:                        return data;
314:                    } else {
315:                        ArrayList list = new ArrayList();
316:
317:                        while (!in.isEnd())
318:                            list.add(new Short((short) in.readInt()));
319:
320:                        in.readEnd();
321:
322:                        short[] data = new short[list.size()];
323:                        for (int i = 0; i < data.length; i++)
324:                            data[i] = ((Short) list.get(i)).shortValue();
325:
326:                        in.addRef(data);
327:
328:                        return data;
329:                    }
330:                }
331:
332:                case INTEGER_ARRAY: {
333:                    if (length >= 0) {
334:                        int[] data = new int[length];
335:
336:                        in.addRef(data);
337:
338:                        for (int i = 0; i < data.length; i++)
339:                            data[i] = in.readInt();
340:
341:                        in.readEnd();
342:
343:                        return data;
344:                    } else {
345:                        ArrayList list = new ArrayList();
346:
347:                        while (!in.isEnd())
348:                            list.add(new Integer(in.readInt()));
349:
350:                        in.readEnd();
351:
352:                        int[] data = new int[list.size()];
353:                        for (int i = 0; i < data.length; i++)
354:                            data[i] = ((Integer) list.get(i)).intValue();
355:
356:                        in.addRef(data);
357:
358:                        return data;
359:                    }
360:                }
361:
362:                case LONG_ARRAY: {
363:                    if (length >= 0) {
364:                        long[] data = new long[length];
365:
366:                        in.addRef(data);
367:
368:                        for (int i = 0; i < data.length; i++)
369:                            data[i] = in.readLong();
370:
371:                        in.readEnd();
372:
373:                        return data;
374:                    } else {
375:                        ArrayList list = new ArrayList();
376:
377:                        while (!in.isEnd())
378:                            list.add(new Long(in.readLong()));
379:
380:                        in.readEnd();
381:
382:                        long[] data = new long[list.size()];
383:                        for (int i = 0; i < data.length; i++)
384:                            data[i] = ((Long) list.get(i)).longValue();
385:
386:                        in.addRef(data);
387:
388:                        return data;
389:                    }
390:                }
391:
392:                case FLOAT_ARRAY: {
393:                    if (length >= 0) {
394:                        float[] data = new float[length];
395:                        in.addRef(data);
396:
397:                        for (int i = 0; i < data.length; i++)
398:                            data[i] = (float) in.readDouble();
399:
400:                        in.readEnd();
401:
402:                        return data;
403:                    } else {
404:                        ArrayList list = new ArrayList();
405:
406:                        while (!in.isEnd())
407:                            list.add(new Float(in.readDouble()));
408:
409:                        in.readEnd();
410:
411:                        float[] data = new float[list.size()];
412:                        for (int i = 0; i < data.length; i++)
413:                            data[i] = ((Float) list.get(i)).floatValue();
414:
415:                        in.addRef(data);
416:
417:                        return data;
418:                    }
419:                }
420:
421:                case DOUBLE_ARRAY: {
422:                    if (length >= 0) {
423:                        double[] data = new double[length];
424:                        in.addRef(data);
425:
426:                        for (int i = 0; i < data.length; i++)
427:                            data[i] = in.readDouble();
428:
429:                        in.readEnd();
430:
431:                        return data;
432:                    } else {
433:                        ArrayList list = new ArrayList();
434:
435:                        while (!in.isEnd())
436:                            list.add(new Double(in.readDouble()));
437:
438:                        in.readEnd();
439:
440:                        double[] data = new double[list.size()];
441:                        in.addRef(data);
442:                        for (int i = 0; i < data.length; i++)
443:                            data[i] = ((Double) list.get(i)).intValue();
444:
445:                        in.readEnd();
446:
447:                        return data;
448:                    }
449:                }
450:
451:                case STRING_ARRAY: {
452:                    if (length >= 0) {
453:                        String[] data = new String[length];
454:                        in.addRef(data);
455:
456:                        for (int i = 0; i < data.length; i++)
457:                            data[i] = in.readString();
458:
459:                        in.readEnd();
460:
461:                        return data;
462:                    } else {
463:                        ArrayList list = new ArrayList();
464:
465:                        while (!in.isEnd())
466:                            list.add(in.readString());
467:
468:                        in.readEnd();
469:
470:                        String[] data = new String[list.size()];
471:                        in.addRef(data);
472:                        for (int i = 0; i < data.length; i++)
473:                            data[i] = (String) list.get(i);
474:
475:                        in.readEnd();
476:
477:                        return data;
478:                    }
479:                }
480:
481:                case OBJECT_ARRAY: {
482:                    if (length >= 0) {
483:                        Object[] data = new Object[length];
484:                        in.addRef(data);
485:
486:                        for (int i = 0; i < data.length; i++)
487:                            data[i] = in.readObject();
488:
489:                        in.readEnd();
490:
491:                        return data;
492:                    } else {
493:                        ArrayList list = new ArrayList();
494:
495:                        in.addRef(list); // XXX: potential issues here
496:
497:                        while (!in.isEnd())
498:                            list.add(in.readObject());
499:
500:                        in.readEnd();
501:
502:                        Object[] data = new Object[list.size()];
503:                        for (int i = 0; i < data.length; i++)
504:                            data[i] = (Object) list.get(i);
505:
506:                        return data;
507:                    }
508:                }
509:
510:                default:
511:                    throw new UnsupportedOperationException(String
512:                            .valueOf(this ));
513:                }
514:            }
515:
516:            public Object readLengthList(AbstractHessianInput in, int length)
517:                    throws IOException {
518:                switch (_code) {
519:                case BOOLEAN_ARRAY: {
520:                    boolean[] data = new boolean[length];
521:
522:                    in.addRef(data);
523:
524:                    for (int i = 0; i < data.length; i++)
525:                        data[i] = in.readBoolean();
526:
527:                    return data;
528:                }
529:
530:                case SHORT_ARRAY: {
531:                    short[] data = new short[length];
532:
533:                    in.addRef(data);
534:
535:                    for (int i = 0; i < data.length; i++)
536:                        data[i] = (short) in.readInt();
537:
538:                    return data;
539:                }
540:
541:                case INTEGER_ARRAY: {
542:                    int[] data = new int[length];
543:
544:                    in.addRef(data);
545:
546:                    for (int i = 0; i < data.length; i++)
547:                        data[i] = in.readInt();
548:
549:                    return data;
550:                }
551:
552:                case FLOAT_ARRAY: {
553:                    float[] data = new float[length];
554:                    in.addRef(data);
555:
556:                    for (int i = 0; i < data.length; i++)
557:                        data[i] = (float) in.readDouble();
558:
559:                    return data;
560:                }
561:
562:                case DOUBLE_ARRAY: {
563:                    double[] data = new double[length];
564:                    in.addRef(data);
565:
566:                    for (int i = 0; i < data.length; i++)
567:                        data[i] = in.readDouble();
568:
569:                    return data;
570:                }
571:
572:                case STRING_ARRAY: {
573:                    String[] data = new String[length];
574:                    in.addRef(data);
575:
576:                    for (int i = 0; i < data.length; i++)
577:                        data[i] = in.readString();
578:
579:                    return data;
580:                }
581:
582:                case OBJECT_ARRAY: {
583:                    Object[] data = new Object[length];
584:                    in.addRef(data);
585:
586:                    for (int i = 0; i < data.length; i++)
587:                        data[i] = in.readObject();
588:
589:                    return data;
590:                }
591:
592:                default:
593:                    throw new UnsupportedOperationException(String
594:                            .valueOf(this));
595:                }
596:            }
597:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.