001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.iiop;
030:
031: import java.io.IOException;
032:
033: public class UnmarshallObject {
034: public final static int BOOLEAN = 0;
035: public final static int BYTE = 1;
036: public final static int SHORT = 2;
037: public final static int CHAR = 3;
038: public final static int INT = 4;
039: public final static int LONG = 5;
040: public final static int FLOAT = 6;
041: public final static int DOUBLE = 7;
042:
043: public final static int STRING = 8;
044:
045: public final static int BOOLEAN_ARRAY = 9;
046: public final static int BYTE_ARRAY = 10;
047: public final static int SHORT_ARRAY = 11;
048: public final static int CHAR_ARRAY = 12;
049: public final static int INT_ARRAY = 13;
050: public final static int LONG_ARRAY = 14;
051: public final static int FLOAT_ARRAY = 15;
052: public final static int DOUBLE_ARRAY = 16;
053: public final static int STRING_ARRAY = 17;
054:
055: private int code;
056:
057: private UnmarshallObject(int code) {
058: this .code = code;
059: }
060:
061: public Object unmarshall(IiopReader reader) throws IOException {
062: switch (code) {
063: case BOOLEAN:
064: return new Boolean(reader.read_boolean());
065: case BYTE:
066: return new Byte(reader.read_octet());
067: case SHORT:
068: return new Short(reader.read_short());
069: case CHAR:
070: return new Character(reader.read_wchar());
071: case INT:
072: return new Integer(reader.read_long());
073: case LONG:
074: return new Long(reader.read_longlong());
075: case FLOAT:
076: return new Float(reader.read_float());
077: case DOUBLE:
078: return new Double(reader.read_double());
079: case STRING:
080: return reader.read_wstring();
081: case BOOLEAN_ARRAY: {
082: boolean[] array = new boolean[reader.read_sequence_length()];
083: reader.read_boolean_array(array, 0, array.length);
084: return array;
085: }
086: case BYTE_ARRAY: {
087: byte[] array = new byte[reader.read_sequence_length()];
088: reader.read_octet_array(array, 0, array.length);
089: return array;
090: }
091: case CHAR_ARRAY: {
092: char[] array = new char[reader.read_sequence_length()];
093: reader.read_wchar_array(array, 0, array.length);
094: return array;
095: }
096: case SHORT_ARRAY: {
097: short[] array = new short[reader.read_sequence_length()];
098: reader.read_short_array(array, 0, array.length);
099: return array;
100: }
101: case INT_ARRAY: {
102: int[] array = new int[reader.read_sequence_length()];
103: reader.read_long_array(array, 0, array.length);
104: return array;
105: }
106: case LONG_ARRAY: {
107: long[] array = new long[reader.read_sequence_length()];
108: reader.read_longlong_array(array, 0, array.length);
109: return array;
110: }
111: case FLOAT_ARRAY: {
112: float[] array = new float[reader.read_sequence_length()];
113: reader.read_float_array(array, 0, array.length);
114: return array;
115: }
116: case DOUBLE_ARRAY: {
117: double[] array = new double[reader.read_sequence_length()];
118: reader.read_double_array(array, 0, array.length);
119: return array;
120: }
121: case STRING_ARRAY: {
122: String[] array = new String[reader.read_sequence_length()];
123: for (int i = 0; i < array.length; i++)
124: array[i] = reader.read_wstring();
125: return array;
126: }
127: default:
128: throw new IOException("unknown type");
129: }
130: }
131: }
|