Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BreakStep |
|
| 2.25;2.25 |
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>false</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 BreakStep extends BaseStep { | |
38 | ||
39 | ||
40 | // ----------------------------------------------------------= Constructors | |
41 | ||
42 | ||
43 | /** | |
44 | * Construct a default instance of this Step. | |
45 | */ | |
46 | public BreakStep() { | |
47 | ||
48 | 0 | super(); |
49 | ||
50 | 0 | } |
51 | ||
52 | ||
53 | /** | |
54 | * Construct an instance of this Step with the specified identifier. | |
55 | * | |
56 | * @param id Step identifier | |
57 | */ | |
58 | public BreakStep(String id) { | |
59 | ||
60 | 0 | super(); |
61 | 0 | setId(id); |
62 | ||
63 | 0 | } |
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 | 0 | BlockState state = null; |
81 | while (true) { | |
82 | try { | |
83 | 0 | state = context.peekBlockState(); |
84 | 0 | if (state.getBlock() instanceof Iterator) |
85 | 0 | break; |
86 | 0 | context.popBlockState(); |
87 | 0 | continue; |
88 | 0 | } catch (EmptyStackException e) { |
89 | 0 | 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 | 0 | state.setNest(false); |
96 | 0 | context.setNextStep(state.getBlock()); |
97 | ||
98 | 0 | } |
99 | ||
100 | ||
101 | /** | |
102 | * Render a string representation of this Step. | |
103 | */ | |
104 | public String toString() { | |
105 | ||
106 | 0 | StringBuffer sb = new StringBuffer("<core:break"); |
107 | 0 | if (getId() != null) { |
108 | 0 | sb.append(" id=\""); |
109 | 0 | sb.append(getId()); |
110 | 0 | sb.append("\""); |
111 | } | |
112 | 0 | sb.append("/>"); |
113 | 0 | return (sb.toString()); |
114 | ||
115 | } | |
116 | ||
117 | ||
118 | } |