01: /*
02: * JavaInstanceofCmd.java --
03: *
04: * This class implements the built-in "instanceof" command in Tcl.
05: *
06: * Copyright (c) 1997 by Sun Microsystems, Inc.
07: *
08: * See the file "license.terms" for information on usage and redistribution
09: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10: *
11: * RCS: @(#) $Id: JavaInstanceofCmd.java,v 1.3 2006/04/13 07:36:50 mdejong Exp $
12: */
13:
14: package tcl.lang;
15:
16: import tcl.lang.reflect.PkgInvoker;
17:
18: class JavaInstanceofCmd implements Command {
19:
20: /*
21: *----------------------------------------------------------------------
22: *
23: * cmdProc --
24: *
25: * This procedure is invoked to process the "java::instanceof" Tcl
26: * command. See the user documentation for details on what it
27: * does.
28: *
29: * Results:
30: * None.
31: *
32: * Side effects:
33: * A standard Tcl result is stored in the interpreter.
34: *
35: *----------------------------------------------------------------------
36: */
37:
38: public void cmdProc(Interp interp, // The current interpreter.
39: TclObject argv[]) // The command arguments.
40: throws TclException // Standard Tcl Exception.
41: {
42: if (argv.length != 3) {
43: throw new TclNumArgsException(interp, 1, argv,
44: "object class");
45: }
46:
47: Class cls = null;
48: Object obj = null;
49:
50: obj = ReflectObject.get(interp, argv[1]);
51: cls = ClassRep.get(interp, argv[2]);
52:
53: // instanceof an inaccessible type is not legal in Java.
54: if (!PkgInvoker.isAccessible(cls)) {
55: JavaInvoke.notAccessibleError(interp, cls);
56: }
57:
58: if (obj == null) {
59: interp.setResult(false);
60: } else {
61: interp.setResult(cls.isInstance(obj));
62: }
63: }
64:
65: } // end JavaInstanceofCmd
|