1 package jalview.ws.rest;
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.io.OutputStreamWriter;
6 import java.io.PrintWriter;
7 import java.io.StringWriter;
8 import java.io.UnsupportedEncodingException;
9 import java.nio.charset.Charset;
10 import java.util.ArrayList;
12 import org.apache.http.entity.mime.content.ContentBody;
13 import org.apache.http.entity.mime.content.StringBody;
15 import sun.io.CharacterEncoding;
16 import sun.misc.CharacterEncoder;
18 /** Service Input info { a sequence of [ Sequence Id vector (min,max,moltype, separator,regex,colrange(start-end)), Sequence(format-bare or alignment, moltype, min, max, separator)), Alignment(format, moltype),
20 public abstract class InputType {
25 public enum molType { NUC, PROT, MIX}
28 public int max=0; // unbounded
29 protected ArrayList<Class> inputData=new ArrayList<Class>();
31 * initialise the InputType with a list of jalview data classes that the RestJob needs to be able to provide to it.
34 protected InputType(Class[] types)
44 * do basic tests to ensure the job's service takes this parameter, and the job's input data can be used to generate the input data
48 public boolean validFor(RestJob restJob)
50 if (!validFor(restJob.rsd))
52 for (Class cl:inputData)
54 if (!restJob.hasDataOfType(cl))
62 public boolean validFor(RestServiceDescription restServiceDescription)
64 if (!restServiceDescription.inputParams.values().contains(this))
69 protected ContentBody utf8StringBody(String content, String type)
71 Charset utf8 = Charset.forName("UTF-8");
74 return new StringBody(utf8.encode(content).asCharBuffer().toString());
76 return new StringBody(utf8.encode(content).asCharBuffer().toString(), type, utf8);
78 } catch (Exception ex)
80 System.err.println("Couldn't transform string\n"+content+"\nException was :");
81 ex.printStackTrace(System.err);
87 * @param rj data from which input is to be extracted and formatted
88 * @return StringBody or FileBody ready for posting
90 abstract public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException,NoValidInputDataException;
93 * @return true if no input data needs to be provided for this parameter
95 public boolean isConstant()
97 return (inputData==null || inputData.size()==0);