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 021 package org.apache.directory.server.changepw.exceptions; 022 023 024 import java.util.Arrays; 025 import java.util.Collections; 026 import java.util.List; 027 028 029 /** 030 * Type safe enumeration of Change Password error types 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 * @version $Rev: 902331 $ 034 */ 035 public final class ErrorType implements Comparable<ErrorType> 036 { 037 // TODO Add i18n. Don't no if these error messages are also a response to the client. 038 // If so shall they really be i18n? 039 040 /** 041 * Constant for the "Request failed due to being malformed" error type. 042 */ 043 public static final ErrorType KRB5_KPASSWD_MALFORMED = new ErrorType( 1, "Request failed due to being malformed." ); 044 045 /** 046 * Constant for the "Request failed due to a hard error in processing the request" error type. 047 */ 048 public static final ErrorType KRB5_KPASSWD_HARDERROR = new ErrorType( 2, 049 "Request failed due to a hard error in processing the request." ); 050 051 /** 052 * Constant for the "Request failed due to an error in authentication processing" error type. 053 */ 054 public static final ErrorType KRB5_KPASSWD_AUTHERROR = new ErrorType( 3, 055 "Request failed due to an error in authentication processing." ); 056 057 /** 058 * Constant for the "Request failed due to a soft error in processing the request" error type. 059 */ 060 public static final ErrorType KRB5_KPASSWD_SOFTERROR = new ErrorType( 4, 061 "Request failed due to a soft error in processing the request." ); 062 063 /** 064 * Constant for the "Requestor not authorized" error type. 065 */ 066 public static final ErrorType KRB5_KPASSWD_ACCESSDENIED = new ErrorType( 5, "Requestor not authorized." ); 067 068 /** 069 * Constant for the "Protocol version unsupported" error type. 070 */ 071 public static final ErrorType KRB5_KPASSWD_BAD_VERSION = new ErrorType( 6, "Protocol version unsupported." ); 072 073 /** 074 * Constant for the "Initial flag required" error type. 075 */ 076 public static final ErrorType KRB5_KPASSWD_INITIAL_FLAG_NEEDED = new ErrorType( 7, "Initial flag required." ); 077 078 /** 079 * Constant for the "Request failed for an unknown reason" error type. 080 */ 081 public static final ErrorType KRB5_KPASSWD_UNKNOWN_ERROR = new ErrorType( 8, 082 "Request failed for an unknown reason." ); 083 084 /** 085 * Array for building a List of VALUES. 086 */ 087 private static final ErrorType[] values = 088 { KRB5_KPASSWD_MALFORMED, KRB5_KPASSWD_HARDERROR, KRB5_KPASSWD_AUTHERROR, KRB5_KPASSWD_SOFTERROR, 089 KRB5_KPASSWD_ACCESSDENIED, KRB5_KPASSWD_BAD_VERSION, KRB5_KPASSWD_INITIAL_FLAG_NEEDED, 090 KRB5_KPASSWD_UNKNOWN_ERROR }; 091 092 /** 093 * A list of all the error type constants. 094 */ 095 public static final List<ErrorType> VALUES = Collections.unmodifiableList( Arrays.asList( values ) ); 096 097 /** 098 * The name of the error type. 099 */ 100 private final String name; 101 102 /** 103 * The value/code for the error type. 104 */ 105 private final int ordinal; 106 107 108 /** 109 * Private constructor prevents construction outside of this class. 110 */ 111 private ErrorType( int ordinal, String name ) 112 { 113 this.ordinal = ordinal; 114 this.name = name; 115 } 116 117 118 /** 119 * Returns the message for this Change Password error. 120 * 121 * @return the message for this Change Password error. 122 */ 123 public String getMessage() 124 { 125 return name; 126 } 127 128 129 /** 130 * Returns the message for this Change Password error. 131 * 132 * @return the message for this Change Password error. 133 */ 134 public String toString() 135 { 136 return name; 137 } 138 139 140 /** 141 * Compares this type to another object hopefully one that is of the same 142 * type. 143 * 144 * @param that the object to compare this ErrorType to 145 * @return ordinal - that.ordinal; 146 */ 147 public int compareTo( ErrorType that ) 148 { 149 return this.ordinal - that.ordinal; 150 } 151 152 153 /** 154 * Gets the ordinal by its ordinal value. 155 * 156 * @param ordinal the ordinal value of the ordinal 157 * @return the type corresponding to the ordinal value 158 */ 159 public static ErrorType getTypeByOrdinal( int ordinal ) 160 { 161 for ( int ii = 0; ii < values.length; ii++ ) 162 { 163 if ( values[ii].ordinal == ordinal ) 164 { 165 return values[ii]; 166 } 167 } 168 169 return KRB5_KPASSWD_UNKNOWN_ERROR; 170 } 171 172 173 /** 174 * Gets the ordinal value associated with this Change Password error. 175 * 176 * @return the ordinal value associated with this Change Password error 177 */ 178 public int getOrdinal() 179 { 180 return ordinal; 181 } 182 }