View Javadoc

1   /*$Id: DefaultProtocolLibrary.java,v 1.3 2004/11/29 20:00:56 clq2 Exp $
2    * Created on 16-Jun-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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 $Log: DefaultProtocolLibrary.java,v $
119 Revision 1.3  2004/11/29 20:00:56  clq2
120 nww-itn07-684
121 
122 Revision 1.1.78.1  2004/11/26 15:14:21  nw
123 stuff brougt over from head
124 
125 Revision 1.2  2004/11/22 18:26:37  clq2
126 nww-itn07-715a
127 
128 Revision 1.1.84.1  2004/11/22 14:27:21  nw
129 added factory, and create-from-string-uri methods, to make
130 this package more accessible from other user's code / scripts.
131 
132 Revision 1.1  2004/07/26 12:07:38  nw
133 renamed indirect package to protocol,
134 renamed classes and methods within protocol package
135 javadocs
136 
137 Revision 1.2  2004/07/01 11:16:22  nw
138 merged in branch
139 nww-itn06-componentization
140 
141 Revision 1.1.2.2  2004/07/01 01:42:46  nw
142 final version, before merge
143 
144 Revision 1.1.2.1  2004/06/17 09:21:23  nw
145 finished all major functionality additions to core
146  
147 */