Contexts

Contexts provide a hierarchical structure to JNDI names, and composite names group together related names. The initial context provides a top-level view of the namespace and any sub-contexts reflect the hierarchical composite name structure.

Listing Contexts

The namespace represents contexts as names, and you can look these up just like any other name. You can obtain a listing of the names in a context by using Context.list(). This method provides a list of name and class bindings as a javax.naming.NamingEnumeration, where each element in the enumeration is a javax.naming.NameClassPair object. Listing 3.5 shows a simple program to list the names and classes for the example sams sub context.

Listing 3.5. Full Text of JNDIListSAMS.java ...

Get Sams Teach Yourself J2EE™ in 21 Days 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.