01: /*
02: * WrappedCommand.java
03: *
04: * Wrapper for commands located inside a Jacl interp.
05: *
06: * Copyright (c) 1999 Mo DeJong.
07: *
08: * See the file "license.terms" for information on usage and
09: * redistribution of this file, and for a DISCLAIMER OF ALL
10: * WARRANTIES.
11: *
12: * RCS: @(#) $Id: WrappedCommand.java,v 1.6 2006/01/26 19:49:18 mdejong Exp $
13: */
14:
15: package tcl.lang;
16:
17: import java.util.*;
18:
19: /**
20: * A Wrapped Command is like the Command struct defined in the C version
21: * in the file generic/tclInt.h. It is "wrapped" around a TclJava Command
22: * interface reference. We need to wrap Command references so that we
23: * can keep track of sticky issues like what namespace the command is
24: * defined in without requiring that every implementation of a Command
25: * interface provide method to do this. This class is only used in
26: * the internal implementation of Jacl.
27: */
28:
29: public class WrappedCommand {
30: public HashMap table; // Reference to the table that this command is
31: // defined inside. The hashKey member can be
32: // used to lookup this WrappedCommand instance
33: // in the table of WrappedCommands. The table
34: // member combined with the hashKey member are
35: // are equivilent to the C version's Command->hPtr.
36: public String hashKey; // A string that stores the name of the command.
37: // This name is NOT fully qualified.
38:
39: public Namespace ns; // The namespace where the command is located
40:
41: public Command cmd; // The actual Command interface that we are wrapping.
42:
43: public boolean deleted; // Means that the command is in the process
44: // of being deleted. Other attempts to
45: // delete the command should be ignored.
46:
47: ImportRef importRef; // List of each imported Command created in
48: // another namespace when this command is
49: // imported. These imported commands
50: // redirect invocations back to this
51: // command. The list is used to remove all
52: // those imported commands when deleting
53: // this "real" command.
54:
55: public int cmdEpoch; // Incremented to invalidate any references
56:
57: // that point to this command when it is
58: // renamed, deleted, hidden, or exposed.
59: // This field always have a value in the
60: // range 1 to Integer.MAX_VALUE (inclusive).
61: // User code should NEVER modify this value.
62:
63: // Increment the cmdProch field. This method is used by the interpreter
64: // to indicate that a command was hidden, renamed, or deleted.
65:
66: void incrEpoch() {
67: cmdEpoch++;
68: if (cmdEpoch == Integer.MIN_VALUE) {
69: // Integer overflow, really unlikely but possible.
70: cmdEpoch = 1;
71: }
72: }
73:
74: public String toString() {
75: StringBuffer sb = new StringBuffer();
76:
77: sb.append("Wrapper for ");
78: if (ns != null) {
79: sb.append(ns.fullName);
80: if (!ns.fullName.equals("::")) {
81: sb.append("::");
82: }
83: }
84: if (table != null) {
85: sb.append(hashKey);
86: }
87:
88: sb.append(" -> ");
89: sb.append(cmd.getClass().getName());
90:
91: sb.append(" cmdEpoch is ");
92: sb.append(cmdEpoch);
93:
94: return sb.toString();
95: }
96: }
|