KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > iiop > UnmarshallObject


1 /*
2  * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.iiop;
30
31 import java.io.IOException JavaDoc;
32
33 public class UnmarshallObject {
34   public final static int BOOLEAN = 0;
35   public final static int BYTE = 1;
36   public final static int SHORT = 2;
37   public final static int CHAR = 3;
38   public final static int INT = 4;
39   public final static int LONG = 5;
40   public final static int FLOAT = 6;
41   public final static int DOUBLE = 7;
42   
43   public final static int STRING = 8;
44   
45   public final static int BOOLEAN_ARRAY = 9;
46   public final static int BYTE_ARRAY = 10;
47   public final static int SHORT_ARRAY = 11;
48   public final static int CHAR_ARRAY = 12;
49   public final static int INT_ARRAY = 13;
50   public final static int LONG_ARRAY = 14;
51   public final static int FLOAT_ARRAY = 15;
52   public final static int DOUBLE_ARRAY = 16;
53   public final static int STRING_ARRAY = 17;
54
55   private int code;
56
57   private UnmarshallObject(int code)
58   {
59     this.code = code;
60   }
61
62   public Object JavaDoc unmarshall(IiopReader reader)
63     throws IOException JavaDoc
64   {
65     switch (code) {
66     case BOOLEAN:
67       return new Boolean JavaDoc(reader.read_boolean());
68     case BYTE:
69       return new Byte JavaDoc(reader.read_octet());
70     case SHORT:
71       return new Short JavaDoc(reader.read_short());
72     case CHAR:
73       return new Character JavaDoc(reader.read_wchar());
74     case INT:
75       return new Integer JavaDoc(reader.read_long());
76     case LONG:
77       return new Long JavaDoc(reader.read_longlong());
78     case FLOAT:
79       return new Float JavaDoc(reader.read_float());
80     case DOUBLE:
81       return new Double JavaDoc(reader.read_double());
82     case STRING:
83       return reader.read_wstring();
84     case BOOLEAN_ARRAY:
85     {
86       boolean []array = new boolean[reader.read_sequence_length()];
87       reader.read_boolean_array(array, 0, array.length);
88       return array;
89     }
90     case BYTE_ARRAY:
91     {
92       byte []array = new byte[reader.read_sequence_length()];
93       reader.read_octet_array(array, 0, array.length);
94       return array;
95     }
96     case CHAR_ARRAY:
97     {
98       char []array = new char[reader.read_sequence_length()];
99       reader.read_wchar_array(array, 0, array.length);
100       return array;
101     }
102     case SHORT_ARRAY:
103     {
104       short []array = new short[reader.read_sequence_length()];
105       reader.read_short_array(array, 0, array.length);
106       return array;
107     }
108     case INT_ARRAY:
109     {
110       int []array = new int[reader.read_sequence_length()];
111       reader.read_long_array(array, 0, array.length);
112       return array;
113     }
114     case LONG_ARRAY:
115     {
116       long []array = new long[reader.read_sequence_length()];
117       reader.read_longlong_array(array, 0, array.length);
118       return array;
119     }
120     case FLOAT_ARRAY:
121     {
122       float []array = new float[reader.read_sequence_length()];
123       reader.read_float_array(array, 0, array.length);
124       return array;
125     }
126     case DOUBLE_ARRAY:
127     {
128       double []array = new double[reader.read_sequence_length()];
129       reader.read_double_array(array, 0, array.length);
130       return array;
131     }
132     case STRING_ARRAY:
133     {
134       String JavaDoc []array = new String JavaDoc[reader.read_sequence_length()];
135       for (int i = 0; i < array.length; i++)
136         array[i] = reader.read_wstring();
137       return array;
138     }
139     default:
140       throw new IOException JavaDoc("unknown type");
141     }
142   }
143 }
144
Popular Tags