You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Benjamin de Dardel <be...@gmail.com> on 2010/09/06 14:00:03 UTC

attribute name with dash

Hi all,

I would like to define an attribute with a dash : 'not-null'.

    /# build.xml
    <column name="..." type="..." not-null="true"/>

    # Column.java
    public void setNotNull(String value) {
         // ...
    }/

I get the message :

    /column doesn't support the "not-null" attribute/

Is it possible to define attribute name with dash ?

Regards,
Benjamin de Dardel

Re: attribute name with dash

Posted by Benjamin de Dardel <be...@gmail.com>.
Wonderful, thank you for your responses.
They resolve my current problem
... and also an old one for ant4hg project, where the main task class
contains many many attributes !

2010/9/7 <Ja...@rzf.fin-nrw.de>

> >> 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: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

AW: attribute name with dash

Posted by Ja...@rzf.fin-nrw.de.
>> 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: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: attribute name with dash

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-09-06, Benjamin de Dardel wrote:

> 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.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org