可以在你需要定义和执行一些顺序操作的时候采用Commons Chain。
下载地址:http://commons.apache.org/downloads/download_chain.cgi
五个工作类:
GetCustomerInfo.jar
package demo.chain;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
public class GetCustomerInfo implements Command ...{
public boolean execute(Context context) throws Exception ...{
System.out.println("Get customer info");
context.put("customerName","George Burdell");
return false;
}
}
TestDriveVehicle.jar
package demo.chain;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
public class TestDriveVehicle implements Command ...{
public boolean execute(Context context) throws Exception ...{
System.out.println("Test drive the vehicle");
return false;
}
}
NegotiateSale.jar
package demo.chain;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
public class NegotiateSale implements Command ...{
public boolean execute(Context context) throws Exception ...{
System.out.println("Negotiate sale");
return false;
}
}