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      private SortResultCode( int val, String desc )
56      {
57          this.val = val;
58          this.desc = desc;
59      }
60  
61      public int getVal()
62      {
63          return val;
64      }
65      
66      /**
67       * returns the enum value representing the given code.
68       * 
69       * @param code the result code
70       * @return returns the corresponding ResultCode, throws IllegalArgumentException when there
71       *         is no matching ResultCode exists for the given value.
72       */
73      public static SortResultCode get( int code )
74      {
75          switch ( code )
76          {
77              case 0:
78                  return SUCCESS;
79  
80              case 1:
81                  return OPERATIONSERROR;
82  
83              case 3:
84                  return TIMELIMITEXCEEDED;
85                  
86              case 8:
87                  return STRONGAUTHREQUIRED;
88  
89              case 11:
90                  return ADMINLIMITEXCEEDED;
91                  
92              case 16:
93                  return NOSUCHATTRIBUTE;
94                  
95              case 18:
96                  return INAPPROPRIATEMATCHING;
97                  
98              case 50:
99                  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 }