Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PeekStep |
|
| 1.6666666666666667;1.667 |
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.io; | |
18 | ||
19 | ||
20 | import java.util.EmptyStackException; | |
21 | import org.apache.commons.workflow.Context; | |
22 | import org.apache.commons.workflow.StepException; | |
23 | import org.apache.commons.workflow.base.BaseStep; | |
24 | ||
25 | ||
26 | /** | |
27 | * <p>Write the top value from the evaluation stack to standard output, | |
28 | * without removing it.</p> | |
29 | * | |
30 | * <p><strong>WARNING</strong> - This will probably be | |
31 | * replaced later by a more general purpose input/output mechanism.</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 PeekStep extends BaseStep { | |
38 | ||
39 | ||
40 | // ----------------------------------------------------------= Constructors | |
41 | ||
42 | ||
43 | /** | |
44 | * Construct a default instance of this Step. | |
45 | */ | |
46 | public PeekStep() { | |
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 PeekStep(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 | // Retrieve a copy of the top value from the evaluation stack | |
80 | 0 | Object value = null; |
81 | try { | |
82 | 0 | value = context.peek(); |
83 | 0 | } catch (EmptyStackException e) { |
84 | 0 | throw new StepException("Evaluation stack is empty", e, this); |
85 | 0 | } |
86 | ||
87 | // Display it to standard output | |
88 | 0 | System.out.println(value); |
89 | ||
90 | 0 | } |
91 | ||
92 | ||
93 | } |