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.Context;
022 import org.apache.commons.workflow.StepException;
023 import org.apache.commons.workflow.base.BaseStep;
024
025
026 /**
027 * <p>Push a new copy of the top item on the evaluation
028 * stack onto the stack.</p>
029 *
030 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
031 * @author Craig R. McClanahan
032 */
033
034 public class DuplicateStep extends BaseStep {
035
036
037 // ----------------------------------------------------------= Constructors
038
039
040 /**
041 * Construct a default instance of this Step.
042 */
043 public DuplicateStep() {
044
045 super();
046
047 }
048
049
050 /**
051 * Construct an instance of this Step with the specified identifier.
052 *
053 * @param id Step identifier
054 */
055 public DuplicateStep(String id) {
056
057 super();
058 setId(id);
059
060 }
061
062
063 // --------------------------------------------------------- Public Methods
064
065
066 /**
067 * Perform the executable actions related to this Step, in the context of
068 * the specified Context.
069 *
070 * @param context The Context that is tracking our execution state
071 *
072 * @exception StepException if a processing error has occurred
073 */
074 public void execute(Context context) throws StepException {
075
076 // Peek at the top value on the evaluation stack
077 Object value = null;
078 try {
079 value = context.peek();
080 } catch (EmptyStackException e) {
081 throw new StepException("Evaluation stack is empty", e, this);
082 }
083
084 // Push another copy of this value
085 context.push(value);
086
087 }
088
089
090 }