01: package CVS_Shared.Network;
02:
03: /**
04: * All CVS communications are carried out using
05: * Sequence objects, which are sent through the net.
06: *
07: * They ONLY consist of an identifier and a vector.
08: * The vector's content depends on the identifier.
09: *
10: * A sequence can be a request, an answer, an information and so on.
11: * The meaning is given by the identifier and associated data
12: * is carried by the data vector, which can be a tree structure
13: * which only has to be known by the sending / receiving methods.
14: * The identifier carries the meaning and serves as selector for these methods.
15: *
16: * Also version information can be put into the datavector.
17: */
18:
19: import java.util.Vector;
20: import java.io.DataInputStream;
21: import java.io.DataOutputStream;
22: import Schmortopf.Utility.io.FileUtilities;
23: import CVS_Shared.Constants;
24:
25: public class Sequence {
26: private static final int SequenceVersion = 1;
27: private int version = SequenceVersion;
28:
29: private int identifier = 0; // One of the static ints from CVS_Shared.Constants
30: private Vector dataVector = new Vector();
31:
32: /**
33: * Creates a sequence for sending using send() after this.
34: * identifier: One of the static ints from CVS_Shared.Constants.
35: */
36: public Sequence(final int identifier, final Vector dataVector) {
37: this .identifier = identifier;
38: this .dataVector = dataVector;
39: } // Constructor
40:
41: /**
42: * Creates a sequence for reading, using receive() after this creation.
43: */
44: public Sequence() {
45: } // Constructor
46:
47: public void send(final DataOutputStream dataOutputStream)
48: throws Exception {
49: dataOutputStream.writeInt(this .version);
50: dataOutputStream.writeInt(this .identifier);
51: FileUtilities.SendVector(this .dataVector, dataOutputStream,
52: null, 0);
53: }
54:
55: public void receive(final DataInputStream dataInputStream)
56: throws Exception {
57: this .version = dataInputStream.readInt();
58: this .identifier = dataInputStream.readInt();
59: this .dataVector = FileUtilities.ReceiveVector(dataInputStream,
60: null, 0);
61: }
62:
63: public int getVersion() {
64: return this .version;
65: }
66:
67: public int getIdentifier() {
68: return this .identifier;
69: }
70:
71: public Vector getDataVector() {
72: return this .dataVector;
73: }
74:
75: } // Sequence
|