FileDocCategorySizeDatePackage
SelectSelector.javaAPI DocApache Ant 1.706430Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.types.selectors

SelectSelector

public class SelectSelector extends BaseSelectorContainer
This selector just holds one other selector and forwards all requests to it. It exists so that there is a single selector type that can exist outside of any targets, as an element of project. It overrides all of the reference stuff so that it works as expected. Note that this is the only selector you can reference.
since
1.5

Fields Summary
private String
ifProperty
private String
unlessProperty
Constructors Summary
public SelectSelector()
Default constructor.

    
Methods Summary
public voidappendSelector(FileSelector selector)
Add a new selector into this container.

param
selector the new selector to add

        if (isReference()) {
            throw noChildrenAllowed();
        }
        super.appendSelector(selector);
    
private org.apache.tools.ant.types.selectors.SelectSelectorgetRef()
Performs the check for circular references and returns the referenced Selector.

        Object o = getCheckedRef(this.getClass(), "SelectSelector");
        return (SelectSelector) o;
    
public FileSelector[]getSelectors(org.apache.tools.ant.Project p)
Returns the set of selectors as an array.

param
p the current project
return
an array of selectors in this container

        if (isReference()) {
            return getRef().getSelectors(p);
        }
        return super.getSelectors(p);
    
public booleanhasSelectors()
Indicates whether there are any selectors here.

return
whether any selectors are in this container

        if (isReference()) {
            return getRef().hasSelectors();
        }
        return super.hasSelectors();
    
public booleanisSelected(java.io.File basedir, java.lang.String filename, java.io.File file)
Returns true (the file is selected) only if the if property (if any) exists, the unless property (if any) doesn't exist, and the contained selector (if any) selects the file. If there is no contained selector, return true (because we assume that the point was to test the if and unless conditions).

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

        validate();

        // Deal with if and unless properties first
        if (!(passesConditions())) {
            return false;
        }

        Enumeration e = selectorElements();
        if (!(e.hasMoreElements())) {
            return true;
        }
        FileSelector f = (FileSelector) e.nextElement();
        return f.isSelected(basedir, filename, file);
    
public booleanpassesConditions()
Ensures that the selector passes the conditions placed on it with if and unless.

return
true if conditions are passed

        if (ifProperty != null
            && getProject().getProperty(ifProperty) == null) {
            return false;
        } else if (unlessProperty != null
            && getProject().getProperty(unlessProperty) != null) {
            return false;
        }
        return true;
    
public intselectorCount()
Gives the count of the number of selectors in this container

return
the number of selectors in this container

        if (isReference()) {
            return getRef().selectorCount();
        }
        return super.selectorCount();
    
public java.util.EnumerationselectorElements()
Returns an enumerator for accessing the set of selectors.

return
an enumerator that goes through each of the selectors

        if (isReference()) {
            return getRef().selectorElements();
        }
        return super.selectorElements();
    
public voidsetIf(java.lang.String ifProperty)
Sets the if attribute to a property which must exist for the selector to select any files.

param
ifProperty the property to check

        this.ifProperty = ifProperty;
    
public voidsetUnless(java.lang.String unlessProperty)
Sets the unless attribute to a property which cannot exist for the selector to select any files.

param
unlessProperty the property to check

        this.unlessProperty = unlessProperty;
    
public java.lang.StringtoString()

return
a string describing this object

        StringBuffer buf = new StringBuffer();
        if (hasSelectors()) {
            buf.append("{select");
            if (ifProperty != null) {
                buf.append(" if: ");
                buf.append(ifProperty);
            }
            if (unlessProperty != null) {
                buf.append(" unless: ");
                buf.append(unlessProperty);
            }
            buf.append(" ");
            buf.append(super.toString());
            buf.append("}");
        }
        return buf.toString();
    
public voidverifySettings()
Makes sure that there is only one entry, sets an error message if not.

        int cnt = selectorCount();
        if (cnt < 0 || cnt > 1) {
            setError("Only one selector is allowed within the "
                + "<selector> tag");
        }