Mercurial > hg > Database > jungle-network
comparison src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java @ 2:20498c88a70d
add Container
author | one |
---|---|
date | Sun, 09 Jun 2013 13:53:16 +0900 |
parents | |
children | 3770d2be3e73 |
comparison
equal
deleted
inserted
replaced
1:8ee02d1a2b12 | 2:20498c88a70d |
---|---|
1 package jungle.test.datasegment.store.operations; | |
2 | |
3 import java.io.IOException; | |
4 import java.nio.ByteBuffer; | |
5 | |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; | |
12 | |
13 import org.msgpack.MessagePack; | |
14 import org.msgpack.annotation.Message; | |
15 import org.msgpack.template.OrdinalEnumTemplate; | |
16 import org.msgpack.template.Template; | |
17 import org.msgpack.type.Value; | |
18 | |
19 @Message | |
20 public class DefaultNodeOperationContainer { | |
21 | |
22 public int pos; | |
23 public String key; | |
24 public Value value; | |
25 public Value commandValue; | |
26 | |
27 | |
28 public DefaultNodeOperationContainer() { | |
29 | |
30 } | |
31 | |
32 public void unconvert(NodeOperation op) throws IOException { | |
33 MessagePack msgpack = new MessagePack(); | |
34 pos = op.getPosition(); | |
35 key = op.getKey(); | |
36 value = null; | |
37 if (op.getValue() != null) { | |
38 ByteBuffer b = op.getValue(); | |
39 Value v = msgpack.unconvert(b); | |
40 value = v; | |
41 } | |
42 Command c = op.getCommand(); | |
43 msgpack.register(c.getClass(), new OrdinalEnumTemplate(c.getClass())); | |
44 Value cValue = msgpack.unconvert(c); | |
45 commandValue = cValue; | |
46 } | |
47 | |
48 public NodeOperation convert() throws IOException{ | |
49 MessagePack msgpack = new MessagePack(); | |
50 Command c = msgpack.convert(commandValue, Command.class); | |
51 ByteBuffer b = null; | |
52 if (value != null) { | |
53 b = msgpack.convert(value, ByteBuffer.class); | |
54 } | |
55 if (c == Command.PUT_ATTRIBUTE) { | |
56 return new PutAttributeOperation(key, b); | |
57 } else if (c == Command.APPEND_CHILD) { | |
58 return new AppendChildAtOperation(pos); | |
59 } else if (c == Command.DELETE_CHILD) { | |
60 return new DeleteChildAtOperation(pos); | |
61 } else if (c == Command.DELETE_ATTRIBUTE){ | |
62 return new DeleteAttributeOperation(key); | |
63 } | |
64 return null; | |
65 } | |
66 | |
67 | |
68 } |