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