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