用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)

          搜索

          最新評論

          主站蜘蛛池模板: 宁海县| 衡阳市| 新巴尔虎左旗| 荔波县| 荣成市| 南皮县| 浮梁县| 长武县| 凯里市| 安宁市| 保山市| 鱼台县| 兴义市| 商丘市| 正阳县| 禄劝| 乌什县| 达州市| 东台市| 博野县| 清新县| 翁牛特旗| 天祝| 郎溪县| 色达县| 汾西县| 石狮市| 彝良县| 金塔县| 栾城县| 平顶山市| 新丰县| 富民县| 金溪县| 南丰县| 丹阳市| 台北县| 石林| 富民县| 高要市| 上虞市|