View Javadoc

1   /*$Id: AgslProtocol.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.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 $Log: AgslProtocol.java,v $
109 Revision 1.1  2004/07/26 12:07:38  nw
110 renamed indirect package to protocol,
111 renamed classes and methods within protocol package
112 javadocs
113 
114 Revision 1.2  2004/07/01 11:16:22  nw
115 merged in branch
116 nww-itn06-componentization
117 
118 Revision 1.1.2.2  2004/07/01 01:42:46  nw
119 final version, before merge
120 
121 Revision 1.1.2.1  2004/06/17 09:21:23  nw
122 finished all major functionality additions to core
123  
124 */