public interface Plugin
Plugin
is the base interface for all plug-ins within BladeRunnerJS. Plug-ins are discovered automatically by BladeRunnerJS (using the
SPI Mechanism introduced in Java 6), and are constructed using a zero-arg
constructor. The setBRJS()
method is used in lieu of a parameterized constructor, and is invoked before any non-identifier methods
(see below).
Because plug-ins form part of the model, yet use the model to initialize themselves, an untenable circular dependency exists. To overcome this
problem, each concrete plug-in instance is wrapped inside a virtual proxy that
delays plug-in initialization until somebody attempts to actually use the plug-in. Since code interested in interacting with a subset of the plug-ins
will often need to query all of them to locate the ones it needs, certain identifier-methods are proxied through before the object's
setBRJS()
method has been invoked, which plug-in authors must be aware of.
Another consequence of wrapping all plug-ins in a virtual proxy is that the instanceof
operator and the Object.getClass()
method do not work as expected. The instanceOf()
and getPluginClass()
methods are provided to overcome these deficiencies.
Modifier and Type | Method and Description |
---|---|
<P extends Plugin> |
castTo(java.lang.Class<P> pluginInterface)
An alternative to Java's class casting mechanism that is needed because BladeRunnerJS wraps plug-ins within virtual proxy
wrappers, preventing class casting from working.
|
void |
close()
Invoked during the invocation of
BRJS.close() , offering plug-ins a chance to release any resources they may be holding on to. |
java.lang.Class<?> |
getPluginClass()
An alternative to Java's
Object.getClass() method that is needed because BladeRunnerJS wraps plug-ins within virtual proxy
wrappers, causing the native Object.getClass() method to become ineffective. |
<P extends Plugin> |
instanceOf(java.lang.Class<P> pluginInterface)
An alternative to Java's
instanceof operator that is needed because BladeRunnerJS wraps plug-ins within virtual proxy
wrappers, causing the native instanceof operator to become ineffective. |
void |
setBRJS(BRJS brjs)
Invoked after construction, and before any non-identifier methods have been invoked, so plug-ins have a reference to the BladeRunnerJS model.
|
void setBRJS(BRJS brjs)
brjs
- The reference to the BladeRunnerJS model.void close()
BRJS.close()
, offering plug-ins a chance to release any resources they may be holding on to.<P extends Plugin> boolean instanceOf(java.lang.Class<P> pluginInterface)
instanceof
operator that is needed because BladeRunnerJS wraps plug-ins within virtual proxy
wrappers, causing the native instanceof
operator to become ineffective.
Plug-ins are not expected to implement this method themselves, and should instead extend one of the AbstractPlugin
sub-classes (e.g. AbstractCommandPlugin
).
P
- Any pluginpluginInterface
- The interface which this object may, or may not be, an instance of.true
, if this object is an instance of the given interface, and false
otherwise.<P extends Plugin> P castTo(java.lang.Class<P> pluginInterface)
Plug-ins are not expected to implement this method themselves, and should instead extend one of the AbstractPlugin
sub-classes (e.g. AbstractCommandPlugin
).
P
- Any pluginpluginInterface
- The interface which this object may, or may not be, an instance of.java.lang.Class<?> getPluginClass()
Object.getClass()
method that is needed because BladeRunnerJS wraps plug-ins within virtual proxy
wrappers, causing the native Object.getClass()
method to become ineffective.
Plug-ins are not expected to implement this method themselves, and should instead extend one of the AbstractPlugin
sub-classes (e.g. AbstractCommandPlugin
).