1 18 package org.apache.tools.ant.taskdefs.optional.script; 19 20 import org.apache.tools.ant.Task; 21 import org.apache.tools.ant.MagicNames; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.DynamicConfigurator; 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import java.util.List ; 27 import java.util.ArrayList ; 28 29 35 public class ScriptDefBase extends Task implements DynamicConfigurator { 36 37 38 private Map nestedElementMap = new HashMap (); 39 40 41 private Map attributes = new HashMap (); 42 43 private String text; 44 45 49 public void execute() { 50 getScript().executeScript(attributes, nestedElementMap, this); 51 } 52 53 private ScriptDef getScript() { 54 String name = getTaskType(); 55 Map scriptRepository 56 = (Map ) getProject().getReference(MagicNames.SCRIPT_REPOSITORY); 57 if (scriptRepository == null) { 58 throw new BuildException("Script repository not found for " + name); 59 } 60 61 ScriptDef definition = (ScriptDef) scriptRepository.get(getTaskType()); 62 if (definition == null) { 63 throw new BuildException("Script definition not found for " + name); 64 } 65 return definition; 66 } 67 68 74 public Object createDynamicElement(String name) { 75 List nestedElementList = (List ) nestedElementMap.get(name); 76 if (nestedElementList == null) { 77 nestedElementList = new ArrayList (); 78 nestedElementMap.put(name, nestedElementList); 79 } 80 Object element = getScript().createNestedElement(name); 81 nestedElementList.add(element); 82 return element; 83 } 84 85 91 public void setDynamicAttribute(String name, String value) { 92 ScriptDef definition = getScript(); 93 if (!definition.isAttributeSupported(name)) { 94 throw new BuildException("<" + getTaskType() 95 + "> does not support the \"" + name + "\" attribute"); 96 } 97 98 attributes.put(name, value); 99 } 100 101 107 public void addText(String text) { 108 this.text = getProject().replaceProperties(text); 109 } 110 111 116 public String getText() { 117 return text; 118 } 119 120 127 public void fail(String message) { 128 throw new BuildException(message); 129 } 130 } 131 132 | Popular Tags |