View Javadoc

1   /*$Id: HttpProtocol.java,v 1.1 2004/07/26 12:07:38 nw 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.component.descriptor.ComponentDescriptor;
14  
15  import java.io.IOException;
16  import java.io.InputStream;
17  import java.io.OutputStream;
18  import java.net.URI;
19  
20  import junit.framework.Test;
21  
22  /*** Protocol implementation for http:/
23   * @todo replae with more robust implementation based on commons HttpClient.
24   * @author Noel Winstanley nw@jb.man.ac.uk 16-Jun-2004
25   *
26   */
27  public class HttpProtocol implements Protocol, ComponentDescriptor {
28      /*** Construct a new HttpProtocol
29       * 
30       */
31      public HttpProtocol() {
32          super();
33      }
34      /***
35       * @see org.astrogrid.applications.parameter.protocol.Protocol#getProtocolName()
36       */
37      public String getProtocolName() {
38          return "http";
39      }
40      /***
41       * @see org.astrogrid.applications.parameter.protocol.Protocol#createIndirectValue(java.net.URI)
42       */
43      public ExternalValue createIndirectValue(final URI reference) throws InaccessibleExternalValueException {
44          return new ExternalValue() {
45  
46              public InputStream read() throws InaccessibleExternalValueException {
47                  try {
48                  return reference.toURL().openStream();
49                  } catch (IOException e) {
50                      throw new InaccessibleExternalValueException(reference.toString(),e );
51                  }
52              }
53  
54              public OutputStream write() throws InaccessibleExternalValueException {              
55                try {
56                  return reference.toURL().openConnection().getOutputStream();
57                } catch (IOException e) {
58                      throw new InaccessibleExternalValueException(reference.toString(),e );
59                  }
60              }
61          };
62      }
63      /***
64       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
65       */
66      public String getName() {
67          return "HttpProtocol";
68      }
69      /***
70       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
71       */
72      public String getDescription() {
73          return "Protocol adapter for http:/ protocol";
74      }
75      /***
76       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
77       */
78      public Test getInstallationTest() {
79          return null;
80      }
81  }
82  
83  
84  /* 
85  $Log: HttpProtocol.java,v $
86  Revision 1.1  2004/07/26 12:07:38  nw
87  renamed indirect package to protocol,
88  renamed classes and methods within protocol package
89  javadocs
90  
91  Revision 1.2  2004/07/01 11:16:22  nw
92  merged in branch
93  nww-itn06-componentization
94  
95  Revision 1.1.2.2  2004/07/01 01:42:46  nw
96  final version, before merge
97  
98  Revision 1.1.2.1  2004/06/17 09:21:23  nw
99  finished all major functionality additions to core
100  
101 */