1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.parameter.protocol;
12
13 import org.astrogrid.community.User;
14 import org.astrogrid.component.descriptor.ComponentDescriptor;
15 import org.astrogrid.store.Ivorn;
16 import org.astrogrid.store.VoSpaceClient;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.net.URI;
22 import java.net.URISyntaxException;
23
24 import junit.framework.Test;
25
26 /*** protocol implementation for ivo:/
27 * @author Noel Winstanley nw@jb.man.ac.uk 16-Jun-2004
28 *
29 */
30 public class IvornProtocol implements Protocol , ComponentDescriptor{
31 /*** Construct a new IvornProtocol
32 *
33 */
34 public IvornProtocol() {
35 super();
36 }
37 /***
38 * @see org.astrogrid.applications.parameter.protocol.Protocol#getProtocolName()
39 */
40 public String getProtocolName() {
41 return Ivorn.SCHEME;
42 }
43 /***
44 * @see org.astrogrid.applications.parameter.protocol.Protocol#createIndirectValue(java.net.URI)
45 * @todo find nice way to pass correct user value in here.
46 */
47 public ExternalValue createIndirectValue(final URI reference) throws InaccessibleExternalValueException {
48 final Ivorn ivorn;
49 try {
50 ivorn = new Ivorn(reference.toString());
51 }
52 catch (URISyntaxException e) {
53 throw new InaccessibleExternalValueException(reference.toString(),e);
54 }
55 return new ExternalValue() {
56
57 VoSpaceClient client = new VoSpaceClient(new User());
58
59 public InputStream read() throws InaccessibleExternalValueException {
60 try {
61 return client.getStream(ivorn);
62 } catch (IOException e) {
63 throw new InaccessibleExternalValueException(ivorn.toString(),e);
64 }
65 }
66
67 public OutputStream write() throws InaccessibleExternalValueException {
68 try {
69 return client.putStream(ivorn);
70 } catch (IOException e) {
71 throw new InaccessibleExternalValueException(ivorn.toString(),e);
72 }
73 }
74 };
75 }
76 /***
77 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
78 */
79 public String getName() {
80 return "IvornProtocol";
81 }
82 /***
83 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
84 */
85 public String getDescription() {
86 return "protocol adapter for ivo: urns";
87 }
88 /***
89 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
90 */
91 public Test getInstallationTest() {
92 return null;
93 }
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114