001/*
002 *  Copyright 2018 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.linkdirectory.dynamic;
017
018/**
019 * Common exception for dynamic information
020 */
021public class DynamicInformationException extends RuntimeException
022{
023    /**
024     * Enum for type of exception
025     */
026    public enum ExceptionType
027    {
028        /** The connection is not authorized */
029        UNAUTHORIZED,
030        /** Connection timed out */
031        TIMEOUT,
032        /** Configuration exception (unknown host, host unreachable, 404, ...) */
033        CONFIGURATION_EXCEPTION,
034        /** Nothing defined */
035        UNKNOWN;
036    }
037    
038    private ExceptionType _type = ExceptionType.UNKNOWN;
039    
040    /**
041     * Constructs a new exception with the specified detail message.
042     * @param message the detail message.
043     */
044    public DynamicInformationException(String message)
045    {
046        this(message, ExceptionType.UNKNOWN);
047    }
048    
049    /**
050     * Constructs a new exception with the specified detail message.
051     * @param message the detail message.
052     * @param type reason of the exception
053     */
054    public DynamicInformationException(String message, ExceptionType type)
055    {
056        super(message);
057        this._type = type;
058    }
059
060    /**
061     * Constructs a new exception with the specified detail message and cause.
062     * @param message the detail message.
063     * @param cause the cause.
064     */
065    public DynamicInformationException(String message, Throwable cause)
066    {
067        this(message, ExceptionType.UNKNOWN, cause);
068    }
069    
070    /**
071     * Constructs a new exception with the specified detail message and cause.
072     * @param message the detail message.
073     * @param type reason of the exception
074     * @param cause the cause.
075     */
076    public DynamicInformationException(String message, ExceptionType type, Throwable cause)
077    {
078        super(message, cause);
079        this._type = type;
080    }
081
082    /**
083     * Constructs a new exception with the specified cause.
084     * @param cause the specified cause.
085     */
086    public DynamicInformationException(Throwable cause)
087    {
088        this(ExceptionType.UNKNOWN, cause);
089    }
090
091    /**
092     * Constructs a new exception with the specified cause.
093     * @param type reason of the exception
094     * @param cause the specified cause.
095     */
096    public DynamicInformationException(ExceptionType type, Throwable cause)
097    {
098        super(cause);
099        this._type = type;
100    }
101    
102    /**
103     * Get the type of exception
104     * @return {@link ExceptionType}
105     */
106    public ExceptionType getType()
107    {
108        return _type;
109    }
110}