O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required