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   *     http://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  package org.apache.directory.api.ldap.model.message.controls;
21  
22  /**
23   * Enumeration of the result codes of a SortResult defined in <a href="http://tools.ietf.org/html/rfc2891">RFC 2891</a>
24   * for server side sort control.
25   *
26   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
27   */
28  public enum SortResultCode
29  {
30      SUCCESS( 0, "Results are sorted"),
31      
32      OPERATIONSERROR( 1, "Server internal failure"),
33      
34      TIMELIMITEXCEEDED( 3, "Timelimit reached before sorting was completed"),
35      
36      STRONGAUTHREQUIRED( 8, "Refused to return sorted results via insecure protocol"),
37      
38      ADMINLIMITEXCEEDED( 11, "Too many matching entries for the server to sort"),
39      
40      NOSUCHATTRIBUTE( 16, "Unrecognized attribute type in sort key"),
41      
42      INAPPROPRIATEMATCHING( 18, "Unrecognized or inappropriate matching rule in sort key"),
43      
44      INSUFFICIENTACCESSRIGHTS( 50, "Refused to return sorted results to this client"),
45      
46      BUSY( 51, "Too busy to process"),
47      
48      UNWILLINGTOPERFORM( 53, "Unable to sort"),
49      
50      OTHER( 80, "Other");
51      
52      int val;
53      String desc;
54      
55      SortResultCode( int val, String desc )
56      {
57          this.val = val;
58          this.desc = desc;
59      }
60  
61      /**
62       * @return The internet value
63       */
64      public int getVal()
65      {
66          return val;
67      }
68      
69      
70      /**
71       * returns the enum value representing the given code.
72       * 
73       * @param code the result code
74       * @return returns the corresponding ResultCode, throws IllegalArgumentException when there
75       *         is no matching ResultCode exists for the given value.
76       */
77      public static SortResultCode get( int code )
78      {
79          switch ( code )
80          {
81              case 0:
82                  return SUCCESS;
83  
84              case 1:
85                  return OPERATIONSERROR;
86  
87              case 3:
88                  return TIMELIMITEXCEEDED;
89                  
90              case 8:
91                  return STRONGAUTHREQUIRED;
92  
93              case 11:
94                  return ADMINLIMITEXCEEDED;
95                  
96              case 16:
97                  return NOSUCHATTRIBUTE;
98                  
99              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 }