FileDocCategorySizeDatePackage
TypeSelector.javaAPI DocApache Ant 1.704166Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.types.selectors

TypeSelector

public class TypeSelector extends BaseExtendSelector
Selector that selects a certain kind of file: directory or regular.
since
1.6

Fields Summary
private String
type
public static final String
TYPE_KEY
Key to used for parameterized custom selector
Constructors Summary
public TypeSelector()
Creates a new TypeSelector instance.


              
      
    
Methods Summary
public booleanisSelected(java.io.File basedir, java.lang.String filename, java.io.File file)
The heart of the matter. This is where the selector gets to decide on the inclusion of a file in a particular fileset.

param
basedir the base directory the scan is being done from
param
filename is the name of the file to check
param
file is a java.io.File object the selector can use
return
whether the file should be selected or not


        // throw BuildException on error
        validate();

        if (file.isDirectory()) {
            return type.equals(FileType.DIR);
        } else {
            return type.equals(FileType.FILE);
        }
    
public voidsetParameters(org.apache.tools.ant.types.Parameter[] parameters)
When using this as a custom selector, this method will be called. It translates each parameter into the appropriate setXXX() call.

param
parameters the complete set of parameters for this selector

        super.setParameters(parameters);
        if (parameters != null) {
            for (int i = 0; i < parameters.length; i++) {
                String paramname = parameters[i].getName();
                if (TYPE_KEY.equalsIgnoreCase(paramname)) {
                    FileType t = new FileType();
                    t.setValue(parameters[i].getValue());
                    setType(t);
                } else {
                    setError("Invalid parameter " + paramname);
                }
            }
        }
    
public voidsetType(org.apache.tools.ant.types.selectors.TypeSelector$FileType fileTypes)
Set the type of file to require.

param
fileTypes the type of file - file or dir

        this.type = fileTypes.getValue();
    
public java.lang.StringtoString()

return
a string describing this object

        StringBuffer buf = new StringBuffer("{typeselector type: ");
        buf.append(type);
        buf.append("}");
        return buf.toString();
    
public voidverifySettings()
Checks to make sure all settings are kosher. In this case, it means that the pattern attribute has been set.

        if (type == null) {
            setError("The type attribute is required");
        }