77
|
1 package alice.jungle.operations;
|
|
2
|
|
3 import java.nio.ByteBuffer;
|
|
4
|
|
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
|
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
|
79
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute;
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
77
|
13
|
|
14 import org.msgpack.annotation.Message;
|
|
15
|
79
|
16 import alice.jungle.datasegment.store.transformer.NetworkAppendChildAt;
|
|
17
|
77
|
18 @Message
|
79
|
19 public class NetworkNodeOperation implements NodeOperation{
|
77
|
20
|
|
21 public int pos;
|
78
|
22 public String key;
|
|
23 public ByteBuffer value;
|
|
24 public int commandType;
|
77
|
25
|
|
26 public NetworkNodeOperation() {
|
|
27 pos = -2;
|
78
|
28 key = null;
|
|
29 value = null;
|
|
30 commandType = 0;
|
77
|
31 }
|
|
32
|
|
33 public NetworkNodeOperation(NodeOperation _op) {
|
|
34 pos = _op.getPosition();
|
|
35 key = _op.getKey();
|
|
36 value = _op.getValue();
|
78
|
37 commandType = getCommandType(_op.getCommand());
|
77
|
38 }
|
|
39
|
78
|
40 public static int getCommandType(Command c) {
|
|
41 switch(c) {
|
|
42 case PUT_ATTRIBUTE:
|
|
43 return 1;
|
|
44 case APPEND_CHILD:
|
|
45 return 2;
|
|
46 case DELETE_CHILD:
|
|
47 return 3;
|
|
48 case DELETE_ATTRIBUTE:
|
|
49 return 4;
|
|
50 default:
|
|
51 break;
|
|
52 }
|
|
53 return 0;
|
77
|
54 }
|
|
55
|
78
|
56 public static Command getCommand(int num) {
|
|
57 switch(num) {
|
|
58 case 1:
|
|
59 return Command.PUT_ATTRIBUTE;
|
|
60 case 2:
|
|
61 return Command.APPEND_CHILD;
|
|
62 case 3:
|
|
63 return Command.DELETE_CHILD;
|
|
64 case 4:
|
|
65 return Command.DELETE_ATTRIBUTE;
|
|
66 default:
|
|
67 break;
|
|
68 }
|
|
69 return null;
|
77
|
70 }
|
|
71
|
78
|
72 public Command getCommand() {
|
|
73 return getCommand(commandType);
|
77
|
74 }
|
|
75
|
|
76 public int getPosition() {
|
|
77 return pos;
|
|
78 }
|
|
79
|
|
80 public String getKey() {
|
|
81 return key;
|
|
82 }
|
|
83
|
|
84 public ByteBuffer getValue() {
|
|
85 return value;
|
|
86 }
|
|
87
|
79
|
88 @Override
|
|
89 public <T extends EditableNode<T>> Either<Error, T> invoke(T _target) {
|
|
90 switch(getCommand(commandType)) {
|
|
91 case PUT_ATTRIBUTE:
|
|
92 PutAttribute putAttribute = new PutAttribute(key,value);
|
|
93 return putAttribute.edit(_target);
|
|
94 case APPEND_CHILD:
|
|
95 NetworkAppendChildAt appendChildAt = new NetworkAppendChildAt(pos);
|
|
96 return appendChildAt.edit(_target);
|
|
97 case DELETE_CHILD:
|
|
98 DeleteChildAt deleteChildAt = new DeleteChildAt(pos);
|
|
99 return deleteChildAt.edit(_target);
|
|
100 case DELETE_ATTRIBUTE:
|
|
101 DeleteAttribute deleteAttribute = new DeleteAttribute(key);
|
|
102 return deleteAttribute.edit(_target);
|
|
103 default:
|
|
104 break;
|
|
105 }
|
|
106 return null;
|
|
107 }
|
|
108
|
77
|
109 }
|