1 18 package org.apache.tools.ant.types.resources.selectors; 19 20 import org.apache.tools.ant.BuildException; 21 import org.apache.tools.ant.types.Resource; 22 import org.apache.tools.ant.types.EnumeratedAttribute; 23 24 28 public class Type implements ResourceSelector { 29 30 private static final String FILE_ATTR = "file"; 31 private static final String DIR_ATTR = "dir"; 32 33 34 public static final Type FILE = new Type(new FileDir(FILE_ATTR)); 35 36 37 public static final Type DIR = new Type(new FileDir(DIR_ATTR)); 38 39 42 public static class FileDir extends EnumeratedAttribute { 43 private static final String [] VALUES = new String [] {FILE_ATTR, DIR_ATTR}; 44 45 48 public FileDir() { 49 } 50 51 55 public FileDir(String value) { 56 setValue(value); 57 } 58 59 63 public String [] getValues() { 64 return VALUES; 65 } 66 } 67 68 private FileDir type = null; 69 70 73 public Type() { 74 } 75 76 80 public Type(FileDir fd) { 81 setType(fd); 82 } 83 84 88 public void setType(FileDir fd) { 89 type = fd; 90 } 91 92 97 public boolean isSelected(Resource r) { 98 if (type == null) { 99 throw new BuildException("The type attribute is required."); 100 } 101 int i = type.getIndex(); 102 return r.isDirectory() ? i == 1 : i == 0; 103 } 104 105 } 106 | Popular Tags |