This discussion is archived
2 Replies Latest reply: Sep 19, 2012 5:28 AM by EJP RSS

How to get name of an entry?

823810 Newbie
Currently Being Moderated
I search in my schema with code below:

List<OrganizationPojo> organizationPojoList = new ArrayList<OrganizationPojo>();
     DirContext ctx = null;
     
     
     try { 
     // get a handle to an Initial DirContext
     ctx = new InitialDirContext(env);
     String[] attrIDs = { "dc", "objectClass","ou" };

     SearchControls ctls = new SearchControls();
     ctls.setReturningAttributes(attrIDs);
     ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
     String filter = "(&(dc=*) (objectClass=organizationalUnit) (ou=*))";
     
     NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
     try
               {     
               while (answer.hasMore())
               {
                         SearchResult sr = (SearchResult) answer.next();
                         LdapName dn = new LdapName((String)sr.getNameInNamespace());
                         LdapName rdn = new LdapName((String)sr.getName());
                         

I learned SearchResult.getName returns the name "relative to search base"

But i only want to get the name of entry.

I am getting dn correctly but can not find out how to get rdn relative to parent in the tree.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points