What types of searches the JNDI can perform?

September 15th, 2006 by uCertify Leave a reply »

The Java Naming and Directory Interface (JNDI) allows the Java programs to interact with any naming service and directory service that implements JNDI. The most used operation of JNDI is the search operation. The search operation contains a connection, the base to start the search from, the scope of the search, and a search filter. The search filter is like a SQL query in which a user can tell the criteria for search. Searches include attribute name and a value to be looked up. Filter can use Boolean logic and wildcards. The JNDI can perform the following types of searches:

  1. Context.lookup(): It returns a stored object corresponding to the DN in the server.
  2. Context.list(): It returns the names bound and the class names of the objects bound in the context. It is used for browser-style applications that just want to display the names of objects in a context. It returns an enumeration of NameClassPair. Each NameClassPair consists of the object’s name and its class name. The following code fragment lists the contents of the “Home22=People” directory (i.e., the files and directories found in “Home22=People” directory).

    NamingEnumeration list = ctx.list(”Home22=People”);

    while (list.hasMore()) {
    NameClassPair List22 = (NameClassPair)list.next();
    System.out.println(List22);
    }

  3. Context.listBindings(): It returns the names bound and the objects bound in the context. It is intended for applications that need to perform operations on the objects in a context. It returns an enumeration of Binding. Binding is a subclass of NameClassPair. A binding contains not only the object’s name and class name, but also the object. The following code enumerates the “Home22=People” context, printing out each binding’s name and object.
    NamingEnumeration bindings_home = ctx.listBindings(”Home22=People”);

    while (bindings_home.hasMore()) {
    Binding Bdhom22 = (Binding)bindings_home.next();
    System.out.println(Bdhom22.getName() + “: ” + Bdhom22.getObject());

Get certified in first attempt download scja - SCJA simulation. Click here to get free CX310-019 SCJA exam practice questions.
Like this article? Share it with others
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.