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