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