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