private static List<List<String>> searchInLDAPSchema(LdapTemplate template,String[] returnAttributes,final RootDSE rootDSE,final List<String> ldapServerUrls,StringBuilder errorString){
  try {
    String schemaDN=rootDSE.getSchemaNamingContext();
    _log.debug("Searching in LDAP schema DN {} ",schemaDN);
    @SuppressWarnings("unchecked") List<List<String>> attributeList=template.search(schemaDN,"(objectclass=*)",SearchControls.OBJECT_SCOPE,returnAttributes,new LDAPSchemaContextMapper());
    if (CollectionUtils.isEmpty(attributeList)) {
      errorString.append(MessageFormat.format("The attributes {0} could not be found in LDAP schema {1} at server {2}",returnAttributes.toString(),schemaDN,ldapServerUrls.toString()));
    }
    return attributeList;
  }
 catch (  CommunicationException e) {
    errorString.append(MessageFormat.format("Connection to LDAP server {0} failed during search for attribute {1}. LDAP error: {2}",ldapServerUrls.toString(),returnAttributes.toString(),stripNonPrintableCharacters(e.getMessage())));
    return null;
  }
catch (  Exception e) {
    errorString.append(MessageFormat.format("Exception during attribute {0} search against server {1} failed because of LDAP error: {2}",returnAttributes.toString(),ldapServerUrls.toString(),stripNonPrintableCharacters(e.getMessage())));
    return null;
  }
}

private static List < List < String > > searchInLDAPSchema ( LdapTemplate template , String [ ] returnAttributes , final RootDSE rootDSE , final List < String > ldapServerUrls , StringBuilder errorString ) { try { String schemaDN = rootDSE . getSchemaNamingContext ( ) ; _log . debug ( "Searching in LDAP schema DN {} " , schemaDN ) ; @ SuppressWarnings ( "unchecked" ) List < List < String > > attributeList = template . search ( schemaDN , "(objectclass=*)" , SearchControls . OBJECT_SCOPE , returnAttributes , new LDAPSchemaContextMapper ( ) ) ; if ( CollectionUtils . isEmpty ( attributeList ) ) { errorString . append ( MessageFormat . format ( "The attributes {0} could not be found in LDAP schema {1} at server {2}" , returnAttributes . toString ( ) , schemaDN , ldapServerUrls . toString ( ) ) ) ; } return attributeList ; } catch ( CommunicationException e ) { errorString . append ( MessageFormat . format ( "Connection to LDAP server {0} failed during search for attribute {1}. LDAP error: {2}" , ldapServerUrls . toString ( ) , returnAttributes . toString ( ) , stripNonPrintableCharacters ( e . getMessage ( ) ) ) ) ; return null ; } catch ( Exception e ) { errorString . append ( MessageFormat . format ( "Exception during attribute {0} search against server {1} failed because of LDAP error: {2}" , returnAttributes . toString ( ) , ldapServerUrls . toString ( ) , stripNonPrintableCharacters ( e . getMessage ( ) ) ) ) ; return null ; } }
a method that searches ldap schema to find if the given attribute is a valid attribute of the schema or not . these attributes include attributetypes , objectclasses , etc .
