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    private SortResultCode( int val, String desc )
056    {
057        this.val = val;
058        this.desc = desc;
059    }
060
061    public int getVal()
062    {
063        return val;
064    }
065    
066    /**
067     * returns the enum value representing the given code.
068     * 
069     * @param code the result code
070     * @return returns the corresponding ResultCode, throws IllegalArgumentException when there
071     *         is no matching ResultCode exists for the given value.
072     */
073    public static SortResultCode get( int code )
074    {
075        switch ( code )
076        {
077            case 0:
078                return SUCCESS;
079
080            case 1:
081                return OPERATIONSERROR;
082
083            case 3:
084                return TIMELIMITEXCEEDED;
085                
086            case 8:
087                return STRONGAUTHREQUIRED;
088
089            case 11:
090                return ADMINLIMITEXCEEDED;
091                
092            case 16:
093                return NOSUCHATTRIBUTE;
094                
095            case 18:
096                return INAPPROPRIATEMATCHING;
097                
098            case 50:
099                return INSUFFICIENTACCESSRIGHTS;
100                
101            case 51:
102                return BUSY;
103                
104            case 53:
105                return UNWILLINGTOPERFORM;
106                
107            case 80:
108                return OTHER;
109
110            default:
111                throw new IllegalArgumentException( "Unknown sort response result code " + code );
112        }
113    }
114}