- Forward


The Java Naming and Directory Interface (JNDI)
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Overview
Back SMYC Forward
  • Purpose:
    • Provide naming and directory functionality
  • Design Objective:
    • Independent of any specific naming/directory service implementation
The Layers/Stack
Back SMYC Forward
  • Java Application:
    • The user of the service
  • JNDI API:
    • An abstraction layer that provides an interface to a service provider
  • Service Provider:
    • An implementation of a particular naming/directory service
The javax.naming Package
Back SMYC Forward
  • Purpose:
    • Provides the functionality for accessing naming services
  • The Context Interface:
    • bind(), rebind(), and unbind()
    • lookup()
    • listBindings()
  • The Reference Class:
    • A reference to an entity that can't be directly bound to the naming/directory system
The javax.naming.directory Package
Back SMYC Forward
  • Purpose:
    • Provides the functionality for accessing directory services
  • The DirContext Interface:
    • getAttributes()
    • search()
Some Other Packages
Back SMYC Forward
  • The javax.naming.event Package:
    • NamingEvent
    • NamingListener
  • The javax.naming.spi Package:
    • Provides functionality for service providers to create Java objects, etc...
Outline of an Example using LDAP
Back SMYC Forward
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
Back SMYC Forward
CourseDatabase db; try { db = (CourseDatabase)Naming.lookup("rmi://localhost:22801/CourseDatabase"); // Use the result } catch (NamingException ne) { // Handle the exception }
There's Always More to Learn
Back -