View Javadoc

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