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