1bfd71dccbed9078f3b6a47de32e72b2d88e0292
[jalview.git] / src / jalview / ws / jws2 / dm / JabaWsParamSet.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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 jalview.util.MessageManager;
24 import jalview.ws.jws2.JabaParamStore;
25 import jalview.ws.params.ArgumentI;
26 import jalview.ws.params.WsParamSetI;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import compbio.metadata.Option;
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
58                   .getString("error.cannot_create_jabaws_param_set"));
59         }
60         else
61         {
62           jabaArguments = JabaParamStore.getJabafromJwsArgs(jobParams);
63         }
64       }
65     }
66     name = storeSetName;
67     description = descr;
68     sourceFile = null;
69     applicableUrls = null;
70   }
71
72   public JabaWsParamSet()
73   {
74
75   }
76
77   private boolean allJaba(List jobParams)
78   {
79
80     boolean allJaba = true;
81     for (Object jp : jobParams)
82     {
83       if (jp instanceof JabaParameter || jp instanceof JabaOption)
84       {
85         allJaba &= true;
86       }
87       else
88       {
89         allJaba = false;
90         break;
91       }
92     }
93     return allJaba;
94   }
95
96   @Override
97   public String getName()
98   {
99     return name;
100   }
101
102   @Override
103   public String getDescription()
104   {
105     return description;
106   }
107
108   /**
109    * @param name
110    *          the name to set
111    */
112   public void setName(String name)
113   {
114     this.name = name;
115   }
116
117   /**
118    * @param description
119    *          the description to set
120    */
121   public void setDescription(String description)
122   {
123     this.description = description;
124   }
125
126   /**
127    * @param applicableUrls
128    *          the applicableUrls to set
129    */
130   public void setApplicableUrls(String[] applicableUrls)
131   {
132     this.applicableUrls = applicableUrls;
133   }
134
135   /**
136    * @param modifiable
137    *          the modifiable to set
138    */
139   public void setModifiable(boolean modifiable)
140   {
141     this.modifiable = modifiable;
142   }
143
144   @Override
145   public String[] getApplicableUrls()
146   {
147     return applicableUrls;
148   }
149
150   @Override
151   public String getSourceFile()
152   {
153     return sourceFile;
154   }
155
156   @Override
157   public void setSourceFile(String newfile)
158   {
159     sourceFile = newfile;
160   }
161
162   boolean modifiable = true;
163
164   @Override
165   public boolean isModifiable()
166   {
167     return modifiable;
168   }
169
170   @Override
171   public List<ArgumentI> getArguments()
172   {
173     return JabaParamStore.getJwsArgsfromJaba(jabaArguments);
174   }
175
176   @Override
177   public void setArguments(List<ArgumentI> args)
178   {
179     if (!allJaba(args))
180     {
181       throw new Error(MessageManager
182               .getString("error.cannot_set_arguments_to_jabaws_param_set"));
183     }
184     jabaArguments = new ArrayList<Option>();
185     for (ArgumentI rg : args)
186     {
187       jabaArguments.add(((JabaOption) rg).opt);
188     }
189   }
190
191   public List<Option> getjabaArguments()
192   {
193     return jabaArguments;
194   }
195
196   public void setjabaArguments(List<Option> args)
197   {
198     jabaArguments = args;
199   }
200
201 }