Getting the Environment for a Context Object

The method getEnvironment in the Context interface will return a Hashtable with all the environment properties that are in effect for the Context. To modify the environment properties for a Context, you must use the addToEnvironment and removeFromEnvironment methods.

Let’s look at an example of getting the environment for a Context. For this example, we are going to create a jndi.properties resource file and let the InitialContext discover the environment properties through this method, instead of specifying them in a Hashtable as Listing 4.2 did. Listing 4.4 shows the jndi.properties file that we will be using.

Listing 4.4. The jndi.properties File for Listing 4.5
 java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory ...

Get Special Edition Using Enterprise JavaBeans™ 2.0 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.