1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import org.apache.tools.ant.AntTypeDefinition; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.ComponentHelper; 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.ProjectHelper; 26 import org.apache.tools.ant.Task; 27 import org.apache.tools.ant.TaskContainer; 28 import org.apache.tools.ant.UnknownElement; 29 30 43 public class PreSetDef extends AntlibDefinition implements TaskContainer { 44 private UnknownElement nestedTask; 45 private String name; 46 47 51 public void setName(String name) { 52 this.name = name; 53 } 54 55 59 public void addTask(Task nestedTask) { 60 if (this.nestedTask != null) { 61 throw new BuildException("Only one nested element allowed"); 62 } 63 if (!(nestedTask instanceof UnknownElement)) { 64 throw new BuildException( 65 "addTask called with a task that is not an unknown element"); 66 } 67 this.nestedTask = (UnknownElement) nestedTask; 68 } 69 70 71 74 public void execute() { 75 if (nestedTask == null) { 76 throw new BuildException("Missing nested element"); 77 } 78 if (name == null) { 79 throw new BuildException("Name not specified"); 80 } 81 name = ProjectHelper.genComponentName(getURI(), name); 82 83 ComponentHelper helper = ComponentHelper.getComponentHelper( 84 getProject()); 85 86 String componentName = ProjectHelper.genComponentName( 87 nestedTask.getNamespace(), nestedTask.getTag()); 88 89 AntTypeDefinition def = helper.getDefinition(componentName); 90 if (def == null) { 91 throw new BuildException( 92 "Unable to find typedef " + componentName); 93 } 94 PreSetDefinition newDef = new PreSetDefinition(def, nestedTask); 95 96 newDef.setName(name); 97 98 helper.addDataTypeDefinition(newDef); 99 log("defining preset " + name, Project.MSG_VERBOSE); 100 } 101 102 107 public static class PreSetDefinition extends AntTypeDefinition { 108 private AntTypeDefinition parent; 109 private UnknownElement element; 110 111 117 public PreSetDefinition(AntTypeDefinition parent, UnknownElement el) { 118 if (parent instanceof PreSetDefinition) { 119 PreSetDefinition p = (PreSetDefinition) parent; 120 el.applyPreSet(p.element); 121 parent = p.parent; 122 } 123 this.parent = parent; 124 this.element = el; 125 } 126 127 132 public void setClass(Class clazz) { 133 throw new BuildException("Not supported"); 134 } 135 136 141 public void setClassName(String className) { 142 throw new BuildException("Not supported"); 143 } 144 145 149 public String getClassName() { 150 return parent.getClassName(); 151 } 152 153 158 public void setAdapterClass(Class adapterClass) { 159 throw new BuildException("Not supported"); 160 } 161 162 167 public void setAdaptToClass(Class adaptToClass) { 168 throw new BuildException("Not supported"); 169 } 170 171 177 public void setClassLoader(ClassLoader classLoader) { 178 throw new BuildException("Not supported"); 179 } 180 181 185 public ClassLoader getClassLoader() { 186 return parent.getClassLoader(); 187 } 188 189 194 public Class getExposedClass(Project project) { 195 return parent.getExposedClass(project); 196 } 197 198 203 public Class getTypeClass(Project project) { 204 return parent.getTypeClass(project); 205 } 206 207 208 212 public void checkClass(Project project) { 213 parent.checkClass(project); 214 } 215 216 223 public Object createObject(Project project) { 224 return parent.create(project); 225 } 226 227 232 public UnknownElement getPreSets() { 233 return element; 234 } 235 236 243 public Object create(Project project) { 244 return this; 245 } 246 247 254 public boolean sameDefinition(AntTypeDefinition other, Project project) { 255 return (other != null && other.getClass() == getClass() && parent != null 256 && parent.sameDefinition(((PreSetDefinition) other).parent, project) 257 && element.similar(((PreSetDefinition) other).element)); 258 } 259 260 267 public boolean similarDefinition( 268 AntTypeDefinition other, Project project) { 269 return (other != null && other.getClass().getName().equals( 270 getClass().getName()) && parent != null 271 && parent.similarDefinition(((PreSetDefinition) other).parent, project) 272 && element.similar(((PreSetDefinition) other).element)); 273 } 274 } 275 } 276 | Popular Tags |