定義可裝配的流程編排器

流程編排器

流程編排器

package com;


import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author lingao
 * @version $Id: ProcessorArrayList.java, v 0.1 2018年12月21日 1:32 PM lingao Exp $
 */
public final class ProcessorArrayList<E extends Object> extends ArrayList<E> {

    private List<E> procList;

    private final String name;

    public ProcessorArrayList(String name){
        this.name = name;
    }

    public void init(){
        if(!isEmpty(procList)){
            /** 存在list中的值還是個list情況 */
            for(Object obj : procList){
                if(obj instanceof List){
                    addAll((List<E>)obj);
                }else{
                    add((E) obj);
                }
            }
        }
    }

    private boolean isEmpty(List list){
        return list == null || list.isEmpty();
    }

    /**
     * Getter method for property <tt>procList</tt>.
     *
     * @return property value of procList
     */
    public List<E> getProcList() {
        return procList;
    }

    /**
     * Setter method for property <tt>procList</tt>.
     *
     * @param procList value to be assigned to property procList
     */
    public void setProcList(List<E> procList) {
        this.procList = procList;
    }

}
package com.processor;

/**
 *
 * @author lingao
 * @version $Id: ApplyPayProcessor.java, v 0.1 2018年12月22日 6:04 PM lingao Exp $
 */
public class ApplyPayProcessor {

    public ApplyPayProcessor(){
    }
}
package com.processor;

/**
 *
 * @author lingao
 * @version $Id: RequestLogProcessor.java, v 0.1 2018年12月21日 2:22 PM lingao Exp $
 */
public class RequestLogProcessor {

    public RequestLogProcessor(){
    }
}
package com.processor;

/**
 *
 * @author lingao
 * @version $Id: ResponseLogProcessor.java, v 0.1 2018年12月21日 2:22 PM lingao Exp $
 */
public class ResponseLogProcessor {
    public ResponseLogProcessor(){
    }
}
package com.processor;

/**
 *
 * @author lingao
 * @version $Id: RiskVerifyProcessor.java, v 0.1 2018年12月21日 2:29 PM lingao Exp $
 */
public class RiskVerifyProcessor {

    public RiskVerifyProcessor(){
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="requestLog1Processor" class="com.processor.RequestLogProcessor" />
    <bean id="responseLog1Processor" class="com.processor.ResponseLogProcessor" />
    <bean id="riskVerify1Processor" class="com.processor.RiskVerifyProcessor" />
    <bean id="applyPay1Processor" class="com.processor.ApplyPayProcessor"/>

    <bean id="prefix" class="com.ProcessorArrayList" init-method="init">
        <constructor-arg value="prefix" />
        <property name="procList">
            <list>
                <ref bean="requestLog1Processor" />
            </list>
        </property>
    </bean>

    <bean id="suffix" class="com.ProcessorArrayList" init-method="init">
        <constructor-arg value="suffix"/>
        <property name="procList">
            <list>
                <ref bean="responseLog1Processor" />
            </list>
        </property>
    </bean>

    <bean id="commonPayProcessors" class="com.ProcessorArrayList" init-method="init">
        <constructor-arg value="commonPayProcessors"/>
        <property name="procList">
            <list>
                <ref bean="prefix"/>
                <ref bean="riskVerify1Processor"/>
                <ref bean="suffix"/>
            </list>
        </property>
    </bean>

    <bean id="testProc" class="com.ProcessorArrayList" init-method="init">
        <constructor-arg value="testProc"/>
        <property name="procList">
            <list>
                <ref bean="commonPayProcessors"/>
                <ref bean="applyPay1Processor"/>
            </list>
        </property>
    </bean>

</beans>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章