The NamingShell Application

The rest of the examples in this chapter are going to be based on the NamingShell code shown in Example 7-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 7-2. The NamingShell Class

import java.io.*; import java.util.*; import javax.naming.*; class NamingShell { // Private variables private static Hashtable COMMAND_TABLE = new Hashtable( ); private static String JNDIPROPS_FILENAME = ".jndienv"; 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; // 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 String getDefaultPropsFilename( ) { return JNDIPROPS_FILENAME; } public static Context getInitialContext( ) { return INITIAL_CONTEXT; } public static String getInitialName( ) { return INITIAL_NAME; } public static String getPrompt( ...

Get Java Enterprise in a Nutshell, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.