e883ea465bf9976d8d9df0a479e0665e1ae42033
[jalview.git] / src / jalview / ws / WSClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 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 for all
30    * jalview web service clients
31    */
32   /**
33    * displayed name for this web service
34    */
35   protected String WebServiceName;
36
37   /**
38    * specific job title (e.g. 'ClustalW Alignment of Selection from Aligment
39    * from Cut and Paste input')
40    */
41   protected String WebServiceJobTitle;
42
43   /**
44    * String giving additional information such as method citations for this
45    * service
46    */
47   protected String WebServiceReference;
48
49   /**
50    * Service endpoint
51    */
52   protected String WsURL;
53
54   /**
55    * Web service information used to initialise the WSClient attributes
56    */
57   protected WebserviceInfo wsInfo;
58
59   /**
60    * total number of jobs managed by this web service client instance.
61    */
62   int jobsRunning = 0;
63
64   /**
65    * TODO: this is really service metadata, and should be moved elsewhere.
66    * mappings between abstract interface names and menu entries
67    */
68   protected java.util.Hashtable ServiceActions;
69   {
70     ServiceActions = new java.util.Hashtable();
71     ServiceActions.put("MsaWS", "Multiple Sequence Alignment");
72     ServiceActions.put("SecStrPred", "Secondary Structure Prediction");
73   };
74
75   public WSClient()
76   {
77   }
78
79   /**
80    * initialise WSClient service information attributes from the service handle
81    * 
82    * @param sh
83    * @return the service instance information GUI for this client and job.
84    */
85   protected WebserviceInfo setWebService(ServiceHandle sh)
86   {
87     return setWebService(sh, false);
88   }
89
90   /**
91    * original service handle that this client was derived from
92    */
93   ServiceHandle serviceHandle = null;
94
95   /**
96    * initialise WSClient service information attributes from the service handle
97    * 
98    * @param sh
99    * @param headless
100    *                true implies no GUI objects will be created.
101    * @return the service instance information GUI for this client and job.
102    */
103   protected WebserviceInfo setWebService(ServiceHandle sh, boolean headless)
104   {
105     WebServiceName = sh.getName();
106     if (ServiceActions.containsKey(sh.getAbstractName()))
107     {
108       WebServiceJobTitle = sh.getName(); // TODO: control sh.Name specification
109                                           // properly
110       // add this for short names. +(String)
111       // ServiceActions.get(sh.getAbstractName());
112     }
113     else
114     {
115       WebServiceJobTitle = sh.getAbstractName() + " using " + sh.getName();
116
117     }
118     WebServiceReference = sh.getDescription();
119     WsURL = sh.getEndpointURL();
120     WebserviceInfo wsInfo = null;
121     if (!headless)
122     {
123       wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
124     }
125     return wsInfo;
126   }
127
128   /**
129    * convenience method to pass the serviceHandle reference that instantiated
130    * this service on to the menu entry constructor
131    * 
132    * @param wsmenu
133    *                the menu to which any menu entries/sub menus are to be
134    *                attached
135    * @param alignFrame
136    *                the alignFrame instance that provides input data for the
137    *                service
138    */
139   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
140   {
141     if (serviceHandle == null)
142     {
143       throw new Error(
144               "IMPLEMENTATION ERROR: cannot attach WS Menu Entry without service handle reference!");
145     }
146     attachWSMenuEntry(wsmenu, serviceHandle, alignFrame);
147   }
148
149   /**
150    * method implemented by each WSClient implementation that creates menu
151    * entries that enact their service using data from alignFrame.
152    * 
153    * @param wsmenu
154    *                where new menu entries (and submenus) are to be attached
155    * @param serviceHandle
156    *                the serviceHandle document for the service that entries are
157    *                created for
158    * @param alignFrame
159    */
160   public abstract void attachWSMenuEntry(JMenu wsmenu,
161           final ServiceHandle serviceHandle, final AlignFrame alignFrame);
162 }