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.Descriptor;
23 import org.apache.commons.workflow.StepException;
24 import org.apache.commons.workflow.base.DescriptorStep;
25
26
27 /**
28 * <p>For each associated <code>Descriptor</code>, pop the top value from
29 * the evaluation stack, and store it as specified by that Descriptor,
30 * in the order that descriptors are listed.</p>
31 *
32 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
33 * @author Craig R. McClanahan
34 */
35
36 public class PutStep extends DescriptorStep {
37
38
39 // ----------------------------------------------------------= Constructors
40
41
42 /**
43 * Construct a default instance of this Step.
44 */
45 public PutStep() {
46
47 super();
48
49 }
50
51
52 /**
53 * Construct an instance of this Step with the specified identifier.
54 *
55 * @param id Step identifier
56 */
57 public PutStep(String id) {
58
59 super();
60 setId(id);
61
62 }
63
64
65 /**
66 * Construct an instance of this Step with the specified identifier
67 * and associated Descriptor.
68 *
69 * @param id Step identifier
70 * @param descriptor Initial descriptor
71 */
72 public PutStep(String id, Descriptor descriptor) {
73
74 super();
75 setId(id);
76 addDescriptor(descriptor);
77
78 }
79
80
81 // --------------------------------------------------------- Public Methods
82
83
84 /**
85 * Perform the executable actions related to this Step, in the context of
86 * the specified Context.
87 *
88 * @param context The Context that is tracking our execution state
89 *
90 * @exception StepException if a processing error has occurred
91 */
92 public void execute(Context context) throws StepException {
93
94 // Process all associated descriptors
95 Descriptor descriptors[] = findDescriptors();
96 for (int i = 0; i < descriptors.length; i++) {
97 Object value = null;
98 try {
99 value = context.pop();
100 } catch (EmptyStackException e) {
101 throw new StepException("Evaluation stack is empty", e, this);
102 }
103 descriptors[i].put(context, value);
104 }
105
106 }
107
108
109 }