This section describes common adapter structure.
TrackStudio takes each type of adapter as consisting of three components: the adapter interface, the proper adapter and AdapterManager realizing the pipeline.
Let's take the realization and interaction of the system components in the work of adapters:
1) Interface. The adapter interface must extend Adapter or KernelAdapter. The following requirements are demanded of the method signature:
public boolean authorizeImpl(User user, String password, boolean result) throws GranException;
Interface example:
// $Id: OpenAPI.dtx,v 1.14 2004/05/31 13:49:10 maximkr Exp $ package gran.app.adapter.template; import gran.app.adapter.Adapter; import gran.exception.GranException; public interface TemplateAdapter extends Adapter // or KernelAdapter { public String methodThatReturnSomethingImpl(String param, String result) throws GranException; public void methodThatReturnNothingImpl(String param) throws GranException; }
2) An adapter has the following structure:
// $Id: OpenAPI.dtx,v 1.14 2004/05/31 13:49:10 maximkr Exp $ package gran.app.adapter.template; import gran.exception.GranException; import gran.tools.Logger; public class BaseTemplateAdapter implements TemplateAdapter { private static Logger log = new Logger("gran.app.adapter.template.TemplateAdapter"); public boolean init() { return true; } public String getDescription() { return "Base Template Adapter"; } public String methodThatReturnSomethingImpl(String param, String result) throws GranException { return param + " OK"; } public void methodThatReturnNothingImpl(String param) throws GranException { return; } }
Within an adapter, methods can be called only through AdapterManager. Direct calling *Impl-methods is not recommended as it may cause problems when enhancing the system.
3) SomeAdapterManager controls the lists of adapters supporting the defined interface and is responsible for the correct passing of the parameters. The realization of SomeAdapterManager may have the following structure:
// $Id: OpenAPI.dtx,v 1.14 2004/05/31 13:49:10 maximkr Exp $ package gran.app.adapter.template; import java.util.Collection; import java.util.Iterator; import gran.exception.GranException; public class TemplateAdapterManager { private Collection am = null; public TemplateAdapterManager(Collection adapters) { am = adapters; } public String methodThatReturnSomething(String param) throws GranException { String result = null; for (Iterator iter = am.iterator(); iter.hasNext();) { TemplateAdapter adp = (TemplateAdapter) iter.next(); result = adp.methodThatReturnSomethingImpl(param, result); } return result; } public void methodThatReturnNothing(String param) throws GranException { for (Iterator iter = am.iterator(); iter.hasNext();) { TemplateAdapter adp = (TemplateAdapter) iter.next(); adp.methodThatReturnNothingImpl(param); } } }
The system enhancement is carried out through classes realizing the existing interfaces (for example, gran.app.adapter.ExportAdapter). At the same time you do not have to modify the initial system code, the adapter interface or AdapterManager.
To call the adapters, a singleton class AdapterManager is used. This class stores the list of all adapters available on the system and allows registering new adapters in the system. To call a method (e.g. for exporting), you must execute the following:
AdapterManager.getInstance().getExportAdapterManager() .export(taskid, userid);
Sample adapters:
1) An adapter realizing the user authentication.
2) A debugging adapter logging all the information about the called adapters and their parameters.
3) An adapter for exporting data.