ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlton Brown <cblists...@gmail.com>
Subject Re: How to reference a custom type via refid?
Date Sun, 20 Mar 2011 00:16:07 GMT
On Thu, Mar 17, 2011 at 4:12 AM, Antoine Levy-Lambert <antoine@gmx.de>wrote:

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

Thanks for your thoughts... this is the approach I ended up taking, not sure
if it's the best way, but it works:

  public void addConfigured(MyType arg) {
    if (arg.isReference()) {
      element = (MyType) arg.getRefid().getReferencedObject();
    } else {
      element = arg;
    }
// proceed to do stuff with element

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message