001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.api.ldap.model.message.controls;
021
022/**
023 * Enumeration of the result codes of a SortResult defined in <a href="http://tools.ietf.org/html/rfc2891">RFC 2891</a>
024 * for server side sort control.
025 *
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 */
028public enum SortResultCode
029{
030    SUCCESS( 0, "Results are sorted"),
031    
032    OPERATIONSERROR( 1, "Server internal failure"),
033    
034    TIMELIMITEXCEEDED( 3, "Timelimit reached before sorting was completed"),
035    
036    STRONGAUTHREQUIRED( 8, "Refused to return sorted results via insecure protocol"),
037    
038    ADMINLIMITEXCEEDED( 11, "Too many matching entries for the server to sort"),
039    
040    NOSUCHATTRIBUTE( 16, "Unrecognized attribute type in sort key"),
041    
042    INAPPROPRIATEMATCHING( 18, "Unrecognized or inappropriate matching rule in sort key"),
043    
044    INSUFFICIENTACCESSRIGHTS( 50, "Refused to return sorted results to this client"),
045    
046    BUSY( 51, "Too busy to process"),
047    
048    UNWILLINGTOPERFORM( 53, "Unable to sort"),
049    
050    OTHER( 80, "Other");
051    
052    int val;
053    String desc;
054    
055    SortResultCode( int val, String desc )
056    {
057        this.val = val;
058        this.desc = desc;
059    }
060
061    /**
062     * @return The internet value
063     */
064    public int getVal()
065    {
066        return val;
067    }
068    
069    
070    /**
071     * returns the enum value representing the given code.
072     * 
073     * @param code the result code
074     * @return returns the corresponding ResultCode, throws IllegalArgumentException when there
075     *         is no matching ResultCode exists for the given value.
076     */
077    public static SortResultCode get( int code )
078    {
079        switch ( code )
080        {
081            case 0:
082                return SUCCESS;
083
084            case 1:
085                return OPERATIONSERROR;
086
087            case 3:
088                return TIMELIMITEXCEEDED;
089                
090            case 8:
091                return STRONGAUTHREQUIRED;
092
093            case 11:
094                return ADMINLIMITEXCEEDED;
095                
096            case 16:
097                return NOSUCHATTRIBUTE;
098                
099            case 18:
100                return INAPPROPRIATEMATCHING;
101                
102            case 50:
103                return INSUFFICIENTACCESSRIGHTS;
104                
105            case 51:
106                return BUSY;
107                
108            case 53:
109                return UNWILLINGTOPERFORM;
110                
111            case 80:
112                return OTHER;
113
114            default:
115                throw new IllegalArgumentException( "Unknown sort response result code " + code );
116        }
117    }
118}