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