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.Agsl;
16 import org.astrogrid.store.delegate.StoreClient;
17 import org.astrogrid.store.delegate.StoreDelegateFactory;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.net.MalformedURLException;
23 import java.net.URI;
24
25 import junit.framework.Test;
26
27 /*** Protocol implemrantion for Astrogrid Store Locators
28 * @author Noel Winstanley nw@jb.man.ac.uk 16-Jun-2004
29 * @todo this is only a first stab - dunno what I'm meant to be doing here. so really unlikely this protocol will work.
30 */
31 public class AgslProtocol implements Protocol, ComponentDescriptor {
32 /*** Construct a new AgslProtocol
33 *
34 */
35 public AgslProtocol() {
36 super();
37 }
38 /***
39 * @see org.astrogrid.applications.parameter.protocol.Protocol#getProtocolName()
40 */
41 public String getProtocolName() {
42 return Agsl.SCHEME;
43 }
44 /***
45 * @see org.astrogrid.applications.parameter.protocol.Protocol#createIndirectValue(java.net.URI)
46 * @todo find nice way to pass correct user value in here.
47 */
48 public ExternalValue createIndirectValue(final URI reference) throws InaccessibleExternalValueException{
49 final Agsl agsl;
50
51 try {
52 agsl = new Agsl(reference.toString());
53 }
54 catch (MalformedURLException e1) {
55 throw new InaccessibleExternalValueException(reference.toString(),e1);
56 }
57
58 final StoreClient client;
59 try {
60 client = StoreDelegateFactory.createDelegate(new User(), agsl);
61 }
62 catch (IOException e2) {
63
64 throw new InaccessibleExternalValueException(reference.toString(),e2);
65 }
66 return new ExternalValue() {
67
68
69 public InputStream read() throws InaccessibleExternalValueException {
70 try {
71 return client.getStream(agsl.toString());
72 } catch (IOException e) {
73 throw new InaccessibleExternalValueException(agsl.toString(),e);
74 }
75 }
76
77 public OutputStream write() throws InaccessibleExternalValueException {
78 try {
79 return client.putStream(agsl.toString(),true);
80 } catch (IOException e) {
81 throw new InaccessibleExternalValueException(agsl.toString(),e);
82 }
83 }
84 };
85 }
86 /***
87 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
88 */
89 public String getName() {
90 return "AglsProtocol";
91 }
92 /***
93 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
94 */
95 public String getDescription() {
96 return "Protocol adapter for AGSLs";
97 }
98 /***
99 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
100 */
101 public Test getInstallationTest() {
102 return null;
103 }
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124