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