package com.toby.zerenliang;
public interface IHandle {
/**
* 逻辑处理
*
* @param mtMsg MT数据
* @return 成功返回true,否则false
*/ public boolean process(MtMsg mtMsg);
/**
* 增加下级Handler.寄主Handler可以看情况调用该下级Handler
*
* @param hdl 下级Handler
* @return 下级Handler
*/ public IHandle addNextHandler(IHandle hdl);
}
package com.toby.zerenliang;
public class MtMsg {
public int age;
public String name;
}
package com.toby.zerenliang;
public class OneHandler
implements IHandle {
private IHandle nextHdl;
@Override
public IHandle addNextHandler(IHandle hdl) {
this.nextHdl = hdl;
return this.nextHdl;
}
@Override
public boolean process(MtMsg mtMsg) {
/**
* 业务逻辑处理
*/ System.out.println("业务逻辑处理one");
if(nextHdl !=
null)
return nextHdl.process(mtMsg);
else return true;
}
}
package com.toby.zerenliang;
public class TwoHandler
implements IHandle {
private IHandle nextHdl;
@Override
public IHandle addNextHandler(IHandle hdl) {
this.nextHdl = hdl;
return this.nextHdl;
}
@Override
public boolean process(MtMsg mtMsg) {
/**
* 业务逻辑处理
*/ System.out.println("业务逻辑处理two");
if(nextHdl !=
null)
return nextHdl.process(mtMsg);
else return true;
}
}
package com.toby.zerenliang;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
MtMsg mm = new MtMsg();
mm.age = 17;
mm.name = "名字";
IHandle iHandle = new OneHandler();
iHandle.addNextHandler(new TwoHandler());
iHandle.process(mm);
}
}