1 29 package net.sourceforge.groboutils.mbtf.v1.assembler; 30 31 32 import net.sourceforge.groboutils.mbtf.v1.IState; 33 import net.sourceforge.groboutils.mbtf.v1.ITransition; 34 import net.sourceforge.groboutils.mbtf.v1.IValidate; 35 import net.sourceforge.groboutils.mbtf.v1.IAction; 36 37 import net.sourceforge.groboutils.mbtf.v1.engine.TransitionImpl; 38 39 import java.util.Vector ; 40 41 42 49 public class AsmblTransition 50 { 51 private String name; 52 private Vector validates = new Vector (); 53 private IAction action; 54 private String nextState; 55 56 private TransitionImpl iTrans; 57 58 59 62 public AsmblTransition() 63 { 64 } 66 67 68 public void setName( String name ) 69 { 70 if (name == null) 71 { 72 throw new IllegalArgumentException ("no null args"); 73 } 74 75 resetTransition( true ); 77 78 this.name = name; 79 } 80 81 82 public String getName() 83 { 84 return this.name; 85 } 86 87 88 public void setNextStateName( String name ) 89 { 90 if (name == null) 91 { 92 throw new IllegalArgumentException ("no null args"); 93 } 94 95 resetTransition( false ); 97 98 this.nextState = name; 99 } 100 101 102 public String getNextStateName() 103 { 104 return this.nextState; 105 } 106 107 108 public void addValidate( IValidate v ) 109 { 110 if (v != null) 111 { 112 resetTransition( true ); 114 115 this.validates.addElement( v ); 116 } 117 } 118 119 120 public void setAction( IAction a ) 121 { 122 if (a == null) 123 { 124 throw new IllegalArgumentException ("no null args"); 125 } 126 127 resetTransition( true ); 129 130 this.action = a; 131 } 132 133 134 public IValidate[] getValidates() 135 { 136 IValidate v[] = new IValidate[ this.validates.size() ]; 137 this.validates.copyInto( v ); 138 return v; 139 } 140 141 142 public IAction getAction() 143 { 144 return this.action; 145 } 146 147 148 public ITransition getTransition() 149 { 150 if (this.iTrans == null) 151 { 152 this.iTrans = new TransitionImpl( getName(), null, getAction(), 153 getValidates() ); 154 } 155 return this.iTrans; 156 } 157 158 159 public void setDestinationState( IState state ) 160 { 161 getTransition(); 163 164 if (state == null) 166 { 167 throw new IllegalArgumentException ("no null args"); 168 } 169 if (!state.getName().equals( getNextStateName() )) 170 { 171 throw new IllegalArgumentException ("Invalid state name"); 172 } 173 174 if (!this.iTrans.isDestinationStateSet()) 176 { 177 this.iTrans.setDestinationState( state ); 178 } 179 } 180 181 182 protected void resetTransition( boolean saveState ) 183 { 184 if (saveState && this.iTrans != null && 185 this.iTrans.isDestinationStateSet()) 186 { 187 throw new IllegalStateException ("Cannot reset transition"); 188 } 189 else 190 { 191 this.iTrans = null; 192 } 193 } 194 } 195 196 | Popular Tags |