public LDAPUrl(final boolean isSecured,final String host,final Integer port,final DN name,final SearchScope scope,final Filter filter,final String... attributes){
  final StringBuilder urlBuffer=new StringBuilder();
  this.isSecured=isSecured;
  if (this.isSecured) {
    urlBuffer.append(SSL_URL_SCHEME);
  }
 else {
    urlBuffer.append(DEFAULT_URL_SCHEME);
  }
  urlBuffer.append("://");
  if (host == null) {
    this.host=DEFAULT_HOST;
  }
 else {
    this.host=host;
    urlBuffer.append(this.host);
  }
  int listenPort=DEFAULT_PORT;
  if (port == null) {
    listenPort=isSecured ? DEFAULT_SSL_PORT : DEFAULT_PORT;
  }
 else {
    listenPort=port.intValue();
    if (listenPort < 1 || listenPort > 65535) {
      final LocalizableMessage msg=ERR_LDAPURL_BAD_PORT.get(listenPort);
      throw new LocalizedIllegalArgumentException(msg);
    }
    urlBuffer.append(COLON_CHAR);
    urlBuffer.append(listenPort);
  }
  this.port=listenPort;
  urlBuffer.append(SLASH_CHAR);
  if (name != null) {
    this.name=name;
    percentEncoder(name.toString(),urlBuffer);
  }
 else {
    this.name=DEFAULT_DN;
  }
  urlBuffer.append(QUESTION_CHAR);
switch (attributes.length) {
case 0:
    this.attributes=Collections.emptyList();
  break;
case 1:
this.attributes=Collections.singletonList(attributes[0]);
urlBuffer.append(attributes[0]);
break;
default :
this.attributes=Collections.unmodifiableList(Arrays.asList(attributes));
urlBuffer.append(attributes[0]);
for (int i=1; i < attributes.length; i++) {
urlBuffer.append(COMMA_CHAR);
urlBuffer.append(attributes[i]);
}
break;
}
urlBuffer.append(QUESTION_CHAR);
if (scope != null) {
this.scope=scope;
urlBuffer.append(scope);
}
 else {
this.scope=DEFAULT_SCOPE;
}
urlBuffer.append(QUESTION_CHAR);
if (filter != null) {
this.filter=filter;
urlBuffer.append(this.filter);
}
 else {
this.filter=DEFAULT_FILTER;
}
urlString=urlBuffer.toString();
}

public LDAPUrl ( final boolean isSecured , final String host , final Integer port , final DN name , final SearchScope scope , final Filter filter , final String ... attributes ) { final StringBuilder urlBuffer = new StringBuilder ( ) ; this . isSecured = isSecured ; if ( this . isSecured ) { urlBuffer . append ( SSL_URL_SCHEME ) ; } else { urlBuffer . append ( DEFAULT_URL_SCHEME ) ; } urlBuffer . append ( "://" ) ; if ( host == null ) { this . host = DEFAULT_HOST ; } else { this . host = host ; urlBuffer . append ( this . host ) ; } int listenPort = DEFAULT_PORT ; if ( port == null ) { listenPort = isSecured ? DEFAULT_SSL_PORT : DEFAULT_PORT ; } else { listenPort = port . intValue ( ) ; if ( listenPort < 1 || listenPort > 65535 ) { final LocalizableMessage msg = ERR_LDAPURL_BAD_PORT . get ( listenPort ) ; throw new LocalizedIllegalArgumentException ( msg ) ; } urlBuffer . append ( COLON_CHAR ) ; urlBuffer . append ( listenPort ) ; } this . port = listenPort ; urlBuffer . append ( SLASH_CHAR ) ; if ( name != null ) { this . name = name ; percentEncoder ( name . toString ( ) , urlBuffer ) ; } else { this . name = DEFAULT_DN ; } urlBuffer . append ( QUESTION_CHAR ) ; switch ( attributes . length ) { case 0 : this . attributes = Collections . emptyList ( ) ; break ; case 1 : this . attributes = Collections . singletonList ( attributes [ 0 ] ) ; urlBuffer . append ( attributes [ 0 ] ) ; break ; default : this . attributes = Collections . unmodifiableList ( Arrays . asList ( attributes ) ) ; urlBuffer . append ( attributes [ 0 ] ) ; for ( int i = 1 ; i < attributes . length ; i ++ ) { urlBuffer . append ( COMMA_CHAR ) ; urlBuffer . append ( attributes [ i ] ) ; } break ; } urlBuffer . append ( QUESTION_CHAR ) ; if ( scope != null ) { this . scope = scope ; urlBuffer . append ( scope ) ; } else { this . scope = DEFAULT_SCOPE ; } urlBuffer . append ( QUESTION_CHAR ) ; if ( filter != null ) { this . filter = filter ; urlBuffer . append ( this . filter ) ; } else { this . filter = DEFAULT_FILTER ; } urlString = urlBuffer . toString ( ) ; }
creates a new ldap url including the full set of parameters for a search request .
