Methods Summary |
---|
private static void | execute(Command c, java.util.Vector v)
if (c == null) {
System.out.println("No command was loaded; cannot execute the command.");
return;
}
try {
c.execute(CURRENT_CONTEXT, v);
}
catch (CommandException ce) {
System.out.println(ce.getMessage());
}
|
private static void | execute(java.lang.String s, java.util.Vector v)
execute(loadCommand(s), v);
|
private static void | exit(int status)
// Shell operations
System.exit(status);
|
public static java.util.Hashtable | getCommands() return COMMAND_TABLE;
|
public static javax.naming.Context | getCurrentContext() return CURRENT_CONTEXT;
|
public static java.lang.String | getCurrentName() return CURRENT_NAME;
|
public static javax.naming.Context | getInitialContext() return INITIAL_CONTEXT;
|
public static java.lang.String | getInitialName() return INITIAL_NAME;
|
public static java.lang.String | getPrompt() return PROMPT;
|
public static Command | loadCommand(java.lang.String commandName)
// The method returns a null command unless some of its
// internal logic assigns a new reference to it
Command theCommand = null;
// First see if the command is already present in the hashtable
if (COMMAND_TABLE.containsKey(commandName)) {
theCommand = (Command)COMMAND_TABLE.get(commandName);
return theCommand;
}
try {
// Here we use a little introspection to see if a class
// implements Command before we instantiate it
Class commandInterface = Class.forName(CMD_PKG + ".Command");
Class commandClass = Class.forName(CMD_PKG + "." + commandName);
// Check to see if the class is assignable from Command
// and if so, put the instance in the command table
if (!(commandInterface.isAssignableFrom(commandClass)))
System.out.println("[" + commandName + "]: Not a command");
else {
theCommand = (Command)commandClass.newInstance();
COMMAND_TABLE.put(commandName, theCommand);
}
}
catch (ClassNotFoundException cnfe) {
System.out.println("[" + commandName + "]: command not found");
}
catch (IllegalAccessException iae) {
System.out.println("[" + commandName + "]: illegal access");
}
catch (InstantiationException ie) {
System.out.println("["+commandName+"]: command couldn't be instantiated");
}
return theCommand;
|
public static void | main(java.lang.String[] args)
NamingShell shell = new NamingShell(args);
NamingShell.readInput();
System.out.println("Exiting");
|
private static void | readInput()
// Get the input from System.in
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Begin reading input
try {
while (RUNNING) {
System.out.print(PROMPT + "% ");
// Tokenize the line, read each token, and pass the token
// into a convenient remaining arguments Vector that we
// pass into the Command
StringTokenizer tokenizer = new StringTokenizer(br.readLine());
Vector remainingArgs = new Vector();
String commandToken = "";
if (tokenizer.hasMoreTokens()) {
commandToken = tokenizer.nextToken();
while (tokenizer.hasMoreTokens())
remainingArgs.addElement(tokenizer.nextToken());
}
// Dynamically load the class for the appropriate command
// based upon the case-sensitive name of the first token,
// which is the command token
if (!(commandToken.equals("")))
execute(commandToken, remainingArgs);
}
}
catch (java.io.IOException ioe) {
System.out.println("Caught an IO exception reading a line of input");
}
|
public static void | setCurrentContext(javax.naming.Context ctx)
CURRENT_CONTEXT = ctx;
|
public static void | setCurrentName(java.lang.String name)
CURRENT_NAME = name;
setPrompt(name);
|
public static void | setInitialContext(javax.naming.Context ctx)
INITIAL_CONTEXT = ctx;
|
public static void | setInitialName(java.lang.String name)
INITIAL_NAME = name;
|
public static void | setPrompt(java.lang.String prompt) PROMPT = prompt;
|