001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.admin.client.cli; 028 import org.opends.messages.Message; 029 030 import static org.opends.messages.AdminMessages.*; 031 032 033 import java.util.HashMap; 034 035 import org.opends.admin.ads.ADSContextException.ErrorType; 036 037 /** 038 * 039 * The enumeration which defines the return code. 040 * 041 */ 042 public enum DsFrameworkCliReturnCode 043 { 044 /** 045 * successful. 046 */ 047 SUCCESSFUL(0, INFO_ADMIN_SUCCESSFUL.get()), 048 049 /** 050 * successful but no operation was performed. 051 */ 052 SUCCESSFUL_NOP(SUCCESSFUL.getReturnCode(), INFO_ADMIN_SUCCESSFUL_NOP.get()), 053 054 /** 055 * Unable to initialize arguments. 056 */ 057 CANNOT_INITIALIZE_ARGS(1, ERR_ADMIN_NO_MESSAGE.get()), 058 059 /** 060 * Cannot parse arguments. 061 */ 062 ERROR_PARSING_ARGS(2, ERR_ADMIN_NO_MESSAGE.get()), 063 /** 064 * Return code: Cannot get the connection to the ADS. 065 */ 066 CANNOT_CONNECT_TO_ADS(3, ERR_ADMIN_NO_MESSAGE.get()), 067 068 /** 069 * The host name is missing. 070 */ 071 MISSING_HOSTNAME(4, ERR_ADMIN_MISSING_HOSTNAME.get()), 072 073 /** 074 * The host name is not valid. 075 */ 076 NOVALID_HOSTNAME(5, ERR_ADMIN_NOVALID_HOSTNAME.get()), 077 078 /** 079 * The installation path is missing. 080 */ 081 MISSING_IPATH(6, ERR_ADMIN_MISSING_IPATH.get()), 082 083 /** 084 * The installation path is not valid. 085 */ 086 NOVALID_IPATH(7, ERR_ADMIN_NOVALID_IPATH.get()), 087 088 /** 089 * An access permission error. 090 */ 091 ACCESS_PERMISSION(8, ERR_ADMIN_ACCESS_PERMISSION.get()), 092 093 /** 094 * The entity is already registered. 095 */ 096 ALREADY_REGISTERED(9, ERR_ADMIN_ALREADY_REGISTERED.get()), 097 098 /** 099 * The installation is broken. 100 */ 101 BROKEN_INSTALL(10, ERR_ADMIN_BROKEN_INSTALL.get()), 102 103 /** 104 * The entity is not yet registered. 105 */ 106 NOT_YET_REGISTERED(11, ERR_ADMIN_NOT_YET_REGISTERED.get()), 107 108 /** 109 * The port is missing. 110 */ 111 MISSING_PORT(12, ERR_ADMIN_MISSING_PORT.get()), 112 113 /** 114 * The port is not valid. 115 */ 116 NOVALID_PORT(13, ERR_ADMIN_NOVALID_PORT.get()), 117 118 /** 119 * The name is missing. 120 */ 121 MISSING_NAME(14, ERR_ADMIN_MISSING_NAME.get()), 122 123 /** 124 * The administration UID is missing. 125 */ 126 MISSING_ADMIN_UID(15, ERR_ADMIN_MISSING_ADMIN_UID.get()), 127 128 /** 129 * The administrator password is missing. 130 */ 131 MISSING_ADMIN_PASSWORD(16, ERR_ADMIN_MISSING_ADMIN_PASSWORD.get()), 132 133 /** 134 * Unexpected error (potential bug). 135 */ 136 ERROR_UNEXPECTED(17, ERR_ADMIN_ERROR_UNEXPECTED.get()), 137 138 /** 139 * Unexpected error (potential bug). 140 */ 141 CONFLICTING_ARGS(18, ERR_ADMIN_NO_MESSAGE.get()), 142 143 /** 144 * The server entity is not yet registered. 145 */ 146 SERVER_NOT_REGISTERED(19, ERR_ADMIN_SERVER_NOT_REGISTERED.get()); 147 148 // The retunCodevalue of the value. 149 private final int returnCode; 150 151 // The message id to be used of the value. 152 private final Message message; 153 154 // Private constructor. 155 private DsFrameworkCliReturnCode(int returnCode, Message message) 156 { 157 this.returnCode = returnCode; 158 this.message = message; 159 } 160 161 /** 162 * Get the corresponding message. 163 * 164 * @return The corresponding message. 165 */ 166 public Message getMessage() 167 { 168 return message; 169 } 170 171 /** 172 * Get the corresponding return code value. 173 * 174 * @return The corresponding return code value. 175 */ 176 public int getReturnCode() 177 { 178 return returnCode; 179 } 180 181 /** 182 * Indicate whenever the association between ADS errors and return 183 * has been done. 184 */ 185 private static boolean initialized = false ; 186 187 /** 188 * The association map between ADS Error and Return code. 189 */ 190 private static HashMap<ErrorType, DsFrameworkCliReturnCode> 191 adsErrorToReturnCode = new HashMap<ErrorType, DsFrameworkCliReturnCode>(); 192 193 /** 194 * Associates a set of ADS errors to return code. 195 */ 196 private static void registerAdsError() 197 { 198 adsErrorToReturnCode.put(ErrorType.MISSING_HOSTNAME, 199 MISSING_HOSTNAME); 200 adsErrorToReturnCode.put(ErrorType.NOVALID_HOSTNAME, 201 NOVALID_HOSTNAME); 202 adsErrorToReturnCode.put(ErrorType.MISSING_IPATH, 203 MISSING_IPATH); 204 adsErrorToReturnCode.put(ErrorType.NOVALID_IPATH, 205 NOVALID_IPATH); 206 adsErrorToReturnCode.put(ErrorType.ACCESS_PERMISSION, 207 ACCESS_PERMISSION); 208 adsErrorToReturnCode.put(ErrorType.ALREADY_REGISTERED, 209 ALREADY_REGISTERED); 210 adsErrorToReturnCode.put(ErrorType.BROKEN_INSTALL, 211 BROKEN_INSTALL); 212 adsErrorToReturnCode.put(ErrorType.UNEXPECTED_ADS_BACKEND_TYPE, 213 BROKEN_INSTALL); 214 adsErrorToReturnCode.put(ErrorType.NOT_YET_REGISTERED, 215 NOT_YET_REGISTERED); 216 adsErrorToReturnCode.put(ErrorType.MISSING_PORT, 217 MISSING_PORT); 218 adsErrorToReturnCode.put(ErrorType.NOVALID_PORT, 219 NOVALID_PORT); 220 adsErrorToReturnCode.put(ErrorType.MISSING_NAME, 221 MISSING_NAME); 222 adsErrorToReturnCode.put(ErrorType.MISSING_ADMIN_UID, 223 MISSING_ADMIN_UID); 224 adsErrorToReturnCode.put(ErrorType.MISSING_ADMIN_PASSWORD, 225 MISSING_ADMIN_PASSWORD); 226 adsErrorToReturnCode.put(ErrorType.ERROR_UNEXPECTED, 227 ERROR_UNEXPECTED); 228 } 229 230 /** 231 * Get ReturnCode from an ADS error. 232 * @param error The ADS error 233 * @return the ReturnCode associated to the ADS error. 234 */ 235 public static DsFrameworkCliReturnCode 236 getReturncodeFromAdsError(ErrorType error) 237 { 238 if (! initialized) 239 { 240 registerAdsError(); 241 initialized = true ; 242 } 243 return adsErrorToReturnCode.get(error); 244 } 245 } 246 247