1 18 package org.apache.tools.ant.helper; 19 20 import java.io.File ; 21 import java.util.ArrayList ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.Vector ; 26 27 import org.xml.sax.Locator ; 28 import org.xml.sax.Attributes ; 29 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.Target; 33 import org.apache.tools.ant.Location; 34 import org.apache.tools.ant.RuntimeConfigurable; 35 36 37 41 public class AntXMLContext { 42 43 private Project project; 44 45 46 private File buildFile; 47 48 52 private Vector targetVector = new Vector (); 53 54 58 private File buildFileParent; 59 60 61 private String currentProjectName; 62 63 67 private Locator locator; 68 69 75 private Target implicitTarget = new Target(); 76 77 79 private Target currentTarget = null; 80 81 84 private Vector wStack = new Vector (); 85 86 90 private boolean ignoreProjectTag = false; 91 92 93 private Map prefixMapping = new HashMap (); 94 95 96 97 private Map currentTargets = null; 98 99 103 public AntXMLContext(Project project) { 104 this.project = project; 105 implicitTarget.setProject(project); 106 implicitTarget.setName(""); 107 targetVector.addElement(implicitTarget); 108 } 109 110 114 public void setBuildFile(File buildFile) { 115 this.buildFile = buildFile; 116 this.buildFileParent = new File (buildFile.getParent()); 117 implicitTarget.setLocation(new Location(buildFile.getAbsolutePath())); 118 } 119 120 124 public File getBuildFile() { 125 return buildFile; 126 } 127 128 132 public File getBuildFileParent() { 133 return buildFileParent; 134 } 135 136 140 public Project getProject() { 141 return project; 142 } 143 144 148 public String getCurrentProjectName() { 149 return currentProjectName; 150 } 151 152 156 public void setCurrentProjectName(String name) { 157 this.currentProjectName = name; 158 } 159 160 165 public RuntimeConfigurable currentWrapper() { 166 if (wStack.size() < 1) { 167 return null; 168 } 169 return (RuntimeConfigurable) wStack.elementAt(wStack.size() - 1); 170 } 171 172 177 public RuntimeConfigurable parentWrapper() { 178 if (wStack.size() < 2) { 179 return null; 180 } 181 return (RuntimeConfigurable) wStack.elementAt(wStack.size() - 2); 182 } 183 184 188 public void pushWrapper(RuntimeConfigurable wrapper) { 189 wStack.addElement(wrapper); 190 } 191 192 195 public void popWrapper() { 196 if (wStack.size() > 0) { 197 wStack.removeElementAt(wStack.size() - 1); 198 } 199 } 200 201 205 public Vector getWrapperStack() { 206 return wStack; 207 } 208 209 213 public void addTarget(Target target) { 214 targetVector.addElement(target); 215 currentTarget = target; 216 } 217 218 222 public Target getCurrentTarget() { 223 return currentTarget; 224 } 225 226 230 public Target getImplicitTarget() { 231 return implicitTarget; 232 } 233 234 238 public void setCurrentTarget(Target target) { 239 this.currentTarget = target; 240 } 241 242 246 public void setImplicitTarget(Target target) { 247 this.implicitTarget = target; 248 } 249 250 254 public Vector getTargets() { 255 return targetVector; 256 } 257 258 268 public void configureId(Object element, Attributes attr) { 269 String id = attr.getValue("id"); 270 if (id != null) { 271 project.addIdReference(id, element); 272 } 273 } 274 275 279 public Locator getLocator() { 280 return locator; 281 } 282 283 287 public void setLocator(Locator locator) { 288 this.locator = locator; 289 } 290 291 295 public boolean isIgnoringProjectTag() { 296 return ignoreProjectTag; 297 } 298 299 303 public void setIgnoreProjectTag(boolean flag) { 304 this.ignoreProjectTag = flag; 305 } 306 307 313 public void startPrefixMapping(String prefix, String uri) { 314 List list = (List ) prefixMapping.get(prefix); 315 if (list == null) { 316 list = new ArrayList (); 317 prefixMapping.put(prefix, list); 318 } 319 list.add(uri); 320 } 321 322 327 public void endPrefixMapping(String prefix) { 328 List list = (List ) prefixMapping.get(prefix); 329 if (list == null || list.size() == 0) { 330 return; } 332 list.remove(list.size() - 1); 333 } 334 335 341 public String getPrefixMapping(String prefix) { 342 List list = (List ) prefixMapping.get(prefix); 343 if (list == null || list.size() == 0) { 344 return null; 345 } 346 return (String ) list.get(list.size() - 1); 347 } 348 349 353 public Map getCurrentTargets() { 354 return currentTargets; 355 } 356 357 361 public void setCurrentTargets(Map currentTargets) { 362 this.currentTargets = currentTargets; 363 } 364 365 } 366 367 368 | Popular Tags |