01: /*
02: * Created on Sep 27, 2004
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.xdev.base.xssl.util.build;
08:
09: import java.util.HashMap;
10: import java.util.List;
11:
12: import org.jdom.Attribute;
13: import org.jdom.Content;
14: import org.jdom.Element;
15:
16: /**
17: * @author Administrator
18: *
19: * TODO To change the template for this generated type comment go to
20: * Window - Preferences - Java - Code Style - Code Templates
21: */
22: public class AntTask extends AntBuilder {
23:
24: private StringBuffer taskString = new StringBuffer();
25:
26: /**
27: * @param id
28: */
29: public AntTask(String id) {
30: super (id);
31: // TODO Auto-generated constructor stub
32: }
33:
34: /**
35: * @param id
36: * @param properties
37: */
38: public AntTask(String id, HashMap properties) {
39: super (id, properties);
40: // TODO Auto-generated constructor stub
41: }
42:
43: protected void set() throws Exception {
44: super .set();
45:
46: taskString = new StringBuffer();
47:
48: List list = this .getAttributes();
49:
50: int size = list.size();
51:
52: Attribute attr = null;
53:
54: taskString.append("<").append(this .getReferenceId());
55:
56: for (int i = 0; i < size; i++) {
57:
58: attr = (Attribute) list.get(i);
59:
60: taskString.append(" ").append(attr.getName()).append(
61: " = \"").append(this .getProperty(attr.getName()))
62: .append("\"");
63: }
64:
65: taskString.append(">");
66: }
67:
68: public void buildAnt() {
69:
70: boolean hasAntParent = false;
71:
72: Element parent = this ;
73:
74: while (parent != null
75: && !(hasAntParent = (parent instanceof AntTask))
76: && !parent.isRootElement()) {
77:
78: parent = (Element) parent.getParent();
79: }
80:
81: this .buffer.insert(0, taskString.toString());
82:
83: if (!hasAntParent) {
84: this .buffer.insert(0, "<target name=\"dummy\">");
85: }
86:
87: this .buffer.append("</").append(this .getReferenceId()).append(
88: ">");
89:
90: if (!hasAntParent) {
91: this .buffer.append("</target>");
92: }
93:
94: this .setProperty("ant-target", "dummy");
95: this .setProperty("ant-logfile", "ant-tasks.out");
96:
97: super.buildAnt();
98: }
99: }
|