JAL-1620 version bump and release notes
[jalview.git] / src / jalview / ws / jws2 / dm / JabaWsParamSet.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
3  * Copyright (C) 2014 The Jalview Authors
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.jws2.dm;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import compbio.metadata.Option;
27
28 import jalview.util.MessageManager;
29 import jalview.ws.jws2.JabaParamStore;
30 import jalview.ws.params.ArgumentI;
31 import jalview.ws.params.WsParamSetI;
32
33 public class JabaWsParamSet implements WsParamSetI
34 {
35   /**
36    * raw jaba arguments.
37    */
38   List<Option> jabaArguments;
39
40   String name, description, applicableUrls[], sourceFile;
41
42   public JabaWsParamSet(String storeSetName, String descr, List jobParams)
43   {
44     if (jobParams.size() > 0)
45     {
46       if (jobParams.get(0) instanceof Option)
47       {
48         jabaArguments = new ArrayList<Option>();
49         // if classCastExceptions are raised then there has been an
50         // implementation error.
51         jabaArguments.addAll((List<Option>) jobParams);
52       }
53       else
54       {
55         if (!allJaba(jobParams))
56         {
57           throw new Error(MessageManager.getString("error.cannot_create_jabaws_param_set"));
58         }
59         else
60         {
61           jabaArguments = JabaParamStore.getJabafromJwsArgs(jobParams);
62         }
63       }
64     }
65     name = storeSetName;
66     description = descr;
67     sourceFile = null;
68     applicableUrls = null;
69   }
70
71   public JabaWsParamSet()
72   {
73
74   }
75
76   private boolean allJaba(List jobParams)
77   {
78
79     boolean allJaba = true;
80     for (Object jp : jobParams)
81     {
82       if (jp instanceof JabaParameter || jp instanceof JabaOption)
83       {
84         allJaba &= true;
85       }
86       else
87       {
88         allJaba = false;
89         break;
90       }
91     }
92     return allJaba;
93   }
94
95   @Override
96   public String getName()
97   {
98     return name;
99   }
100
101   @Override
102   public String getDescription()
103   {
104     return description;
105   }
106
107   /**
108    * @param name
109    *          the name to set
110    */
111   public void setName(String name)
112   {
113     this.name = name;
114   }
115
116   /**
117    * @param description
118    *          the description to set
119    */
120   public void setDescription(String description)
121   {
122     this.description = description;
123   }
124
125   /**
126    * @param applicableUrls
127    *          the applicableUrls to set
128    */
129   public void setApplicableUrls(String[] applicableUrls)
130   {
131     this.applicableUrls = applicableUrls;
132   }
133
134   /**
135    * @param modifiable
136    *          the modifiable to set
137    */
138   public void setModifiable(boolean modifiable)
139   {
140     this.modifiable = modifiable;
141   }
142
143   @Override
144   public String[] getApplicableUrls()
145   {
146     return applicableUrls;
147   }
148
149   @Override
150   public String getSourceFile()
151   {
152     return sourceFile;
153   }
154
155   @Override
156   public void setSourceFile(String newfile)
157   {
158     sourceFile = newfile;
159   }
160
161   boolean modifiable = true;
162
163   @Override
164   public boolean isModifiable()
165   {
166     return modifiable;
167   }
168
169   @Override
170   public List<ArgumentI> getArguments()
171   {
172     return JabaParamStore.getJwsArgsfromJaba(jabaArguments);
173   }
174
175   @Override
176   public void setArguments(List<ArgumentI> args)
177   {
178     if (!allJaba(args))
179     {
180       throw new Error(MessageManager.getString("error.cannot_set_arguments_to_jabaws_param_set"));
181     }
182     jabaArguments = new ArrayList<Option>();
183     for (ArgumentI rg : args)
184     {
185       jabaArguments.add(((JabaOption) rg).opt);
186     }
187   }
188
189   public List<Option> getjabaArguments()
190   {
191     return jabaArguments;
192   }
193
194   public void setjabaArguments(List<Option> args)
195   {
196     jabaArguments = args;
197   }
198
199 }