用command-chain完成的For循環(huán)

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

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評論

          主站蜘蛛池模板: 浦县| 临安市| 阳山县| 石泉县| 高阳县| 陆川县| 太仆寺旗| 广宁县| 皮山县| 玉田县| 广水市| 沙坪坝区| 天津市| 双牌县| 石柱| 革吉县| 类乌齐县| 民乐县| 高平市| 大港区| 榆中县| 隆昌县| 普兰县| 万载县| 桐庐县| 石景山区| 德格县| 涡阳县| 赤城县| 武胜县| 承德市| 五华县| 峨山| 岳西县| 巧家县| 新河县| 万载县| 新丰县| 麦盖提县| 东辽县| 绥中县|