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 2008 Sun Microsystems, Inc. 026 */ 027 028 package org.opends.admin.ads; 029 030 import org.opends.messages.Message; 031 import org.opends.server.types.OpenDsException; 032 033 034 /** 035 * This is the exception that is thrown in ADSContext. 036 * @see org.opends.admin.ads.ADSContext 037 * 038 */ 039 public class ADSContextException extends OpenDsException { 040 041 private static final long serialVersionUID = 1984039711031042813L; 042 043 private String toString; 044 045 /** 046 * The enumeration containing the different error types. 047 * 048 */ 049 public enum ErrorType 050 { 051 /** 052 * The host name is missing. 053 */ 054 MISSING_HOSTNAME(), 055 /** 056 * The host name is not valid. 057 */ 058 NOVALID_HOSTNAME(), 059 /** 060 * The installation path is missing. 061 */ 062 MISSING_IPATH(), 063 /** 064 * The installation path is not valid. 065 */ 066 NOVALID_IPATH(), 067 /** 068 * An access permission error. 069 */ 070 ACCESS_PERMISSION(), 071 /** 072 * The entity is already registered. 073 */ 074 ALREADY_REGISTERED(), 075 /** 076 * The installation is broken. 077 */ 078 BROKEN_INSTALL(), 079 /** 080 * The entity is not yet registered. 081 */ 082 NOT_YET_REGISTERED(), 083 /** 084 * The port is missing. 085 */ 086 MISSING_PORT(), 087 /** 088 * The port is not valid. 089 */ 090 NOVALID_PORT(), 091 /** 092 * The name is missing. 093 */ 094 MISSING_NAME(), 095 /** 096 * The administration UID is missing. 097 */ 098 MISSING_ADMIN_UID(), 099 /** 100 * The administrator password is missing. 101 */ 102 MISSING_ADMIN_PASSWORD(), 103 /** 104 * There is already a backend with the name of the ADS backend but not 105 * of the expected type. 106 */ 107 UNEXPECTED_ADS_BACKEND_TYPE(), 108 /** 109 * Unexpected error (potential bug). 110 */ 111 ERROR_UNEXPECTED(); 112 }; 113 114 ErrorType error; 115 Throwable embeddedException; 116 117 /** 118 * Creates an ADSContextException of the given error type. 119 * @param error the error type. 120 */ 121 public ADSContextException(ErrorType error) 122 { 123 this.error = error; 124 } 125 126 /** 127 * Creates an ADSContextException of the given error type with the provided 128 * error cause. 129 * @param error the error type. 130 * @param x the throwable that generated this exception. 131 */ 132 public ADSContextException(ErrorType error, Throwable x) 133 { 134 this.error = error; 135 this.embeddedException = x; 136 } 137 138 /** 139 * Returns the error type of this exception. 140 * @return the error type of this exception. 141 */ 142 public ErrorType getError() 143 { 144 return error; 145 } 146 147 /** 148 * Returns the throwable that caused this exception. It might be null. 149 * @return the throwable that caused this exception. 150 */ 151 public Throwable getCause() 152 { 153 return embeddedException; 154 } 155 156 /** 157 * Retrieves a message providing the reason for this exception. 158 * 159 * @return A message providing the reason for this exception. 160 */ 161 public Message getReason() 162 { 163 if (toString == null) 164 { 165 toString = "ADSContextException: error type "+error+"."; 166 if (getCause() != null) 167 { 168 toString += " Root cause: "+getCause().toString(); 169 } 170 } 171 return Message.raw(toString); // TODO: i18n 172 } 173 174 /** 175 * {@inheritDoc} 176 */ 177 public void printStackTrace() 178 { 179 super.printStackTrace(); 180 if (embeddedException != null) 181 { 182 System.out.println("embeddedException = {"); 183 embeddedException.printStackTrace(); 184 System.out.println("}"); 185 } 186 } 187 }