用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 刘铮 阅读(341) 评论(0)  编辑  收藏 所属分类: JAVA General


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


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论