ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Levy-Lambert <anto...@gmx.de>
Subject Re: How to reference a custom type via refid?
Date Thu, 17 Mar 2011 08:12:19 GMT
On 3/16/11 2:09 PM, Carlton Brown wrote:
> In a custom type, if I want to define it and reference it later, what's the
> Java code to do that?
>
> <my:type refid="foo" name="alpha"/>
this is probably what you want to write

<my:type id="foo" name="alpha"/>

> <my:task>
>     <my:type name="omega">
>       <my:type refid="foo"/>
>     </my:type>
> </my:task>
>
> The MyType class extends org.apache.tools.ant.types.DataType and it has a
> method addConfigured(MyType).  But the above sample code creates a new
> my:type instance, it does not seem to dereference to foo.
Because MyType extends DataType it has a default setRefid(Reference r)
method.

You may want to override this default method to do some extra checks,
for instance to throw exceptions
if the build file writer uses both refid and other attributes or nested
elements.

Here is the setRefid method of AbstractFileSet in the code of ant :

    public void setRefid(Reference r) throws BuildException {
        if (dir != null || defaultPatterns.hasPatterns(getProject())) {
            throw tooManyAttributes();
        }
        if (!additionalPatterns.isEmpty()) {
            throw noChildrenAllowed();
        }
        if (!selectors.isEmpty()) {
            throw noChildrenAllowed();
        }
        super.setRefid(r);
    }

> I read the docs but I didn't recognize anything that explains this.
>
> Thanks in advance,
>
> Carlton
>
Regards,

Antoine

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


Mime
View raw message