This section covers the following tasks:
To create an initial context, you must do the following:
The first value is the initial context factory, which is listed in the documentation for the naming system's service provider. The initial context factories are also stored as static String variables in the NJCL class com.novell.utility.naming.Environment.
For example, the NDS initial context factory has the String value
Environment.NDS_INITIAL_CONTEXT_FACTORY
The second value is the provider URL. The NDS provider URL takes the form of
nds://[tree name]/[fully distinguished name]
as in
nds://planetary/.admin.administration
You may have to specify other values in order to create the initial context. Refer to the documentation for a naming system's service provider to learn about other values it may require.
Creating an initial context requires that you set certain JNDI properties for the creation of that context. JNDI uses key/value pairs associated with java.util.Hashtable to represent a JNDI property. The JNDI interface javax.naming.Context stores the hashtable keys as static String variables. You determined the value for this key in the previous step.
For example, the key for the initial context factory pair has the String value
Context.INITIAL_CONTEXT_FACTORY
and the key for the provider URL pair has the String value
Context.PROVIDER_URL
Use the Hashtable.put() method to insert key/value pairs into the hashtable as in the following:
Hashtable hash = new Hashtable();
hash.put("key", "value");
In order to construct a new instance of an initial context, you must tell the JNDI naming manager about the appropriate JNDI properties it should use to create that context. You set those properties in the previous step when creating the Hashtable object. Once you have created the initial context, you do not need to do anything else with it in order to start accessing the naming system with JNDI.
The Java class Acl.java has a static method called createInitialContext(), which demonstrates how to create an initial context. See the section of code in Acl.java beginning with the following line of code:
private static DirContext createInitialContext
(String _providerURL)
To look up a context, you must do the following:
The Java class NetWareObjectLister.java has the following line of code that demonstrates how to look up a context:
Object obj =
initialCtx.lookup(MyEnvironment.DISTINGUISHED_NAME);
To access attributes, you must do the following:
The getAttributes method takes the name of the context whose attributes you want to get as a parameter.
To get your own context's attributes, pass in an empty string.
When the getAttributes() method is called, an Attributes interface is returned.
Both of these methods return a Naming Enumeration, which can contain objects of different classes.
The Java class Acl.java has a static method called printACL(), which demonstrates how to access attributes. See the section of code in Acl.java beginning with the following line or code:
private static boolean printACL(DirContext target)