JMU
The Java Naming and Directory Interface (JNDI)
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Overview
The Layers/Stack
The javax.naming Package
The javax.naming.directory Package
Some Other Packages
Outline of an Example using LDAP
  Map<String, Object> environment;

  environment = new HashMap<String, Object>;
  environment.put(Context.INITIAL_CONTEXT_FACTORY,
                  "com.sun.jndi.ldap.LdapCtxFactory");
  environment.put(Context.PROVIDER_URL,
                  "ldap://localhost:22801/o=Cartoons");

  try
  {
    Context context = new InitialContext(environment);
    LdapContext result = (LdapContext) context.lookup("cn=Barney Rubble,ou=People");

    // Use the result

    context.close();
  }
  catch (NamingException ne)
  {
    // Handle the exception
  }
  
Outline of an Example using the RMI Registry
  CourseDatabase   db;

  try 
  {
    db = (CourseDatabase)Naming.lookup("rmi://localhost:22801/CourseDatabase");

    // Use the result
  }
  catch (NamingException ne) 
  {
    // Handle the exception
  }