1 16 19 20 26 package org.apache.xml.utils.synthetic; 27 28 import org.apache.xml.utils.synthetic.reflection.Method; 29 30 34 public class TestDriver 35 { 36 37 38 public static int sampleField = 32; 39 40 41 private boolean inTest = false; 42 43 49 public static void main(String [] args) 50 { 51 52 try 54 { 55 System.out.println("Proxying java.awt.Frame..."); 56 57 Class myC = Class.forName("java.awt.Frame"); 58 59 myC.toSource(System.out, 0); 60 System.out.println( 61 "\nProxying org.apache.xml.utils.synthetic.TestDriver..."); 62 63 myC = 64 Class.forName("com.ibm.org.apache.xml.utils.synthetic.TestDriver"); 65 66 myC.toSource(System.out, 0); 67 } 68 catch (ClassNotFoundException e) 69 { 70 System.out.println("Couldn't proxy: "); 71 e.printStackTrace(); 72 } 73 74 try 76 { 77 System.out.println("\nBuild a new beast..."); 78 79 Class myC = Class.declareClass( 80 "com.ibm.org.apache.xml.utils.synthetic.BuildMe"); 81 Class inner = myC.declareInnerClass("island"); 82 83 inner.addExtends(Class.forName("java.lang.String")); 84 85 Method m = inner.declareMethod("getValue"); 86 87 m.setReturnType(Class.forName("java.lang.String")); 88 m.getBody().append("return toString();"); 89 myC.toSource(System.out, 0); 90 } 91 catch (ClassNotFoundException e) 92 { 93 e.printStackTrace(); 94 } 95 catch (SynthesisException e) 96 { 97 e.printStackTrace(); 98 } 99 catch (IllegalStateException e) 100 { 101 System.out.println("Unwritten function: " + e); 102 e.printStackTrace(); 103 } 104 } 105 106 112 public static void dumpClass(Class C) 113 { 114 115 System.out.println("toString(): " + C); 116 System.out.println("\tisPrimitive(): " + C.isPrimitive()); 117 System.out.println("\tisInterface(): " + C.isInterface()); 118 System.out.println("\tisInstance(\"foo\"): " + C.isInstance("foo")); 119 System.out.println("\tisArray(): " + C.isArray()); 120 System.out.println("\tgetRealClass(): " + C.getRealClass()); 121 } 122 123 127 public void quickcheck() 128 { 129 130 Inner a = new Inner(); 131 132 a.setTest(!a.getTest()); 133 } 134 135 139 private class Inner 140 { 141 142 148 public boolean getTest() 149 { 150 return inTest; 151 } 152 153 159 public void setTest(boolean test) 160 { 161 inTest = test; 162 } 163 } 164 } 165 | Popular Tags |