1 import java.applet.Applet; 2 import java.lang.reflect.Array; 3 import java.lang.reflect.Field; 4 5 import netscape.javascript.JSObject; 6 7 public class JSToJTypeConv extends Applet { 8 9 public byte _byte = 0; 10 public char _char = 'A'; 11 public short _short = 0; 12 public int _int = 0; 13 public long _long = 0L; 14 public float _float = 0F; 15 public double _double = 0.0; 16 public boolean _boolean = false; 17 18 public byte[] _byteArray = null; 19 public char[] _charArray = null; 20 public short[] _shortArray = null; 21 public int[] _intArray = null; 22 public long[] _longArray = null; 23 public float[] _floatArray = null; 24 public double[] _doubleArray = null; 25 public char[][] _charArray2D = null; 26 27 public Byte _Byte = null; 28 public Character _Character = 'A'; 29 public Short _Short = 0; 30 public Integer _Integer = 0; 31 public Long _Long = 0L; 32 public Float _Float = 0F; 33 public Double _Double = 0.0; 34 public String _String = ""; 35 public Boolean _Boolean = false; 36 public JSObject _JSObject = null; 37 38 public Byte[] _ByteArray = null; 39 public Character[] _CharacterArray = null; 40 public Short[] _ShortArray = null; 41 public Integer[] _IntegerArray = null; 42 public Long[] _LongArray = null; 43 public Float[] _FloatArray = null; 44 public Double[] _DoubleArray = null; 45 public String[] _StringArray = null; 46 public String[][] _StringArray2D = null; 47 48 public Object _Object = null; 49 50 getArrayAsStr(Object array)51 public String getArrayAsStr(Object array) { 52 if( array == null){ 53 return "null"; 54 }else{ 55 int size = Array.getLength(array); 56 57 String ret = ""; 58 for (int i=0; i < size; i++) { 59 ret += ((Array.get(array, i) == null) ? "null" : Array.get(array, i).toString()); 60 ret += ","; 61 } 62 63 if (ret.length() > 0) { 64 ret = ret.substring(0, ret.length()-1); 65 } 66 67 return "["+ret+"]"; 68 } 69 } 70 init()71 public void init() { 72 String initStr = "JSToJTypeConv applet initialized."; 73 System.out.println(initStr); 74 } 75 76 public class DummyObject { 77 private String str; 78 DummyObject(String s)79 public DummyObject(String s) { 80 this.str = s; 81 } 82 setStr(String s)83 public void setStr(String s) { 84 this.str = s; 85 } 86 toString()87 public String toString() { 88 return str; 89 } 90 } 91 getNewDummyObject(String s)92 public DummyObject getNewDummyObject(String s){ 93 return new DummyObject(s); 94 } 95 printNewValueAndFinish(String fieldname)96 public void printNewValueAndFinish(String fieldname) throws Exception { 97 if( fieldname.equals("_Object")){ 98 System.out.println( "New value is: " + _Object + " class is " + _Object.getClass().getName() + 99 " superclass is " + _Object.getClass().getSuperclass().getName() ); 100 }else{ 101 102 Field field = getClass().getDeclaredField(fieldname); 103 Object value = field.get(this); 104 105 //2D arrays 106 if( fieldname.contains("2D") ){ 107 Object row1 = Array.get(value,0); 108 Object row2 = Array.get(value,1); 109 Object row3 = Array.get(value,2); 110 System.out.println( "New value is: [" + getArrayAsStr(row1) + "," + getArrayAsStr(row2) + "," + getArrayAsStr(row3) + "]"); 111 112 //arrays 113 }else if (value != null && value.getClass().isArray()) { 114 System.out.println("New value is: " + getArrayAsStr(value)); 115 116 //classic fields 117 } else { 118 System.out.println("New value is: " + value); 119 } 120 } 121 122 System.out.println("afterTests"); 123 } 124 } 125