On Thu, Mar 17, 2011 at 4:12 AM, Antoine Levy-Lambert <anto...@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

Reply via email to