JNDI (Java Naming and Directory Interface) is an application-designed API that provides developers with universal, unified interfaces of various names and directory services, and similar JDBCs are built on abstraction.
Existing directory and services accessible by JNDI are:
DNS, XNAM, Novell Directory Service, LDAP (Lightweight Directory Access Protocol Light Directory Access Protocol), CORBA Object Service, File System, Windows XP / 2000 / NT / ME / 9X Registry, RMI, DSML V1 & V2, NIS.
JNDI advantages:
Contains a lot of name and directory services, using universal interfaces to access different kinds of services;
You can connect to multiple naming or directory services at the same time;
Establish logic associations, allowing the names with Java objects or resources, without having to guide objects or resources physical IDs.
JNDI (Java Naming and Directory Interface) is an application-designed API that provides developers with universal, unified interfaces of various names and directory services, and similar JDBCs are built on abstraction. The existing directory and services accessible by JNDI are: DNS, XNAM, Novell Directory Services, LDAP (Lightweight Directory Access Protocol Light Directory Access Protocol), CORBA Object Services, File System, Windows XP / 2000 / NT / ME / 9X Registration, RMI, DSML V1 & V2, NIS. JNDI Advantages: Contains a lot of name and directory service, use universal interfaces to access different kinds of services; can connect to multiple naming or directory services simultaneously; establish logic associations, allowing names to associate names with Java objects or resources. Not to guide the physical ID of the object or resource. JNDI package: javax.naming: naming operation; javax.naming.directory: directory operation; javax.naming.event: request event notification in the named directory server; javax.naming.ldap: provides LDAP support; javax.naming.spi : Allow dynamic insertion different implementation. Using JNDI's naming and service feature to meet enterprise APIs to name and service access, such as EJBS, JMS, JDBC 2.0, and RMI on IIOP through JNDI to use CORBA naming service. JNDI and JDBC: JNDI provide a unified way to find and access services on the web. By specifying a resource name, the name corresponds to a record in the database or naming service, and returns the information necessary for the database connection establishment. Code example: try {context cntxt = new initialContext (); DataSource DS = (DataSource) CNTXT.LOOKUP ("JDBC / DPT");} Catch (Namingexception Ne) {...} JNDI and JMS: Message Communication is software components Or a way to use to communicate. JMS is a Java technology that allows applications to create, send, receive, and read messages. Code Example: try {Properties env = new Properties (); InitialContext inictxt = new InitialContext (env); TopicConnectionFactory connFactory = (TopicConnectionFactory) inictxt.lookup ( "TTopicConnectionFactory"); ...} catch (NamingException ne) {... } Access a specific directory: For an example, people are an object, he has several properties, such as this person's name, phone number, email address, postal code and other attributes.
Throughtribute Attr = Directory.GetaTRibutes ("email"); string email = (string) attr.get (); by using JNDI to let customers use the name or attribute of the object: Foxes = Directory.Search ("O = WIZ, C = US", "SN = FOX", Controls); finds an object such as a printer, a database, finds an example of a printer by using JNDI: Printer Printer = (Printer) Namespace. LOOKUP (PrinterName); Printer.Print (Document); Browse Name NameEnumeration List = Namespace.List ("O = Widget, C = US); While (list.hasmore ()) {NameClasspair entry = (NameClasspair) list .next (); intertry.getname (), entry.getclassname ());} Reference: http://java.sun.com/products/jndi/examples.htmlhttp: //java.sun.com/ Products / JNDI / ServiceProviders.html Common JNDI Actions: Commonly used JNDI Actions: Void Bind (String Sname, Object Object); - Binding: Process Void Rebind (String Sname) associated with objects; - Re-binding: Rebind the object the same name already existing name; - Release: Used to release the object from the directory from the directory void lookup (String sname, object object); Find: Return to a total object void rename (String SoldName, String SNEWNAME); - Renounced: Name NamingeNumeration Listbinding (String Sname) bound to the object name; Object list NaminGenumer at a String Sname; code example: Recent name, class name, and binding object. NamingEnumeration namEnumList = ctxt.listBinding ( "cntxtName"); ... while (namEnumList.hasMore ()) {Binding bnd = (Binding) namEnumList.next (); String sObjName = bnd.getName (); String sClassName = bnd. GetClassName (); someObject objlocal = (someobject) Bnd.getObject ();