View Javadoc

1   /*
2    * Copyright 1999-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  
17  package org.apache.commons.workflow.core;
18  
19  
20  import java.util.EmptyStackException;
21  import org.apache.commons.workflow.BlockState;
22  import org.apache.commons.workflow.Context;
23  import org.apache.commons.workflow.Iterator;
24  import org.apache.commons.workflow.Step;
25  import org.apache.commons.workflow.StepException;
26  import org.apache.commons.workflow.base.BaseStep;
27  
28  
29  /**
30   * <p>Locate the closest surrounding Iterator, set the nesting control
31   * to <code>true</code>, and transfer control to the Iterator.</p>
32   *
33   * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
34   * @author Craig R. McClanahan
35   */
36  
37  public class ContinueStep extends BaseStep {
38  
39  
40      // ----------------------------------------------------------= Constructors
41  
42  
43      /**
44       * Construct a default instance of this Step.
45       */
46      public ContinueStep() {
47  
48          super();
49  
50      }
51  
52  
53      /**
54       * Construct an instance of this Step with the specified identifier.
55       *
56       * @param id Step identifier
57       */
58      public ContinueStep(String id) {
59  
60          super();
61          setId(id);
62  
63      }
64  
65  
66      // --------------------------------------------------------- Public Methods
67  
68  
69      /**
70       * Perform the executable actions related to this Step, in the context of
71       * the specified Context.
72       *
73       * @param context The Context that is tracking our execution state
74       *
75       * @exception StepException if a processing error has occurred
76       */
77      public void execute(Context context) throws StepException {
78  
79          // Locate the closest surrounding Iterator's BlockState
80          BlockState state = null;
81          while (true) {
82              try {
83                  state = context.peekBlockState();
84                  if (state.getBlock() instanceof Iterator)
85                      break;
86                  context.popBlockState();
87                  continue;
88              } catch (EmptyStackException e) {
89                  throw new StepException("Must be nested in an Iterator Block",
90                                          this);
91              }
92          }
93  
94          // Set the nesting repeat indicator, and transfer control
95          state.setNest(true);
96          context.setNextStep(state.getBlock());
97  
98      }
99  
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 }