39
|
1 package jungle.test.bbs;
|
|
2
|
|
3 import java.nio.ByteBuffer;
|
15
|
4
|
31
|
5 import alice.jungle.core.NetworkDefaultJungle;
|
20
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
|
15
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
39
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
15
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
|
39
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog;
|
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
|
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
|
15
|
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
|
39
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
15
|
19
|
|
20 public class JungleManager {
|
24
|
21 static Jungle jungle = new NetworkDefaultJungle(null,"hoge",new DefaultTreeEditor(new DefaultTraverser()));
|
15
|
22
|
|
23 public JungleManager() {
|
|
24
|
|
25 }
|
|
26
|
|
27 public Jungle getJungle() {
|
|
28 return jungle;
|
|
29 }
|
|
30
|
18
|
31 public JungleTree createNewTree(String name) {
|
15
|
32 return jungle.createNewTree(name);
|
|
33 }
|
|
34
|
|
35
|
39
|
36 public Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,TreeOperationLog _log) {
|
|
37 JungleTreeEditor editor = _editor;
|
|
38 Either<Error, JungleTreeEditor> either = null;
|
|
39 for (TreeOperation op : _log) {
|
|
40 either = _edit(editor, op);
|
|
41 if(either.isA()) {
|
|
42 return either;
|
|
43 }
|
|
44 editor = either.b();
|
|
45 }
|
|
46 return either;
|
|
47 }
|
|
48
|
|
49 private Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor,
|
|
50 TreeOperation op) {
|
|
51 NodePath path = op.getNodePath();
|
|
52 NodeOperation nodeOp = op.getNodeOperation();
|
|
53 Command c = nodeOp.getCommand();
|
|
54 String key = "";
|
|
55 switch (c) {
|
|
56 case PUT_ATTRIBUTE:
|
|
57 key = nodeOp.getKey();
|
|
58 ByteBuffer value = nodeOp.getValue();
|
|
59 return editor.putAttribute(path, key, value);
|
|
60 case DELETE_ATTRIBUTE:
|
|
61 key = nodeOp.getKey();
|
|
62 return editor.deleteAttribute(path, key);
|
|
63 case APPEND_CHILD:
|
|
64 return editor.addNewChildAt(path, 0);
|
|
65 case DELETE_CHILD:
|
|
66 return editor.deleteChildAt(path, 0);
|
|
67 }
|
|
68 return null;
|
|
69 }
|
15
|
70 }
|