com.ibm.jc.tools
Class JCShellPlugin

java.lang.Object
  extended bycom.ibm.jc.tools.JCShellPlugin
Direct Known Subclasses:
OPAppletPlugin

public abstract class JCShellPlugin
extends java.lang.Object

Base class for JCShell plugins. This class allows to extend the shell behavior reflecting specific on-card applets and their functionality in the shell.

Note, classes implementing this interface must have a public default constructor in order to allow the shell to instantiate them dynamically.

See Also:
JCShell

Field Summary
static int GUI
          Execute mode.
static int HELP
          Execute mode.
static JCInfo info
          Used to translate values to readable text (default JCInfo.INFO)
static int RUN
          Execute mode.
static int USAGE
          Execute mode.
 
Constructor Summary
JCShellPlugin()
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
abstract  void execute(int mode, java.lang.String cmd, int cmdNo, java.lang.String[] argv)
          Parse and execute the specified command.
 boolean execute(int mode, java.lang.String cmd, java.lang.String[] argv, java.lang.Object argsSpec)
          Parse and execute the specified command using GetOpt specification.
 byte[] getAID()
           
 JCApplet getApplet()
           
abstract  java.lang.String[] getCommands()
          Return the list of supported commands.
 java.lang.String getNickName()
           
 java.lang.String getSpecialVariable(java.lang.String name)
          Return value of special variable.
 void initialize(java.lang.String nickName, byte[] aid)
          Initialize a new instance of this off-card applet representative.
static java.lang.String[] joinLists(java.lang.String[] subCmds, java.lang.String[] superCmds)
          Join two string array.
 void setApplet(JCApplet applet)
          Associate applet with plugin.
static void throwModeNotSupported(int mode)
          Throw an exception to notify shell that requested mode is not supported.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RUN

public static final int RUN
Execute mode. Run the command with given ags.

See Also:
Constant Field Values

GUI

public static final int GUI
Execute mode. Run some GUI to receive commands arguments. Use given arguments as pre-setup values.

See Also:
Constant Field Values

USAGE

public static final int USAGE
Execute mode. Print a short usage for the given command. No arguments supplied.

See Also:
Constant Field Values

HELP

public static final int HELP
Execute mode. Print some detailed help about the given command. No arguments supplied.

See Also:
Constant Field Values

info

public static JCInfo info
Used to translate values to readable text (default JCInfo.INFO)

Constructor Detail

JCShellPlugin

public JCShellPlugin()
Method Detail

joinLists

public static java.lang.String[] joinLists(java.lang.String[] subCmds,
                                           java.lang.String[] superCmds)
Join two string array. Useful for combining command lists of subclass and superclass.


getNickName

public java.lang.String getNickName()
Returns:
nick name of this particular applet.

getApplet

public JCApplet getApplet()
Returns:
applet this plugin is managing.

getAID

public byte[] getAID()
Returns:
AID of this applet.

equals

public boolean equals(java.lang.Object o)
Returns:
true if either o is a String and equals the nick name, if it is a byte[] and equals the AID, or if it is a JCApplet and equals applet managed by this plugin.

setApplet

public void setApplet(JCApplet applet)
Associate applet with plugin.

Parameters:
applet - associate an applet with the plugin. If null then disconnect plugin from applet (card pulled out).

getSpecialVariable

public java.lang.String getSpecialVariable(java.lang.String name)
Return value of special variable.

Parameters:
name - variable name (without leading plugin nickname)
Returns:
value or null if variable is not set

initialize

public void initialize(java.lang.String nickName,
                       byte[] aid)
Initialize a new instance of this off-card applet representative.

Parameters:
nickName - nick name of the applet
aid - the aid of the applet
Returns:
the upgraded (subclass of JCApplet) applet representative.

getCommands

public abstract java.lang.String[] getCommands()
Return the list of supported commands.

Returns:
command list (this value should not change between different calls)

throwModeNotSupported

public static void throwModeNotSupported(int mode)
Throw an exception to notify shell that requested mode is not supported.


execute

public abstract void execute(int mode,
                             java.lang.String cmd,
                             int cmdNo,
                             java.lang.String[] argv)
Parse and execute the specified command. This method is called by the shell if getArgSpec returned null for a particular cmd/cmdNo pair.

Parameters:
mode - what to do with the given command: RUN, GUI, USAGE, HELP
cmd - the command name from the command list as returned by this class
cmdNo - the index into the command list as returned by getCommands().
argv - the parsed argument vector. No present in all mode (see constants)
Returns:
false if GUI, USAGE, or HELP is not supported for the particular command
Throws:
java.lang.RuntimeException - Command execution may fail with any exception. Shell will catch it and will print some diagnosis.

execute

public boolean execute(int mode,
                       java.lang.String cmd,
                       java.lang.String[] argv,
                       java.lang.Object argsSpec)
Parse and execute the specified command using GetOpt specification. This method implements GUI, HELP, and argument parsing from argv using the GetOpt specification. It can be called by particular command implementations.

Parameters:
mode - what to do with the given command: RUN, GUI, USAGE, HELP
cmd - the command name from the command list as returned by this class
argv - the parsed argument vector. No present in all mode (see constants)
argsSpec - the GetOpt argument specification. This must be of type com.ibm.util.getopt.ArgEater or com.ibm.util.getopt.ArgEater[].
Returns:
true if mode was RUN and if parsing did succeed.