Opened 18 years ago

Closed 17 years ago

Last modified 17 years ago

#436 closed task (fixed)

Create extension system for the web application

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 and http://baseplugins.thep.lu.se/ticket/103

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 (29)

comment:1 by Nicklas Nordborg, 18 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, 17 years ago

Milestone: BASE 2.6BASE 2.x+

comment:5 by Nicklas Nordborg, 17 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, 17 years ago

Description: modified (diff)
Milestone: BASE 2.x+BASE 2.7
Priority: majorcritical

comment:7 by Nicklas Nordborg, 17 years ago

(In [4157]) References #436: Creating branch for prototyping web extensions

comment:8 by Nicklas Nordborg, 17 years ago

(In [4158]) References #436: Create extension system for the web application

Started working on a prototype. Basic concept is working.

comment:9 by Nicklas Nordborg, 17 years ago

(In [4163]) References #436: Create extension system for the web application

The core part is now more or lesse working. Will start a "real" web client implementation to test and enhance it.

comment:10 by Nicklas Nordborg, 17 years ago

(In [4168]) References #436: Create extension system for the web application

Started with extension points for the menu and toolbars. Started with an web-based administration/information of installed extensions.

comment:11 by Nicklas Nordborg, 17 years ago

(In [4169]) References #436: Create extension system for the web application

Fixed compilation error

comment:12 by Nicklas Nordborg, 17 years ago

(In [4170]) References #436: Create extension system for the web application

comment:13 by Nicklas Nordborg, 17 years ago

(In [4180]) References #436: Create extension system for the web application

Started with the automatic installation / resource extraction servlet.

comment:14 by Nicklas Nordborg, 17 years ago

(In [4181]) References #436: Create extension system for the web application

Most of the system is now functional. Some minor functions, error handlin and documentation remains.

comment:15 by Nicklas Nordborg, 17 years ago

Description: modified (diff)

comment:16 by Nicklas Nordborg, 17 years ago

(In [4184]) References #436: Create extension system for the web application

First version of developer documentation.

comment:17 by Nicklas Nordborg, 17 years ago

(In [4185]) References #436: Create extension system for the web application

More logging and fixed issues found during writing documentation.

comment:18 by Nicklas Nordborg, 17 years ago

(In [4198]) References #436: Create extension system for the web application

Major code and documentation cleanup of core classes. Added lots of more administrative functions. Automatic and manual installation is enabled.

comment:19 by Nicklas Nordborg, 17 years ago

(In [4202]) References #436: Create extension system for the web application

All major features are now in place. Next step is to create more documentation and weed out remaining bugs and other irregularities. It should now be possible to start with beta-testing of actually developing external extensions.

comment:20 by Nicklas Nordborg, 17 years ago

(In [4206]) References #436: Create extension system for the web application

Updated documentation for the extension system.

comment:21 by Nicklas Nordborg, 17 years ago

(In [4207]) References #436: Create extension system for the web application

Refactored factory interfaces to make it possible to create dynamic factories that works with different types of extension points and actions. Documentation will be updated next week.

comment:22 by Nicklas Nordborg, 17 years ago

(In [4208]) References #436: Create extension system for the web application

Updated documentation to reflect latest changes. This ticket is now more or less finished. Will keep it open until #932 and #933 has been completed.

comment:23 by Nicklas Nordborg, 17 years ago

(In [4217]) References #436: Create extension system for the web application

Fixed compilation error.

comment:24 by Nicklas Nordborg, 17 years ago

(In [4224]) References #436: Create extension system for the web application

Svn should ignore installed extensions in WEB-INF/extensions

comment:25 by Nicklas Nordborg, 17 years ago

(In [4233]) References #436: Create extension system for the web application

Improved error handling.

comment:26 by Nicklas Nordborg, 17 years ago

(In [4236]) References #436: Create extension system for the web application

Improved error handling in case of bad-behaving action factories.

comment:27 by Nicklas Nordborg, 17 years ago

(In [4237]) References #436: Create extension system for the web application

Added ClientContext.getDbControl()

comment:28 by Nicklas Nordborg, 17 years ago

Resolution: fixed
Status: assignedclosed

comment:29 by Nicklas Nordborg, 17 years ago

(In [4264]) References #436: Create extension system for the web application

Better error handling to protect the system from mis-behaving factories.

Note: See TracTickets for help on using tickets.