ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.server.bof.event;
 
import com.vci.corba.common.data.VCIInvocationInfo;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.server.bof.event.IServerEvent;
import com.vci.server.bof.server.ServiceParams;
import com.vci.server.mw.ServerContextVariable;
 
public class ServerPreEvent implements IServerEvent {
    
    private static ServerPreEvent instance = null;
    
    public static ServerPreEvent getInstance() {
        if(instance == null) {
            instance = new ServerPreEvent();
        }
        return instance;
    }
 
    @Override
    public void doAction(ServiceParams params) throws Exception {
        String className = ServerContextVariable.getVariablebyKey(PRE_EVENT_KEY);
        if(className != null && className.length() > 0) {
            //取过数据之后把这个变量置为空字符串,避免在后置事件调用服务端方法时,再次触发前后置事件而造成迭代
            VCIInvocationInfo info = HibernateSessionFactory.getVciSessionInfo();
            String[] exAttrs = info.extAttribs;
            for (int i = 0; i < exAttrs.length; ++i) {
                if ((exAttrs[i] != null) && 
                        (exAttrs[i].indexOf(PRE_EVENT_KEY + "=") == 0)) {                    
                    exAttrs[i] = "";
                    info.extAttribs = exAttrs;
                    break;
                }
            }
            String[] classNames = className.split(EVENT_SEP);
            for(String name : classNames) {                
                Class<?> c = Class.forName(name);
                Object obj = c.newInstance();
                System.out.println("触发前置事件:" + c.getSimpleName() + "!");
                c.getDeclaredMethod("doAction", ServiceParams.class).invoke(obj, params);
            }
        }
    }
 
}