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