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.IValidate; 34 import net.sourceforge.groboutils.mbtf.v1.ITransition; 35 36 import net.sourceforge.groboutils.mbtf.v1.engine.StateImpl; 37 38 import java.util.Vector ; 39 40 41 48 public class AsmblState 49 { 50 private String name; 51 private Vector validates = new Vector (); 52 private Vector transNames = new Vector (); 53 private boolean startState; 54 private boolean endState; 55 56 59 public AsmblState() 60 { 61 } 63 64 65 public void setName( String name ) 66 { 67 if (name == null) 68 { 69 throw new IllegalArgumentException ("no null args"); 70 } 71 this.name = name; 72 } 73 74 75 public String getName() 76 { 77 return this.name; 78 } 79 80 81 public void addValidate( IValidate v ) 82 { 83 if (v != null) 84 { 85 this.validates.addElement( v ); 86 } 87 } 88 89 90 public void addTransitionName( String n ) 91 { 92 if (n != null) 93 { 94 this.transNames.addElement( n ); 95 } 96 } 97 98 99 public IValidate[] getValidates() 100 { 101 IValidate v[] = new IValidate[ this.validates.size() ]; 102 this.validates.copyInto( v ); 103 return v; 104 } 105 106 107 public String [] getTransitionNames() 108 { 109 String s[] = new String [ this.transNames.size() ]; 110 this.transNames.copyInto( s ); 111 return s; 112 } 113 114 115 public void setIsStartState( boolean on ) 116 { 117 this.startState = on; 118 } 119 120 121 public boolean isStartState() 122 { 123 return this.startState; 124 } 125 126 127 public void setIsFinalState( boolean on ) 128 { 129 this.endState = on; 130 } 131 132 133 public boolean isFinalState() 134 { 135 return this.endState; 136 } 137 138 139 145 public IState createState( AsmblTransitionSet set ) 146 { 147 String transNames[] = getTransitionNames(); 149 int len = transNames.length; 150 ITransition t[] = new ITransition[ len ]; 151 152 for (int i = len; --i >= 0;) 153 { 154 AsmblTransition at = set.getTransition( transNames[i] ); 155 if (at == null) 156 { 157 throw new IllegalArgumentException ("expecting transition '"+ 158 transNames[i]+"'"); 159 } 160 t[i] = at.getTransition(); 161 } 162 163 return new StateImpl( getName(), t, getValidates() ); 164 } 165 } 166 167 | Popular Tags |