Formatting
[jalview.git] / src / jalview / ws / MsaWSClient.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.*;
22
23 import ext.vamsas.*;
24 import jalview.datamodel.*;
25 import jalview.gui.*;
26
27 /**
28  * DOCUMENT ME!
29  *
30  * @author $author$
31  * @version $Revision$
32  */
33 public class MsaWSClient
34     extends WSClient
35 {
36   /**
37    * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
38    */
39   ext.vamsas.MuscleWS server;
40   AlignFrame alignFrame;
41
42   /**
43    * Creates a new MsaWSClient object that uses a service
44    * given by an externally retrieved ServiceHandle
45    *
46    * @param sh service handle of type AbstractName(MsaWS)
47    * @param altitle DOCUMENT ME!
48    * @param msa DOCUMENT ME!
49    * @param submitGaps DOCUMENT ME!
50    * @param preserveOrder DOCUMENT ME!
51    */
52
53   public MsaWSClient(ext.vamsas.ServiceHandle sh, String altitle,
54                      jalview.datamodel.AlignmentView msa,
55                      boolean submitGaps, boolean preserveOrder,
56                      Alignment seqdataset,
57                      AlignFrame _alignFrame)
58   {
59     super();
60     alignFrame = _alignFrame;
61     if (!sh.getAbstractName().equals("MsaWS"))
62     {
63       JOptionPane.showMessageDialog(Desktop.desktop,
64                                     "The Service called \n" + sh.getName() +
65                                     "\nis not a \nMultiple Sequence Alignment Service !",
66                                     "Internal Jalview Error",
67                                     JOptionPane.WARNING_MESSAGE);
68
69       return;
70     }
71
72     if ( (wsInfo = setWebService(sh)) == null)
73     {
74       JOptionPane.showMessageDialog(Desktop.desktop,
75                                     "The Multiple Sequence Alignment Service named " +
76                                     sh.getName() +
77                                     " is unknown", "Internal Jalview Error",
78                                     JOptionPane.WARNING_MESSAGE);
79
80       return;
81     }
82     startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
83
84   }
85
86   private void startMsaWSClient(String altitle, AlignmentView msa,
87                                 boolean submitGaps, boolean preserveOrder,
88                                 Alignment seqdataset)
89   {
90     if (!locateWebService())
91     {
92       return;
93     }
94
95     wsInfo.setProgressText( ( (submitGaps) ? "Re-alignment" : "Alignment") +
96                            " of " + altitle + "\nJob details\n");
97     String jobtitle = WebServiceName.toLowerCase();
98     if (jobtitle.endsWith("alignment"))
99     {
100       if (submitGaps
101           && (!jobtitle.endsWith("realignment")
102               || jobtitle.indexOf("profile") == -1))
103       {
104         int pos = jobtitle.indexOf("alignment");
105         jobtitle = WebServiceName.substring(0, pos) + "re-alignment of " +
106             altitle;
107       }
108       else
109       {
110         jobtitle = WebServiceName + " of " + altitle;
111       }
112     }
113     else
114     {
115       jobtitle = WebServiceName + (submitGaps ? " re" : " ") + "alignment of " +
116           altitle;
117     }
118
119     MsaWSThread msathread = new MsaWSThread(server, WsURL, wsInfo, alignFrame,
120                                             WebServiceName,
121                                             jobtitle,
122                                             msa,
123                                             submitGaps, preserveOrder,
124                                             seqdataset);
125     wsInfo.setthisService(msathread);
126     msathread.start();
127   }
128
129   /**
130    * Initializes the server field with a valid service implementation.
131    *
132    * @return true if service was located.
133    */
134   private boolean locateWebService()
135   {
136     // TODO: MuscleWS transmuted to generic MsaWS client
137     MuscleWSServiceLocator loc = new MuscleWSServiceLocator(); // Default
138
139     try
140     {
141       this.server = (MuscleWS) loc.getMuscleWS(new java.net.URL(WsURL));
142       ( (MuscleWSSoapBindingStub)this.server).setTimeout(60000); // One minute timeout
143     }
144     catch (Exception ex)
145     {
146       wsInfo.setProgressText("Serious! " + WebServiceName +
147                              " Service location failed\nfor URL :" + WsURL +
148                              "\n" +
149                              ex.getMessage());
150       wsInfo.setStatus(WebserviceInfo.ERROR);
151       ex.printStackTrace();
152
153       return false;
154     }
155
156     loc.getEngine().setOption("axis", "1");
157
158     return true;
159   }
160
161   protected String getServiceActionKey()
162   {
163     return "MsaWS";
164   }
165
166   protected String getServiceActionDescription()
167   {
168     return "Multiple Sequence Alignment";
169   }
170 }