Apache 公共链基本示例
Apache Commons Chain Basic Example
我需要为一个项目进入 Apache 公共链。所以我试图在 运行 之后得到一个基本示例:http://www.onjava.com/pub/a/onjava/2005/03/02/commonchains.html
Commons Chain 通过 Maven 安装。
我写了以下Chain Base:
public class PFChain extends ChainBase {
public PFChain() {
super();
addCommand(new CalcE());
addCommand(new CalcDOEB());
addCommand(new CalcG());
}
public static void executePFChain() {
Command process = new PFChain();
Context context = new ContextBase();
try {
process.execute(context);
} catch (Exception e) {
System.out.println("errortext");
e.printStackTrace();
}
}
}
我的三个命令类是这样的:
public class CalcDOEB implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating DOEB...");
return true;
}
}
public class CalcE implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating E");
return true;
}
}
public class CalcG implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculation G...");
return true;
}
}
现在奇怪的是,他只执行了链中的第一个命令。
所有这些都有效,但前提是它们位于命令列表的开头。
当我打开调试器时,我看到它们都在列表中。
这个错误是从哪里来的,我该如何解决?
你好,
尼古拉斯
尝试将所有 return 语句更改为 false
而不是 true
。
当你 return 为真时,你结束链。因为您不希望链结束,所以需要 return false 代替。
要了解更多相关信息,请查看 Javadoc:
https://commons.apache.org/proper/commons-chain/apidocs/org/apache/commons/chain/Command.html#CONTINUE_PROCESSING
我需要为一个项目进入 Apache 公共链。所以我试图在 运行 之后得到一个基本示例:http://www.onjava.com/pub/a/onjava/2005/03/02/commonchains.html
Commons Chain 通过 Maven 安装。
我写了以下Chain Base:
public class PFChain extends ChainBase {
public PFChain() {
super();
addCommand(new CalcE());
addCommand(new CalcDOEB());
addCommand(new CalcG());
}
public static void executePFChain() {
Command process = new PFChain();
Context context = new ContextBase();
try {
process.execute(context);
} catch (Exception e) {
System.out.println("errortext");
e.printStackTrace();
}
}
}
我的三个命令类是这样的:
public class CalcDOEB implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating DOEB...");
return true;
}
}
public class CalcE implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating E");
return true;
}
}
public class CalcG implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculation G...");
return true;
}
}
现在奇怪的是,他只执行了链中的第一个命令。 所有这些都有效,但前提是它们位于命令列表的开头。
当我打开调试器时,我看到它们都在列表中。
这个错误是从哪里来的,我该如何解决?
你好,
尼古拉斯
尝试将所有 return 语句更改为 false
而不是 true
。
当你 return 为真时,你结束链。因为您不希望链结束,所以需要 return false 代替。
要了解更多相关信息,请查看 Javadoc: https://commons.apache.org/proper/commons-chain/apidocs/org/apache/commons/chain/Command.html#CONTINUE_PROCESSING