P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package foundation.state;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import foundation.dao.preload.Bucket;
import foundation.util.Util;
 
public class MachineBucket extends Bucket<StateMachine> {
 
    private static Object locker = new Object();
    private static MachineBucket instance;
    private Map<String, StateMachine> dataMachineMap;
    
    
    public MachineBucket() {
        dataMachineMap = new HashMap<String, StateMachine>();
    }
    
    public static MachineBucket getInstance() {
        if (instance == null) {
            synchronized (locker) {
                if (instance == null) {
                    instance = new MachineBucket();
                }
            }
        }
        
        return instance;
    }
    
    public static MachineBucket newInstance() {
        return new MachineBucket();
    }
    
    @Override
    public void activate() {
        instance = this;
    }
 
    public void loadtarget(String dataName, StateMachine machine) {
        dataMachineMap.put(dataName, machine);
    }
 
    public static StateMachine getMachineByDataName(String dataName) {
        StateMachine result = instance.dataMachineMap.get(dataName);
        
        if (result == null) {
            logger.error("数据对象{}对应的状态机没有找到", dataName);
        }
        
        return result;
    }
    
    public static StateMachine getMachineById(String machineId) {
        StateMachine result = instance.get(machineId);
        
        if (result == null) {
            logger.error("状态机{}没有找到", machineId);
        }
        
        return result;
    }
    
    public static boolean isInFreedom(String dataName, String stateCode) {
        if (Util.isEmpty(stateCode)) {
            return true;
        }
        
        StateMachine machine = getMachineByDataName(dataName);
        
        if (machine == null) {
            return false;
        }
        
        State state = machine.getState(stateCode);
        
        if (state == null) {
            return false;
        }
        
        return state.isInFreedom();
    }
    
    public static StateField getStateField(String dataName) {
        StateMachine machine = getMachineByDataName(dataName);
        
        if (machine == null) {
            return null;
        }
        
        return machine.getStateField();
    }
}