All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.schoolwow.workflow.service.WorkFlowInvocationHandler Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package cn.schoolwow.workflow.service;

import cn.schoolwow.workflow.domain.QuickWorkFlowConfig;
import cn.schoolwow.workflow.service.deploy.WorkFlowDeploy;
import cn.schoolwow.workflow.service.deploy.WorkFlowDeployImpl;
import cn.schoolwow.workflow.service.execute.WorkFlowInstanceService;
import cn.schoolwow.workflow.service.execute.WorkFlowInstanceServiceImpl;
import cn.schoolwow.workflow.service.option.WorkFlowOption;
import cn.schoolwow.workflow.service.option.WorkFlowOptionImpl;
import cn.schoolwow.workflow.service.task.WorkFlowTaskService;
import cn.schoolwow.workflow.service.task.WorkFlowTaskServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 代理模式对象
 */
public class WorkFlowInvocationHandler implements InvocationHandler {
    private WorkFlowOption workFlowOption;
    private WorkFlowDeploy workFlowDeploy;
    private WorkFlowInstanceService workFlowExecute;
    private WorkFlowTaskService workFlowTaskService;
    private Object[] interfaceInstanceArray;

    public WorkFlowInvocationHandler(QuickWorkFlowConfig quickWorkFlowConfig) {
        workFlowOption = new WorkFlowOptionImpl(quickWorkFlowConfig);
        workFlowDeploy = new WorkFlowDeployImpl(quickWorkFlowConfig);
        workFlowExecute = new WorkFlowInstanceServiceImpl(quickWorkFlowConfig);
        workFlowTaskService = new WorkFlowTaskServiceImpl(quickWorkFlowConfig);
        interfaceInstanceArray = new Object[]{
                workFlowOption,
                workFlowDeploy,
                workFlowExecute,
                workFlowTaskService
        };
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String interfaceName = method.getDeclaringClass().getSimpleName();
        for(Object interfaceInstance:interfaceInstanceArray){
            Class interfaceClass = interfaceInstance.getClass().getInterfaces()[0];
            if(interfaceClass.getSimpleName().equalsIgnoreCase(interfaceName)){
                try {
                    return method.invoke(interfaceInstance, args);
                }catch (InvocationTargetException e){
                    Throwable targetException = e.getTargetException();
                    throw targetException;
                }
            }
        }
        throw new IllegalAccessError("不支持调用该方法!方法名:"+method.getName());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy