~donal-k-fellows/taverna-server/2.4.1i-maintenance

« back to all changes in this revision

Viewing changes to server-client/src/main/java/uk/org/taverna/server/client/Input.java

  • Committer: Donal Fellows
  • Date: 2015-04-15 12:48:16 UTC
  • Revision ID: git-v1:7d9d515bf1290958d0cc8462d8a1560204ca5569
Working towards removing the generated classes from the API delivered to
consumers of this API, making it easier to change how the binding layer
is implemented.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package uk.org.taverna.server.client;
 
2
 
 
3
import java.io.IOException;
 
4
import java.io.InputStream;
 
5
 
 
6
import org.apache.tika.io.IOUtils;
 
7
import org.taverna.server.client.wadl.TavernaServer.Root.RunsRunName.Input.InputName;
 
8
 
 
9
import uk.org.taverna.server.client.generic.port.InputPort;
 
10
import uk.org.taverna.server.client.rest.InputDescription;
 
11
import uk.org.taverna.server.client.rest.InputDescription.Value;
 
12
 
 
13
public class Input {
 
14
        private InputPort port;
 
15
        private Run run;
 
16
        private InputName handle;
 
17
 
 
18
        Input(Run run, InputPort port) {
 
19
                this.port = port;
 
20
                this.run = run;
 
21
                this.handle = run.run.input().inputName(port.getName());
 
22
        }
 
23
 
 
24
        public String getName() {
 
25
                return port.getName();
 
26
        }
 
27
 
 
28
        public Integer getDepth() {
 
29
                return port.getDepth();
 
30
        }
 
31
 
 
32
        public Character getListSeparator() {
 
33
                String sep = handle.getAsInputDescriptionXml().getListDelimiter();
 
34
                if (sep == null || sep.isEmpty())
 
35
                        return null;
 
36
                return sep.charAt(0);
 
37
        }
 
38
 
 
39
        public String getValue() {
 
40
                InputDescription idesc = handle.getAsInputDescriptionXml();
 
41
                Value v = idesc.getValue();
 
42
                if (v != null)
 
43
                        return v.getValue();
 
44
                String name = idesc.getFile().getValue();
 
45
                try (InputStream s = new File(run, name).getAsStream()) {
 
46
                        return IOUtils.toString(s);
 
47
                } catch (IOException e) {
 
48
                        // Can't read from the input; should COMPLAIN but this is really a
 
49
                        // "can't happen" case.
 
50
                        return null;
 
51
                }
 
52
        }
 
53
 
 
54
        public void setValue(String value) {
 
55
                Value v = new Value();
 
56
                v.setValue(value);
 
57
                InputDescription idesc = new InputDescription();
 
58
                idesc.setValue(v);
 
59
                handle.putXmlAsInputDescription(idesc);
 
60
        }
 
61
 
 
62
        public void setValue(String value, char listSeparator) {
 
63
                Value v = new Value();
 
64
                v.setValue(value);
 
65
                InputDescription idesc = new InputDescription();
 
66
                idesc.setValue(v);
 
67
                idesc.setListDelimiter(new String(new char[] { listSeparator }));
 
68
                handle.putXmlAsInputDescription(idesc);
 
69
        }
 
70
}