Previous | Next | Trail Map | Beyond the Basics | URLs

As Data for Configuration

There are a couple of ways in which a URL string is used in configuration. One way is its use as a referral. A referral is basically configuration data on an LDAP server. See the Referrals (in the Tips for LDAP Users trail) lesson for details. Another way in which a URL string is used in configuration is for configuring the initial context implementation. This use is described in this section.

The JNDI defines an environment property, Context.PROVIDER_URL(in the API reference documentation) ("java.naming.provider.url") for configuring the initial context implementation. Here's an example that configures the initial context implemented by a file system service provider, com.sun.jndi.fscontext.FSContextFactory:

// Initial Environment with various properties
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, 
    "com.sun.jndi.fscontext.FSContextFactory");
env.put(Context.PROVIDER_URL, "file:/");

// Call constructor
Context ctx = new InitialContext(env);
The URL string in this case is a file URL. It specifies the file directory root for the implementation.

Here is an example that configures the initial context of Sun's LDAP service provider:

// Initial Environment with various properties
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, 
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=jnditutorial");

// Call constructor
Context ctx = new InitialContext(env);
In this example, the URL string supplied is an ldap URL. It specifies the LDAP server's machine and port number, and the distinguished name of the root naming context (o=jnditutorial).

From these two examples, you can see that the format of the provider URL string is service provider-specific. The provider determines the URL schemes that it supports. Also, most service providers specify a default value for the java.naming.provider.url property. For example, Sun's file system service provider specifies that the default provider URL names the root of the file system if the java.naming.provider.url property has not been specified.

URLs: End of Lesson

What's next? Now you can:


Previous | Next | Trail Map | Beyond the Basics | URLs