Mercurial > hg > Database > jungle-network
comparison src/alice/jungle/datasegment/store/container/DefaultNodeOperationContainer.java @ 75:87ec5dd0dc27
Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
author | one |
---|---|
date | Tue, 15 Oct 2013 14:43:29 +0900 |
parents | src/alice/jungle/datasegment/store/operations/DefaultNodeOperationContainer.java@85bc7416ae02 |
children |
comparison
equal
deleted
inserted
replaced
74:19e278488b42 | 75:87ec5dd0dc27 |
---|---|
1 package alice.jungle.datasegment.store.container; | |
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.type.Value; | |
17 | |
18 import alice.codesegment.SingletonMessage; | |
19 | |
20 @Message | |
21 public class DefaultNodeOperationContainer { | |
22 | |
23 public int pos; | |
24 public String key; | |
25 public Value value; | |
26 public Value commandValue; | |
27 | |
28 public static void main(String[] args) throws IOException { | |
29 String key = "hoge"; | |
30 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); | |
31 PutAttributeOperation op = new PutAttributeOperation(key, b); | |
32 DefaultNodeOperationContainer container = new DefaultNodeOperationContainer(); | |
33 container.unconvert(op); | |
34 NodeOperation convertedOp = container.convert(); | |
35 System.out.println("pos : "+convertedOp.getPosition()); | |
36 System.out.println("Command : "+convertedOp.getCommand()); | |
37 System.out.println("key : "+convertedOp.getKey()); | |
38 System.out.println("value : "+new String(convertedOp.getValue().array())); | |
39 | |
40 } | |
41 | |
42 public DefaultNodeOperationContainer() { | |
43 | |
44 } | |
45 | |
46 public void unconvert(NodeOperation op) throws IOException { | |
47 // MessagePack msgpack = new MessagePack(); | |
48 MessagePack msgpack = SingletonMessage.getInstance(); | |
49 pos = op.getPosition(); | |
50 key = op.getKey(); | |
51 value = null; | |
52 if (op.getValue() != null) { | |
53 ByteBuffer b = op.getValue(); | |
54 byte[] bytes = b.array(); | |
55 Value v = msgpack.unconvert(bytes); | |
56 value = v; | |
57 } | |
58 Command c = op.getCommand(); | |
59 msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); | |
60 Value cValue = msgpack.unconvert(c); | |
61 commandValue = cValue; | |
62 } | |
63 | |
64 public NodeOperation convert() throws IOException{ | |
65 // MessagePack msgpack = new MessagePack(); | |
66 MessagePack msgpack = SingletonMessage.getInstance(); | |
67 msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); | |
68 Command c = msgpack.convert(commandValue, Command.class); | |
69 ByteBuffer b = null; | |
70 if (value != null) { | |
71 b = ByteBuffer.wrap(msgpack.convert(value, byte[].class)); | |
72 } | |
73 if (c == Command.PUT_ATTRIBUTE) { | |
74 return new PutAttributeOperation(key, b); | |
75 } else if (c == Command.APPEND_CHILD) { | |
76 return new AppendChildAtOperation(pos); | |
77 } else if (c == Command.DELETE_CHILD) { | |
78 return new DeleteChildAtOperation(pos); | |
79 } else if (c == Command.DELETE_ATTRIBUTE){ | |
80 return new DeleteAttributeOperation(key); | |
81 } | |
82 return null; | |
83 } | |
84 | |
85 } |