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