1 29 package net.sourceforge.groboutils.mbtf.v1.ant; 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.BuildException; 33 import org.apache.tools.ant.Location; 34 import org.apache.tools.ant.taskdefs.Definer; 35 import org.apache.tools.ant.types.Reference; 36 import org.apache.tools.ant.types.DataType; 37 import org.apache.tools.ant.Task; 38 39 import java.lang.reflect.Method ; 40 41 import net.sourceforge.groboutils.mbtf.v1.IValidate; 42 import net.sourceforge.groboutils.mbtf.v1.IErrors; 43 import net.sourceforge.groboutils.mbtf.v1.ISystem; 44 import net.sourceforge.groboutils.mbtf.v1.TestHaltRuntimeException; 45 46 47 56 public class ReferenceType extends DataType 57 { 58 private String sysRefId; 59 60 61 protected Location location = Location.UNKNOWN_LOCATION; 62 65 public void setLocation(Location location) { 66 this.location = location; 67 } 68 69 70 public void setSysId( String id ) 71 { 72 this.sysRefId = id; 73 } 74 75 76 public void setSystem( ISystem sys ) 77 { 78 if (this.sysRefId != null && sys != null) 79 { 80 project.addReference( this.sysRefId, sys ); 81 } 82 } 83 84 85 88 public void execute() 89 throws BuildException 90 { 91 if (!isReference()) 93 { 94 throw new BuildException( "does not have a reference", location ); 95 } 96 Object o = getCheckedRef( Object .class, "task or target" ); 97 98 Class c = o.getClass(); 100 Method m; 101 try 102 { 103 m = c.getMethod( "execute", new Class [0] ); 104 } 105 catch (Exception e) 106 { 107 throw new BuildException("No 'execute' method for "+c.getName(), 108 e, location ); 109 } 110 111 try 112 { 113 m.invoke( o, new Object [0] ); 114 } 115 catch (BuildException be) 116 { 117 throw be; 118 } 119 catch (TestHaltRuntimeException thre) 120 { 121 throw thre; 122 } 123 catch (Exception e) 124 { 125 throw new BuildException( "Unexpected exception", e, location ); 126 } 127 } 128 129 130 public void execute( ISystem system, IErrors errors ) 131 { 132 setSystem( system ); 133 134 try 135 { 136 execute(); 137 } 138 catch (TestHaltRuntimeException thre) 139 { 140 throw thre; 141 } 142 catch (Exception e) 143 { 144 errors.addError( e.getMessage(), e ); 145 } 146 } 147 } 148 149 | Popular Tags |