The actual API should be as simple as possible and leverage already existing file handling APIs. For instance, classes already exits for representing files, directories and file filtering. These should be used to allow the programmer to specify locations to search for plug-ins and filtering criteria to select only plug-in files. Once a plug-in file has been found and checked for conformance to the plug-in API file format a Plug-in Descriptor object should be returned to the programmer. This object will provide an interface for accessing all information in the plug-in information file. In addition, it should provide load and unload methods. The load method should insure that the classes in the plug-in are loaded or at least now in the class path
and should return an instantiation of the plug-in class. The plug-in class should be instantiated by the plug-in API only once. Thus if load is called multiple times without an intervening unload the same object should be returned. When an unload occurs the plug-in description should attempt to unload any classes in the plug-in, however if components from the plug-in are still in use this is not possible. After an unload, a call to load will instantiate a new instance of the plug-in class and return it.
During the plug-in load and unload process the API should invoke the appropriate methods on the plug-in class if they are present (using reflection). See the plug-in file format specification for information on the methods and their arguments.
Once the program has obtained the plug-in class it is up to it to interact with the object appropriately. This will generally be achieved by casting the object to some application specific interface class or through the use of reflection. The object may act either directly as the plug-in or may act as a factory for other objects.
The final component of the plug-in API should be a way for the plug-in to use and load none byte-code based resources from its own plug-in file. This should be achieved by passing a resource loader object to the plug-in class if it has the appropriate method (See plug-in file format specification).
jwalker@cs.oberlin.edu |