8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts * Portions Copyrighted 2016 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.sm;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.locale.Locale;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.text.MessageFormat;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.ResourceBundle;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see java.lang.Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see java.lang.Throwable
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.all.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class InvalidAttributeValueException extends SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String resourceBundleName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String rbName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String attributeI18nKey;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String errCode;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs an <code>InvalidAttributeValueException</code> with no
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specified detail message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public InvalidAttributeValueException() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs an <code>InvalidAttributeValueException</code> with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specified detail message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param s
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the detail message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public InvalidAttributeValueException(String s) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super(s);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs an <code>InvalidAttributeValueException</code> with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specified error code. It can be used to pass localized error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param rbName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Resource Bundle name where localized error message is located.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param errorCode
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * error code or message id to be used for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>ResourceBundle.getString()</code> to locate error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * message
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param args
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * any arguments to be used for error message formatting
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>getMessage()</code> will construct error message using
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * English resource bundle.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public InvalidAttributeValueException(String rbName, String errorCode,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] args) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super(rbName, errorCode, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster resourceBundleName = rbName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster errCode = errorCode;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (args.length > 2) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.rbName = (String) args[1];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.attributeI18nKey = (String) args[2];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a localized error message
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Uses the locale object to create the appropriate localized
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * error message
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return localized error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getL10NMessage(java.util.Locale locale) {
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts String message;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts if ((resourceBundleName == null) || (locale == null) || (attributeI18nKey == null) || (rbName == null)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster message = super.getL10NMessage(locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts ResourceBundle bundle = amCache.getResBundle(resourceBundleName, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String mid = Locale.getString(bundle, errCode, debug);
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts ResourceBundle serviceResouceBundle = amCache.getResBundle(rbName, locale);
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts String localizedAttributeName = Locale.getString(serviceResouceBundle, attributeI18nKey, debug);
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts if (localizedAttributeName.equals(attributeI18nKey)) {
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts return super.getL10NMessage(locale);
cce3e5a486446fd128c721aab8a93d8ae03ef9c9James Phillpotts }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] argsEx = { localizedAttributeName };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster message = MessageFormat.format(mid, (Object[])argsEx);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return message;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}