Java DirContext get attribute

Description

Java DirContext get attribute

import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class Main {
   public static void main(String args[]) {
      try {/*from  w  w  w .  j  a  v a 2  s  . com*/
         DirContext ctx = new InitialDirContext();
         Attributes attrs = ctx.getAttributes(args[0]);
         for (NamingEnumeration ne = attrs.getAll(); ne.hasMore();) {
            Attribute attr = (Attribute) ne.next();
            System.out.println("attribute: " + attr.getID());
            for (NamingEnumeration e = attr.getAll(); e.hasMore();)
               System.out.println("value: " + e.next());
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related