1 29 package net.sourceforge.groboutils.mbtf.v1.ant; 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.Task; 33 import org.apache.tools.ant.ProjectComponent; 34 import org.apache.tools.ant.Location; 35 import org.apache.tools.ant.BuildException; 36 import org.apache.tools.ant.types.Reference; 37 import org.apache.tools.ant.types.DataType; 38 import org.apache.tools.ant.taskdefs.Definer; 39 40 import java.util.Vector ; 41 42 import net.sourceforge.groboutils.mbtf.v1.IValidate; 43 import net.sourceforge.groboutils.mbtf.v1.ISystem; 44 45 import net.sourceforge.groboutils.mbtf.v1.assembler.AsmblState; 46 47 import org.apache.log4j.Logger; 48 49 50 60 public abstract class AbstractStateMachineType extends DataType 61 { 62 private static final Logger LOG = Logger.getLogger( 63 AbstractStateMachineType.class ); 64 65 public void execute() 66 throws BuildException 67 { 68 } 70 71 protected Location location = Location.UNKNOWN_LOCATION; 72 75 public void setLocation(Location location) { 76 this.location = location; 77 } 78 79 80 private Vector validates = new Vector (); 81 private String name; 82 83 84 public void setName( String name ) 85 { 86 this.name = name; 87 } 88 89 90 public String getName() 91 { 92 if (isReference()) 93 { 94 return ((AbstractStateMachineType)getCheckedRef( 95 AbstractStateMachineType.class, "state machine type" )). 96 getName(); 97 } 98 return this.name; 99 } 100 101 102 public IValidate[] getValidates() 103 { 104 if (isReference()) 105 { 106 return ((AbstractStateMachineType)getCheckedRef( 107 AbstractStateMachineType.class, "state machine type" )). 108 getValidates(); 109 } 110 IValidate[] v = new IValidate[ this.validates.size() ]; 111 this.validates.copyInto( v ); 112 if (getProject() != null) 113 { 114 for (int i = 0; i < v.length; ++i) 115 { 116 IValidate vv = v[i]; 117 if (vv instanceof ProjectComponent) 118 { 119 LOG.debug("Setting project of "+vv); 120 ((ProjectComponent)vv).setProject( getProject() ); 121 } 122 else 123 { 124 LOG.debug("Validator "+vv+" not a ProjectComponent, but "+ 125 vv.getClass().getName()); 126 } 127 } 128 } 129 else 130 { 131 LOG.debug("Ant type "+this+" never had project set"); 132 } 133 return v; 134 } 135 136 137 public void addConfiguredValidateJava( ValidateJavaType type ) 138 { 139 if (type != null) 140 { 141 LOG.debug("Adding ValidateJavaType "+type); 142 this.validates.addElement( type ); 143 } 144 } 145 146 147 public void addConfiguredValidateAnt( ValidateTaskType type ) 148 { 149 if (type != null) 150 { 151 this.validates.addElement( type ); 152 } 153 } 154 155 156 protected void verifySettings() 157 throws BuildException 158 { 159 if (isReference()) 160 { 161 ((AbstractStateMachineType)getCheckedRef( 162 AbstractStateMachineType.class, "state machine type" )). 163 verifySettings(); 164 return; 165 } 166 if (this.name == null) 167 { 168 throw new BuildException( "name not set", location ); 169 } 170 if (this.validates.size() <= 0) 171 { 172 throw new BuildException( "no validation types registered", 173 location ); 174 } 175 } 176 } 177 178 | Popular Tags |