001/*
002 *  Copyright 2015 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.runtime.plugin;
017
018import java.util.Collection;
019
020/**
021 * Exception thrown by the {@link PluginsManager} when plugins loading fails.<br>
022 * It is only the case when the safe mode itself fails to load.
023 */
024public class PluginException extends RuntimeException
025{
026    private Collection<PluginIssue> _errors;
027    private Collection<PluginIssue> _safeModeErrors;
028    
029    /**
030     * Constructor.
031     * @param message the detail message.
032     * @param errors the errors gathered by the PluginsManager while loading plugins
033     * @param safeModeErrors the errors gathered by the PluginsManager while loading the safe mode.
034     */
035    public PluginException(String message, Collection<PluginIssue> errors, Collection<PluginIssue> safeModeErrors)
036    {
037        super(message);
038        _errors = errors;
039        _safeModeErrors = safeModeErrors;
040    }
041    
042    /**
043     * Constructor.
044     * @param message the detail message.
045     * @param cause the cause, if any.
046     * @param errors the errors gathered by the PluginsManager while loading plugins
047     * @param safeModeErrors the errors gathered by the PluginsManager while loading the safe mode.
048     */
049    public PluginException(String message, Throwable cause, Collection<PluginIssue> errors, Collection<PluginIssue> safeModeErrors)
050    {
051        super(message, cause);
052        _errors = errors;
053        _safeModeErrors = safeModeErrors;
054    }
055    
056    /**
057     * Returns errors gathered by the PluginsManager while loading plugins.
058     * @return errors gathered by the PluginsManager while loading plugins.
059     */
060    public Collection<PluginIssue> getErrors()
061    {
062        return _errors;
063    }
064    
065    /**
066     * Returns errors gathered by the PluginsManager while loading the safe mode.
067     * @return errors gathered by the PluginsManager while loading the safe mode.
068     */
069    public Collection<PluginIssue> getSafeModeErrors()
070    {
071        return _safeModeErrors;
072    }
073}