This solution describes how to create a JNDI shell that accepts commands from an input stream and executes these commands. A demo JNDIShell browser, with accompanying source code, is provided to show the functionality of this JNDI shell solution.
The JNDI shell implementation consists of two major components (JNDIShell class and shell class) with other supporting interfaces and classes.
The JNDIShell class contains the JNDI specific shell implementations. Sample source code is provided by the JNDIShell.java file. The primary purpose of the JNDIShell class is to control the shell state. The specific tasks included in this class are as follows:
The shell class is a generic shell that does general initialization, parses the command line, and controls input and output. Its primary purpose is to set up the environment in which the JNDIShell class can operate. This generic shell contains two principal methods (main and runShell) and 23 internal classes, which define the different default commands that are implemented.
Sample source code is provided by the shell.java file.
The primary purpose of the main method is to interpret any strings passed to it as command line parameters. More specifically it performs the following functions:
The primary purpose of the runShell method is to run the shell given a set of minimal options and the necessary input and output streams. More specifically it performs the following functions:
com.novell.service.nw.NetWareInitialContetFactory
if no other initial context is provided.
A command class is included for each of the 23 default shell commands. Because each command class implements the CommandWithHelp interface, each has a getHelpStrs method for printing the command help information. These commands are bound to the shell, and because of the load and unload commands, all of them can be changed during the course of shell execution.
The JNDIShell class and the shell class use the following additional interfaces and classes.
The JNDI Shell demo is a text-based browser that allows you to explore JNDI providers. It is designed for users who have a basic knowledge of the JNDI Context and DirContext interfaces. JNDIShell can call basic JNDI Context and DirContext methods.
Some possible uses for JNDIShell are:
To run the JNDIShell demo utility, follow the procedures below.
javac shell.java
java shell
java shell -?
load <cmdclass> <cmdname>
where <cmdclass> is the name of the class you created and <cmdname> is the command name to which you want to bind the class.
Edit the shell.ini file to change the initial environment. To use the JNDI providers other than those supplied by Novell, set the environment key 'java.naming.factory.initial' to the class name of the desired initial context factory.
For all commands, at the command line, enter
?
For one particular command, at the command line, enter
? <cmd>
This source code demonstrates how to create the functionality of a generic shell that accepts commands from an input stream and executes these commands.