View Javadoc

1   /*$Id: IvornProtocol.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.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  $Log: IvornProtocol.java,v $
99  Revision 1.1  2004/07/26 12:07:38  nw
100 renamed indirect package to protocol,
101 renamed classes and methods within protocol package
102 javadocs
103 
104 Revision 1.2  2004/07/01 11:16:22  nw
105 merged in branch
106 nww-itn06-componentization
107 
108 Revision 1.1.2.2  2004/07/01 01:42:46  nw
109 final version, before merge
110 
111 Revision 1.1.2.1  2004/06/17 09:21:23  nw
112 finished all major functionality additions to core
113  
114 */