1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.gridservice.server;
30
31 import org.apache.mina.common.ByteBuffer;
32
33 import uk.ac.rdg.resc.jstyx.server.StyxFile;
34 import uk.ac.rdg.resc.jstyx.server.StyxFileClient;
35 import uk.ac.rdg.resc.jstyx.types.ULong;
36 import uk.ac.rdg.resc.jstyx.StyxException;
37 import uk.ac.rdg.resc.jstyx.StyxUtils;
38
39 /***
40 * A StyxFile that provides an interface to a ServiceDataElement
41 *
42 * @author Jon Blower
43 * $Revision: 401 $
44 * $Date: 2005-09-08 08:08:59 +0100 (Thu, 08 Sep 2005) $
45 * $Log$
46 * Revision 1.6 2005/09/08 07:08:59 jonblower
47 * Removed "String user" from list of parameters to StyxFile.write()
48 *
49 * Revision 1.5 2005/08/30 16:29:00 jonblower
50 * Added processAndReplyRead() helper functions to StyxFile
51 *
52 * Revision 1.4 2005/03/24 09:48:31 jonblower
53 * Changed 'count' from long to int throughout for reading and writing
54 *
55 * Revision 1.3 2005/03/19 21:47:02 jonblower
56 * Further fixes relating to releasing ByteBuffers
57 *
58 * Revision 1.2 2005/03/18 16:45:18 jonblower
59 * Released ByteBuffers after use
60 *
61 * Revision 1.1 2005/03/16 22:16:44 jonblower
62 * Added Styx Grid Service classes to core module
63 *
64 * Revision 1.2 2005/03/16 17:59:35 jonblower
65 * Changed following changes to core JStyx library (replacement of java.nio.ByteBuffers with MINA's ByteBuffers)
66 *
67 * Revision 1.1 2005/02/16 19:22:31 jonblower
68 * Commit adding of SGS files to CVS
69 *
70 */
71 class SDEFile extends StyxFile
72 {
73 private ServiceDataElement sde;
74
75 public SDEFile(ServiceDataElement sde) throws StyxException
76 {
77 super(sde.getName());
78 this.sde = sde;
79 }
80
81 public void read(StyxFileClient client, long offset, int count, int tag)
82 throws StyxException
83 {
84 byte[] bytes = this.sde.getBytes();
85 this.processAndReplyRead(bytes, client, offset, count, tag);
86 }
87
88 /***
89 * We implicitly assume that the new value of the Service Data is
90 * contained in a single write message
91 * @todo: what happens if this isn't the case?
92 */
93 public void write(StyxFileClient client, long offset, int count,
94 ByteBuffer data, boolean truncate, int tag)
95 throws StyxException
96 {
97
98 if(this.sde.isReadOnly())
99 {
100 throw new StyxException("Cannot write to this file");
101 }
102
103
104 byte[] bytes = new byte[(int)count];
105 data.get(bytes);
106 this.sde.setValue(bytes);
107 this.replyWrite(client, count, tag);
108 }
109
110 public ULong getLength()
111 {
112 return new ULong(this.sde.getBytes().length);
113 }
114
115 }