FileDocCategorySizeDatePackage
IsReference.javaAPI DocApache Ant 1.702735Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs.condition

IsReference

public class IsReference extends org.apache.tools.ant.ProjectComponent implements Condition
Condition that tests whether a given reference has been defined.

Optionally tests whether it is of a given type/class.

since
Ant 1.6

Fields Summary
private org.apache.tools.ant.types.Reference
ref
private String
type
Constructors Summary
Methods Summary
public booleaneval()

return
true if the reference exists and if type is set, if the reference is the same type
exception
BuildException if an error occurs

        if (ref == null) {
            throw new BuildException("No reference specified for isreference "
                                     + "condition");
        }

        Object o = getProject().getReference(ref.getRefId());

        if (o == null) {
            return false;
        } else if (type == null) {
            return true;
        } else {
            Class typeClass =
                (Class) getProject().getDataTypeDefinitions().get(type);

            if (typeClass == null) {
                typeClass =
                    (Class) getProject().getTaskDefinitions().get(type);
            }

            if (typeClass == null) {
                // don't know the type, should throw exception instead?
                return false;
            }

            return typeClass.isAssignableFrom(o.getClass());
        }
    
public voidsetRefid(org.apache.tools.ant.types.Reference r)
Set the refid attribute.

param
r a Reference value

        ref = r;
    
public voidsetType(java.lang.String type)
Set the type attribute. This is optional attribute.

param
type an ant component type name

        this.type = type;