001: /*
002: * AdaptorGenTest.java --
003: *
004: * Test program to obtain output of the AdaptorGen
005: * class.
006: *
007: * Copyright (c) 1997 Sun Microsystems, Inc.
008: *
009: * See the file "license.terms" for information on usage and
010: * redistribution of this file, and for a DISCLAIMER OF ALL
011: * WARRANTIES.
012: *
013: * RCS: @(#) $Id: AdaptorGenTest.java,v 1.1 1999/05/10 04:08:58 dejong Exp $
014: */
015:
016: package tcl.lang;
017:
018: import java.util.*;
019: import java.lang.reflect.*;
020: import java.beans.*;
021: import java.io.*;
022:
023: /*
024: * This program can be used to test the operation of the AdaptorGen
025: * class -- it saves the data generated by the AdaptorGen class into a
026: * .class file, which can then be examined using tools such as javap.
027: */
028:
029: public class AdaptorGenTest {
030:
031: public static void main(String args[]) {
032: if (args.length != 4) {
033: System.out
034: .println("usage: java tcl.lang.AdaptorGenTest clsName eventSetName genClsName fileName");
035: System.out
036: .println(" clsName - fully qualified name of a class");
037: System.out
038: .println(" eventSetName - fully qualified name of an event listener interface");
039: System.out
040: .println(" supported by this class");
041: System.out
042: .println(" genClsName - fully qualified name of the generated adaptor class");
043: System.out
044: .println(" fileName - name of the .class file to store the adaptor class");
045: System.exit(0);
046: }
047:
048: String clsName = args[0];
049: String eventSetName = args[1];
050: String genClsName = args[2];
051: String fileName = args[3];
052:
053: Class cls = null;
054: EventSetDescriptor desc, d[];
055: AdaptorGen gen;
056:
057: try {
058: cls = Class.forName(clsName);
059: } catch (Exception e) {
060: e.printStackTrace();
061: System.exit(0);
062: }
063:
064: BeanInfo beanInfo = null;
065:
066: try {
067: beanInfo = Introspector.getBeanInfo(cls);
068: } catch (IntrospectionException e) {
069: e.printStackTrace();
070: System.exit(0);
071: }
072:
073: EventSetDescriptor events[] = beanInfo.getEventSetDescriptors();
074: if (events == null) {
075: System.out.println("no events for class " + cls);
076: System.exit(0);
077: }
078:
079: desc = null;
080: for (int i = 0; i < events.length; i++) {
081: if (events[i].getListenerType().getName().equals(
082: eventSetName)) {
083: desc = events[i];
084: break;
085: }
086: }
087:
088: if (desc != null) {
089: gen = new AdaptorGen();
090: byte code[] = gen.generate(desc, EventAdaptor.class,
091: genClsName);
092: try {
093: FileOutputStream out = new FileOutputStream(fileName);
094: out.write(code);
095: out.close();
096: } catch (IOException e) {
097: e.printStackTrace();
098: System.exit(0);
099: }
100: } else {
101: System.out.println("cannot find event set" + eventSetName);
102: }
103: }
104:
105: } // end AdaptorGenTest
|