001 /* 002 * Copyright 1999-2001,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.workflow.core; 018 019 020 import java.util.EmptyStackException; 021 import org.apache.commons.workflow.BlockState; 022 import org.apache.commons.workflow.Context; 023 import org.apache.commons.workflow.Iterator; 024 import org.apache.commons.workflow.Step; 025 import org.apache.commons.workflow.StepException; 026 import org.apache.commons.workflow.base.BaseStep; 027 028 029 /** 030 * <p>Locate the closest surrounding Iterator, set the nesting control 031 * to <code>true</code>, and transfer control to the Iterator.</p> 032 * 033 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $ 034 * @author Craig R. McClanahan 035 */ 036 037 public class ContinueStep extends BaseStep { 038 039 040 // ----------------------------------------------------------= Constructors 041 042 043 /** 044 * Construct a default instance of this Step. 045 */ 046 public ContinueStep() { 047 048 super(); 049 050 } 051 052 053 /** 054 * Construct an instance of this Step with the specified identifier. 055 * 056 * @param id Step identifier 057 */ 058 public ContinueStep(String id) { 059 060 super(); 061 setId(id); 062 063 } 064 065 066 // --------------------------------------------------------- Public Methods 067 068 069 /** 070 * Perform the executable actions related to this Step, in the context of 071 * the specified Context. 072 * 073 * @param context The Context that is tracking our execution state 074 * 075 * @exception StepException if a processing error has occurred 076 */ 077 public void execute(Context context) throws StepException { 078 079 // Locate the closest surrounding Iterator's BlockState 080 BlockState state = null; 081 while (true) { 082 try { 083 state = context.peekBlockState(); 084 if (state.getBlock() instanceof Iterator) 085 break; 086 context.popBlockState(); 087 continue; 088 } catch (EmptyStackException e) { 089 throw new StepException("Must be nested in an Iterator Block", 090 this); 091 } 092 } 093 094 // Set the nesting repeat indicator, and transfer control 095 state.setNest(true); 096 context.setNextStep(state.getBlock()); 097 098 } 099 100 101 /** 102 * Render a string representation of this Step. 103 */ 104 public String toString() { 105 106 StringBuffer sb = new StringBuffer("<core:continue"); 107 if (getId() != null) { 108 sb.append(" id=\""); 109 sb.append(getId()); 110 sb.append("\""); 111 } 112 sb.append("/>"); 113 return (sb.toString()); 114 115 } 116 117 118 }