1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import org.apache.geronimo.interop.util.ArrayUtil; 21 22 import java.lang.reflect.*; 23 24 public class ArrayHelper implements ObjectHelper 25 { 26 private ValueType _element; 27 28 private ObjectHelper _primitive; 29 30 public ArrayHelper(Class elementClass) 31 { 32 if (elementClass.isPrimitive()) 33 { 34 _primitive = PrimitiveType.getArrayHelper(elementClass); 35 } 36 else 37 { 38 _element = ValueType.getInstance(elementClass); 39 } 40 } 41 42 public Object read(ObjectInputStream input) 43 { 44 if (_primitive != null) 45 { 46 return _primitive.read(input); 47 } 48 CdrInputStream cdrInput = input._cdrInput; 49 int n = cdrInput.read_long(); 50 Object [] array = (Object [])Array.newInstance(_element._class, n); 51 for (int i = 0; i < n; i++) 52 { 53 array[i] = input.readObject(_element); 54 } 55 return array; 56 } 57 58 public void write(ObjectOutputStream output, Object value) 59 { 60 if (_primitive != null) 61 { 62 _primitive.write(output, value); 63 return; 64 } 65 CdrOutputStream cdrOutput = output._cdrOutput; 66 Object [] array = (Object [])value; 67 if (array == null) 68 { 69 array = ArrayUtil.EMPTY_OBJECT_ARRAY; 70 } 71 int n = array.length; 72 cdrOutput.write_long(n); 73 for (int i = 0; i < n; i++) 74 { 75 output.writeObject(_element, array[i]); 76 } 77 } 78 } 79 | Popular Tags |