Reputation: 14863
build.xml
<taskdef
onerror ="ignore"
name ="monitor-client"
classpath="${jar-client}"
classname="hpms.app.mon.client.AntTask" />
<target name="run-client" depends="compile-sample" description="Launch monitor">
<monitor-client
layout ="Layout.xml"
gui ="true"
autostart ="true">
<log-server
port ="3000"
capacity="2048" />
...
AntTask.java
public final class AntTask extends Task {
private ...
public void setLayout( String layout ) {
}
public void setGui( boolean gui ) {
}
public void setAutostart( boolean autostart ) {
}
public void addConfiguredLogServer( LogServer logServer ) {
}
@Override
public void execute() {
...
}
}
Execution
Buildfile: ...\build.xml
compile-sample:
run-client:
BUILD FAILED
...\build.xml:116: monitor-client doesn't support the nested "log-server" element.
Question
I search the applicable naming rules for elements and attributes and the mapping rules to Java language.
Upvotes: 5
Views: 553
Reputation: 14863
Answer based on matt comment, many thanks to him!
Apache ANT use two ways to identify element and attributes:
org.apache.tools.ant.DynamicElement
and org.apache.tools.ant.AttributeElement
Interfaces must be used to map XML identifiers to Java identifiers when special characters are used, like hyphen, as shown below:
import org.apache.tools.ant.DynamicElement;
import org.apache.tools.ant.Task;
public final class AntTask extends Task implements DynamicElement {
private ...
public void setLayout( String layout ) {
}
public void setGui( boolean gui ) {
}
@Override
public Object createDynamicElement( String name ) {
if( name.equals( "log-server" )) {
return new Logserver();
}
return null;
}
...
@Override
public void execute() {
}
}
Upvotes: 1
Reputation: 72874
org.apache.tools.ant.IntrospectionHelper
is the class that does introspection to extract attributes from setter methods.
From the Javadocs of the constructor:
void setFoo(Bar)
is recognised as a method for setting the value of attributefoo
, so long asBar
is non-void and is not an array type. Non-String parameter types always overload String parameter types, but that is the only guarantee made in terms of priority.
Upvotes: 1