update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / jws2 / dm / JabaWsParamSet.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.jws2.dm;
19
20 import java.io.BufferedReader;
21 import java.io.IOException;
22 import java.io.Reader;
23 import java.io.Writer;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import compbio.metadata.Argument;
28 import compbio.metadata.Option;
29
30 import jalview.ws.jws2.JabaParamStore;
31 import jalview.ws.jws2.ParameterUtils;
32 import jalview.ws.params.ArgumentI;
33 import jalview.ws.params.ParamDatastoreI;
34 import jalview.ws.params.WsParamSetI;
35
36 public class JabaWsParamSet implements WsParamSetI
37 {
38   /**
39    * raw jaba arguments.
40    */
41   List<Option> jabaArguments;
42
43   String name, description, applicableUrls[], sourceFile;
44
45   public JabaWsParamSet(String storeSetName, String descr, List jobParams)
46   {
47     if (jobParams.size() > 0)
48     {
49       if (jobParams.get(0) instanceof Option)
50       {
51         jabaArguments = new ArrayList<Option>();
52         // if classCastExceptions are raised then there has been an
53         // implementation error.
54         jabaArguments.addAll((List<Option>) jobParams);
55       }
56       else
57       {
58         if (!allJaba(jobParams))
59         {
60           throw new Error(
61                   "Cannot create a JabaWSParamSet from non-JabaWS parameters");
62         }
63         else
64         {
65           jabaArguments = JabaParamStore.getJabafromJwsArgs(jobParams);
66         }
67       }
68     }
69     name = storeSetName;
70     description = descr;
71     sourceFile = null;
72     applicableUrls = null;
73   }
74
75   public JabaWsParamSet()
76   {
77
78   }
79
80   private boolean allJaba(List jobParams)
81   {
82
83     boolean allJaba = true;
84     for (Object jp : jobParams)
85     {
86       if (jp instanceof JabaParameter || jp instanceof JabaOption)
87       {
88         allJaba &= true;
89       }
90       else
91       {
92         allJaba = false;
93         break;
94       }
95     }
96     return allJaba;
97   }
98
99   @Override
100   public String getName()
101   {
102     return name;
103   }
104
105   @Override
106   public String getDescription()
107   {
108     return description;
109   }
110
111   /**
112    * @param name
113    *          the name to set
114    */
115   public void setName(String name)
116   {
117     this.name = name;
118   }
119
120   /**
121    * @param description
122    *          the description to set
123    */
124   public void setDescription(String description)
125   {
126     this.description = description;
127   }
128
129   /**
130    * @param applicableUrls
131    *          the applicableUrls to set
132    */
133   public void setApplicableUrls(String[] applicableUrls)
134   {
135     this.applicableUrls = applicableUrls;
136   }
137
138   /**
139    * @param modifiable
140    *          the modifiable to set
141    */
142   public void setModifiable(boolean modifiable)
143   {
144     this.modifiable = modifiable;
145   }
146
147   @Override
148   public String[] getApplicableUrls()
149   {
150     return applicableUrls;
151   }
152
153   @Override
154   public String getSourceFile()
155   {
156     return sourceFile;
157   }
158
159   @Override
160   public void setSourceFile(String newfile)
161   {
162     sourceFile = newfile;
163   }
164
165   boolean modifiable = true;
166
167   @Override
168   public boolean isModifiable()
169   {
170     return modifiable;
171   }
172
173   @Override
174   public List<ArgumentI> getArguments()
175   {
176     return JabaParamStore.getJwsArgsfromJaba(jabaArguments);
177   }
178
179   @Override
180   public void setArguments(List<ArgumentI> args)
181   {
182     if (!allJaba(args))
183     {
184       throw new Error(
185               "Cannot set arguments to a JabaWSParamSet that are not JabaWS arguments");
186     }
187     jabaArguments = new ArrayList<Option>();
188     for (ArgumentI rg : args)
189     {
190       jabaArguments.add(((JabaOption) rg).opt);
191     }
192   }
193
194   public List<Option> getjabaArguments()
195   {
196     return jabaArguments;
197   }
198
199   public void setjabaArguments(List<Option> args)
200   {
201     jabaArguments = args;
202   }
203
204 }