View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin;
21  
22  import java.util.Properties;
23  
24  import org.xnap.pkg.PackageInfo;
25  import org.xnap.util.VersionParser;
26  
27  /***
28   * This class serves as a plugin information record.
29   */
30  public class PluginInfo extends PackageInfo
31  {
32  
33      //--- Constant(s) ---
34  
35      //--- Data field(s) ---
36  
37      private Plugin plugin;
38      private String type;
39      private boolean enabled = false;
40  	private boolean enableOnStartup = false;
41  	private boolean canDisable = true;
42  
43      //--- Constructor(s) ---
44  
45      /***
46  	 *
47       */
48      public PluginInfo(Properties props)
49      {
50  		super(props);
51  	}
52  
53      //--- Method(s) ---
54  
55  	public boolean areRequirementsSatisfied()
56  	{
57    		// compare jre version
58    		int requiredJRE 
59    			= VersionParser.compare(System.getProperty("java.version"), 
60    									getProperty("Required-JRE", "0"));
61    		return requiredJRE >= 0;
62  	}
63  
64  	/***
65  	 * Returns true, if the plugin can be disabled.
66  	 */
67  	public boolean canDisable()
68  	{
69  		return canDisable;
70  	}
71  
72      /***
73       * Returns the name of the authors of the plugin.
74       */
75      public String getAuthors()
76      {
77  		return getProperty("Authors", "");
78      }
79  
80      /***
81       * Returns the class name of the class that implements the 
82       * {@link org.xnap.plugin.Plugin Plugin} interface.
83       */
84      public String getClassName()
85      {
86  		return getProperty("Class-Name");
87      }
88  
89      /***
90       * Returns a short description of the plugin's functionality.
91       */
92      public String getDescription()
93      {
94  		return getProperty("Description", "");
95      }
96  
97  	public boolean getEnableOnStartup()
98  	{
99  		return enableOnStartup;
100 	}
101 
102     /***
103      * Returns the license plugin is published in.
104      */
105     public String getLicense()
106     {
107 		return getProperty("License", "");
108     }
109 
110 	public String getLicenseFilename()
111 	{
112 		String filename = getProperty("License-File", "");
113 		if (filename.length() == 0) {
114 			if (getLicense().equals("GPL")) {
115 				return "COPYING";
116 			}
117 			else if (getLicense().equals("LGPL")) {
118 				return "COPYING.LIB";
119 			}
120 		}
121 		return filename;
122 	}
123 
124     /***
125      * Returns a reference to the plugin.
126      *
127      * @return null, if plugin is not enabled
128      */
129     public Plugin getPlugin()
130     {
131 		return plugin;
132     }
133 
134     public String getSection()
135     {
136 		return getProperty("Section", "Other");
137     }
138 
139     /***
140      * Returns true, if plugin has been loaded and enabled.
141      */
142     public boolean isEnabled()
143     {
144 		return enabled;
145     }
146 
147     /***
148      * Returns true, if plugin has been loaded.
149      */
150     public boolean isLoaded()
151     {
152 		return getPlugin() != null;
153     }
154 
155 	public void setDisableable(boolean canDisable)
156 	{
157 		this.canDisable = canDisable;
158 	}
159 
160     /***
161      * Called by the {@link PluginManager} after the plugin has been
162      * successfully enabled.
163      */
164     public void setEnabled(boolean newValue)
165     {
166 		enabled = newValue;
167 		if (enabled) {
168 			enableOnStartup = true;
169 		}
170     }
171 
172     /***
173      * Called by the {@link xnap.gui.wizard.PluginWizardPanel}.
174      */
175     public void setEnableOnStartup(boolean newValue)
176     {
177 		enableOnStartup = newValue;
178     }
179 
180     /***
181      * Sets the reference to the instanciated plugin for this info record to
182      * <code>newValue</code>.
183      */
184     public void setPlugin(Plugin newValue)
185     {
186 		plugin = newValue;
187     }
188 
189     //--- Inner Class(es) ---
190 
191 }