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