ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Marsili <rsilis...@yahoo.com>
Subject subclass filters with more than params
Date Fri, 14 Apr 2006 10:20:30 GMT
Hi!
I want to subclass a FilterReader, but want more than just
passing parameters to it. I want nested types and attributes.
In the build.xml I tried the following

<copy file="${src.file}" tofile="${dest.file}">
  <filterchain>
    <filterreader classname="net.thedomain.antx.MyFilter"
        additionalattr="somevalue">
      <nested-type/>
    </filterreader>
  </filterchain>
</copy>

but it's not allowed.

So I ended up subclassing Copy and FilterChain ...  


package net.thedomain.antx;

import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FilterChain;

public class CoCopy extends Copy {

  public CoCopy() {
    super();
  }

  public class CoFilterChain extends FilterChain {

    public void addMyFilter(MyFilter myFilter) {
      getFilterReaders().addElement(myFilter);
    }
  }

  /**
   * Adds a CoFilterChain.
   * @return a filter chain object
   */
  public FilterChain createCoFilterChain() {
    CoFilterChain filterChain = new CoFilterChain();
    getFilterChains().addElement(filterChain);
    return filterChain;
  }
}

... which seems to work fine when used like this ...

<taskdef name="cocopy"
    classname="net.thedomain.antx.CoCopy">
<cocopy file="${src.file}"
    tofile="${dest.file}">
  <cofilterchain>
    <myfilter additionalattr="somevalue">
      <nested-type/>
    </myfilter>
    <headfilter lines="32"/>
  </cofilterchain>
</cocopy>

... but I don't like it very much.

So, my questions are:
-Is there a way to do this without having to subclass
<copy> and <filterchain>?
-If not, isn't it possible to extend introspection
to allow addInstanceOf of nested elements 
representing subclasses of some class?
Something like

class FilterChain
  void addInstanceOfFilterReader(FilterReader rdr)

<copy file="${test.source}"
    tofile="${test.dest}">
  <filterchain>
    <defineclass name="myfilter"
                 classname="net.thedomain.antx.MyFilter">
    <myfilter additionalattr="somevalue">
      <nested-type/>
    </myfilter>
    <headfilter lines="32"/>
  </filterchain>
</copy>

I know, I don't really know what I'm talking about.
But I'm curios ;-).

BTW. The ant tool and source code are beautiful!

Thanks
Stefano Marsili


		
---------------------------------
Love cheap thrills? Enjoy PC-to-Phone  calls to 30+ countries for just 2ยข/min with Yahoo!
Messenger with Voice.
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message