1 29 package net.sourceforge.groboutils.mbtf.v1.ant; 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.ProjectHelper; 33 import org.apache.tools.ant.Task; 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.types.Reference; 36 import org.apache.tools.ant.types.DataType; 37 import org.apache.tools.ant.taskdefs.Definer; 38 39 import java.util.Vector ; 40 41 import net.sourceforge.groboutils.mbtf.v1.IValidate; 42 import net.sourceforge.groboutils.mbtf.v1.ISystem; 43 44 import net.sourceforge.groboutils.mbtf.v1.assembler.AsmblState; 45 46 47 57 public class StateType extends AbstractStateMachineType 58 { 59 public static final String DEFAULT_ANT_NAME = "mbtf.state"; 60 61 62 private Vector transitions = new Vector (); 63 private boolean startState = false; 64 private boolean finalState = false; 65 66 67 public static class RefTransitionType 68 { 69 private String name; 70 71 public void setName( String name ) 72 { 73 this.name = name; 74 } 75 76 public String getName() 77 { 78 return this.name; 79 } 80 } 81 public void addTransition( RefTransitionType trans ) 82 { 83 if (trans != null) 84 { 85 this.transitions.addElement( trans ); 86 } 87 } 88 89 90 public String [] getTransitionNames() 91 { 92 if (isReference()) 93 { 94 return ((StateType)getCheckedRef( 95 StateType.class, DEFAULT_ANT_NAME )). 96 getTransitionNames(); 97 } 98 99 String [] s = new String [ this.transitions.size() ]; 100 for (int i = s.length; --i >= 0;) 101 { 102 s[i] = ((RefTransitionType)this.transitions.elementAt( i )). 103 getName(); 104 } 105 return s; 106 } 107 108 109 public void setStartState( boolean on ) 110 { 111 this.startState = on; 112 } 113 114 115 public boolean getStartState() 116 { 117 if (isReference()) 118 { 119 return ((StateType)getCheckedRef( 120 StateType.class, DEFAULT_ANT_NAME )). 121 getStartState(); 122 } 123 return this.startState; 124 } 125 126 127 public void setFinalState( boolean on ) 128 { 129 this.finalState = on; 130 } 131 132 133 public boolean getFinalState() 134 { 135 if (isReference()) 136 { 137 return ((StateType)getCheckedRef( 138 StateType.class, DEFAULT_ANT_NAME )). 139 getFinalState(); 140 } 141 return this.finalState; 142 } 143 144 145 public AsmblState createState() 146 throws BuildException 147 { 148 if (isReference()) 149 { 150 return ((StateType)getCheckedRef( 151 StateType.class, DEFAULT_ANT_NAME )). 152 createState(); 153 } 154 155 verifySettings(); 156 157 AsmblState as = new AsmblState(); 158 as.setName( getName() ); 159 as.setIsStartState( getStartState() ); 160 as.setIsFinalState( getFinalState() ); 161 162 IValidate v[] = getValidates(); 163 for (int i = 0; i < v.length; ++i) 164 { 165 as.addValidate( v[i] ); 166 } 167 168 String names[] = getTransitionNames(); 169 for (int i = 0; i < names.length; ++i) 170 { 171 as.addTransitionName( names[i] ); 172 } 173 174 return as; 175 } 176 } 177 178 | Popular Tags |