* Create a SearchRequestCodec ready to be sent.
*/
private SearchRequestCodec createSearchMessage( SearchRequest searchRequest ) throws LdapException
{
// Create a new codec SearchRequest object
SearchRequestCodec request = new SearchRequestCodec();
// Creates the messageID and stores it into the
// initial message and the transmitted message.
int newId = messageId.incrementAndGet();
searchRequest.setMessageId( newId );
request.setMessageId( newId );
// Set the name
try
{
DN dn = new DN( searchRequest.getBaseDn() );
request.setBaseObject( dn );
}
catch ( InvalidNameException ine )
{
String msg = "The given dn '" + searchRequest.getBaseDn() + "' is not valid";
LOG.error( msg );
LdapException ldapException = new LdapException( msg );
ldapException.initCause( ine );
throw ldapException;
}
// Set the scope
request.setScope( searchRequest.getScope() );
// Set the typesOnly flag
request.setDerefAliases( searchRequest.getDerefAliases().getValue() );
// Set the timeLimit
request.setTimeLimit( searchRequest.getTimeLimit() );
// Set the sizeLimit
request.setSizeLimit( searchRequest.getSizeLimit() );
// Set the typesOnly flag
request.setTypesOnly( searchRequest.getTypesOnly() );
// Set the filter
Filter filter = null;
try
{
ExprNode filterNode = FilterParser.parse( searchRequest.getFilter() );
filter = LdapTransformer.transformFilter( filterNode );
}
catch ( ParseException pe )
{
String msg = "The given filter '" + searchRequest.getFilter() + "' is not valid";
LOG.error( msg );
LdapException ldapException = new LdapException( msg );
ldapException.initCause( pe );
throw ldapException;
}
request.setFilter( filter );
// Set the attributes
Set<String> attributes = searchRequest.getAttributes();
if ( attributes != null )
{
for ( String attribute : attributes )
{
request.addAttribute( attribute );
}
}
// Add the controls
setControls( searchRequest.getControls(), request );