001: /*
002: * TclPkgInvoker --
003: *
004: * This class tests the tcl.lang.reflect.PkgInvoker class. Please
005: * see the comments in PkgInvoker.java for details.
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: TclPkgInvoker.java,v 1.1 1999/05/10 04:08:59 dejong Exp $
014: *
015: */
016:
017: package tcl.lang;
018:
019: import tcl.lang.reflect.*;
020: import java.lang.reflect.*;
021: import java.beans.*;
022:
023: public class TclPkgInvoker extends PkgInvoker {
024:
025: /*
026: *----------------------------------------------------------------------
027: *
028: * invokeConstructor --
029: *
030: * Invoke the given constructor with the arguments.
031: *
032: * Results:
033: * The new object instance returned by the constructor.
034: *
035: * Side effects:
036: * The constructor may have arbitraty side effects.
037: *
038: *----------------------------------------------------------------------
039: */
040:
041: public Object invokeConstructor(Constructor constructor, // The constructor to invoke.
042: Object args[]) // Arguments for the constructor.
043: throws InstantiationException, // Standard exceptions thrown by
044: IllegalAccessException, // Constructor.newInstance.
045: IllegalArgumentException, InvocationTargetException {
046: return constructor.newInstance(args);
047: }
048:
049: /*
050: *----------------------------------------------------------------------
051: *
052: * invokeMethod --
053: *
054: * Invoke the given method of the obj with the arguments.
055: *
056: * Results:
057: * The value returned by the method.
058: *
059: * Side effects:
060: * The method may have arbitraty side effects.
061: *
062: *----------------------------------------------------------------------
063: */
064:
065: public Object invokeMethod(Method method, // The method to invoke.
066: Object obj, // The object associated with the method.
067: // May be null if the method is static.
068: Object args[]) // The arguments for the method.
069: throws IllegalAccessException, // Standard exceptions throw by Method.Invoke.
070: IllegalArgumentException, InvocationTargetException {
071: return method.invoke(obj, args);
072: }
073:
074: /*
075: *----------------------------------------------------------------------
076: *
077: * getField --
078: *
079: * Query the value of the given field.
080: *
081: * Results:
082: * The value of the field.
083: *
084: * Side effects:
085: * None.
086: *
087: *----------------------------------------------------------------------
088: */
089:
090: public Object getField(Field field, // The field to query.
091: Object obj) // The object that owns the field. May be
092: // null for static fields.
093: throws IllegalArgumentException, // Standard exceptions thrown by Field.get().
094: IllegalAccessException {
095: return field.get(obj);
096: }
097:
098: /*
099: *----------------------------------------------------------------------
100: *
101: * setField --
102: *
103: * Modify the value of the given field.
104: *
105: * Results:
106: * None.
107: *
108: * Side effects:
109: * When successful, the field is modified to be the new value.
110: *
111: *----------------------------------------------------------------------
112: */
113:
114: public void setField(Field field, // The field to modify.
115: Object obj, // The object that owns the field. May be
116: // null for static fields.
117: Object value) // New value for the field.
118: throws IllegalArgumentException, // Standard exceptions thrown by Field.set().
119: IllegalAccessException {
120: field.set(obj, value);
121: }
122:
123: } // end TclPkgInvoker
|