Listing the Bindings of a Context
by, 07-07-2012 at 04:16 PM (491 Views)
Contextís listBinding() method give out some alternate mean to access the Context children. It has been seen that aNamingEnumeration would be returned by the list(), of NameValuePair objects where access is being provided by every NameValuePair to the class name and name of every single child present in Context. A NamingEnumeration is also returned by listBinding() however in this particular case Binding objects are present in enumeration. NameValuePair has a subclass Binding. Actual child object is present in it along with its class and name. The getObject() method could also be used of Binding so that to obtain the child object.
An empty string could be passed to listBindings() just like list() so that binding could be returned for context.
When operations are required to be performed at the Context children, listBindings() are used. This makes it easy to save time and to get bothered to lookup all children individually. However you shall be aware that listBindings() are quite expensive sort of operations as every child object is needed to be obtained from the naming system underlying. If all objects are not needed then it is better to use list() so that Children names could be obtained and then you could just look up the required objects.Java Code:NamingEnumeration bindings = initialContext.listBindings("");