>> Is it possible to define attribute name with dash ?
>
>Not with Ant's built-in reflection logic. Any attribute can only
>consist of characters leagl inside a Java method name.
>
>You can define attributes with a dash when you implement
>org.apache.tools.ant.DynamicAttribute or DynamicAttributeNS in which
>case your setDynamicAttribute method will get invoked for any attribute
>that does not directly map to a setter method.
And a sample:
<project>
<javac srcdir="." destdir="." includeantruntime="true"/>
<taskdef name="my" classname="MyTask" classpath="."/>
<my normal="normal" with-dash="with-dash" unknown="unknown"
unknown2="two"/>
</project>
import org.apache.tools.ant.Task;
import org.apache.tools.ant.DynamicAttribute;
import java.util.*;
public class MyTask extends Task implements DynamicAttribute {
String normal;
String withDash;
Map<String,String> otherData = new HashMap<String,String>();
public void setNormal(String s) {
this.normal = s;
}
public void setDynamicAttribute(String name, String value) {
if (name.equals("with-dash")) {
this.withDash = value;
} else {
otherData.put(name, value);
}
}
public void execute() {
log("normal : " + normal);
log("with-dash: " + withDash);
if (!otherData.isEmpty()) {
for(String key : otherData.keySet()) {
log("- " + key + "=" + otherData.get(key));
}
}
}
}
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]