1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.statemachine.context;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.mina.statemachine.State;
26
27
28
29
30
31
32
33 public abstract class AbstractStateContext implements StateContext {
34 private State currentState = null;
35
36 private Map<Object, Object> attributes = null;
37
38
39
40
41 @Override
42 public Object getAttribute(Object key) {
43 return getAttributes().get(key);
44 }
45
46
47
48
49 @Override
50 public State getCurrentState() {
51 return currentState;
52 }
53
54
55
56
57 @Override
58 public void setAttribute(Object key, Object value) {
59 getAttributes().put(key, value);
60 }
61
62
63
64
65 @Override
66 public void setCurrentState(State state) {
67 currentState = state;
68 }
69
70 protected Map<Object, Object> getAttributes() {
71 if (attributes == null) {
72 attributes = new HashMap<>();
73 }
74 return attributes;
75 }
76
77
78
79
80 @Override
81 public String toString() {
82 StringBuilder sb = new StringBuilder();
83
84 sb.append("StateContext[");
85 sb.append("currentState=").append(currentState);
86 sb.append(",attributes=").append(attributes);
87 sb.append("]");
88
89 return sb.toString();
90 }
91 }