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 */
020
021package org.apache.directory.api.ldap.extras.controls.vlv;
022
023
024/**
025 * Enumeration of the result codes of a Virtual List View response control as specified in draft-ietf-ldapext-ldapv3-vlv-09.
026 *
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 */
029public enum VirtualListViewResultCode
030{
031    /** A success */
032    SUCCESS(0, "Success"),
033
034    /** The operation failed dur to some internal error */
035    OPERATIONSERROR(1, "Server internal failure"),
036
037    /** teh time limit has been exceeded */
038    TIMELIMITEXCEEDED(3, "Timelimit exceeded"),
039
040    /** The admin limit has been exceeded */
041    ADMINLIMITEXCEEDED(11, "Admin limit exceeded"),
042
043    /** The matching rule is inappropriate */
044    INAPPROPRIATEMATCHING(18, "Unrecognized or inappropriate matching rule"),
045
046    /** The access right are insufficient */
047    INSUFFICIENTACCESSRIGHTS(50, "Insufficient access rights"),
048
049    /** Unwilling to perform the operation */
050    UNWILLINGTOPERFORM(53, "Unwilling to perform"),
051
052    /** No Sort Control provided */
053    SORTCONTROLMISSING(60, "Sort control missing"),
054
055    /** The offset is incorrect */
056    OFFSETRANGEERROR(61, "Offset range error"),
057    
058    /** SS is missing */
059    OPENLDAP_SSSMISSING(76, "SSS missing"), // OpenLDAP-specific error code
060    
061    /** The range is invalid */
062    OPENLDAP_RANGEERRROR(77, "Range error"), // OpenLDAP-specific error code
063
064    /** Another error */
065    OTHER(80, "Other");
066
067    /** The associated value */
068    private int value;
069    
070    /** The associated description */
071    private String desc;
072
073
074    VirtualListViewResultCode( int value, String desc )
075    {
076        this.value = value;
077        this.desc = desc;
078    }
079
080
081    /**
082     * @return The associated integer value
083     */
084    public int getValue()
085    {
086        return value;
087    }
088
089
090    /**
091     * @return The associated description
092     */
093    public String getDesc()
094    {
095        return desc;
096    }
097
098
099    /**
100     * returns the enum value representing the given code.
101     * 
102     * @param code the result code
103     * @return returns the corresponding ResultCode, throws IllegalArgumentException when there
104     *         is no matching ResultCode exists for the given value.
105     */
106    public static VirtualListViewResultCode get( int code )
107    {
108        switch ( code )
109        {
110            case 0:
111                return SUCCESS;
112
113            case 1:
114                return OPERATIONSERROR;
115
116            case 3:
117                return TIMELIMITEXCEEDED;
118
119            case 11:
120                return ADMINLIMITEXCEEDED;
121
122            case 18:
123                return INAPPROPRIATEMATCHING;
124
125            case 50:
126                return INSUFFICIENTACCESSRIGHTS;
127
128            case 53:
129                return UNWILLINGTOPERFORM;
130
131            case 60:
132                return SORTCONTROLMISSING;
133
134            case 61:
135                return OFFSETRANGEERROR;
136                
137            case 76:
138                return OPENLDAP_SSSMISSING;
139
140            case 77:
141                return OPENLDAP_RANGEERRROR;
142
143            case 80:
144                return OTHER;
145
146            default:
147                throw new IllegalArgumentException( "Unknown VLV response result code " + code );
148        }
149    }
150}