用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 劉錚 閱讀(364) 評論(0)  編輯  收藏 所屬分類: JAVA General

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評論

          主站蜘蛛池模板: 姜堰市| 亳州市| 巴彦淖尔市| 沾益县| 石嘴山市| 鞍山市| 怀柔区| 阿克陶县| 赤峰市| 新晃| 菏泽市| 尚志市| 千阳县| 当雄县| 盐城市| 元朗区| 铁岭县| 和硕县| 固镇县| 伊通| 苏尼特左旗| 民和| 阿拉善右旗| 靖边县| 高阳县| 永泰县| 齐河县| 井研县| 大邑县| 饶阳县| 高阳县| 客服| 本溪| 手机| 佛坪县| 南部县| 奉化市| 邯郸县| 乐至县| 禹城市| 清原|