1700481429
代码清单34-9 具体的ls命令
1700481430
1700481431
public class LSCommand extends Command{
1700481432
1700481433
public String execute(CommandVO vo){
1700481434
1700481435
//返回链表的首节点
1700481436
1700481437
CommandName firstNode=super.buildChain(AbstractLS.class).get(0);
1700481438
1700481439
return firstNode.handleMessage(vo);
1700481440
1700481441
}
1700481442
1700481443
}
1700481444
1700481445
很简单的方法,先建立一个命令族的责任链,然后找到首节点调用。在该类中我们使用CommandVO类,它是一个封装对象,其代码如代码清单34-10所示。
1700481446
1700481447
代码清单34-10 命令对象
1700481448
1700481449
public class CommandVO{
1700481450
1700481451
//定义参数名与参数的分隔符号,一般是空格
1700481452
1700481453
public final static String DIVIDE_FLAG=””;
1700481454
1700481455
//定义参数前的符号,UNIX一般是-,如ls-la
1700481456
1700481457
public final static String PREFIX=”-“;
1700481458
1700481459
//命令名,如ls、du
1700481460
1700481461
private String commandName=””;
1700481462
1700481463
//参数列表
1700481464
1700481465
private ArrayList<String>paramList=new ArrayList<String>();
1700481466
1700481467
//操作数列表
1700481468
1700481469
private ArrayList<String>dataList=new ArrayList<String>();
1700481470
1700481471
//通过构造函数传递进来命令
1700481472
1700481473
public CommandVO(String commandStr){
1700481474
1700481475
//常规判断
1700481476
1700481477
if(commandStr!=null && commandStr.length()!=0){
1700481478
[
上一页 ]
[ :1.700481429e+09 ]
[
下一页 ]