ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Resource changes
Date Mon, 17 Nov 2008 12:18:52 GMT
Hi all,

while trying to be able to write a decorator for Resource while
allowing the decorator to provide Touchable, Appendable and
FileProvider if the wrapped resource does, I took much inspiration
from Bruce and Nicolas and added the floowing method to the Resource

     * Returns a view of this resource that implements the interface
     * given as the argument or null if there is no such view.
     * <p>This allows extension interfaces to be added to resources
     * without growing the number of permutations of interfaces
     * decorators/adapters need to implement.</p>
     * <p>This implementation of the method will return the current
     * instance itself if it can be assigned to the given class.</p>
     * @since ant 1.8.0
    public Object as(Class clazz) {
        return clazz.isAssignableFrom(getClass()) ? this : null;

so if you need an Appendable resource you do

    Appendable a = (Appendable)
    if (a != null)

and don't perform any instanceof checks.  This allows decorators to
delegate the as call as well.

I've also modified any usage of Touchable and Appendable in Ant's code
base to use as instead of instanceof and at one point probably will
for FileProvider as well (want to finish the decorator first, though).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message