KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > utils > synthetic > TestDriver


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: TestDriver.java,v 1.6 2004/02/17 04:23:24 minchau Exp $
18  */

19
20 /**
21  * Test driver for com.sun.org.apache.xml.internal.utils.synthetic.Class and com.sun.org.apache.xml.internal.utils.synthetic.reflection.
22  * <p>
23  * toSource should probably be factored out into a separate
24  * java generator class, so we could generate other languages as well.
25  */

26 package com.sun.org.apache.xml.internal.utils.synthetic;
27
28 import com.sun.org.apache.xml.internal.utils.synthetic.reflection.Method;
29
30 /**
31  * Class TestDriver <needs-comment/>
32  * @xsl.usage internal
33  */

34 public class TestDriver
35 {
36
37   /** Field sampleField */
38   public static int sampleField = 32;
39
40   /** Field inTest */
41   private boolean inTest = false;
42
43   /**
44    * Method _main
45    *
46    *
47    * @param args
48    */

49   public static void _main(String JavaDoc[] args)
50   {
51
52     // Proxy a class
53
try
54     {
55       System.out.println("Proxying java.awt.Frame...");
56
57       Class JavaDoc myC = Class.forName("java.awt.Frame");
58
59       myC.toSource(System.out, 0);
60       System.out.println(
61         "\nProxying com.sun.org.apache.xml.internal.utils.synthetic.TestDriver...");
62
63       myC =
64         Class.forName("com.ibm.com.sun.org.apache.xml.internal.utils.synthetic.TestDriver");
65
66       myC.toSource(System.out, 0);
67     }
68     catch (ClassNotFoundException JavaDoc e)
69     {
70       System.out.println("Couldn't proxy: ");
71       e.printStackTrace();
72     }
73
74     // Start getting serious
75
try
76     {
77       System.out.println("\nBuild a new beast...");
78
79       Class JavaDoc myC = Class.declareClass(
80         "com.ibm.com.sun.org.apache.xml.internal.utils.synthetic.BuildMe");
81       Class JavaDoc 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 JavaDoc e)
92     {
93       e.printStackTrace();
94     }
95     catch (SynthesisException e)
96     {
97       e.printStackTrace();
98     }
99     catch (IllegalStateException JavaDoc e)
100     {
101       System.out.println("Unwritten function: " + e);
102       e.printStackTrace();
103     }
104   }
105
106   /**
107    * Method dumpClass
108    *
109    *
110    * @param C
111    */

112   public static void dumpClass(Class JavaDoc 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   /**
124    * Method quickcheck
125    *
126    */

127   public void quickcheck()
128   {
129
130     Inner a = new Inner();
131
132     a.setTest(!a.getTest());
133   }
134
135   /**
136    * Class Inner <needs-comment/>
137    * @xsl.usage internal
138    */

139   private class Inner
140   {
141
142     /**
143      * Method getTest
144      *
145      *
146      * @return
147      */

148     public boolean getTest()
149     {
150       return inTest;
151     }
152
153     /**
154      * Method setTest
155      *
156      *
157      * @param test
158      */

159     public void setTest(boolean test)
160     {
161       inTest = test;
162     }
163   }
164 }
165
Popular Tags