1 29 package net.sourceforge.groboutils.mbtf.v1.engine; 30 31 32 import net.sourceforge.groboutils.mbtf.v1.IState; 33 import net.sourceforge.groboutils.mbtf.v1.IAction; 34 import net.sourceforge.groboutils.mbtf.v1.IValidate; 35 import net.sourceforge.groboutils.mbtf.v1.ITransition; 36 37 38 48 public class TransitionImpl implements ITransition 49 { 50 private String name; 51 private IState destination; 52 private IAction action; 53 private IValidate[] validate; 54 55 56 public TransitionImpl( String name, IState dest, IAction a, IValidate[] v ) 57 { 58 60 61 if (name == null || a == null) 62 { 63 throw new IllegalArgumentException ("no null args"); 64 } 65 66 if (v == null) 67 { 68 v = new IValidate[0]; 69 } 70 else 71 { 72 int len = v.length; 73 IValidate[] vv = new IValidate[ len ]; 74 for (int i = len; --i >= 0;) 75 { 76 if (v[i] == null) 77 { 78 throw new IllegalArgumentException ( 79 "no nulls allowed in IValidate array"); 80 } 81 vv[i] = v[i]; 83 } 84 v = vv; 85 } 86 87 this.name = name; 88 setDestinationState( dest ); 89 this.action = a; 90 this.validate = v; 91 } 92 93 94 100 public String getName() 101 { 102 return this.name; 103 } 104 105 106 111 public IState getDestinationState() 112 { 113 if (isDestinationStateSet()) 114 { 115 return this.destination; 116 } 117 throw new IllegalStateException ("Destination was never set."); 119 } 120 121 122 127 public IAction getAction() 128 { 129 return this.action; 130 } 131 132 133 139 public IValidate[] getValidates() 140 { 141 int len = this.validate.length; 142 IValidate v[] = new IValidate[ len ]; 143 System.arraycopy( this.validate, 0, v, 0, len ); 144 return v; 145 } 146 147 149 156 public void setDestinationState( IState dest ) 157 { 158 if (isDestinationStateSet()) 159 { 160 throw new IllegalStateException ( 161 "Destination has already been set."); 162 } 163 else 164 { 165 this.destination = dest; 166 } 167 } 168 169 170 175 public boolean isDestinationStateSet() 176 { 177 return (this.destination != null); 178 } 179 180 181 public String toString() 182 { 183 return "[Transition "+getName()+"]"; 184 } 185 } 186 187 | Popular Tags |