}
private SearchParameter getSearchParameter( ISearch search )
{
SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();
// add children detetion attributes
if ( search.isInitHasChildrenFlag() )
{
if ( search.getConnection().getSchema().hasAttributeTypeDescription(
IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_HAS_SUBORDINATES;
searchParameter.setReturningAttributes( returningAttributes );
}
else if ( search.getConnection().getSchema().hasAttributeTypeDescription(
IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_NUM_SUBORDINATES;
searchParameter.setReturningAttributes( returningAttributes );
}
else if ( search.getConnection().getSchema().hasAttributeTypeDescription(
IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT )
&& !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OPERATIONAL_ATTRIBUTE_SUBORDINATE_COUNT;
searchParameter.setReturningAttributes( returningAttributes );
}
}
// to init the alias/referral flag we need the objectClass
if ( search.isInitAliasAndReferralFlag() )
{
if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OBJECTCLASS_ATTRIBUTE ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OBJECTCLASS_ATTRIBUTE;
searchParameter.setReturningAttributes( returningAttributes );
}
}
// if returning attributes are requested but objectClass isn't included
// then add it
if ( search.getReturningAttributes() == null || search.getReturningAttributes().length > 0 )
{
if ( !Utils.containsIgnoreCase( Arrays.asList( searchParameter.getReturningAttributes() ),
IAttribute.OBJECTCLASS_ATTRIBUTE ) )
{
String[] returningAttributes = new String[searchParameter.getReturningAttributes().length + 1];
System.arraycopy( searchParameter.getReturningAttributes(), 0, returningAttributes, 0, searchParameter
.getReturningAttributes().length );
returningAttributes[returningAttributes.length - 1] = IAttribute.OBJECTCLASS_ATTRIBUTE;
searchParameter.setReturningAttributes( returningAttributes );
}
}
// filter controls if not supported by server
if ( searchParameter.getControls() != null )
{
Set suppportedConrolSet = new HashSet();
if ( connection.getRootDSE() != null
&& connection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ) != null )
{
IAttribute scAttribute = connection.getRootDSE().getAttribute(
IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL );
String[] supportedControls = scAttribute.getStringValues();
for ( int i = 0; i < supportedControls.length; i++ )
{
suppportedConrolSet.add( supportedControls[i].toLowerCase() );
}
}
Control[] controls = searchParameter.getControls();
List controlList = new ArrayList();
for ( int i = 0; i < controls.length; i++ )
{
if ( suppportedConrolSet.contains( controls[i].getOid().toLowerCase() ) )
{
controlList.add( controls[i] );
}
}
searchParameter.setControls( ( Control[] ) controlList.toArray( new Control[controlList.size()] ) );
}
return searchParameter;
}