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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.quicksetup;
028import org.forgerock.i18n.LocalizableMessage;
029
030import org.opends.server.types.OpenDsException;
031
032/**
033 * This exception is used to encapsulate all the error that we might have
034 * during the installation.
035 *
036 * @see org.opends.quicksetup.installer.Installer
037 * @see org.opends.quicksetup.installer.offline.OfflineInstaller
038 */
039public class ApplicationException extends OpenDsException {
040
041  private static final long serialVersionUID = -3527273444231560341L;
042
043  private ReturnCode type;
044
045  /**
046   * Creates a new ApplicationException of type FILE_SYSTEM_ERROR.
047   * @param msg localized exception message
048   * @param e Exception cause
049   * @return ApplicationException with Type property being FILE_SYSTEM_ERROR
050   */
051  public static ApplicationException createFileSystemException(LocalizableMessage msg,
052      Exception e)
053  {
054    return new ApplicationException(ReturnCode.FILE_SYSTEM_ACCESS_ERROR,
055        msg, e);
056  }
057
058  /**
059   * The constructor of the ApplicationException.
060   *
061   * @param type
062   *          the type of error we have.
063   * @param localizedMsg
064   *          a localized string describing the problem.
065   * @param rootCause
066   *          the root cause of this exception.
067   */
068  public ApplicationException(ReturnCode type, LocalizableMessage localizedMsg,
069                              Throwable rootCause)
070  {
071    super(localizedMsg, rootCause);
072    this.type = type;
073  }
074
075  /**
076   * Returns the Type of this exception.
077   * @return the Type of this exception.
078   */
079  public ReturnCode getType()
080  {
081    return type;
082  }
083
084  /** {@inheritDoc} */
085  public String toString()
086  {
087    return getMessage();
088  }
089}