用command-chain完成的For循环

package nl.enovation.commons.command;

import java.util.Collection;

import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;

public class ForeachCommand implements Command {
    private String collectionProperty;
    private String instanceProperty;
    private Command command;
   
    @SuppressWarnings("unchecked")
    public boolean execute(Context context) throws Exception {
        Collection<? extends Object> collection = (Collection<? extends Object>) context.get(collectionProperty);
        if (collection != null) {
            for(Object object : collection) {
                context.put(instanceProperty, object);
                if (PROCESSING_COMPLETE == command.execute(context)) {
                    return PROCESSING_COMPLETE;
                } // else continue
            }
        }
        return CONTINUE_PROCESSING;
    }

    public String getCollectionProperty() {
        return collectionProperty;
    }

    public void setCollectionProperty(String collectionProperty) {
        this.collectionProperty = collectionProperty;
    }

    public String getInstanceProperty() {
        return instanceProperty;
    }

    public void setInstanceProperty(String instanceProperty) {
        this.instanceProperty = instanceProperty;
    }

    public Command getCommand() {
        return command;
    }

    public void setCommand(Command command) {
        this.command = command;
    }

}

posted on 2008-01-22 10:24 刘铮 阅读(353) 评论(0)  编辑  收藏 所属分类: JAVA General


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论