1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.parameter.protocol;
12
13 import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
14 import org.astrogrid.component.descriptor.ComponentDescriptor;
15
16 import java.net.URI;
17 import java.net.URISyntaxException;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import junit.framework.Test;
22
23 /*** Default implementation of {@link org.astrogrid.applications.parameter.protocol.ProtocolLibrary}
24 * @author Noel Winstanley nw@jb.man.ac.uk 16-Jun-2004
25 *
26 */
27 public class DefaultProtocolLibrary implements ProtocolLibrary, ComponentDescriptor {
28 /*** add a protocl to the set supported by this library */
29 public void addProtocol(Protocol p) {
30 map.put(p.getProtocolName().toLowerCase(),p);
31
32 }
33
34
35 /*** Construct a new DefaultIndirectionProtocolLibrary
36 *
37 */
38 public DefaultProtocolLibrary() {
39 super();
40 this.map = new HashMap();
41 }
42 protected final Map map;
43 /***
44 * @see org.astrogrid.applications.parameter.protocol.ProtocolLibrary#getExternalValue(org.astrogrid.applications.beans.v1.parameters.ParameterValue)
45 */
46 public ExternalValue getExternalValue(ParameterValue pval)
47 throws InaccessibleExternalValueException, UnrecognizedProtocolException{
48 URI reference;
49 try {
50 reference = new URI(pval.getValue());
51 }
52 catch (URISyntaxException e) {
53 throw new UnrecognizedProtocolException(pval.getValue(),e);
54 }
55 return getExternalValue(reference);
56 }
57 /***
58 * @see org.astrogrid.applications.parameter.protocol.ProtocolLibrary#getExternalValue(java.net.URI)
59 */
60 public ExternalValue getExternalValue(URI reference) throws InaccessibleExternalValueException, UnrecognizedProtocolException {
61 Protocol p = (Protocol) map.get(reference.getScheme());
62 if (p == null) {
63 throw new UnrecognizedProtocolException(reference.toString());
64 }
65 return p.createIndirectValue(reference);
66 }
67
68
69
70 /***
71 * @see org.astrogrid.applications.parameter.protocol.ProtocolLibrary#getExternalValue(java.lang.String)
72 */
73 public ExternalValue getExternalValue(String location) throws InaccessibleExternalValueException, UnrecognizedProtocolException, URISyntaxException {
74 return getExternalValue(new URI(location));
75 }
76 /***
77 * @see org.astrogrid.applications.parameter.protocol.ProtocolLibrary#listSupportedProtocols()
78 */
79 public String[] listSupportedProtocols() {
80 return (String[])map.keySet().toArray(new String[]{});
81 }
82 /***
83 * @see org.astrogrid.applications.parameter.protocol.ProtocolLibrary#isProtocolSupported(java.lang.String)
84 */
85 public boolean isProtocolSupported(String protocol) {
86 return map.containsKey(protocol.toLowerCase());
87 }
88
89
90 /***
91 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
92 */
93 public String getName() {
94 return "DefaultIndirectionProtocolLibrary";
95 }
96
97
98 /***
99 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
100 */
101 public String getDescription() {
102 return "Supported Protocols:" + map.keySet();
103 }
104
105
106 /***
107 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
108 */
109 public Test getInstallationTest() {
110 return null;
111 }
112
113
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147