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
018/**
019 * Represents an issue while initializing the plugin system.
020 */
021public class PluginIssue
022{
023    /**
024     * Issue code enumeration.
025     */
026    public enum PluginIssueCode
027    {
028        /**
029         * A plugin referenced in a jar file has no corresponding plugin.xml
030         */
031        BUNDLED_PLUGIN_NOT_PRESENT, 
032        
033        /**
034         * The plugin name does not match the regexp.
035         */
036        PLUGIN_NAME_INVALID, 
037        
038        /**
039         * There's no plugin.xml in the specified directory.
040         */
041        PLUGIN_NOFILE,
042        
043        /**
044         * A plugin with this name is already declared.
045         */
046        PLUGIN_NAME_EXIST, 
047        
048        /**
049         * A plugin.xml is not valid against the schema.
050         */
051        CONFIGURATION_UNREADABLE, 
052
053        /**
054         * An extension point is already declared in another plugin.
055         */
056        EXTENSIONPOINT_ALREADY_EXIST,
057        
058        /**
059         * An extension to the same point is alredy declared with the same id.
060         */
061        EXTENSION_ALREADY_EXIST, 
062        
063        /**
064         * A component with the same role is alredy declared.
065         */
066        COMPONENT_ALREADY_EXIST,
067        
068        /**
069         * A class referenced by an extension point, extension or component does not exist.
070         */
071        CLASSNOTFOUND, 
072        
073        /**
074         * An extension point's class does not implement {@link ExtensionPoint}.
075         */
076        EXTENSIONPOINT_CLASS_INVALID, 
077        
078        /**
079         * A component role is required to point to a specific component id which doesn't actually exist.
080         */
081        COMPONENT_NOT_DECLARED, 
082        
083        /**
084         * Circular dependency detected on a feature.
085         */
086        CIRCULAR_DEPENDENCY, 
087        
088        /**
089         * Unable to load an external configuration file.
090         */
091        EXTERNAL_CONFIGURATION, 
092        
093        /**
094         * The application Init class does not implement {@link Init}.
095         */
096        INIT_CLASS_INVALID, 
097        
098        /**
099         * An extension refers to a non-existing point.
100         */
101        INVALID_POINT
102    }
103
104    private PluginIssueCode _code;
105    private String _message;
106    private String _pluginName;
107    private String _featureName;
108    private String _location;
109    private Exception _cause;
110    
111    PluginIssue(String pluginName, String featureName, PluginIssueCode code, String location, String message)
112    {
113        _pluginName = pluginName;
114        _featureName = featureName;
115        _code = code;
116        _location = location;
117        _message = message;
118    }
119    
120    PluginIssue(String pluginName, String featureName, PluginIssueCode code, String location, String message, Exception cause)
121    {
122        _pluginName = pluginName;
123        _featureName = featureName;
124        _code = code;
125        _location = location;
126        _message = message;
127        _cause = cause;
128    }
129    
130    /**
131     * Returns the code associated with this issue.
132     * @return the code associated with this issue.
133     */
134    public PluginIssueCode getCode()
135    {
136        return _code;
137    }
138    
139    /**
140     * Returns the message associated with this issue.
141     * @return the message associated with this issue.
142     */
143    public String getMessage()
144    {
145        return _message;
146    }
147    
148    /**
149     * Returns the plugin name associated with this issue, if any.
150     * @return the plugin name associated with this issue, if any.
151     */
152    public String getPluginName()
153    {
154        return _pluginName;
155    }
156    
157    /**
158     * Returns the feature name associated with this issue, if any.
159     * @return the feature name associated with this issue, if any.
160     */
161    public String getFeatureName()
162    {
163        return _featureName;
164    }
165    
166    /**
167     * Returns the location of this issue, if any.
168     * @return the location of this issue, if any.
169     */
170    public String getLocation()
171    {
172        return _location;
173    }
174    
175    /**
176     * Returns the cause of this issue, if any.
177     * @return the cause of this issue, if any.
178     */
179    public Exception getCause()
180    {
181        return _cause;
182    }
183    
184    @Override
185    public String toString()
186    {
187        return "[" + _code.toString() + (_location != null ? ", " + _location : "") + "] " + _message + (_cause != null ? (" (" + _cause.getMessage() + ")") : "");
188    }
189}