View Javadoc

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 org.apache.commons.workflow.Context;
21  import org.apache.commons.workflow.StepException;
22  import org.apache.commons.workflow.base.BaseStep;
23  
24  
25  /**
26   * <p>Push the specified String value onto the top of the evaluation
27   * stack.</p>
28   *
29   * <p>Supported Attributes:</p>
30   * <ul>
31   * <li><strong>value</strong> - String value to be pushed.</li>
32   * </ul>
33   *
34   * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
35   * @author Craig R. McClanahan
36   */
37  
38  public class StringStep extends BaseStep {
39  
40  
41      // ----------------------------------------------------------= Constructors
42  
43  
44      /**
45       * Construct a default instance of this Step.
46       */
47      public StringStep() {
48  
49          super();
50  
51      }
52  
53  
54      /**
55       * Construct an instance of this Step with the specified identifier.
56       *
57       * @param id Step identifier
58       */
59      public StringStep(String id) {
60  
61          super();
62          setId(id);
63  
64      }
65  
66  
67      /**
68       * Construct a fully configured instance of this Step.
69       *
70       * @param id Step identifier
71       * @param value String value to be pushed
72       */
73      public StringStep(String id, String value) {
74  
75          super();
76          setId(id);
77          setValue(value);
78  
79      }
80  
81  
82      // ------------------------------------------------------------- Properties
83  
84  
85      /**
86       * The string value to be pushed.
87       */
88      protected String value = null;
89  
90      public String getValue() {
91          return (this.value);
92      }
93  
94      public void setValue(String value) {
95          this.value = value;
96      }
97  
98  
99      // --------------------------------------------------------- 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 }