001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyrighted [year] [name of copyright owner]".
013 *
014 *      Copyright 2009 Sun Microsystems, Inc.
015 *      Portions copyright 2011 ForgeRock AS
016 */
017
018package org.forgerock.i18n;
019
020/**
021 * Thrown to indicate that a method has been passed an illegal or inappropriate
022 * argument.
023 * <p>
024 * A {@code LocalizedIllegalArgumentException} contains a localized error
025 * message which may be used to provide the user with detailed diagnosis
026 * information. The localized message can be retrieved using the
027 * {@link #getMessageObject} method.
028 */
029public class LocalizedIllegalArgumentException extends IllegalArgumentException
030        implements LocalizableException {
031
032    /**
033     * Generated serialization ID.
034     */
035    private static final long serialVersionUID = -8512235024837904757L;
036
037    // The I18N message associated with this exception.
038    private final LocalizableMessage message;
039
040    /**
041     * Creates a new localized illegal argument exception with the provided
042     * message.
043     *
044     * @param message
045     *            The message that explains the problem that occurred.
046     */
047    public LocalizedIllegalArgumentException(final LocalizableMessage message) {
048        super(String.valueOf(message));
049        this.message = message;
050    }
051
052    /**
053     * Creates a new localized illegal argument exception with the provided
054     * message and cause.
055     *
056     * @param message
057     *            The message that explains the problem that occurred.
058     * @param cause
059     *            The cause which may be later retrieved by the
060     *            {@link #getCause} method. A {@code null} value is permitted,
061     *            and indicates that the cause is nonexistent or unknown.
062     */
063    public LocalizedIllegalArgumentException(final LocalizableMessage message,
064            final Throwable cause) {
065        super(String.valueOf(message), cause);
066        this.message = message;
067    }
068
069    /**
070     * {@inheritDoc}
071     */
072    public final LocalizableMessage getMessageObject() {
073        return this.message;
074    }
075}