1 18 19 package org.apache.tools.ant.taskdefs.condition; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.ProjectComponent; 23 import org.apache.tools.ant.types.Reference; 24 25 32 public class IsReference extends ProjectComponent implements Condition { 33 private Reference ref; 34 private String type; 35 36 41 public void setRefid(Reference r) { 42 ref = r; 43 } 44 45 50 public void setType(String type) { 51 this.type = type; 52 } 53 54 59 public boolean eval() throws BuildException { 60 if (ref == null) { 61 throw new BuildException("No reference specified for isreference " 62 + "condition"); 63 } 64 65 Object o = getProject().getReference(ref.getRefId()); 66 67 if (o == null) { 68 return false; 69 } else if (type == null) { 70 return true; 71 } else { 72 Class typeClass = 73 (Class ) getProject().getDataTypeDefinitions().get(type); 74 75 if (typeClass == null) { 76 typeClass = 77 (Class ) getProject().getTaskDefinitions().get(type); 78 } 79 80 if (typeClass == null) { 81 return false; 83 } 84 85 return typeClass.isAssignableFrom(o.getClass()); 86 } 87 } 88 89 } 90 | Popular Tags |