JNDI est système d'annuaire générique. Il sait gérer “out-of-box” : LDAP, DNS, NIS, NDS, RMI et CORBA.
Manipulation des associations.
Manipulation des répertoires.
Traitement des évènements en provenance de l'annuaire.
API spécialisée pour les annuaires compatibles LDAP.
API de programmation des pilotes JNDI.
import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class Bind { public static String BIND = "drazzib/test"; public static void main (String[] args) { Object object = "DATA"; try { Context initialContext = new InitialContext(); initialContext.bind(BIND, object); System.out.println("Bound object to name: " + BIND); } catch (NamingException e) { System.err.println("Unable to bind (" + object + ") to the name '" + BIND + "'"); e.printStackTrace(); } } }
import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class Lookup { public static void main (String[] args) { try { Context initialContext = new InitialContext(); Object object = initialContext.lookup(Bind.BIND); if ( object instanceof java.lang.String) { String s = (String) object; System.out.println("Looked up this object: " + s); } else { System.err.println("Object is not of type " + "java.lang.String"); } } catch (NamingException e) { System.err.println("Unable to find an object bound to the name " + Bind.BIND); } } }