I have been trying to find out a way to discover all the attributes supported by an object class in the Directory Context. I have tried to use getattributes()
method of the Directory Context, but this displays only those attributes which are populated. I am interested in discovering all attributes supported only the specific object class, not all attributes for all object classes. The following are the code snippets that I have already tried.
//Approach 1
System.out.println("using bindings.......");
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
searchControls.setReturningAttributes( new String[]
{ "objectClasses" } );
NamingEnumeration<SearchResult> results = conn.getInitialContext().search( "cn=schema", "(ObjectClass=*)", searchControls );
SearchResult result = results.next();
Attributes entry = result.getAttributes();
javax.naming.directory.Attribute objectClasses = entry.get( "objectClasses" );
System.out.println( objectClasses );
System.out.println("................................");
//Approach 2
DirContext tedClasses = (conn.getInitialContext().getSchemaClassDefinition(entryName));
// Enumerate the class definitions
NamingEnumeration namingEnum = tedClasses.search("", null);
System.out.println("attrs are:");
while (namingEnum.hasMore()) {
System.out.println(namingEnum.next());
}
Where conn.getInitialContext()
gives the directory context