Create extension system for the web application
Description (last modified by )
Create an extension/plug-in system for the web application that makes it possible to add menu items to the menu, toolbar buttons to the toolbars on list and view pages, and possibly also to other places like "Actions" or "Tools" column in some lists, etc.
First, I think we should use the name extension or web extension so we don't confuse it with the existing plug-in system.
The first use case we have is to make the MeV-launcher an extension, so I will use this as an example below.
Each place were it should be possible to add extension must be defined as an extension point. The definition consists of an ID, based on the normal Java conventions, and a class. For example: ID=net.sf.basedb.clients.web.bioassayset.tools, class=ActionButton
The ID must of course be unique. The class is a real class or an interface that extensions that attach to an extension point must provide an object/implementation of. The class/interface usually defines some attributes that is needed to create the visual appearance of the extension. The ActionButton may, for example, have the following methods: getImage(), getTitle(), getOnClick().
An extension extends an extension point with a specific implementation, for example, the 'Launch MeV' button. An extension itself should also define a unique ID, the ID of the extension point it should be attached to, and a factory class that can be used to create objects of the class specified by the extension point. We only need one instance of a factory class for each extension and it must be thread safe. The web core will use the factory class to create the objects needed for the presentation, ie. ActionButtonFactory will create ActionButton:s. The factory class can be initialised at startup with a set of configuration parameters. BASE should ship with some useful factory classes, for example:
- ImmutableActionButtonFactory: Everything is fixed, the button has always the same icon, title and executes the same code when the button is clicked.
- PermissionButtonFactory: The appearance is based on the logged in user's permission. The button can either be disabled or hidden unless a specific permission requirement is met.
An extension can of course also provide it's own factory class, for example: MeVLauncherButtonFactory. In all cases the factory classes will be provided with information about the logged in user, the current item, etc.
A central registry is needed were extension points and extensions can be registered. The registry is the main hub that is connecting all parts of the extension system.
It should be possible to install/remove/update extensions on the fly on a running web server. To make this possible we need some kind of monitoring application that can automatically detect when things are changed. I think this is easiest implemented as a servlet marked to start when the Tomcat server is started. The servlet will for example monitor the /WEB-INF/extensions directory.
To install an extension a new JAR file is added to this directory. To remove an extension the JAR file is simply deleted, and to update an extension the JAR file is replaced with a new one. The JAR file must of course follow a specific layout.
When the servlet detects a change, for example a new JAR file, it will load information from the JAR file, register any extentions and extension points it can find with the central registry. When the registration has been completed the new extension becomes immediately visible in the web interface. Likewise, when the servlet detects that a JAR file has been removed, it will unregister all extensions/extension points that was present in that file.
Extension JAR files
An extension should be packaged in a single JAR file. It must have an XML file at /META-INF/extensions.xml that describes the extension points and/or extension contained in the JAR file. This should be enough in the simplest case. In the case of the MeV launcher lots of other files are needed, but they can't be located in the /WEB-INF/extensions directory. I think it would be nice to simply have a single JAR file for an extensions. The auto-loader servlet could then extract all files in the /resources/ subdirectory and place those files in the /plugins/ directory on the Tomcat server. I am not sure exactly how this should be done at the moment, and if there is any risk of overwriting other extensions files or not. The JAR file may of course also contain actual implementations of factories and/or extension objects. A separate class loader for each JAR file is needed (if we want to be able to install/update/remove extensions independently from each other).
Change History (29)
comment:5 by , 16 years ago
|new → assigned
|Create plugin system for web application → Create extension system for the web application
comment:6 by , 16 years ago
|BASE 2.x+ → BASE 2.7
|major → critical