1 18 package org.apache.tools.ant.taskdefs.optional.extension; 19 20 import java.util.ArrayList ; 21 import java.util.Arrays ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.types.DataType; 25 import org.apache.tools.ant.types.FileSet; 26 import org.apache.tools.ant.types.Reference; 27 28 34 public class ExtensionSet 35 extends DataType { 36 39 private final ArrayList extensions = new ArrayList (); 40 41 44 private final ArrayList extensionsFilesets = new ArrayList (); 45 46 51 public void addExtension(final ExtensionAdapter extensionAdapter) { 52 extensions.add(extensionAdapter); 53 } 54 55 60 public void addLibfileset(final LibFileSet fileSet) { 61 extensionsFilesets.add(fileSet); 62 } 63 64 69 public void addFileset(final FileSet fileSet) { 70 extensionsFilesets.add(fileSet); 71 } 72 73 80 public Extension[] toExtensions(final Project proj) 81 throws BuildException { 82 final ArrayList extensionsList = ExtensionUtil.toExtensions(extensions); 83 ExtensionUtil.extractExtensions(proj, extensionsList, extensionsFilesets); 84 return (Extension[]) extensionsList.toArray(new Extension[extensionsList.size()]); 85 } 86 87 97 public void setRefid(final Reference reference) 98 throws BuildException { 99 if (!extensions.isEmpty() || !extensionsFilesets.isEmpty()) { 100 throw tooManyAttributes(); 101 } 102 final Object object = 104 reference.getReferencedObject(getProject()); 105 if (object instanceof ExtensionSet) { 106 final ExtensionSet other = (ExtensionSet) object; 107 extensions.addAll(other.extensions); 108 extensionsFilesets.addAll(other.extensionsFilesets); 109 } else { 110 final String message = 111 reference.getRefId() + " doesn\'t refer to a ExtensionSet"; 112 throw new BuildException(message); 113 } 114 115 super.setRefid(reference); 116 } 117 118 122 public String toString() { 123 return "ExtensionSet" + Arrays.asList(toExtensions(getProject())); 124 } 125 } 126 | Popular Tags |