added SeqSearch service interface. Documented and refactored web service client ...
[jalview.git] / src / jalview / ws / WSClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.ws;
20
21 import javax.swing.JMenu;
22
23 import ext.vamsas.*;
24 import jalview.gui.*;
25
26 public abstract class WSClient
27 {
28   /**
29    * WSClient holds the basic attributes that are displayed to the user
30    * for all jalview web service clients
31    */
32   /**
33    * displayed name for this web service
34    */
35   protected String WebServiceName;
36   /**
37    * specific job title (e.g. 'ClustalW Alignment of Selection from Aligment from Cut and Paste input')
38    */
39   protected String WebServiceJobTitle;
40   /**
41    * String giving additional information such as method citations for this service 
42    */
43   protected String WebServiceReference;
44   /**
45    * Service endpoint
46    */
47   protected String WsURL;
48   /**
49    * Web service information used to initialise the WSClient attributes
50    */
51   protected WebserviceInfo wsInfo;
52   /**
53    * total number of jobs managed by this web service client instance. 
54    */
55   int jobsRunning = 0;
56   /**
57    * TODO: this is really service metadata, and should be moved elsewhere.
58    * mappings between abstract interface names and menu entries
59    */
60   protected java.util.Hashtable ServiceActions;
61   {
62     ServiceActions = new java.util.Hashtable();
63     ServiceActions.put("MsaWS", "Multiple Sequence Alignment");
64     ServiceActions.put("SecStrPred", "Secondary Structure Prediction");
65   };
66   public WSClient()
67   {
68   }
69   /**
70    * initialise WSClient service information attributes from the service handle
71    * @param sh
72    * @return the service instance information GUI for this client and job.
73    */
74   protected WebserviceInfo setWebService(ServiceHandle sh)
75   {
76     return setWebService(sh, false);
77   }
78   /**
79    * original service handle that this client was derived from
80    */
81   ServiceHandle serviceHandle=null;
82     /**
83      * initialise WSClient service information attributes from the service handle
84      * @param sh
85      * @param headless true implies no GUI objects will be created.
86      * @return the service instance information GUI for this client and job.
87      */
88   protected WebserviceInfo setWebService(ServiceHandle sh, boolean headless)
89   {
90     WebServiceName = sh.getName();
91     if (ServiceActions.containsKey(sh.getAbstractName()))
92     {
93       WebServiceJobTitle = sh.getName(); // TODO: control sh.Name specification properly
94       // add this for short names. +(String) ServiceActions.get(sh.getAbstractName());
95     }
96     else
97     {
98       WebServiceJobTitle = sh.getAbstractName() + " using " + sh.getName();
99
100     }
101     WebServiceReference = sh.getDescription();
102     WsURL = sh.getEndpointURL();
103     WebserviceInfo wsInfo = null;
104     if (!headless)
105     {
106       wsInfo = new WebserviceInfo(WebServiceJobTitle,
107                                                WebServiceReference);
108     }
109     return wsInfo;
110   }
111   /**
112    * convenience method to pass the serviceHandle reference that instantiated this 
113    * service on to the menu entry constructor
114    * @param wsmenu the menu to which any menu entries/sub menus are to be attached
115    * @param alignFrame the alignFrame instance that provides input data for the service
116    */
117   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
118   {
119     if (serviceHandle==null)
120     {
121       throw new Error("IMPLEMENTATION ERROR: cannot attach WS Menu Entry without service handle reference!");
122     }
123     attachWSMenuEntry(wsmenu, serviceHandle, alignFrame);
124   }
125   /**
126    * method implemented by each WSClient implementation that creates menu entries that enact their service
127    * using data from alignFrame.
128    * @param wsmenu where new menu entries (and submenus) are to be attached
129    * @param serviceHandle the serviceHandle document for the service that entries are created for
130    * @param alignFrame
131    */
132   public abstract void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle serviceHandle, final AlignFrame alignFrame);
133 }