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.StepException;
022 import org.apache.commons.workflow.base.BaseStep;
023
024
025 /**
026 * <p>Push the specified String value onto the top of the evaluation
027 * stack.</p>
028 *
029 * <p>Supported Attributes:</p>
030 * <ul>
031 * <li><strong>value</strong> - String value to be pushed.</li>
032 * </ul>
033 *
034 * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
035 * @author Craig R. McClanahan
036 */
037
038 public class StringStep extends BaseStep {
039
040
041 // ----------------------------------------------------------= Constructors
042
043
044 /**
045 * Construct a default instance of this Step.
046 */
047 public StringStep() {
048
049 super();
050
051 }
052
053
054 /**
055 * Construct an instance of this Step with the specified identifier.
056 *
057 * @param id Step identifier
058 */
059 public StringStep(String id) {
060
061 super();
062 setId(id);
063
064 }
065
066
067 /**
068 * Construct a fully configured instance of this Step.
069 *
070 * @param id Step identifier
071 * @param value String value to be pushed
072 */
073 public StringStep(String id, String value) {
074
075 super();
076 setId(id);
077 setValue(value);
078
079 }
080
081
082 // ------------------------------------------------------------- Properties
083
084
085 /**
086 * The string value to be pushed.
087 */
088 protected String value = null;
089
090 public String getValue() {
091 return (this.value);
092 }
093
094 public void setValue(String value) {
095 this.value = value;
096 }
097
098
099 // --------------------------------------------------------- Public Methods
100
101
102 /**
103 * Perform the executable actions related to this Step, in the context of
104 * the specified Context.
105 *
106 * @param context The Context that is tracking our execution state
107 *
108 * @exception StepException if a processing error has occurred
109 */
110 public void execute(Context context) throws StepException {
111
112 // Validate that a value has been specified
113 if (value == null)
114 throw new StepException("No value specified", this);
115
116 // Push the value onto the evaluation stack
117 context.push(value);
118
119 }
120
121
122 /**
123 * Render a string representation of this Step.
124 */
125 public String toString() {
126
127 StringBuffer sb = new StringBuffer("<core:string");
128 if (getId() != null) {
129 sb.append(" id=\"");
130 sb.append(getId());
131 sb.append("\"");
132 }
133 if (getValue() != null) {
134 sb.append(" value=\"");
135 sb.append(getValue());
136 sb.append("\"");
137 }
138 sb.append("/>");
139 return (sb.toString());
140
141 }
142
143
144 }