The NamingShell Application

The rest of the examples in this chapter are going to be based on the NamingShell code shown in Example 9-2. NamingShell is an extensible JNDI shell that enables us to perform naming operations in any JNDI-accessible naming system. The shell provides methods for getting and setting the current object and other shell-related details, and it also keeps track of the name of the current object, something a Context can’t do for itself.

Example 9-2. The NamingShell class

import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Hashtable; import java.util.StringTokenizer; import java.util.Vector; import javax.naming.Context; class NamingShell { // Private variables private static Hashtable COMMAND_TABLE = new Hashtable(); private static String PROMPT = "[no initial context]"; private static String VERSION = "1.0"; private static Context CURRENT_CONTEXT, INITIAL_CONTEXT; private static String CURRENT_NAME, INITIAL_NAME; private static boolean RUNNING = true; private static String CMD_PKG = "com.oreilly.jent.jndi"; // Shell operations private static void exit(int status) { System.exit(status); } // Accessor methods public static Hashtable getCommands() { return COMMAND_TABLE; } public static Context getCurrentContext() { return CURRENT_CONTEXT; } public static String getCurrentName() { return CURRENT_NAME; } public static Context getInitialContext() { return INITIAL_CONTEXT; } public static String getInitialName() { return INITIAL_NAME; ...

Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.