tcl.lang
Class WrappedCommand

java.lang.Object
  extended by tcl.lang.WrappedCommand

public class WrappedCommand
extends Object

A Wrapped Command is like the Command struct defined in the C version in the file generic/tclInt.h. It is "wrapped" around a TclJava Command interface reference. We need to wrap Command references so that we can keep track of sticky issues like what namespace the command is defined in without requiring that every implementation of a Command interface provide method to do this. This class also handles command and execution traces. This class is only used in the internal implementation of Jacl.


Field Summary
 Command cmd
          The actual command interface that is being wrapped
 int cmdEpoch
          incremented to invalidate any references.
 boolean deleted
          Means that the command is in the process of being deleted.
 String hashKey
          A string that stores the name of the command.
 Namespace ns
          The namespace where the command is located
 HashMap<String,WrappedCommand> table
          Reference to the table that this command is defined inside.
 
Constructor Summary
WrappedCommand()
           
 
Method Summary
 boolean hasCommandTraces()
           
 void invoke(Interp interp, TclObject[] objv)
          Call cmd.cmdProc after calling execution traces on this command, and call execution traces after this command exits.
 boolean mustCallInvoke(Interp interp)
           
 void removeAllCommandTraces()
          Eliminate all the command traces on thsi command
 String toString()
           
 void traceCommand(CommandTrace trace)
          Set a command trace on this command
 TclObject traceCommandInfo(Interp interp)
          Get a list of all command traces on this command
 void traceExecution(ExecutionTrace trace)
          Set an execution trace on this command
 TclObject traceExecutionInfo(Interp interp)
          Get a list of all execution traces on this command
 void untraceCommand(int type, String callbackCmd)
          Remove a command trace on this command
 void untraceExecution(int type, String callbackCmd)
          Remove an execution trace on this command
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

table

public HashMap<String,WrappedCommand> table
Reference to the table that this command is defined inside. The hashKey member can be used to lookup this WrappedCommand instance in the table of WrappedCommands. The table member combined with the hashKey member are are equivilent to the C version's Command->hPtr.


hashKey

public String hashKey
A string that stores the name of the command. This name is NOT fully qualified.


ns

public Namespace ns
The namespace where the command is located


cmd

public Command cmd
The actual command interface that is being wrapped


deleted

public boolean deleted
Means that the command is in the process of being deleted. Other attempts to delete the command should be ignored.


cmdEpoch

public int cmdEpoch
incremented to invalidate any references. that point to this command when it is renamed, deleted, hidden, or exposed. This field always have a value in the range 1 to Integer.MAX_VALUE (inclusive). User code should NEVER modify this value.

Constructor Detail

WrappedCommand

public WrappedCommand()
Method Detail

hasCommandTraces

public boolean hasCommandTraces()
Returns:
true if there are any command traces on this command

removeAllCommandTraces

public void removeAllCommandTraces()
Eliminate all the command traces on thsi command


untraceCommand

public void untraceCommand(int type,
                           String callbackCmd)
                    throws TclException
Remove a command trace on this command

Parameters:
type - CommandTrace.RENAME or CommandTrace.DELETE
callbackCmd - callback command to remove
Throws:
TclException

traceCommand

public void traceCommand(CommandTrace trace)
                  throws TclException
Set a command trace on this command

Parameters:
trace - trace to add to command
Throws:
TclException

traceCommandInfo

public TclObject traceCommandInfo(Interp interp)
                           throws TclException
Get a list of all command traces on this command

Parameters:
interp - interpreter for error messages
Returns:
List, in the form of [trace command info]
Throws:
TclException

traceExecution

public void traceExecution(ExecutionTrace trace)
                    throws TclException
Set an execution trace on this command

Parameters:
trace - trace to add to command
Throws:
TclException

untraceExecution

public void untraceExecution(int type,
                             String callbackCmd)
                      throws TclException
Remove an execution trace on this command

Parameters:
type - ExecutionTrace.ENTER, ExecutionTrace.LEAVE, ExecutionTrace.ENTERSTEP or ExecutionTrace.LEAVESTEP
callbackCmd - callback command to remove
Throws:
TclException

traceExecutionInfo

public TclObject traceExecutionInfo(Interp interp)
                             throws TclException
Get a list of all execution traces on this command

Parameters:
interp - interpreter for error messages
Returns:
List, in the form of [trace execution info]
Throws:
TclException

mustCallInvoke

public final boolean mustCallInvoke(Interp interp)
Returns:
true if the caller must call WrappedCommand.invoke(Interp, TclObject[]) because there are execution traces in effect. Note that it is always OK to call invoke() instead of cmd.cmdProc(), but doing so adds an extra Java stack frame that may limit how deep Tcl code stack frames can go.

invoke

public void invoke(Interp interp,
                   TclObject[] objv)
            throws TclException
Call cmd.cmdProc after calling execution traces on this command, and call execution traces after this command exits. Application code should use this call, rather than directly calling Command.cmdProc(Interp, TclObject[]) which does not fire execution traces.

Parameters:
interp - The interpreter containing the context for thie command, and where results are returned
objv - argument list for command; objv[0] is the command name itself
Throws:
TclException - on any errors

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015. All rights reserved.