View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     https://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  
21  package org.apache.directory.api.ldap.extras.controls.vlv;
22  
23  import org.apache.directory.api.i18n.I18n;
24  
25  /**
26   * Enumeration of the result codes of a Virtual List View response control as specified in draft-ietf-ldapext-ldapv3-vlv-09.
27   *
28   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
29   */
30  public enum VirtualListViewResultCode
31  {
32      /** A success */
33      SUCCESS(0, "Success"),
34  
35      /** The operation failed dur to some internal error */
36      OPERATIONSERROR(1, "Server internal failure"),
37  
38      /** teh time limit has been exceeded */
39      TIMELIMITEXCEEDED(3, "Timelimit exceeded"),
40  
41      /** The admin limit has been exceeded */
42      ADMINLIMITEXCEEDED(11, "Admin limit exceeded"),
43  
44      /** The matching rule is inappropriate */
45      INAPPROPRIATEMATCHING(18, "Unrecognized or inappropriate matching rule"),
46  
47      /** The access right are insufficient */
48      INSUFFICIENTACCESSRIGHTS(50, "Insufficient access rights"),
49  
50      /** Unwilling to perform the operation */
51      UNWILLINGTOPERFORM(53, "Unwilling to perform"),
52  
53      /** No Sort Control provided */
54      SORTCONTROLMISSING(60, "Sort control missing"),
55  
56      /** The offset is incorrect */
57      OFFSETRANGEERROR(61, "Offset range error"),
58      
59      /** SS is missing */
60      OPENLDAP_SSSMISSING(76, "SSS missing"), // OpenLDAP-specific error code
61      
62      /** The range is invalid */
63      OPENLDAP_RANGEERRROR(77, "Range error"), // OpenLDAP-specific error code
64  
65      /** Another error */
66      OTHER(80, "Other");
67  
68      /** The associated value */
69      private int value;
70      
71      /** The associated description */
72      private String desc;
73  
74  
75      VirtualListViewResultCode( int value, String desc )
76      {
77          this.value = value;
78          this.desc = desc;
79      }
80  
81  
82      /**
83       * @return The associated integer value
84       */
85      public int getValue()
86      {
87          return value;
88      }
89  
90  
91      /**
92       * @return The associated description
93       */
94      public String getDesc()
95      {
96          return desc;
97      }
98  
99  
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 }