Listing the Children of a JNDI Context
by, 07-07-2012 at 05:13 PM (1411 Views)
One common operation of JNDI is nameís list retrieval of the children. E.g, Enterprise JavaBeans names could be obtained by an application to check if one of them is running or childer names list of InitialContext so that Swing JTree component could be populated. Objectís children names are listed by the help of list() method.
Javax.naming.NameClassPair objectís javax.naming.NamingEnumeration is returned by list() method where class & name of one single Context child is present in every NameClassPair. It shall be noted that NameClassPair is itself not the child. This is method getName() which ables us to learn the child name and getClassName() allow us to access the class name of child.Java Code:NamingEnumeration children = initialContext.list("");
Interface java.util.Enumeration is implemented by the NamingEnumeration therefore loop is allowed via the calling list() results by usage of familiar methods of enumeration. NamingEnumeration is used by JNDI as naming operationís return type; in enumeration the actual object would be varying based upon operations.