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         * A component did not initialize properly.
105         */
106        INITIALIZATION_EXCEPTION
107    }
108
109    private PluginIssueCode _code;
110    private String _message;
111    private String _pluginName;
112    private String _featureName;
113    private String _location;
114    private Exception _cause;
115    
116    PluginIssue(String pluginName, String featureName, PluginIssueCode code, String location, String message)
117    {
118        _pluginName = pluginName;
119        _featureName = featureName;
120        _code = code;
121        _location = location;
122        _message = message;
123    }
124    
125    PluginIssue(String pluginName, String featureName, PluginIssueCode code, String location, String message, Exception cause)
126    {
127        _pluginName = pluginName;
128        _featureName = featureName;
129        _code = code;
130        _location = location;
131        _message = message;
132        _cause = cause;
133    }
134    
135    /**
136     * Returns the code associated with this issue.
137     * @return the code associated with this issue.
138     */
139    public PluginIssueCode getCode()
140    {
141        return _code;
142    }
143    
144    /**
145     * Returns the message associated with this issue.
146     * @return the message associated with this issue.
147     */
148    public String getMessage()
149    {
150        return _message;
151    }
152    
153    /**
154     * Returns the plugin name associated with this issue, if any.
155     * @return the plugin name associated with this issue, if any.
156     */
157    public String getPluginName()
158    {
159        return _pluginName;
160    }
161    
162    /**
163     * Returns the feature name associated with this issue, if any.
164     * @return the feature name associated with this issue, if any.
165     */
166    public String getFeatureName()
167    {
168        return _featureName;
169    }
170    
171    /**
172     * Returns the location of this issue, if any.
173     * @return the location of this issue, if any.
174     */
175    public String getLocation()
176    {
177        return _location;
178    }
179    
180    /**
181     * Returns the cause of this issue, if any.
182     * @return the cause of this issue, if any.
183     */
184    public Exception getCause()
185    {
186        return _cause;
187    }
188    
189    @Override
190    public String toString()
191    {
192        return "[" + _code.toString() + (_location != null ? ", " + _location : "") + "] " + _message + (_cause != null ? (" (" + _cause.getMessage() + ")") : "");
193    }
194}