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