provide a Plugin Capability to the framework. This permit to implement
new functionnalities when the application permit it. It drastically
simplify the functionalities implementation and reduce the amount of
knowledge to do it.
Extension first point are a class implementing
IExtension
interface, this interface define :
- a name to the plugin.
- a list of extension points
Extension Points:
Extension point are entry points that can be used by the main
application to call the plugin when needed. Extension Point is defined
by the ExtensionPoint interface, this contain :
- a TypeID (type java interface type)
- a pointer to the interface that provide the entry point
a bag implementation of an entry point is proposed in the
SeimplExtensionPoint class (taking type typeid and pointer in the
constructor)
Extension Point Example
Here is an example of the usage of the extension point in a plugin
example ...
Implementing an Extension Point
public class AdvancedImporterExtension implements IExtension,
ImportersExtensionPoint, InformRepositoryExtensionPoint {
private static Logger logger = Logger
.getLogger(AdvancedImporterExtension.class);
public AdvancedImporterExtension() {
logger.debug("AdvancedImporterExtension");
}
public ExtensionPoint[] getExtensionPoints() {
return new ExtensionPoint[] {
new SimpleExtensionPoint(ImportersExtensionPoint.class, this),
new SimpleExtensionPoint(InformRepositoryExtensionPoint.class,
this) };
}
public String getName() {
return "Advanced Midi Importer";
}
public ArrayList<AbstractMidiImporter> getExtensionImporterInstance(
Scale destinationscale) {
logger.debug("getExtensionImporterInstance");
// get midi correspondance ...
if (rep == null) {
logger.warn("Rep is null ...");
return null;
}
Scale gmidi = Scale.getGammeMidiInstance();
ArrayList trans = rep.getTranspositionManager()
.findTransposition(gmidi, destinationscale);
if (trans == null || trans.size() == 0) {
logger.warn("no midi transposition for " + destinationscale);
return null;
}
if (!(trans.get(0) instanceof LinearTransposition))
{
logger.warn ("transposition is not a linear one");
return null;
}
LinearTransposition lt = (LinearTransposition)trans.get(0);
ArrayList<AbstractMidiImporter> l = new ArrayList<AbstractMidiImporter>();
l.add(new TranslatorImporter(destinationscale, lt));
return l;
}
private Repository rep = null;
public void informRepository(Repository repository) {
this.rep = repository;
}
In this example, the plugin provide two extension points, one for
getting a repository reference from the main application (the
InformRepositoryExtensionPoint interface), and one for proposing a new
importer. (thanks to the ImportersExtensionPoint interface)
Using a plugin Extension Point
on the main application side, the usage of the ExtensionManager help a
lot. This Class manage an Extension array of all the plugins loaded with
the application. so in the main application, we have an ExtensionManager
member
private ExtensionManager extm;
this member is initialized some where in the application.
When you want to call a plugin capability, do it that way :
InitExtensionPoint[] allInitPoints = ExtensionPointProvider
.getAllPoints(InitExtensionPoint.class, extm.getExtensions());
for (int i = 0; i < allInitPoints.length; i++) {
InitExtensionPoint init = allInitPoints[i];
init.init(this);
}
ExtensionPointProvider is a helper class that filter the ExtensionPoint
by type and automatically cast in with the proper interface