annotate src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingAttributes.java @ 25:1b448f9249ee

mark
author Shoshi TAMAKI
date Sun, 13 Jan 2013 20:52:19 +0900
parents 3ef2a66a8c5d
children 418088ca2b30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
2
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
3 import java.nio.ByteBuffer;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.SetAttributeOperation;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode;
23
Shoshi TAMAKI
parents: 21
diff changeset
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither;
Shoshi TAMAKI
parents: 21
diff changeset
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
25
Shoshi TAMAKI
parents: 23
diff changeset
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
12
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
13 public class LoggingAttributes implements EditableAttributes
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
14 {
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
15 private final EditableAttributes wrap;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
16 private final Logger log;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
17
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
18 public LoggingAttributes(EditableAttributes _wrap,Logger _log)
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
19 {
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
20 wrap = _wrap;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
21 log = _log;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
22 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
23
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
24 @Override
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
25 public ByteBuffer get(String _key)
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
26 {
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
27 return wrap.get(_key);
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
28 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
29
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
30 @Override
23
Shoshi TAMAKI
parents: 21
diff changeset
31 public Either<Error,EditableNode> delete(final String _key)
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
32 {
23
Shoshi TAMAKI
parents: 21
diff changeset
33
Shoshi TAMAKI
parents: 21
diff changeset
34 Either<Error,EditableNode> either = wrap.delete(_key);
Shoshi TAMAKI
parents: 21
diff changeset
35 if(either.isA()){
Shoshi TAMAKI
parents: 21
diff changeset
36 return either;
Shoshi TAMAKI
parents: 21
diff changeset
37 }
Shoshi TAMAKI
parents: 21
diff changeset
38
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
39 Operation opDelete = new DeleteAttributeOperation(){
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
40 @Override
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
41 public String getKey(){
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
42 return _key;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
43 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
44 };
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
45
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
46 Logger newLog = log.add(opDelete);
23
Shoshi TAMAKI
parents: 21
diff changeset
47 EditableNode newWrap = either.b();
Shoshi TAMAKI
parents: 21
diff changeset
48 EditableNode newLoggingNode = new LoggingNode(newWrap,newLog);
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
49
23
Shoshi TAMAKI
parents: 21
diff changeset
50 return DefaultEither.newB(newLoggingNode);
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
51 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
52
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
53 @Override
23
Shoshi TAMAKI
parents: 21
diff changeset
54 public Either<Error,EditableNode> put(final String _key,final ByteBuffer _value)
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
55 {
23
Shoshi TAMAKI
parents: 21
diff changeset
56 Either<Error,EditableNode> either = wrap.put(_key,_value);
Shoshi TAMAKI
parents: 21
diff changeset
57 if(either.isA()){
Shoshi TAMAKI
parents: 21
diff changeset
58 return either;
Shoshi TAMAKI
parents: 21
diff changeset
59 }
Shoshi TAMAKI
parents: 21
diff changeset
60
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
61 Operation opPut = new SetAttributeOperation(){
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
62 @Override
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
63 public String getKey(){
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
64 return _key;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
65 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
66
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
67 @Override
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
68 public ByteBuffer getValue(){
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
69 return _value;
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
70 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
71 };
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
72
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
73 Logger newLog = log.add(opPut);
23
Shoshi TAMAKI
parents: 21
diff changeset
74 EditableNode newLoggingNode = new LoggingNode(either.b(),newLog);
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
75
23
Shoshi TAMAKI
parents: 21
diff changeset
76 return DefaultEither.newB(newLoggingNode);
21
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
77 }
848f73545c4d add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff changeset
78 }