001: /*
002: * JavaEventCmd.java --
003: *
004: * Implements the built-in "java:event" Tcl command.
005: *
006: * Copyright (c) 1997 Sun Microsystems, Inc.
007: *
008: * See the file "license.terms" for information on usage and
009: * redistribution of this file, and for a DISCLAIMER OF ALL
010: * WARRANTIES.
011: *
012: * RCS: @(#) $Id: JavaEventCmd.java,v 1.1.1.1 1998/10/14 21:09:14 cvsadmin Exp $
013: *
014: */
015:
016: package tcl.lang;
017:
018: /*
019: * This class implements the built-in "java::event" command in Tcl.
020: */
021:
022: class JavaEventCmd implements Command {
023:
024: /*
025: * The Bean Event Manager associated with the interp that owns this
026: * BindCmd instance.
027: */
028:
029: BeanEventMgr eventMgr = null;
030:
031: /*
032: * Valid command options.
033: */
034:
035: static final private String validOpts[] = { "-index", };
036:
037: static final int OPT_INDEX = 0;
038:
039: /*
040: *----------------------------------------------------------------------
041: *
042: * cmdProc --
043: *
044: * This procedure is invoked as part of the Command interface to
045: * process the "java::event" Tcl command. See the user
046: * documentation for details on what it does.
047: *
048: * Results:
049: * None.
050: *
051: * Side effects:
052: * See the user documentation.
053: *
054: *----------------------------------------------------------------------
055: */
056:
057: public void cmdProc(Interp interp, // Current interpreter.
058: TclObject argv[]) // Argument list.
059: throws TclException // A standard Tcl exception.
060: {
061: int index;
062: TclObject propObj;
063:
064: if (argv.length > 4) {
065: throw new TclNumArgsException(interp, 1, argv,
066: "?-index num? ?propertyName?");
067: }
068:
069: if (argv.length <= 2) {
070: index = 0;
071: } else {
072: TclIndex.get(interp, argv[1], validOpts, "option", 0);
073:
074: /*
075: * Since we just have one valid option, if the above call returns
076: * without an exception, we've got "-index" (or abreviations).
077: */
078:
079: index = TclInteger.get(interp, argv[2]);
080: }
081:
082: if (argv.length == 2) {
083: propObj = argv[1];
084: } else if (argv.length == 4) {
085: propObj = argv[3];
086: } else {
087: propObj = null;
088: }
089:
090: if (eventMgr == null) {
091: eventMgr = BeanEventMgr.getBeanEventMgr(interp);
092: }
093:
094: BeanEventParamSet p = eventMgr.peekEventParamSet();
095: if (p == null) {
096: throw new TclException(
097: interp,
098: "\""
099: + argv[0]
100: + "\" cannot be invoked outside of an event handler");
101: }
102:
103: if ((index < 0) || (index >= p.params.length)) {
104: throw new TclException(interp, "event parameter #" + index
105: + " doesn't exist");
106: }
107:
108: TclObject param = JavaInvoke.convertJavaObject(interp,
109: p.paramTypes[index], p.params[index]);
110:
111: if (propObj == null) {
112: /*
113: * The property name is not specified, return the whole parameter.
114: */
115:
116: interp.setResult(param);
117: } else {
118: /*
119: * Return the given property of the parameter.
120: */
121:
122: interp.setResult(JavaInvoke.getProperty(interp, param,
123: propObj, true));
124: }
125: }
126:
127: } // end JavaEventCmd
|