public static String format(Attributes attrs) throws NamingException {
  if (attrs == null || attrs.size() == 0) {
    return "objectClass=*";
  }
  String answer;
  answer="(& ";
  Attribute attr;
  for (NamingEnumeration<? extends Attribute> e=attrs.getAll(); e.hasMore(); ) {
    attr=e.next();
    if (attr.size() == 0 || (attr.size() == 1 && attr.get() == null)) {
      answer+="(" + attr.getID() + "="+ "*)";
    }
 else {
      for (NamingEnumeration<?> ve=attr.getAll(); ve.hasMore(); ) {
        String val=getEncodedStringRep(ve.next());
        if (val != null) {
          answer+="(" + attr.getID() + "="+ val+ ")";
        }
      }
    }
  }
  answer+=")";
  return answer;
}

public static String format ( Attributes attrs ) throws NamingException { if ( attrs == null || attrs . size ( ) == 0 ) { return "objectClass=*" ; } String answer ; answer = "(& " ; Attribute attr ; for ( NamingEnumeration < ? extends Attribute > e = attrs . getAll ( ) ; e . hasMore ( ) ; ) { attr = e . next ( ) ; if ( attr . size ( ) == 0 || ( attr . size ( ) == 1 && attr . get ( ) == null ) ) { answer += "(" + attr . getID ( ) + "=" + "*)" ; } else { for ( NamingEnumeration < ? > ve = attr . getAll ( ) ; ve . hasMore ( ) ; ) { String val = getEncodedStringRep ( ve . next ( ) ) ; if ( val != null ) { answer += "(" + attr . getID ( ) + "=" + val + ")" ; } } } } answer += ")" ; return answer ; }
creates an ldap filter as a conjuction of the attributes supplied .
