10 |
|
|
11 |
|
class PluginFilterManager { |
12 |
|
|
13 |
– |
// public method to return an instance of a PluginFilterManager, |
14 |
– |
// as this class is a singleton. |
15 |
– |
public static PluginFilterManager init() throws AlreadyInitialisedException { |
16 |
– |
if (_instance != null){ |
17 |
– |
throw new AlreadyInitialisedException("init() has already been called."); |
18 |
– |
} |
19 |
– |
_instance = new PluginFilterManager(); |
20 |
– |
return _instance; |
21 |
– |
} |
22 |
– |
|
13 |
|
// Return a reference to the single class. |
14 |
+ |
// Construct it if it does not already exist, otherwise just return the reference. |
15 |
|
public static PluginFilterManager getInstance() throws NotInitialisedException { |
16 |
|
if (_instance == null){ |
17 |
< |
throw new NotInitialisedException("An instance of PluginFilterManager hasn't been initialised yet!"); |
17 |
> |
return new PluginFilterManager(); |
18 |
|
} |
19 |
|
return _instance; |
20 |
|
} |
24 |
|
private PluginFilterManager(){ |
25 |
|
|
26 |
|
System.out.println("Creating filter pipeline for plugin filters ..."); |
27 |
+ |
System.out.println(""); |
28 |
|
|
29 |
|
// Look in the specified directory for "*__Plugin.class" files. |
30 |
|
File file = new File(_directory); |
42 |
|
try { |
43 |
|
PluginFilter pf = (PluginFilter)ClassLoader.getSystemClassLoader().loadClass(files[i]).newInstance(); |
44 |
|
_filterPipeline.add(pf); |
45 |
< |
System.out.println("Added filter: "+files[i]); |
45 |
> |
System.out.println("Added filter: "+files[i]+" ("+pf.getDescription()+")"); |
46 |
|
} |
47 |
|
catch (InstantiationException e){ |
48 |
|
System.out.println("Failed to add "+files[i]+" to the plugin filter pipeline."); |
56 |
|
//System.out.println("Ignoring "+files[i]+" in the plugin folder."); |
57 |
|
} |
58 |
|
} |
59 |
< |
|
59 |
> |
|
60 |
> |
System.out.println(""); |
61 |
|
System.out.println("The filter pipeline has been set up with "+_filterPipeline.size()+" plugin filters."); |
62 |
|
|
63 |
|
} |
94 |
|
// A reference to the single instance of this class |
95 |
|
private static PluginFilterManager _instance; |
96 |
|
|
97 |
< |
}- |
97 |
> |
} |