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