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: InvalidAttributeValueException.java,v 1.6 2008/06/25 05:44:04 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.sm; 030 031import com.sun.identity.shared.locale.Locale; 032import java.text.MessageFormat; 033import java.util.ResourceBundle; 034 035 036/** 037 * @see java.lang.Exception 038 * @see java.lang.Throwable 039 * 040 * @supported.all.api 041 */ 042public class InvalidAttributeValueException extends SMSException { 043 private String resourceBundleName; 044 045 private String rbName; 046 047 private String attributeI18nKey; 048 049 private String errCode; 050 051 /** 052 * Constructs an <code>InvalidAttributeValueException</code> with no 053 * specified detail message. 054 */ 055 public InvalidAttributeValueException() { 056 super(); 057 } 058 059 /** 060 * Constructs an <code>InvalidAttributeValueException</code> with the 061 * specified detail message. 062 * 063 * @param s 064 * the detail message. 065 */ 066 public InvalidAttributeValueException(String s) { 067 super(s); 068 } 069 070 /** 071 * Constructs an <code>InvalidAttributeValueException</code> with the 072 * specified error code. It can be used to pass localized error message. 073 * 074 * @param rbName 075 * Resource Bundle name where localized error message is located. 076 * @param errorCode 077 * error code or message id to be used for 078 * <code>ResourceBundle.getString()</code> to locate error 079 * message 080 * @param args 081 * any arguments to be used for error message formatting 082 * <code>getMessage()</code> will construct error message using 083 * English resource bundle. 084 */ 085 public InvalidAttributeValueException(String rbName, String errorCode, 086 Object[] args) { 087 super(rbName, errorCode, args); 088 resourceBundleName = rbName; 089 errCode = errorCode; 090 091 if (args.length > 2) { 092 this.rbName = (String) args[1]; 093 this.attributeI18nKey = (String) args[2]; 094 } 095 } 096 097 /** 098 * Returns a localized error message 099 * 100 * @param locale 101 * Uses the locale object to create the appropriate localized 102 * error message 103 * @return localized error message. 104 */ 105 public String getL10NMessage(java.util.Locale locale) { 106 String message = errCode; 107 108 if ((resourceBundleName == null) || (locale == null) 109 || (attributeI18nKey == null) || (rbName == null)) { 110 message = super.getL10NMessage(locale); 111 } else { 112 ResourceBundle bundle = amCache.getResBundle(resourceBundleName, 113 locale); 114 String mid = Locale.getString(bundle, errCode, debug); 115 ResourceBundle serviceResouceBundle = amCache.getResBundle(rbName, 116 locale); 117 String localizedAttributeName = Locale.getString( 118 serviceResouceBundle, attributeI18nKey, debug); 119 String[] argsEx = { localizedAttributeName }; 120 message = MessageFormat.format(mid, (Object[])argsEx); 121 } 122 123 return message; 124 } 125}