ldapResult.setDiagnosticMessage( "Cannot sort results based on more than one attribute" );
resp.setSortResult( SortResultCode.UNWILLINGTOPERFORM );
return resp;
}
SortKey sk = keys.get( 0 );
AttributeType at = schemaManager.getAttributeType( sk.getAttributeTypeDesc() );
if ( at == null )
{
ldapResult.setDiagnosticMessage( "No attribute with the name " + sk.getAttributeTypeDesc()
+ " exists in the server's schema" );
resp.setSortResult( SortResultCode.NOSUCHATTRIBUTE );
resp.setAttributeName( sk.getAttributeTypeDesc() );
return resp;
}
String mrOid = sk.getMatchingRuleId();
if ( mrOid != null )
{
MatchingRule mr = at.getOrdering();
if ( mr != null )
{
if ( !mrOid.equals( mr.getOid() ) )
{
ldapResult.setDiagnosticMessage( "Given matchingrule " + mrOid
+ " is not applicable for the attribute " + sk.getAttributeTypeDesc() );
resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
resp.setAttributeName( sk.getAttributeTypeDesc() );
return resp;
}
}
try
{
schemaManager.lookupComparatorRegistry( mrOid );
}
catch ( LdapException e )
{
ldapResult.setDiagnosticMessage( "Given matchingrule " + mrOid + " is not supported" );
resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
resp.setAttributeName( sk.getAttributeTypeDesc() );
return resp;
}
}
else
{
MatchingRule mr = at.getOrdering();
if ( mr == null )
{
mr = at.getEquality();
}
ldapResult.setDiagnosticMessage( "Matchingrule is required for sorting by the attribute "
+ sk.getAttributeTypeDesc() );
resp.setSortResult( SortResultCode.INAPPROPRIATEMATCHING );
resp.setAttributeName( sk.getAttributeTypeDesc() );
if ( mr == null )
{
return resp;
}