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.Context;
22 import org.apache.commons.workflow.StepException;
23 import org.apache.commons.workflow.base.BaseStep;
24
25
26 /**
27 * <p>Push a new copy of the top item on the evaluation
28 * stack onto the stack.</p>
29 *
30 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
31 * @author Craig R. McClanahan
32 */
33
34 public class DuplicateStep extends BaseStep {
35
36
37 // ----------------------------------------------------------= Constructors
38
39
40 /**
41 * Construct a default instance of this Step.
42 */
43 public DuplicateStep() {
44
45 super();
46
47 }
48
49
50 /**
51 * Construct an instance of this Step with the specified identifier.
52 *
53 * @param id Step identifier
54 */
55 public DuplicateStep(String id) {
56
57 super();
58 setId(id);
59
60 }
61
62
63 // --------------------------------------------------------- Public Methods
64
65
66 /**
67 * Perform the executable actions related to this Step, in the context of
68 * the specified Context.
69 *
70 * @param context The Context that is tracking our execution state
71 *
72 * @exception StepException if a processing error has occurred
73 */
74 public void execute(Context context) throws StepException {
75
76 // Peek at the top value on the evaluation stack
77 Object value = null;
78 try {
79 value = context.peek();
80 } catch (EmptyStackException e) {
81 throw new StepException("Evaluation stack is empty", e, this);
82 }
83
84 // Push another copy of this value
85 context.push(value);
86
87 }
88
89
90 }