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.Descriptor; 023 import org.apache.commons.workflow.StepException; 024 import org.apache.commons.workflow.base.DescriptorStep; 025 026 027 /** 028 * <p>For each associated <code>Descriptor</code>, pop the top value from 029 * the evaluation stack, and store it as specified by that Descriptor, 030 * in the order that descriptors are listed.</p> 031 * 032 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $ 033 * @author Craig R. McClanahan 034 */ 035 036 public class PutStep extends DescriptorStep { 037 038 039 // ----------------------------------------------------------= Constructors 040 041 042 /** 043 * Construct a default instance of this Step. 044 */ 045 public PutStep() { 046 047 super(); 048 049 } 050 051 052 /** 053 * Construct an instance of this Step with the specified identifier. 054 * 055 * @param id Step identifier 056 */ 057 public PutStep(String id) { 058 059 super(); 060 setId(id); 061 062 } 063 064 065 /** 066 * Construct an instance of this Step with the specified identifier 067 * and associated Descriptor. 068 * 069 * @param id Step identifier 070 * @param descriptor Initial descriptor 071 */ 072 public PutStep(String id, Descriptor descriptor) { 073 074 super(); 075 setId(id); 076 addDescriptor(descriptor); 077 078 } 079 080 081 // --------------------------------------------------------- Public Methods 082 083 084 /** 085 * Perform the executable actions related to this Step, in the context of 086 * the specified Context. 087 * 088 * @param context The Context that is tracking our execution state 089 * 090 * @exception StepException if a processing error has occurred 091 */ 092 public void execute(Context context) throws StepException { 093 094 // Process all associated descriptors 095 Descriptor descriptors[] = findDescriptors(); 096 for (int i = 0; i < descriptors.length; i++) { 097 Object value = null; 098 try { 099 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 }