001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: AMException.java,v 1.7 2009/01/28 05:34:47 ww203982 Exp $ 026 * 027 */ 028 029package com.iplanet.am.sdk; 030 031import com.iplanet.sso.SSOToken; 032import com.iplanet.ums.UMSException; 033import com.sun.identity.shared.locale.L10NMessage; 034import java.text.MessageFormat; 035import java.util.Locale; 036import java.util.ResourceBundle; 037import com.sun.identity.shared.ldap.LDAPException; 038 039/** 040 * The <code>AMException</code> is thrown whenever an error is is encountered 041 * while performing an operation on the data store. 042 * 043 * @deprecated As of Sun Java System Access Manager 7.1. 044 * @supported.all.api 045 */ 046public class AMException extends Exception implements L10NMessage { 047 048 private static final long serialVersionUID = -660487903675407220L; 049 050 private String localizedMsg = null; 051 052 private String errorCode = null; 053 054 private Object args[] = null; 055 056 private LDAPException rootCause = null; 057 058 private String ldapErrorMsg = null; 059 060 private String ldapErrCode = null; 061 062 /** 063 * Constructs a new <code>AMException</code> with detailed message. 064 * 065 * @param msg 066 * The detailed message 067 * @param errorCode 068 * Matches the appropriate entry in 069 * <code>amProfile.properties</code>. 070 */ 071 public AMException(String msg, String errorCode) { 072 super(msg); 073 this.localizedMsg = msg; 074 this.errorCode = errorCode; 075 } 076 077 /** 078 * Convenience method (protected) 079 */ 080 public AMException(SSOToken token, String errorCode) { 081 this.localizedMsg = AMSDKBundle.getString(errorCode, AMCommonUtils 082 .getUserLocale(token)); 083 this.errorCode = errorCode; 084 } 085 086 /** 087 * Constructs a new <code>AMException</code> with detailed message. 088 * 089 * @param msg 090 * The detailed message. 091 * @param errorCode 092 * Matches the appropriate entry in 093 * <code>amProfile.properties</code>. 094 * @param ue 095 * if the root cause is a <code>UMSException</code>. 096 */ 097 public AMException(String msg, String errorCode, UMSException ue) { 098 try { 099 rootCause = (LDAPException) ue.getRootCause(); 100 ldapErrCode = Integer.toString(rootCause.getLDAPResultCode()); 101 ldapErrorMsg = AMSDKBundle.getString(ldapErrCode); 102 } catch (Exception e) { 103 } 104 if (ldapErrorMsg != null) { 105 localizedMsg = msg + "::" + ldapErrorMsg; 106 } else { 107 localizedMsg = msg; 108 } 109 this.errorCode = errorCode; 110 } 111 112 /** 113 * Constructs a new <code>AMException</code> with detailed message. 114 * 115 * @param token 116 * a valid single sign on token of the user performing the 117 * operation. 118 * @param errorCode 119 * Matches the appropriate entry in 120 * <code>amProfile.properties</code>. 121 * @param ue 122 * if the root cause is a <code>UMSException</code>. 123 */ 124 public AMException(SSOToken token, String errorCode, UMSException ue) { 125 try { 126 rootCause = (LDAPException) ue.getRootCause(); 127 ldapErrCode = Integer.toString(rootCause.getLDAPResultCode()); 128 ldapErrorMsg = AMSDKBundle.getString(ldapErrCode); 129 } catch (Exception e) { 130 } 131 String message = AMSDKBundle.getString(errorCode, AMCommonUtils 132 .getUserLocale(token)); 133 if (ldapErrorMsg != null) { 134 localizedMsg = message + "::" + ldapErrorMsg; 135 } else { 136 localizedMsg = message; 137 } 138 this.errorCode = errorCode; 139 } 140 141 /** 142 * Constructs a new <code>AMException</code> with detailed message. 143 * 144 * @param msg 145 * The detailed message. 146 * @param errorCode 147 * Matches the appropriate entry in 148 * <code>amProfile.properties</code>. 149 * @param args 150 * arguments if the error message needs specific values to be 151 * set. 152 */ 153 public AMException(String msg, String errorCode, Object[] args) { 154 super(msg); 155 this.localizedMsg = msg; 156 this.errorCode = errorCode; 157 this.args = args; 158 } 159 160 /** 161 * Constructs a new <code>AMException</code> with detailed message. 162 * 163 * @param msg 164 * The detailed message 165 * @param errorCode 166 * Matches the appropriate entry in 167 * <code>amProfile.properties</code>. 168 * @param args 169 * if the error message needs specific values to be set. 170 * @param ue 171 * if the root cause is a <code>UMSException</code>. 172 */ 173 public AMException(String msg, String errorCode, Object args[], 174 UMSException ue) { 175 try { 176 rootCause = (LDAPException) ue.getRootCause(); 177 ldapErrCode = Integer.toString(rootCause.getLDAPResultCode()); 178 ldapErrorMsg = AMSDKBundle.getString(ldapErrCode); 179 } catch (Exception e) { 180 // Ignore 181 } 182 if (ldapErrorMsg != null) { 183 localizedMsg = msg + "::" + ldapErrorMsg; 184 } else { 185 localizedMsg = msg; 186 } 187 this.errorCode = errorCode; 188 this.args = args; 189 } 190 191 /** 192 * Returns the error code. This error code can be used with the arguments to 193 * construct a localized message. 194 * 195 * @return the error code which can be used to map the message to a user 196 * specific locale. 197 */ 198 public String getErrorCode() { 199 return errorCode; 200 } 201 202 /** 203 * Returns the arguments corresponding to the error code. 204 * 205 * @return the arguments corresponding to the error code or null if no 206 * arguments are need to construct the message. 207 */ 208 public Object[] getMessageArgs() { 209 return args; 210 } 211 212 /** 213 * Overrides the default <code>getMessage()</code> method of super class 214 * Exception. 215 * 216 * @return The error message string. 217 */ 218 public String getMessage() { 219 return localizedMsg; 220 } 221 222 /** 223 * Method to obtain the LDAP error code. 224 * 225 * @return The error code, which can be used to map the message to a 226 * specific locale. Returns a null, if not an LDAP error. 227 */ 228 public String getLDAPErrorCode() { 229 return ldapErrCode; 230 } 231 232 /** 233 * Returns the root <code>LDAPException</code> of this 234 * <code>AMException</code>, if any. 235 * 236 * @return The <code>LDAPException</code> that caused this 237 * <code>AMException</code>. If null, it means no root 238 * <code>LDAPException</code> has been set. 239 */ 240 public LDAPException getLDAPException() { 241 return rootCause; 242 } 243 244 /** 245 * Returns localized error message. 246 * 247 * @param locale 248 * locale of the error message. 249 * @return Localized error message. 250 */ 251 public String getL10NMessage(Locale locale) { 252 String result = errorCode; 253 if (locale != null) { 254 ResourceBundle rb = AMSDKBundle.getBundleFromHash(locale); 255 String mid = com.sun.identity.shared.locale.Locale.getString( 256 rb, errorCode, AMCommonUtils.debug); 257 result = ((args == null) || (args.length == 0)) ? mid 258 : MessageFormat.format(mid, args); 259 } 260 return result; 261 } 262 263 /** 264 * Returns ResourceBundle Name associated with this exception 265 * 266 * @return ResourceBundle Name associated with this exception. 267 */ 268 public String getResourceBundleName() { 269 return AMSDKBundle.BUNDLE_NAME; 270 } 271}
Copyright © 2010-2017, ForgeRock All Rights Reserved.