JAL-715 - allow rest service attributes to be exported and imported as a | separated...
[jalview.git] / src / jalview / ws / rest / params / JobConstant.java
1 package jalview.ws.rest.params;
2
3 import jalview.ws.rest.InputType;
4 import jalview.ws.rest.NoValidInputDataException;
5 import jalview.ws.rest.RestJob;
6
7 import java.io.UnsupportedEncodingException;
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import org.apache.http.entity.mime.content.ContentBody;
12 import org.apache.http.entity.mime.content.StringBody;
13
14 /**
15  * defines a constant value always provided as a parameter.
16  * @author JimP
17  *
18  */
19 public class JobConstant extends InputType
20 {
21
22   String value;
23   /**
24    * 
25    * @param param name of parameter
26    * @param val value of parameter
27    */
28   public JobConstant(String param, String val)
29   {
30     // needs no data from the restJob
31     super(null);
32     this.token = param;
33     value = val;
34   }
35
36   @Override
37   public ContentBody formatForInput(RestJob rj)
38           throws UnsupportedEncodingException, NoValidInputDataException
39   {
40     
41     return new StringBody(value);
42   }
43
44   @Override
45   public List<String> getURLEncodedParameter()
46   {
47     ArrayList<String> prm = new ArrayList<String>();
48     
49     if (value!=null && value.length()>0)
50     {
51       prm.add(value);
52     }
53     return prm;
54   }
55
56   @Override
57   public String getURLtokenPrefix()
58   {
59     return "";
60   }
61
62   @Override
63   public boolean configureFromURLtokenString(List<String> tokenstring,
64           StringBuffer warnings)
65   {
66     if (tokenstring.size()>1) {
67       warnings.append("IMPLEMENTATION ERROR: Constant POST parameters cannot have more than one value.");
68       return false;
69     }
70     if (tokenstring.size()==1) {
71       value = tokenstring.get(0);
72     }
73     return true;
74   }
75
76   @Override
77   public boolean configureProperty(String tok, String val,
78           StringBuffer warnings)
79   {
80     warnings.append("IMPLEMENTATION ERROR: No Properties to configure for a Constant parameter.");
81     return false;
82   }
83 }