Source code: irate/plugin/Plugin.java
1 // Copyright 2003 Stephen Blackheath
2
3 package irate.plugin;
4
5 import nanoxml.XMLElement;
6
7 /**
8 * Base class for all plugins.
9 *
10 * @author Stephen Blackheath
11 */
12 public abstract class Plugin
13 {
14 private PluginApplication app;
15
16 /**
17 * Get a short identifier for this Plugin.
18 */
19 public abstract String getIdentifier();
20
21 /**
22 * Get a short description of this plugin.
23 */
24 public abstract String getDescription();
25
26 /**
27 * @return true if this plugin is currently attached to the application.
28 */
29 public final boolean isAttached()
30 {
31 return app != null;
32 }
33
34 /**
35 * Get access to the application instance.
36 */
37 protected final PluginApplication getApp()
38 {
39 return app;
40 }
41
42 /**
43 * Attach the plugin to the specified application.
44 */
45 public final void attach(PluginApplication app)
46 {
47 if (this.app == null) {
48 this.app = app;
49 doAttach();
50 }
51 }
52
53 /**
54 * Subclasses to override to do real work of attaching.
55 * Application is available through getApp().
56 */
57 protected abstract void doAttach();
58
59 /**
60 * Detach the plugin from the application.
61 */
62 public final void detach()
63 {
64 try {
65 if (app != null)
66 doDetach();
67 }
68 finally {
69 this.app = null;
70 }
71 }
72
73 /**
74 * Subclasses to override to do real work of detaching.
75 * Application is available through getApp().
76 */
77 protected abstract void doDetach();
78
79 /**
80 * Parse the configuration stored in the specified element.
81 */
82 public abstract void parseConfig(XMLElement elt);
83
84 /**
85 * Format the configuration of this plugin by modifying the specified
86 * element.
87 */
88 public abstract void formatConfig(XMLElement elt);
89 }
90