72345194313ceefa4d6ec6345ffd54a7d938627b
[mediacube.git] /
1 package user.commons.nexio.server.protocol;
2
3 import java.io.IOException;
4 import java.util.Calendar;
5
6 public class NexioServerProtocolImpl implements NexioServerProtocol {
7
8         private GetExtendedIDFromIDHandleCommand getExtendedIDFromIDHandleCommand = null;
9         private GetIDMetadataCommand getIDMetadataCommand = null;
10         private GetIDHandleFromExtendedIDCommand getIDHandleFromExtendedIDCommand = null;
11         private GetExtendedFieldGetModifiedTimestampCommand getExtendedFieldGetModifiedTimestampCommand = null;
12         private GetExtendedFieldGetRecordDateTimestampCommand getExtendedFieldGetRecordDateTimestampCommand = null;
13         private ListFirstIDHandleCommand listFirstIDHandleCommand = null;
14         private ListNextIDHandleCommand listNextIDHandleCommand = null;
15         private GetIDFileSizeCommand getIDFileSizeCommand = null;
16         private PortStatusCommand portStatusCommand = null;
17         private GetExtendedFieldCommand getExtendedFieldCommand = null;
18
19         private Connection connection = null;
20
21         public NexioServerProtocolImpl(Connection _connection) {
22                 this.connection = _connection;
23                 getExtendedIDFromIDHandleCommand = new GetExtendedIDFromIDHandleCommand(connection);
24                 getIDMetadataCommand = new GetIDMetadataCommand(connection);
25                 getIDHandleFromExtendedIDCommand = new GetIDHandleFromExtendedIDCommand(connection);
26                 getExtendedFieldGetModifiedTimestampCommand = new GetExtendedFieldGetModifiedTimestampCommand(connection);
27                 getExtendedFieldGetRecordDateTimestampCommand = new GetExtendedFieldGetRecordDateTimestampCommand(connection);
28                 listFirstIDHandleCommand = new ListFirstIDHandleCommand(connection);
29                 listNextIDHandleCommand = new ListNextIDHandleCommand(connection);
30                 getIDFileSizeCommand = new GetIDFileSizeCommand(connection);
31                 portStatusCommand = new PortStatusCommand(connection);
32                 getExtendedFieldCommand = new GetExtendedFieldCommand(connection);
33         }
34
35         @Override
36         public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException {
37                 return getExtendedFieldCommand.execute(id, fieldNumber);
38         }
39
40         @Override
41         public Calendar executeGetExtendedFieldGetModifiedTimestamp(Id id) throws IOException, ProtocolException {
42                 return getExtendedFieldGetModifiedTimestampCommand.execute(id);
43         }
44
45         @Override
46         public Calendar executeGetExtendedFieldGetRecordDateTimestamp(Id id) throws IOException, ProtocolException {
47                 return getExtendedFieldGetRecordDateTimestampCommand.execute(id);
48         }
49
50         @Override
51         public Xid executeGetExtendedIDFromIDHandle(Id id) throws IOException, ProtocolException {
52                 return getExtendedIDFromIDHandleCommand.execute(id);
53         }
54
55         @Override
56         public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException {
57                 return getIDFileSizeCommand.execute(id);
58         }
59
60         @Override
61         public Id executeGetIDHandleFromExtendedID(Xid xid) throws IOException, ProtocolException {
62                 return getIDHandleFromExtendedIDCommand.execute(xid);
63         }
64
65         @Override
66         public byte[] executeGetIDMetadata(Id id) throws IOException, ProtocolException {
67                 return getIDMetadataCommand.execute(id);
68         }
69
70         @Override
71         public Id executeListFirstIDHandle() throws IOException, ProtocolException {
72                 return listFirstIDHandleCommand.execute();
73         }
74
75         @Override
76         public Id executeListNextIDHandle() throws IOException, ProtocolException {
77                 return listNextIDHandleCommand.execute();
78         }
79
80         @Override
81         public byte executePortStatusCommand() throws IOException, ProtocolException {
82                 return portStatusCommand.execute();
83         }
84
85         @Override
86         public Connection getConnection() {
87                 return this.connection;
88         }
89
90         @Override
91         public void setDescription(String id, String description) throws IOException {
92                 byte[] SET_DESCRIPTION = ("...." + id + description).getBytes();
93                 SET_DESCRIPTION[0] = (byte) 0xCF;
94                 SET_DESCRIPTION[1] = (byte) 0xCC;
95                 SET_DESCRIPTION[2] = (byte) 0xBC;
96                 SET_DESCRIPTION[3] = (byte) 0x12;
97                 connection.write(SET_DESCRIPTION);
98                 connection.flush();
99         }
100 }