update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / jws1 / WS1Client.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.jws1;
19
20 import jalview.gui.AlignFrame;
21 import jalview.gui.WebserviceInfo;
22 import jalview.ws.WSClient;
23 import jalview.ws.WSMenuEntryProviderI;
24
25 import javax.swing.JMenu;
26
27 import ext.vamsas.ServiceHandle;
28
29 /**
30  * JWS1 Specific UI attributes and methods
31  * 
32  * @author JimP
33  * 
34  */
35 public abstract class WS1Client extends WSClient implements
36         WSMenuEntryProviderI
37 {
38
39   /**
40    * original service handle that this client was derived from
41    */
42   ServiceHandle serviceHandle = null;
43
44   /**
45    * default constructor
46    */
47   public WS1Client()
48   {
49     super();
50   }
51
52   /**
53    * initialise WSClient service information attributes from the service handle
54    * 
55    * @param sh
56    * @return the service instance information GUI for this client and job.
57    */
58   protected WebserviceInfo setWebService(ServiceHandle sh)
59   {
60     return setWebService(sh, false);
61   }
62
63   /**
64    * initialise WSClient service information attributes from the service handle
65    * 
66    * @param sh
67    * @param headless
68    *          true implies no GUI objects will be created.
69    * @return the service instance information GUI for this client and job.
70    */
71   protected WebserviceInfo setWebService(ServiceHandle sh, boolean headless)
72   {
73     WebServiceName = sh.getName();
74     if (ServiceActions.containsKey(sh.getAbstractName()))
75     {
76       WebServiceJobTitle = sh.getName(); // TODO: control sh.Name specification
77       // properly
78       // add this for short names. +(String)
79       // ServiceActions.get(sh.getAbstractName());
80     }
81     else
82     {
83       WebServiceJobTitle = sh.getAbstractName() + " using " + sh.getName();
84
85     }
86     WebServiceReference = sh.getDescription();
87     WsURL = sh.getEndpointURL();
88     WebserviceInfo wsInfo = null;
89     if (!headless)
90     {
91       wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
92     }
93     return wsInfo;
94   }
95
96   /**
97    * convenience method to pass the serviceHandle reference that instantiated
98    * this service on to the menu entry constructor
99    * 
100    * @param wsmenu
101    *          the menu to which any menu entries/sub menus are to be attached
102    * @param alignFrame
103    *          the alignFrame instance that provides input data for the service
104    */
105   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
106   {
107     if (serviceHandle == null)
108     {
109       throw new Error(
110               "IMPLEMENTATION ERROR: cannot attach WS Menu Entry without service handle reference!");
111     }
112     attachWSMenuEntry(wsmenu, serviceHandle, alignFrame);
113   }
114
115   /**
116    * method implemented by each concrete WS1Client implementation that creates
117    * menu entries that enact their service using data from alignFrame.
118    * 
119    * @param wsmenu
120    *          where new menu entries (and submenus) are to be attached
121    * @param serviceHandle
122    *          the serviceHandle document for the service that entries are
123    *          created for
124    * @param alignFrame
125    */
126   public abstract void attachWSMenuEntry(JMenu wsmenu,
127           final ServiceHandle serviceHandle, final AlignFrame alignFrame);
128
129 }