Opened 17 years ago

Last modified 16 years ago

#436 closed task

Create extension system for the web application — at Version 6

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: critical Milestone: BASE 2.7
Component: web Version:
Keywords: Cc:

Description (last modified by Nicklas Nordborg)

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.

See also: #932 and #933.

Implementation idea

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.

Extension point
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().

Extension
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.
  • etc...

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.

Extension registry
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.

Auto-loading servlet
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).

Summary
In the simplest case an extension can be developed by just writing an XML file and packaging it in a JAR file. The extension is installed by simply putting the JAR file in a special directory on the server. An auto-installation servlet makes sure that everything is immediately visible in the web interface. Extra resources, such as images, javascript files and JSP pages, can also be included in the JAR file and will be extracted automatically by the auto-installation servlet.

Change History (6)

comment:1 by Nicklas Nordborg, 17 years ago

Note! This plugin system has nothing to do with the existing server-side plugin system.

comment:2 by Jari Häkkinen, 17 years ago

Milestone: BASE 2.x+BASE 2.5

comment:3 by Jari Häkkinen, 17 years ago

Milestone: BASE 2.5BASE 2.6

comment:4 by Johan Enell, 16 years ago

Milestone: BASE 2.6BASE 2.x+

comment:5 by Nicklas Nordborg, 16 years ago

Description: modified (diff)
Status: newassigned
Summary: Create plugin system for web applicationCreate extension system for the web application

comment:6 by Nicklas Nordborg, 16 years ago

Description: modified (diff)
Milestone: BASE 2.x+BASE 2.7
Priority: majorcritical
Note: See TracTickets for help on using tickets.