The DirectoryService Class: The getContext Method

The getContext method with no arguments is used to retrieve the base context or the InitialContext for the naming service. As shown in the next listing, the overloaded version of that method accepts a string parameter and firsts tests to see whether or not the instance member for the InitialContext has been set; if it has, there is no attempt to create it. But if it has not been set, then the getContext method is called to retrieve the InitialContext. This is cast as an InitialContext in this example, but the true type of the reference is an InitialDirContext a subclass of InitialContext (and the reason the cast works).

The next step is to call the InitialContext lookup method to retrieve the ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software 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.