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