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.io;
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>, print the value of the
028 * specified Java object to standard output.</p>
029 *
030 * <p><strong>WARNING</strong> - This will probably be
031 * replaced later by a more general purpose input/output mechanism.</p>
032 *
033 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
034 * @author Craig R. McClanahan
035 */
036
037 public class DisplayStep extends DescriptorStep {
038
039
040 // ----------------------------------------------------------= Constructors
041
042
043 /**
044 * Construct a default instance of this Step.
045 */
046 public DisplayStep() {
047
048 super();
049
050 }
051
052
053 /**
054 * Construct an instance of this Step with the specified identifier.
055 *
056 * @param id Step identifier
057 */
058 public DisplayStep(String id) {
059
060 super();
061 setId(id);
062
063 }
064
065
066 /**
067 * Construct an instance of this Step with the specified identifier
068 * and associated Descriptor.
069 *
070 * @param id Step identifier
071 * @param descriptor Initial descriptor
072 */
073 public DisplayStep(String id, Descriptor descriptor) {
074
075 super();
076 setId(id);
077 addDescriptor(descriptor);
078
079 }
080
081
082 // --------------------------------------------------------- Public Methods
083
084
085 /**
086 * Perform the executable actions related to this Step, in the context of
087 * the specified Context.
088 *
089 * @param context The Context that is tracking our execution state
090 *
091 * @exception StepException if a processing error has occurred
092 */
093 public void execute(Context context) throws StepException {
094
095 // Process all associated descriptors
096 Descriptor descriptors[] = findDescriptors();
097 for (int i = 0; i < descriptors.length; i++) {
098 Object value = descriptors[i].get(context);
099 if (value == null)
100 throw new StepException
101 ("Cannot retrieve object for " + descriptors[i], this);
102 System.out.println(value);
103 }
104
105 }
106
107
108 }