tcl.lang
Class Extension

java.lang.Object
  extended by tcl.lang.Extension
Direct Known Subclasses:
BlendExtension, FleetExt, ItclExtension, TclParserExtension

public abstract class Extension
extends Object

Base class for all Tcl Extensions. A Tcl Extension defines a set of commands that can be loaded into an Interp as a single unit. When a Tcl Extension is loaded into an Interp, either statically (using the "new" operator inside Java code) or dynamically (using the java::load command in Tcl scripts), it usually creates a set of commands inside the interpreter. Occasionally, loading an Extension may lead to additional side effects. For example, a communications Extension may open network connections when it's loaded. Please refer to the documentation of the specific Extension for details.


Constructor Summary
Extension()
          Default constructor.
 
Method Summary
abstract  void init(Interp interp)
          Initialize the Extension to run in a normal (unsafe) interpreter.
static void loadOnDemand(Interp interp, String cmdName, String clsName)
          Create a stub command which autoloads the real command the first time the stub command is invoked.
 void safeInit(Interp safeInterp)
          Initialize the Extension to run in a safe interpreter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Extension

public Extension()
Default constructor. Does nothing. The purpose of this constructor is to make sure instances of this Extension can be loaded dynamically using the "java::load" command, which calls Class.newInstance().

Method Detail

init

public abstract void init(Interp interp)
                   throws TclException
Initialize the Extension to run in a normal (unsafe) interpreter. This usually means creating all the commands provided by this class. A particular implementation can arrange the commands to be loaded on-demand using the loadOnDemand() function.

Parameters:
interp - current interpreter.
Throws:
TclException

safeInit

public void safeInit(Interp safeInterp)
              throws TclException
Initialize the Extension to run in a safe interpreter. This method should be written carefully, so that it initializes the safe interpreter only with partial functionality provided by the Extension that is safe for use by untrusted code. The default implementation always throws a TclException, so that a subclass of Extension cannot be loaded into a safe interpreter unless it has overridden the safeInit() method.

Parameters:
safeInterp - the safe interpreter in which the Extension should be initialized.
Throws:
TclException

loadOnDemand

public static final void loadOnDemand(Interp interp,
                                      String cmdName,
                                      String clsName)
Create a stub command which autoloads the real command the first time the stub command is invoked. Register the stub command in the interpreter.

Parameters:
interp - current interp.
cmdName - name of the command, e.g., "after".
clsName - name of the Java class that implements this command, e.g. "tcl.lang.AfterCmd"


Copyright © 2015. All rights reserved.