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