1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import org.apache.geronimo.interop.util.ArrayUtil; 21 22 public class PrimitiveType 23 { 24 public static final int BOOLEAN = 1; 25 public static final int BYTE = 2; 26 public static final int CHAR = 3; 27 public static final int DOUBLE = 4; 28 public static final int FLOAT = 5; 29 public static final int INT = 6; 30 public static final int LONG = 7; 31 public static final int SHORT = 8; 32 33 public static final ObjectHelper BOOLEAN_ARRAY_HELPER = new ObjectHelper() 34 { 35 public Object read(ObjectInputStream input) 36 { 37 int n = input._cdrInput.read_long(); 38 if (n == 0) 39 { 40 return ArrayUtil.EMPTY_BOOLEAN_ARRAY; 41 } 42 boolean[] array = new boolean[n]; 43 input._cdrInput.read_boolean_array(array, 0, n); 44 return array; 45 } 46 47 public void write(ObjectOutputStream output, Object value) 48 { 49 boolean[] array = (boolean[])value; 50 int n = array.length; 51 output._cdrOutput.write_long(n); 52 output._cdrOutput.write_boolean_array(array, 0, n); 53 } 54 } 55 ; 56 57 public static final ObjectHelper BYTE_ARRAY_HELPER = new ObjectHelper() 58 { 59 public Object read(ObjectInputStream input) 60 { 61 int n = input._cdrInput.read_long(); 62 if (n == 0) 63 { 64 return ArrayUtil.EMPTY_BYTE_ARRAY; 65 } 66 byte[] array = new byte[n]; 67 input._cdrInput.read_octet_array(array, 0, n); 68 return array; 69 } 70 71 public void write(ObjectOutputStream output, Object value) 72 { 73 byte[] array = (byte[])value; 74 int n = array.length; 75 output._cdrOutput.write_long(n); 76 output._cdrOutput.write_octet_array(array, 0, n); 77 } 78 } 79 ; 80 81 public static final ObjectHelper CHAR_ARRAY_HELPER = new ObjectHelper() 82 { 83 public Object read(ObjectInputStream input) 84 { 85 int n = input._cdrInput.read_long(); 86 if (n == 0) 87 { 88 return ArrayUtil.EMPTY_CHAR_ARRAY; 89 } 90 char[] array = new char[n]; 91 input._cdrInput.read_wchar_array(array, 0, n); 92 return array; 93 } 94 95 public void write(ObjectOutputStream output, Object value) 96 { 97 char[] array = (char[])value; 98 int n = array.length; 99 output._cdrOutput.write_long(n); 100 output._cdrOutput.write_wchar_array(array, 0, n); 101 } 102 } 103 ; 104 105 public static final ObjectHelper DOUBLE_ARRAY_HELPER = new ObjectHelper() 106 { 107 public Object read(ObjectInputStream input) 108 { 109 int n = input._cdrInput.read_long(); 110 if (n == 0) 111 { 112 return ArrayUtil.EMPTY_DOUBLE_ARRAY; 113 } 114 double[] array = new double[n]; 115 input._cdrInput.read_double_array(array, 0, n); 116 return array; 117 } 118 119 public void write(ObjectOutputStream output, Object value) 120 { 121 double[] array = (double[])value; 122 int n = array.length; 123 output._cdrOutput.write_long(n); 124 output._cdrOutput.write_double_array(array, 0, n); 125 } 126 } 127 ; 128 129 public static final ObjectHelper FLOAT_ARRAY_HELPER = new ObjectHelper() 130 { 131 public Object read(ObjectInputStream input) 132 { 133 int n = input._cdrInput.read_long(); 134 if (n == 0) 135 { 136 return ArrayUtil.EMPTY_FLOAT_ARRAY; 137 } 138 float[] array = new float[n]; 139 input._cdrInput.read_float_array(array, 0, n); 140 return array; 141 } 142 143 public void write(ObjectOutputStream output, Object value) 144 { 145 float[] array = (float[])value; 146 int n = array.length; 147 output._cdrOutput.write_long(n); 148 output._cdrOutput.write_float_array(array, 0, n); 149 } 150 } 151 ; 152 153 public static final ObjectHelper INT_ARRAY_HELPER = new ObjectHelper() 154 { 155 public Object read(ObjectInputStream input) 156 { 157 int n = input._cdrInput.read_long(); 158 if (n == 0) 159 { 160 return ArrayUtil.EMPTY_INT_ARRAY; 161 } 162 int[] array = new int[n]; 163 input._cdrInput.read_long_array(array, 0, n); 164 return array; 165 } 166 167 public void write(ObjectOutputStream output, Object value) 168 { 169 int[] array = (int[])value; 170 int n = array.length; 171 output._cdrOutput.write_long(n); 172 output._cdrOutput.write_long_array(array, 0, n); 173 } 174 } 175 ; 176 177 public static final ObjectHelper LONG_ARRAY_HELPER = new ObjectHelper() 178 { 179 public Object read(ObjectInputStream input) 180 { 181 int n = input._cdrInput.read_long(); 182 if (n == 0) 183 { 184 return ArrayUtil.EMPTY_LONG_ARRAY; 185 } 186 long[] array = new long[n]; 187 input._cdrInput.read_longlong_array(array, 0, n); 188 return array; 189 } 190 191 public void write(ObjectOutputStream output, Object value) 192 { 193 long[] array = (long[])value; 194 int n = array.length; 195 output._cdrOutput.write_long(n); 196 output._cdrOutput.write_longlong_array(array, 0, n); 197 } 198 } 199 ; 200 201 public static final ObjectHelper SHORT_ARRAY_HELPER = new ObjectHelper() 202 { 203 public Object read(ObjectInputStream input) 204 { 205 int n = input._cdrInput.read_long(); 206 if (n == 0) 207 { 208 return ArrayUtil.EMPTY_SHORT_ARRAY; 209 } 210 short[] array = new short[n]; 211 input._cdrInput.read_short_array(array, 0, n); 212 return array; 213 } 214 215 public void write(ObjectOutputStream output, Object value) 216 { 217 short[] array = (short[])value; 218 int n = array.length; 219 output._cdrOutput.write_long(n); 220 output._cdrOutput.write_short_array(array, 0, n); 221 } 222 } 223 ; 224 225 public static int get(Class _class) 226 { 227 if (_class == boolean.class) 228 { 229 return BOOLEAN; 230 } 231 else if (_class == byte.class) 232 { 233 return BYTE; 234 } 235 else if (_class == char.class) 236 { 237 return CHAR; 238 } 239 else if (_class == double.class) 240 { 241 return DOUBLE; 242 } 243 else if (_class == float.class) 244 { 245 return FLOAT; 246 } 247 else if (_class == int.class) 248 { 249 return INT; 250 } 251 else if (_class == long.class) 252 { 253 return LONG; 254 } 255 else if (_class == short.class) 256 { 257 return SHORT; 258 } 259 else 260 { 261 throw new IllegalArgumentException ("class = " +_class.getName()); 262 } 263 } 264 265 public static ObjectHelper getArrayHelper(Class _class) 266 { 267 if (_class == boolean.class) 268 { 269 return BOOLEAN_ARRAY_HELPER; 270 } 271 else if (_class == byte.class) 272 { 273 return BYTE_ARRAY_HELPER; 274 } 275 else if (_class == char.class) 276 { 277 return CHAR_ARRAY_HELPER; 278 } 279 else if (_class == double.class) 280 { 281 return DOUBLE_ARRAY_HELPER; 282 } 283 else if (_class == float.class) 284 { 285 return FLOAT_ARRAY_HELPER; 286 } 287 else if (_class == int.class) 288 { 289 return INT_ARRAY_HELPER; 290 } 291 else if (_class == long.class) 292 { 293 return LONG_ARRAY_HELPER; 294 } 295 else if (_class == short.class) 296 { 297 return SHORT_ARRAY_HELPER; 298 } 299 else 300 { 301 throw new IllegalArgumentException ("class = " +_class.getName()); 302 } 303 } 304 305 public static org.omg.CORBA.TypeCode getTypeCode(int p) 306 { 307 switch (p) 308 { 309 case BOOLEAN: 310 return TypeCode.BOOLEAN; 311 case BYTE: return TypeCode.OCTET; 313 case CHAR: 314 return TypeCode.CHAR; 315 case DOUBLE: 316 return TypeCode.DOUBLE; 317 case FLOAT: 318 return TypeCode.FLOAT; 319 case INT: return TypeCode.LONG; 321 case LONG: return TypeCode.LONGLONG; 323 case SHORT: 324 return TypeCode.SHORT; 325 default: 326 throw new IllegalArgumentException ("primitive type = " + p); 327 } 328 } 329 } 330 | Popular Tags |